diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
index 60304b22f..d9623bcfd 100644
--- a/res/xml/preferences.xml
+++ b/res/xml/preferences.xml
@@ -74,7 +74,7 @@
android:dependency="@string/pref_video_enable_key">
@@ -82,7 +82,7 @@
+ android:defaultValue="false">
diff --git a/src/org/linphone/DialerActivity.java b/src/org/linphone/DialerActivity.java
index 2199f3206..15750f9b8 100644
--- a/src/org/linphone/DialerActivity.java
+++ b/src/org/linphone/DialerActivity.java
@@ -108,7 +108,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
Settings.System mSystemSettings = new Settings.System();
MediaPlayer mRingerPlayer;
- LinphoneCall.State mCurrentCallState;
+
Vibrator mVibrator;
/**
@@ -236,7 +236,6 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
if (LinphoneService.isready()) {
LinphoneCore lLinphoneCore = LinphoneService.instance().getLinphoneCore();
if (lLinphoneCore.isIncall()) {
- mCurrentCallState = lLinphoneCore.getCurrentCall().getState();
if(lLinphoneCore.isInComingInvitePending()) {
callPending(lLinphoneCore.getCurrentCall());
} else {
@@ -448,11 +447,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 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) {
mWakeLock.acquire();
enterIncalMode(lc);
@@ -478,7 +473,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
}
}
}
- mCurrentCallState = state;
+
}
public void show(LinphoneCore lc) {
@@ -576,7 +571,6 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
boolean prefAutomaticallyShareMyCamera = mPref.getBoolean(getString(R.string.pref_video_automatically_share_my_video_key), false);
getVideoManager().setMuted(!(prefVideoEnable && prefAutomaticallyShareMyCamera));
call.enableCamera(prefAutomaticallyShareMyCamera);
- startRinging();
}
public void newOutgoingCall(String aTo) {
newOutgoingCall(aTo,null);
@@ -685,39 +679,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
// 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() {
return AndroidCameraRecordManager.getInstance();
diff --git a/src/org/linphone/LinphoneActivity.java b/src/org/linphone/LinphoneActivity.java
index 39524fcaf..66f2cd204 100644
--- a/src/org/linphone/LinphoneActivity.java
+++ b/src/org/linphone/LinphoneActivity.java
@@ -145,7 +145,7 @@ public class LinphoneActivity extends TabActivity {
} else {
mAudioManager.setSpeakerphoneOn(false);
}
-
+ stopProxymitySensor();//just in case
theLinphoneActivity = null;
}
@@ -249,9 +249,9 @@ public class LinphoneActivity extends TabActivity {
//Log.d(LinphoneService.TAG, "Proximity sensor report ["+event.values[0]+"] , for max range ["+event.sensor.getMaximumRange()+"]");
if (event.values[0] != event.sensor.getMaximumRange() ) {
- LinphoneActivity.instance().hideScreen(true);
+ hideScreen(true);
} else {
- LinphoneActivity.instance().hideScreen(false);
+ hideScreen(false);
}
}
diff --git a/src/org/linphone/LinphoneService.java b/src/org/linphone/LinphoneService.java
index fbeccf64b..73075df4e 100644
--- a/src/org/linphone/LinphoneService.java
+++ b/src/org/linphone/LinphoneService.java
@@ -47,10 +47,15 @@ import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.media.AudioManager;
+import android.media.MediaPlayer;
+import android.media.RingtoneManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Handler;
import android.os.IBinder;
+import android.os.PowerManager;
+import android.os.Vibrator;
import android.preference.PreferenceManager;
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_RED=2;
+ MediaPlayer mRingerPlayer;
+ LinphoneCall.State mCurrentCallState;
+ Vibrator mVibrator;
+ private AudioManager mAudioManager;
private Handler mHandler = new Handler() ;
static boolean isready() {
@@ -107,6 +116,8 @@ public class LinphoneService extends Service implements LinphoneCoreListener {
mNotification.setLatestEventInfo(this, NOTIFICATION_TITLE,"", mNofificationContentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+ mAudioManager = ((AudioManager)getSystemService(Context.AUDIO_SERVICE));
+ mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
try {
copyAssetsFromPackage();
@@ -246,6 +257,11 @@ public class LinphoneService extends Service implements LinphoneCoreListener {
}
public void callState(final LinphoneCore lc,final LinphoneCall call, final State state, final String message) {
Log.i(TAG, "new state ["+state+"]");
+ if (state == LinphoneCall.State.IncomingReceived && !call.equals(mLinphoneCore.getCurrentCall())) {
+ //no multicall support, just decline
+ mLinphoneCore.terminateCall(call);
+ return;
+ }
mHandler.post(new Runnable() {
public void run() {
if (DialerActivity.getDialer()!=null) DialerActivity.getDialer().callState(lc,call,state,message);
@@ -257,7 +273,14 @@ public class LinphoneService extends Service implements LinphoneCoreListener {
lIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
lIntent.setClass(this, LinphoneActivity.class);
startActivity(lIntent);
+ startRinging();
}
+ if (mCurrentCallState == LinphoneCall.State.IncomingReceived) {
+ //previous state was ringing, so stop ringing
+ stopRinging();
+ //routeAudioToReceiver();
+ }
+ mCurrentCallState=state;
}
public void show(LinphoneCore lc) {
// TODO Auto-generated method stub
@@ -439,5 +462,36 @@ public class LinphoneService extends Service implements LinphoneCoreListener {
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();
+ }
+ }
}
diff --git a/src/org/linphone/core/LinphoneCallImpl.java b/src/org/linphone/core/LinphoneCallImpl.java
index 74c701a72..e2aad29a1 100644
--- a/src/org/linphone/core/LinphoneCallImpl.java
+++ b/src/org/linphone/core/LinphoneCallImpl.java
@@ -31,6 +31,7 @@ class LinphoneCallImpl implements LinphoneCall {
native private int getState(long nativePtr);
private native long getCurrentParamsCopy(long nativePtr);
private native void enableCamera(long nativePtr, boolean enabled);
+
protected LinphoneCallImpl(long aNativePtr) {
nativePtr = aNativePtr;
@@ -68,4 +69,7 @@ class LinphoneCallImpl implements LinphoneCall {
public void enableCamera(boolean enabled) {
enableCamera(nativePtr, enabled);
}
+ public boolean equals(Object call) {
+ return nativePtr == ((LinphoneCallImpl)call).nativePtr;
+ }
}