add Networkmanager class

This commit is contained in:
Jehan Monnier 2010-03-03 18:12:26 +01:00
parent 1dd0a7285d
commit ec30570366
7 changed files with 114 additions and 33 deletions

View file

@ -6,7 +6,8 @@
<application android:icon="@drawable/linphone2" android:label="@string/app_name" android:debuggable = "true"> <application android:icon="@drawable/linphone2" android:label="@string/app_name" android:debuggable = "true">
<activity android:name=".LinphoneActivity" <activity android:name=".LinphoneActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"> android:theme="@android:style/Theme.NoTitleBar"
android:launchMode="singleTask">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
@ -21,6 +22,11 @@
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
</intent-filter> </intent-filter>
<intent-filter>
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
</activity> </activity>
<activity android:name=".ContactPickerActivity"> <activity android:name=".ContactPickerActivity">
<intent-filter> <intent-filter>
@ -34,7 +40,10 @@
</activity> </activity>
<service android:name=".LinphoneService"> <service android:name=".LinphoneService">
</service> </service>
</application> <receiver android:name="NetworkManager"><intent-filter><action android:name="android.net.conn.CONNECTIVITY_CHANGE"></action>
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission> <uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission> <uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>

View file

@ -29,6 +29,7 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.media.AudioManager; import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
@ -200,14 +201,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
} }
public void generalState(LinphoneCore lc, GeneralState state) { public void generalState(LinphoneCore lc, GeneralState state) {
switch(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: { case GSTATE_REG_OK: {
break; break;
} }
@ -218,23 +212,35 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
case GSTATE_CALL_IN_INVITE: { case GSTATE_CALL_IN_INVITE: {
// activate red button // activate red button
mHangup.setEnabled(true); mHangup.setEnabled(true);
mAudioManager.setSpeakerphoneOn(true); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT) {
mAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setRouting(AudioManager.MODE_NORMAL, mAudioManager.setRouting(AudioManager.MODE_NORMAL,
AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL); AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
} else {
mAudioManager.setSpeakerphoneOn(true);
}
break; break;
} }
case GSTATE_CALL_IN_CONNECTED: case GSTATE_CALL_IN_CONNECTED:
case GSTATE_CALL_OUT_CONNECTED: { case GSTATE_CALL_OUT_CONNECTED: {
mAudioManager.setSpeakerphoneOn(false); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT) {
mAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAudioManager.setRouting(AudioManager.MODE_NORMAL, mAudioManager.setRouting(AudioManager.MODE_NORMAL,
AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL); AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL);
} else {
mAudioManager.setSpeakerphoneOn(false);
}
break; 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: { case GSTATE_CALL_END: {
mCall.setEnabled(true); exitCallMode();
mHangup.setEnabled(false);
break; break;
} }
} }
@ -248,4 +254,9 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
} }
private void exitCallMode() {
mCall.setEnabled(true);
mHangup.setEnabled(false);
}
} }

View file

@ -25,6 +25,7 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.media.AudioManager; import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
@ -95,11 +96,13 @@ public class LinphoneActivity extends TabActivity {
super.onDestroy(); super.onDestroy();
if (isFinishing()) { if (isFinishing()) {
//restaure audio settings //restaure audio settings
mAudioManager.setSpeakerphoneOn(true); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT) {
mAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setRouting(AudioManager.MODE_NORMAL, mAudioManager.setRouting(AudioManager.MODE_NORMAL,
AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL); AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
} else {
mAudioManager.setSpeakerphoneOn(false);
}
Intent intent = new Intent(Intent.ACTION_MAIN); Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(this, LinphoneService.class); intent.setClass(this, LinphoneService.class);
stopService(intent); stopService(intent);

View file

@ -35,25 +35,16 @@ import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.LinphoneCore.GeneralState; import org.linphone.core.LinphoneCore.GeneralState;
import android.app.AlertDialog;
import android.app.Service; import android.app.Service;
import android.app.TabActivity;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.media.AudioManager; import android.net.ConnectivityManager;
import android.os.Bundle; import android.net.NetworkInfo;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.Message;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; 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 { public class LinphoneService extends Service implements LinphoneCoreListener {
static final public String TAG="Linphone"; static final public String TAG="Linphone";
@ -249,6 +240,10 @@ public class LinphoneService extends Service implements LinphoneCoreListener {
//escape + //escape +
lDefaultProxyConfig.setDialEscapePlus(true); lDefaultProxyConfig.setDialEscapePlus(true);
} }
//init netwaork state
ConnectivityManager lConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
mLinphoneCore.setNetworkStateReachable(lConnectivityManager.getActiveNetworkInfo().getState() ==NetworkInfo.State.CONNECTED);
}catch (LinphoneCoreException e) { }catch (LinphoneCoreException e) {
throw new LinphoneException(e); throw new LinphoneException(e);
} }

View file

@ -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
}
}
}

View file

@ -123,6 +123,15 @@ public interface LinphoneCore {
*/ */
public List<LinphoneCallLog> getCallLogs(); public List<LinphoneCallLog> 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 * destroy linphone core and free all underlying resources
*/ */

View file

@ -51,6 +51,7 @@ class LinphoneCoreImpl implements LinphoneCore {
private native long getCallLog(long nativePtr,int position); private native long getCallLog(long nativePtr,int position);
private native int getNumberOfCallLogs(long nativePtr); private native int getNumberOfCallLogs(long nativePtr);
private native void delete(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 { 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"); throw new RuntimeException("object already destroyed");
} }
} }
public void setNetworkStateReachable(boolean isReachable) {
setNetworkStateReachable(nativePtr,isReachable);
}
} }