mirror of
https://github.com/Tencent/Hippy.git
synced 2026-10-29 14:10:47 +08:00
fix(android): add try-catch for NetInfoModule
This commit is contained in:
+20
-17
@@ -30,6 +30,8 @@ import com.tencent.mtt.hippy.modules.javascriptmodules.EventDispatcher;
|
||||
import com.tencent.mtt.hippy.modules.nativemodules.HippyNativeModuleBase;
|
||||
import com.tencent.mtt.hippy.utils.LogUtils;
|
||||
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
|
||||
@SuppressWarnings({"deprecation", "unused"})
|
||||
@HippyNativeModule(name = "NetInfo")
|
||||
public class NetInfoModule extends HippyNativeModuleBase {
|
||||
@@ -155,24 +157,25 @@ public class NetInfoModule extends HippyNativeModuleBase {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
|
||||
mContext.getGlobalConfigs().getExecutorSupplierAdapter().getBackgroundTaskExecutor()
|
||||
.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String currentConnectivity = getCurrentConnectionType();
|
||||
if (!currentConnectivity.equalsIgnoreCase(mCurrentConnectivity)) {
|
||||
try {
|
||||
mCurrentConnectivity = currentConnectivity;
|
||||
HippyMap data = new HippyMap();
|
||||
data.pushString("network_info", mCurrentConnectivity);
|
||||
mContext.getModuleManager().getJavaScriptModule(EventDispatcher.class)
|
||||
.receiveNativeEvent(EVENT_NAME, data);
|
||||
} catch (Throwable e) {
|
||||
LogUtils.d("ConnectivityReceiver", "onReceive: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
try {
|
||||
mContext.getGlobalConfigs().getExecutorSupplierAdapter()
|
||||
.getBackgroundTaskExecutor().execute(() -> {
|
||||
String currentConnectivity = getCurrentConnectionType();
|
||||
if (!currentConnectivity.equalsIgnoreCase(mCurrentConnectivity)) {
|
||||
try {
|
||||
mCurrentConnectivity = currentConnectivity;
|
||||
HippyMap data = new HippyMap();
|
||||
data.pushString("network_info", mCurrentConnectivity);
|
||||
mContext.getModuleManager().getJavaScriptModule(EventDispatcher.class)
|
||||
.receiveNativeEvent(EVENT_NAME, data);
|
||||
} catch (Throwable e) {
|
||||
LogUtils.d("NetInfoModule", "onReceive sendEvent: ", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} catch (RejectedExecutionException e) {
|
||||
LogUtils.d("NetInfoModule", "onReceive execute: ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user