Commit 29a339be authored by Mickaël Turnel's avatar Mickaël Turnel

Fix network callbacks not unregistered

parent e07b714c
......@@ -164,6 +164,8 @@ public class AndroidPlatformHelper {
}
public synchronized void onLinphoneCoreStop() {
mNetworkManagerAbove21.unregisterNetworkCallbacks(mConnectivityManager);
mNativePtr = 0;
mMainHandler.removeCallbacks(mNetworkUpdateRunner);
}
......
......@@ -34,28 +34,32 @@ import org.linphone.core.tools.AndroidPlatformHelper;
* Intercept network state changes and update linphone core.
*/
public class NetworkManagerAbove21 {
private AndroidPlatformHelper mHelper;
private ConnectivityManager.NetworkCallback mNetworkCallback;
public NetworkManagerAbove21(AndroidPlatformHelper helper) {
mHelper = helper;
}
public NetworkManagerAbove21(final AndroidPlatformHelper helper) {
mNetworkCallback = new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
helper.postNetworkUpdateRunner();
}
@Override
public void onLost(Network network) {
helper.postNetworkUpdateRunner();
}
};
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void registerNetworkCallbacks(ConnectivityManager connectivityManager) {
connectivityManager.registerNetworkCallback(
new NetworkRequest.Builder().build(),
new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
mHelper.postNetworkUpdateRunner();
}
@Override
public void onLost(Network network) {
mHelper.postNetworkUpdateRunner();
}
}
mNetworkCallback
);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void unregisterNetworkCallbacks(ConnectivityManager connectivityManager) {
connectivityManager.unregisterNetworkCallback(mNetworkCallback);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment