Merge branch 'feature/android_connectivity_manager'
This commit is contained in:
commit
2a685cbf83
6 changed files with 11 additions and 231 deletions
|
@ -224,12 +224,7 @@
|
|||
android:name="android.accounts.AccountAuthenticator"
|
||||
android:resource="@xml/authenticator"/>
|
||||
</service>
|
||||
|
||||
<receiver android:name=".receivers.NetworkManager">
|
||||
<intent-filter>
|
||||
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver
|
||||
android:name=".receivers.BluetoothManager"
|
||||
android:enabled="false">
|
||||
|
|
|
@ -12,7 +12,7 @@ force_ice_disablement=0
|
|||
[sip]
|
||||
guess_hostname=1
|
||||
register_only_when_network_is_up=1
|
||||
auto_net_state_mon=0
|
||||
auto_net_state_mon=1
|
||||
auto_answer_replacing_calls=1
|
||||
ping_with_options=0
|
||||
rls_uri=
|
||||
|
|
|
@ -106,10 +106,8 @@ import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
|
|||
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration.AndroidCamera;
|
||||
import org.linphone.mediastream.video.capture.hwconf.Hacks;
|
||||
import org.linphone.receivers.BluetoothManager;
|
||||
import org.linphone.receivers.DozeReceiver;
|
||||
import org.linphone.receivers.HookReceiver;
|
||||
import org.linphone.receivers.KeepAliveReceiver;
|
||||
import org.linphone.receivers.NetworkManager;
|
||||
import org.linphone.receivers.OutgoingCallReceiver;
|
||||
import org.linphone.ui.LinphoneMediaScanner;
|
||||
|
||||
|
@ -155,17 +153,14 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
|||
private static boolean sExited;
|
||||
private boolean mAudioFocused;
|
||||
private boolean echoTesterIsRunning;
|
||||
private boolean dozeModeEnabled;
|
||||
private boolean callGsmON;
|
||||
private int mLastNetworkType = -1;
|
||||
private ConnectivityManager mConnectivityManager;
|
||||
private BroadcastReceiver mKeepAliveReceiver;
|
||||
private BroadcastReceiver mDozeReceiver;
|
||||
private BroadcastReceiver mHookReceiver;
|
||||
private BroadcastReceiver mCallReceiver;
|
||||
private BroadcastReceiver mNetworkReceiver;
|
||||
private IntentFilter mKeepAliveIntentFilter;
|
||||
private IntentFilter mDozeIntentFilter;
|
||||
private IntentFilter mHookIntentFilter;
|
||||
private IntentFilter mCallIntentFilter;
|
||||
private IntentFilter mNetworkIntentFilter;
|
||||
|
@ -611,13 +606,6 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
|||
} catch (Exception e) {
|
||||
Log.e(e);
|
||||
}
|
||||
try {
|
||||
dozeManager(false);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
Log.e(iae);
|
||||
} catch (Exception e) {
|
||||
Log.e(e);
|
||||
}
|
||||
mLc = null;
|
||||
}
|
||||
}
|
||||
|
@ -764,29 +752,11 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
|||
}
|
||||
mProximityWakelock = mPowerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "manager_proximity_sensor");
|
||||
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
mDozeIntentFilter = new IntentFilter();
|
||||
mDozeIntentFilter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
|
||||
mDozeReceiver = new DozeReceiver();
|
||||
dozeModeEnabled = ((PowerManager) mServiceContext.getSystemService(Context.POWER_SERVICE)).isDeviceIdleMode();
|
||||
mServiceContext.registerReceiver(mDozeReceiver, mDozeIntentFilter);
|
||||
}
|
||||
|
||||
mHookIntentFilter = new IntentFilter("com.base.module.phone.HOOKEVENT");
|
||||
mHookIntentFilter.setPriority(999);
|
||||
mHookReceiver = new HookReceiver();
|
||||
mServiceContext.registerReceiver(mHookReceiver, mHookIntentFilter);
|
||||
|
||||
// Since Android N we need to register the network manager
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
|
||||
mNetworkReceiver = new NetworkManager();
|
||||
mNetworkIntentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
mServiceContext.registerReceiver(mNetworkReceiver, mNetworkIntentFilter);
|
||||
}
|
||||
|
||||
updateNetworkReachability();
|
||||
|
||||
resetCameraFromPreferences();
|
||||
|
||||
accountCreator = LinphoneManager.getLc().createAccountCreator(LinphonePreferences.instance().getXmlrpcUrl());
|
||||
|
@ -852,63 +822,6 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
|||
// getLc().getConfig().setInt("misc","transient_provisioning",1);
|
||||
//}
|
||||
|
||||
public void updateNetworkReachability() {
|
||||
if (mConnectivityManager == null) return;
|
||||
|
||||
boolean connected = false;
|
||||
NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo();
|
||||
connected = networkInfo != null && networkInfo.isConnected();
|
||||
|
||||
if (networkInfo == null && Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {
|
||||
for (Network network : mConnectivityManager.getAllNetworks()) {
|
||||
if (network != null) {
|
||||
networkInfo = mConnectivityManager.getNetworkInfo(network);
|
||||
if (networkInfo != null && networkInfo.isConnected()) {
|
||||
connected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (networkInfo == null || !connected) {
|
||||
Log.i("No connectivity: setting network unreachable");
|
||||
mLc.setNetworkReachable(false);
|
||||
} else if (dozeModeEnabled) {
|
||||
Log.i("Doze Mode enabled: shutting down network");
|
||||
mLc.setNetworkReachable(false);
|
||||
} else if (connected) {
|
||||
manageTunnelServer(networkInfo);
|
||||
|
||||
boolean wifiOnly = LinphonePreferences.instance().isWifiOnlyEnabled();
|
||||
if (wifiOnly) {
|
||||
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
|
||||
mLc.setNetworkReachable(true);
|
||||
} else {
|
||||
Log.i("Wifi-only mode, setting network not reachable");
|
||||
mLc.setNetworkReachable(false);
|
||||
}
|
||||
} else {
|
||||
int curtype = networkInfo.getType();
|
||||
|
||||
if (curtype != mLastNetworkType) {
|
||||
//if kind of network has changed, we need to notify network_reachable(false) to make sure all current connections are destroyed.
|
||||
//they will be re-created during setNetworkReachable(true).
|
||||
Log.i("Connectivity has changed.");
|
||||
mLc.setNetworkReachable(false);
|
||||
}
|
||||
mLc.setNetworkReachable(true);
|
||||
mLastNetworkType = curtype;
|
||||
}
|
||||
}
|
||||
|
||||
if (mLc.isNetworkReachable()) {
|
||||
// When network isn't available, push informations might not be set. This should fix the issue.
|
||||
LinphonePreferences prefs = LinphonePreferences.instance();
|
||||
prefs.setPushNotificationEnabled(prefs.isPushNotificationEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
private void destroyLinphoneCore() {
|
||||
if (LinphonePreferences.instance() != null) {
|
||||
// We set network reachable at false before destroy LC to not send register with expires at 0
|
||||
|
@ -920,24 +833,6 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
|||
mLc = null;
|
||||
}
|
||||
|
||||
public void dozeManager(boolean enable) {
|
||||
if (enable) {
|
||||
Log.i("[Doze Mode]: register");
|
||||
mServiceContext.registerReceiver(mDozeReceiver, mDozeIntentFilter);
|
||||
dozeModeEnabled = true;
|
||||
} else {
|
||||
Log.i("[Doze Mode]: unregister");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
try {
|
||||
mServiceContext.unregisterReceiver(mDozeReceiver);
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
dozeModeEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void enableProximitySensing(boolean enable) {
|
||||
if (enable) {
|
||||
if (!mProximitySensingEnabled) {
|
||||
|
@ -1016,18 +911,6 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
|||
return mR.getString(key);
|
||||
}
|
||||
|
||||
/* Simple implementation as Android way seems very complicate:
|
||||
For example: with wifi and mobile actives; when pulling mobile down:
|
||||
I/Linphone( 8397): WIFI connected: setting network reachable
|
||||
I/Linphone( 8397): new state [RegistrationProgress]
|
||||
I/Linphone( 8397): mobile disconnected: setting network unreachable
|
||||
I/Linphone( 8397): Managing tunnel
|
||||
I/Linphone( 8397): WIFI connected: setting network reachable
|
||||
*/
|
||||
public void connectivityChanged(ConnectivityManager cm, boolean noConnectivity) {
|
||||
updateNetworkReachability();
|
||||
}
|
||||
|
||||
private Call ringingCall;
|
||||
|
||||
private MediaPlayer mRingerPlayer;
|
||||
|
@ -1559,10 +1442,6 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
|||
dialog.show();
|
||||
}
|
||||
|
||||
public void setDozeModeEnabled(boolean b) {
|
||||
dozeModeEnabled = b;
|
||||
}
|
||||
|
||||
public String getmDynamicConfigFile() {
|
||||
return mDynamicConfigFile;
|
||||
}
|
||||
|
@ -1712,7 +1591,11 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
|||
|
||||
@Override
|
||||
public void onNetworkReachable(Core lc, boolean enable) {
|
||||
|
||||
if (enable) {
|
||||
// When network isn't available, push informations might not be set. This should fix the issue.
|
||||
LinphonePreferences prefs = LinphonePreferences.instance();
|
||||
prefs.setPushNotificationEnabled(prefs.isPushNotificationEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1042,11 +1042,13 @@ public class LinphonePreferences {
|
|||
|
||||
// Network settings
|
||||
public void setWifiOnlyEnabled(Boolean enable) {
|
||||
getConfig().setBool("app", "wifi_only", enable);
|
||||
if (getLc() == null) return;
|
||||
getLc().enableWifiOnly(enable);
|
||||
}
|
||||
|
||||
public boolean isWifiOnlyEnabled() {
|
||||
return getConfig().getBool("app", "wifi_only", false);
|
||||
if (getLc() == null) return false;
|
||||
return getLc().wifiOnlyEnabled();
|
||||
}
|
||||
|
||||
public void useRandomPort(boolean enabled) {
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
package org.linphone.receivers;
|
||||
|
||||
/*
|
||||
DozeReceiver.java
|
||||
Copyright (C) 2017 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
|
||||
import org.linphone.LinphoneManager;
|
||||
import org.linphone.LinphonePreferences;
|
||||
import org.linphone.LinphoneService;
|
||||
import org.linphone.LinphoneUtils;
|
||||
import org.linphone.R;
|
||||
import org.linphone.core.Core;
|
||||
import org.linphone.mediastream.Log;
|
||||
|
||||
/*
|
||||
* Purpose of this receiver is to disable keep alives when device is on idle
|
||||
* */
|
||||
public class DozeReceiver extends android.content.BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
PowerManager pm;
|
||||
if (!LinphoneService.isReady()) return;
|
||||
|
||||
boolean isDebugEnabled = LinphonePreferences.instance().isDebugEnabled();
|
||||
LinphoneUtils.initLoggingService(isDebugEnabled, context.getString(R.string.app_name));
|
||||
Core lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||
if (lc == null) return;
|
||||
|
||||
pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
boolean dozeM = pm.isDeviceIdleMode();
|
||||
Log.i("[DozeReceiver] Idle Mode: " + dozeM);
|
||||
LinphoneManager.getInstance().setDozeModeEnabled(dozeM);
|
||||
LinphoneManager.getInstance().updateNetworkReachability();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package org.linphone.receivers;
|
||||
|
||||
/*
|
||||
ContactPickerActivity.java
|
||||
Copyright (C) 2017 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
|
||||
import org.linphone.LinphoneManager;
|
||||
|
||||
/**
|
||||
* Intercept network state changes and update linphone core through LinphoneManager.
|
||||
*/
|
||||
public class NetworkManager extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
Boolean lNoConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
|
||||
if (LinphoneManager.isInstanciated()) {
|
||||
LinphoneManager.getInstance().connectivityChanged(cm, lNoConnectivity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue