diff --git a/AndroidManifest.xml b/AndroidManifest.xml index b8c492420..464b6a2f7 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -6,7 +6,8 @@ + android:theme="@android:style/Theme.NoTitleBar" + android:launchMode="singleTask"> @@ -21,6 +22,11 @@ + + + + + @@ -34,7 +40,10 @@ - + + + + diff --git a/src/org/linphone/DialerActivity.java b/src/org/linphone/DialerActivity.java index 26371a4a6..680e864e6 100644 --- a/src/org/linphone/DialerActivity.java +++ b/src/org/linphone/DialerActivity.java @@ -29,6 +29,7 @@ import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.media.AudioManager; +import android.os.Build; import android.os.Bundle; import android.util.Log; import android.view.View; @@ -200,14 +201,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener { } public void generalState(LinphoneCore lc, GeneralState state) { switch(state) { - case GSTATE_CALL_ERROR: { - Toast toast = Toast.makeText(this - ,String.format(getString(R.string.call_error),lc.getRemoteAddress()) - , Toast.LENGTH_LONG); - toast.show(); - break; - } case GSTATE_REG_OK: { break; } @@ -218,23 +212,35 @@ public class DialerActivity extends Activity implements LinphoneCoreListener { case GSTATE_CALL_IN_INVITE: { // activate red button mHangup.setEnabled(true); - mAudioManager.setSpeakerphoneOn(true); - mAudioManager.setMode(AudioManager.MODE_NORMAL); - mAudioManager.setRouting(AudioManager.MODE_NORMAL, - AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL); + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT) { + mAudioManager.setMode(AudioManager.MODE_NORMAL); + mAudioManager.setRouting(AudioManager.MODE_NORMAL, + AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL); + } else { + mAudioManager.setSpeakerphoneOn(true); + } break; } case GSTATE_CALL_IN_CONNECTED: case GSTATE_CALL_OUT_CONNECTED: { - mAudioManager.setSpeakerphoneOn(false); - mAudioManager.setMode(AudioManager.MODE_IN_CALL); - mAudioManager.setRouting(AudioManager.MODE_NORMAL, - AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL); + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT) { + mAudioManager.setMode(AudioManager.MODE_IN_CALL); + mAudioManager.setRouting(AudioManager.MODE_NORMAL, + AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL); + } else { + mAudioManager.setSpeakerphoneOn(false); + } break; } + case GSTATE_CALL_ERROR: { + + Toast toast = Toast.makeText(this + ,String.format(getString(R.string.call_error),lc.getRemoteAddress()) + , Toast.LENGTH_LONG); + toast.show(); + } case GSTATE_CALL_END: { - mCall.setEnabled(true); - mHangup.setEnabled(false); + exitCallMode(); break; } } @@ -248,4 +254,9 @@ public class DialerActivity extends Activity implements LinphoneCoreListener { } + private void exitCallMode() { + mCall.setEnabled(true); + mHangup.setEnabled(false); + } + } diff --git a/src/org/linphone/LinphoneActivity.java b/src/org/linphone/LinphoneActivity.java index f5c49ca6b..5c78b37b3 100644 --- a/src/org/linphone/LinphoneActivity.java +++ b/src/org/linphone/LinphoneActivity.java @@ -25,6 +25,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.media.AudioManager; +import android.os.Build; import android.os.Bundle; import android.util.Log; import android.view.Menu; @@ -95,11 +96,13 @@ public class LinphoneActivity extends TabActivity { super.onDestroy(); if (isFinishing()) { //restaure audio settings - mAudioManager.setSpeakerphoneOn(true); + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT) { mAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL); - + } else { + mAudioManager.setSpeakerphoneOn(false); + } Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClass(this, LinphoneService.class); stopService(intent); diff --git a/src/org/linphone/LinphoneService.java b/src/org/linphone/LinphoneService.java index 2af991af5..c61e55f93 100644 --- a/src/org/linphone/LinphoneService.java +++ b/src/org/linphone/LinphoneService.java @@ -35,25 +35,16 @@ import org.linphone.core.LinphoneProxyConfig; import org.linphone.core.LinphoneCore.GeneralState; -import android.app.AlertDialog; import android.app.Service; -import android.app.TabActivity; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; -import android.media.AudioManager; -import android.os.Bundle; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; import android.os.Handler; import android.os.IBinder; -import android.os.Message; import android.preference.PreferenceManager; import android.util.Log; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.widget.TabHost; -import android.widget.Toast; public class LinphoneService extends Service implements LinphoneCoreListener { static final public String TAG="Linphone"; @@ -91,7 +82,7 @@ public class LinphoneService extends Service implements LinphoneCoreListener { , new File(LINPHONE_RC) , new File(LINPHONE_FACTORY_RC) , null); - + initFromConf(); TimerTask lTask = new TimerTask() { @@ -249,6 +240,10 @@ public class LinphoneService extends Service implements LinphoneCoreListener { //escape + lDefaultProxyConfig.setDialEscapePlus(true); } + //init netwaork state + ConnectivityManager lConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); + mLinphoneCore.setNetworkStateReachable(lConnectivityManager.getActiveNetworkInfo().getState() ==NetworkInfo.State.CONNECTED); + }catch (LinphoneCoreException e) { throw new LinphoneException(e); } diff --git a/src/org/linphone/NetworkManager.java b/src/org/linphone/NetworkManager.java new file mode 100644 index 000000000..1f07bad54 --- /dev/null +++ b/src/org/linphone/NetworkManager.java @@ -0,0 +1,50 @@ +/* +ContactPickerActivity.java +Copyright (C) 2010 Belledonne Communications, Grenoble, France + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +package org.linphone; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.util.Log; + + + +public class NetworkManager extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + + NetworkInfo lNetworkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); + Log.i(LinphoneService.TAG, "Network info ["+lNetworkInfo+"]"); + Boolean lNoConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,false); + //Boolean lIsFailOver = intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER,false); + if (lNoConnectivity| ((lNetworkInfo.getState() == NetworkInfo.State.DISCONNECTED) /*&& !lIsFailOver*/)) { + LinphoneService.instance().getLinphoneCore().setNetworkStateReachable(false); + } else if (lNetworkInfo.getState() == NetworkInfo.State.CONNECTED){ + LinphoneService.instance().getLinphoneCore().setNetworkStateReachable(true); + } else { + //unhandle event + } + + + } + +} diff --git a/src/org/linphone/core/LinphoneCore.java b/src/org/linphone/core/LinphoneCore.java index c886c4038..1f8e73449 100644 --- a/src/org/linphone/core/LinphoneCore.java +++ b/src/org/linphone/core/LinphoneCore.java @@ -123,6 +123,15 @@ public interface LinphoneCore { */ public List getCallLogs(); + /** + * This method is called by the application to notify the Linphone core library when network is reachable. + * Calling this method with true trigger Linphone to initiate a registration process for all proxy + * configuration with parameter register set to enable. + * This method disable the automatic registration mode. It means you must call this method after each network state changes + * @param network state + * + */ + public void setNetworkStateReachable(boolean isReachable); /** * destroy linphone core and free all underlying resources */ diff --git a/src/org/linphone/core/LinphoneCoreImpl.java b/src/org/linphone/core/LinphoneCoreImpl.java index ba6f5a384..b1dedfeb4 100644 --- a/src/org/linphone/core/LinphoneCoreImpl.java +++ b/src/org/linphone/core/LinphoneCoreImpl.java @@ -51,6 +51,7 @@ class LinphoneCoreImpl implements LinphoneCore { private native long getCallLog(long nativePtr,int position); private native int getNumberOfCallLogs(long nativePtr); private native void delete(long nativePtr); + private native void setNetworkStateReachable(long nativePtr,boolean isReachable); LinphoneCoreImpl(LinphoneCoreListener listener, File userConfig,File factoryConfig,Object userdata) throws IOException { @@ -155,4 +156,7 @@ class LinphoneCoreImpl implements LinphoneCore { throw new RuntimeException("object already destroyed"); } } + public void setNetworkStateReachable(boolean isReachable) { + setNetworkStateReachable(nativePtr,isReachable); + } }