Commit f83d6c4a authored by Mickaël Turnel's avatar Mickaël Turnel

AndroidPlatformHelper will now update the network on the main thread

parent 8c8e5f84
...@@ -41,12 +41,14 @@ import android.net.ConnectivityManager; ...@@ -41,12 +41,14 @@ import android.net.ConnectivityManager;
import android.net.Network; import android.net.Network;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.net.ProxyInfo; import android.net.ProxyInfo;
import android.os.Handler;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.PowerManager.WakeLock; import android.os.PowerManager.WakeLock;
import android.os.Build; import android.os.Build;
import android.view.Surface; import android.view.Surface;
import android.view.TextureView; import android.view.TextureView;
import java.lang.Runnable;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.List; import java.util.List;
import java.io.File; import java.io.File;
...@@ -86,6 +88,8 @@ public class AndroidPlatformHelper { ...@@ -86,6 +88,8 @@ public class AndroidPlatformHelper {
private boolean mWifiOnly; private boolean mWifiOnly;
private boolean mUsingHttpProxy; private boolean mUsingHttpProxy;
private NetworkManagerAbove21 mNetworkManagerAbove21; private NetworkManagerAbove21 mNetworkManagerAbove21;
private Handler mMainHandler;
private Runnable mNetworkUpdateRunner;
private native void setNativePreviewWindowId(long nativePtr, Object view); private native void setNativePreviewWindowId(long nativePtr, Object view);
private native void setNativeVideoWindowId(long nativePtr, Object view); private native void setNativeVideoWindowId(long nativePtr, Object view);
...@@ -99,6 +103,14 @@ public class AndroidPlatformHelper { ...@@ -99,6 +103,14 @@ public class AndroidPlatformHelper {
mResources = mContext.getResources(); mResources = mContext.getResources();
MediastreamerAndroidContext.setContext(mContext); MediastreamerAndroidContext.setContext(mContext);
mMainHandler = new Handler(mContext.getMainLooper());
mNetworkUpdateRunner = new Runnable() {
@Override
public void run() {
updateNetworkReachability();
}
};
WifiManager wifiMgr = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); WifiManager wifiMgr = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
mConnectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); mConnectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
...@@ -148,12 +160,12 @@ public class AndroidPlatformHelper { ...@@ -148,12 +160,12 @@ public class AndroidPlatformHelper {
mContext.registerReceiver(mDozeReceiver, mDozeIntentFilter); mContext.registerReceiver(mDozeReceiver, mDozeIntentFilter);
} }
updateNetworkReachability(); postNetworkUpdateRunner();
} }
public void onWifiOnlyEnabled(boolean enabled) { public void onWifiOnlyEnabled(boolean enabled) {
mWifiOnly = enabled; mWifiOnly = enabled;
updateNetworkReachability(); postNetworkUpdateRunner();
} }
public Object getPowerManager() { public Object getPowerManager() {
...@@ -394,6 +406,10 @@ public class AndroidPlatformHelper { ...@@ -394,6 +406,10 @@ public class AndroidPlatformHelper {
} }
} }
public void postNetworkUpdateRunner() {
mMainHandler.post(mNetworkUpdateRunner);
}
public void updateNetworkReachability() { public void updateNetworkReachability() {
if (mConnectivityManager == null) return; if (mConnectivityManager == null) return;
......
...@@ -43,7 +43,7 @@ public class DozeReceiver extends android.content.BroadcastReceiver { ...@@ -43,7 +43,7 @@ public class DozeReceiver extends android.content.BroadcastReceiver {
boolean dozeM = pm.isDeviceIdleMode(); boolean dozeM = pm.isDeviceIdleMode();
if (mHelper != null) { if (mHelper != null) {
mHelper.setDozeModeEnabled(dozeM); mHelper.setDozeModeEnabled(dozeM);
mHelper.updateNetworkReachability(); mHelper.postNetworkUpdateRunner();
} }
} }
} }
......
...@@ -41,7 +41,7 @@ public class NetworkManager extends BroadcastReceiver { ...@@ -41,7 +41,7 @@ public class NetworkManager extends BroadcastReceiver {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Boolean lNoConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); Boolean lNoConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
if (mHelper != null) { if (mHelper != null) {
mHelper.updateNetworkReachability(); mHelper.postNetworkUpdateRunner();
} }
} }
......
...@@ -47,12 +47,12 @@ public class NetworkManagerAbove21 { ...@@ -47,12 +47,12 @@ public class NetworkManagerAbove21 {
new ConnectivityManager.NetworkCallback() { new ConnectivityManager.NetworkCallback() {
@Override @Override
public void onAvailable(Network network) { public void onAvailable(Network network) {
mHelper.updateNetworkReachability(); mHelper.postNetworkUpdateRunner();
} }
@Override @Override
public void onLost(Network network) { public void onLost(Network network) {
mHelper.updateNetworkReachability(); mHelper.postNetworkUpdateRunner();
} }
} }
); );
......
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