fix multiple ring issue
This commit is contained in:
parent
6af2b1ad73
commit
7a3e82bca9
2 changed files with 56 additions and 41 deletions
|
@ -114,7 +114,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
||||||
|
|
||||||
Settings.System mSystemSettings = new Settings.System();
|
Settings.System mSystemSettings = new Settings.System();
|
||||||
MediaPlayer mRingerPlayer;
|
MediaPlayer mRingerPlayer;
|
||||||
LinphoneCall.State mCurrentCallState;
|
|
||||||
Vibrator mVibrator;
|
Vibrator mVibrator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -237,7 +237,6 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
||||||
if (LinphoneService.isready()) {
|
if (LinphoneService.isready()) {
|
||||||
LinphoneCore lLinphoneCore = LinphoneService.instance().getLinphoneCore();
|
LinphoneCore lLinphoneCore = LinphoneService.instance().getLinphoneCore();
|
||||||
if (lLinphoneCore.isIncall()) {
|
if (lLinphoneCore.isIncall()) {
|
||||||
mCurrentCallState = lLinphoneCore.getCurrentCall().getState();
|
|
||||||
if(lLinphoneCore.isInComingInvitePending()) {
|
if(lLinphoneCore.isInComingInvitePending()) {
|
||||||
callPending(lLinphoneCore.getCurrentCall());
|
callPending(lLinphoneCore.getCurrentCall());
|
||||||
} else {
|
} else {
|
||||||
|
@ -449,11 +448,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
||||||
|
|
||||||
public void registrationState(final LinphoneCore lc, final LinphoneProxyConfig cfg,final LinphoneCore.RegistrationState state,final String smessage) {/*nop*/};
|
public void registrationState(final LinphoneCore lc, final LinphoneProxyConfig cfg,final LinphoneCore.RegistrationState state,final String smessage) {/*nop*/};
|
||||||
public void callState(final LinphoneCore lc,final LinphoneCall call, final State state, final String message) {
|
public void callState(final LinphoneCore lc,final LinphoneCall call, final State state, final String message) {
|
||||||
if (mCurrentCallState == LinphoneCall.State.IncomingReceived) {
|
|
||||||
//previous state was ringing, so stop ringing
|
|
||||||
stoptRinging();
|
|
||||||
//routeAudioToReceiver();
|
|
||||||
}
|
|
||||||
if (state == LinphoneCall.State.OutgoingInit) {
|
if (state == LinphoneCall.State.OutgoingInit) {
|
||||||
mWakeLock.acquire();
|
mWakeLock.acquire();
|
||||||
enterIncalMode(lc);
|
enterIncalMode(lc);
|
||||||
|
@ -479,7 +474,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mCurrentCallState = state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show(LinphoneCore lc) {
|
public void show(LinphoneCore lc) {
|
||||||
|
@ -578,7 +573,6 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
||||||
boolean prefAutomaticallyShareMyCamera = mPref.getBoolean(getString(R.string.pref_video_automatically_share_my_video_key), false);
|
boolean prefAutomaticallyShareMyCamera = mPref.getBoolean(getString(R.string.pref_video_automatically_share_my_video_key), false);
|
||||||
getVideoManager().setMuted(!(prefVideoEnable && prefAutomaticallyShareMyCamera));
|
getVideoManager().setMuted(!(prefVideoEnable && prefAutomaticallyShareMyCamera));
|
||||||
call.enableCamera(prefAutomaticallyShareMyCamera);
|
call.enableCamera(prefAutomaticallyShareMyCamera);
|
||||||
startRinging();
|
|
||||||
}
|
}
|
||||||
public void newOutgoingCall(String aTo) {
|
public void newOutgoingCall(String aTo) {
|
||||||
newOutgoingCall(aTo,null);
|
newOutgoingCall(aTo,null);
|
||||||
|
@ -687,39 +681,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
private synchronized void startRinging() {
|
|
||||||
try {
|
|
||||||
if (mAudioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER) && mVibrator !=null) {
|
|
||||||
long[] patern = {0,1000,1000};
|
|
||||||
mVibrator.vibrate(patern, 1);
|
|
||||||
}
|
|
||||||
if (mRingerPlayer == null) {
|
|
||||||
//mRingerPlayer = MediaPlayer.create(getApplicationContext(), RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE));
|
|
||||||
mRingerPlayer = new MediaPlayer();
|
|
||||||
mRingerPlayer.setAudioStreamType(AudioManager.STREAM_RING);
|
|
||||||
mRingerPlayer.setDataSource(getApplicationContext(), RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE));
|
|
||||||
mRingerPlayer.prepare();
|
|
||||||
//mRingerPlayer.setVolume(mAudioManager.getStreamVolume(AudioManager.STREAM_RING),mAudioManager.getStreamVolume(AudioManager.STREAM_RING));
|
|
||||||
mRingerPlayer.setLooping(true);
|
|
||||||
mRingerPlayer.start();
|
|
||||||
} else {
|
|
||||||
Log.w(LinphoneService.TAG,"already ringing");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(LinphoneService.TAG, "cannot handle incoming call",e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
private synchronized void stoptRinging() {
|
|
||||||
if (mRingerPlayer !=null) {
|
|
||||||
mRingerPlayer.stop();
|
|
||||||
mRingerPlayer.release();
|
|
||||||
mRingerPlayer=null;
|
|
||||||
}
|
|
||||||
if (mVibrator!=null) {
|
|
||||||
mVibrator.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private AndroidCameraRecordManager getVideoManager() {
|
private AndroidCameraRecordManager getVideoManager() {
|
||||||
return AndroidCameraRecordManager.getInstance();
|
return AndroidCameraRecordManager.getInstance();
|
||||||
|
|
|
@ -47,10 +47,15 @@ import android.app.Service;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.media.AudioManager;
|
||||||
|
import android.media.MediaPlayer;
|
||||||
|
import android.media.RingtoneManager;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.os.PowerManager;
|
||||||
|
import android.os.Vibrator;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
@ -78,6 +83,10 @@ public class LinphoneService extends Service implements LinphoneCoreListener {
|
||||||
final int IC_LEVEL_GREEN=1;
|
final int IC_LEVEL_GREEN=1;
|
||||||
final int IC_LEVEL_RED=2;
|
final int IC_LEVEL_RED=2;
|
||||||
|
|
||||||
|
MediaPlayer mRingerPlayer;
|
||||||
|
LinphoneCall.State mCurrentCallState;
|
||||||
|
Vibrator mVibrator;
|
||||||
|
private AudioManager mAudioManager;
|
||||||
|
|
||||||
private Handler mHandler = new Handler() ;
|
private Handler mHandler = new Handler() ;
|
||||||
static boolean isready() {
|
static boolean isready() {
|
||||||
|
@ -107,6 +116,8 @@ public class LinphoneService extends Service implements LinphoneCoreListener {
|
||||||
mNotification.setLatestEventInfo(this, NOTIFICATION_TITLE,"", mNofificationContentIntent);
|
mNotification.setLatestEventInfo(this, NOTIFICATION_TITLE,"", mNofificationContentIntent);
|
||||||
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
|
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
|
||||||
mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||||
|
mAudioManager = ((AudioManager)getSystemService(Context.AUDIO_SERVICE));
|
||||||
|
mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
try {
|
try {
|
||||||
copyAssetsFromPackage();
|
copyAssetsFromPackage();
|
||||||
|
|
||||||
|
@ -246,6 +257,10 @@ public class LinphoneService extends Service implements LinphoneCoreListener {
|
||||||
}
|
}
|
||||||
public void callState(final LinphoneCore lc,final LinphoneCall call, final State state, final String message) {
|
public void callState(final LinphoneCore lc,final LinphoneCall call, final State state, final String message) {
|
||||||
Log.i(TAG, "new state ["+state+"]");
|
Log.i(TAG, "new state ["+state+"]");
|
||||||
|
if (state == LinphoneCall.State.IncomingReceived &&mLinphoneCore.isIncall()) {
|
||||||
|
//no multicall support, just decline
|
||||||
|
//mLinphoneCore.terminateCall(call);
|
||||||
|
}
|
||||||
mHandler.post(new Runnable() {
|
mHandler.post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (DialerActivity.getDialer()!=null) DialerActivity.getDialer().callState(lc,call,state,message);
|
if (DialerActivity.getDialer()!=null) DialerActivity.getDialer().callState(lc,call,state,message);
|
||||||
|
@ -257,7 +272,14 @@ public class LinphoneService extends Service implements LinphoneCoreListener {
|
||||||
lIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
lIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
lIntent.setClass(this, LinphoneActivity.class);
|
lIntent.setClass(this, LinphoneActivity.class);
|
||||||
startActivity(lIntent);
|
startActivity(lIntent);
|
||||||
|
startRinging();
|
||||||
}
|
}
|
||||||
|
if (mCurrentCallState == LinphoneCall.State.IncomingReceived) {
|
||||||
|
//previous state was ringing, so stop ringing
|
||||||
|
stopRinging();
|
||||||
|
//routeAudioToReceiver();
|
||||||
|
}
|
||||||
|
mCurrentCallState=state;
|
||||||
}
|
}
|
||||||
public void show(LinphoneCore lc) {
|
public void show(LinphoneCore lc) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
@ -439,5 +461,36 @@ public class LinphoneService extends Service implements LinphoneCoreListener {
|
||||||
return instance().getLinphoneCore();
|
return instance().getLinphoneCore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private synchronized void startRinging() {
|
||||||
|
try {
|
||||||
|
if (mAudioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER) && mVibrator !=null) {
|
||||||
|
long[] patern = {0,1000,1000};
|
||||||
|
mVibrator.vibrate(patern, 1);
|
||||||
|
}
|
||||||
|
if (mRingerPlayer == null) {
|
||||||
|
mRingerPlayer = new MediaPlayer();
|
||||||
|
mRingerPlayer.setAudioStreamType(AudioManager.STREAM_RING);
|
||||||
|
mRingerPlayer.setDataSource(getApplicationContext(), RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE));
|
||||||
|
mRingerPlayer.prepare();
|
||||||
|
mRingerPlayer.setLooping(true);
|
||||||
|
mRingerPlayer.start();
|
||||||
|
} else {
|
||||||
|
Log.w(LinphoneService.TAG,"already ringing");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(LinphoneService.TAG, "cannot handle incoming call",e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
private synchronized void stopRinging() {
|
||||||
|
if (mRingerPlayer !=null) {
|
||||||
|
mRingerPlayer.stop();
|
||||||
|
mRingerPlayer.release();
|
||||||
|
mRingerPlayer=null;
|
||||||
|
}
|
||||||
|
if (mVibrator!=null) {
|
||||||
|
mVibrator.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue