diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/netinfo/BUCK b/ReactAndroid/src/main/java/com/facebook/react/modules/netinfo/BUCK
deleted file mode 100644
index fc907537682..00000000000
--- a/ReactAndroid/src/main/java/com/facebook/react/modules/netinfo/BUCK
+++ /dev/null
@@ -1,26 +0,0 @@
-load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_target", "rn_android_library")
-
-rn_android_library(
- name = "netinfo",
- srcs = glob(["**/*.java"]),
- is_androidx = True,
- provided_deps = [
- react_native_dep("third-party/android/androidx:annotation"),
- react_native_dep("third-party/android/androidx:core"),
- react_native_dep("third-party/android/androidx:fragment"),
- react_native_dep("third-party/android/androidx:legacy-support-core-ui"),
- react_native_dep("third-party/android/androidx:legacy-support-core-utils"),
- ],
- visibility = [
- "PUBLIC",
- ],
- deps = [
- react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
- react_native_dep("third-party/java/infer-annotations:infer-annotations"),
- react_native_dep("third-party/java/jsr-305:jsr-305"),
- react_native_target("java/com/facebook/react/bridge:bridge"),
- react_native_target("java/com/facebook/react/common:common"),
- react_native_target("java/com/facebook/react/module/annotations:annotations"),
- react_native_target("java/com/facebook/react/modules/core:core"),
- ],
-)
diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/netinfo/NetInfoModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/netinfo/NetInfoModule.java
deleted file mode 100644
index 56a953d06c4..00000000000
--- a/ReactAndroid/src/main/java/com/facebook/react/modules/netinfo/NetInfoModule.java
+++ /dev/null
@@ -1,268 +0,0 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- */
-
-package com.facebook.react.modules.netinfo;
-
-import android.annotation.SuppressLint;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.net.ConnectivityManager;
-import android.net.NetworkInfo;
-import androidx.core.net.ConnectivityManagerCompat;
-import android.telephony.TelephonyManager;
-
-import com.facebook.react.bridge.LifecycleEventListener;
-import com.facebook.react.bridge.Promise;
-import com.facebook.react.bridge.ReactApplicationContext;
-import com.facebook.react.bridge.ReactContextBaseJavaModule;
-import com.facebook.react.bridge.ReactMethod;
-import com.facebook.react.bridge.WritableMap;
-import com.facebook.react.bridge.WritableNativeMap;
-import com.facebook.react.module.annotations.ReactModule;
-
-import static com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;
-
-/**
- * Module that monitors and provides information about the connectivity state of the device.
- */
-@SuppressLint("MissingPermission")
-@ReactModule(name = NetInfoModule.NAME)
-public class NetInfoModule extends ReactContextBaseJavaModule
- implements LifecycleEventListener {
-
- // Based on the ConnectionType enum described in the W3C Network Information API spec
- // (https://wicg.github.io/netinfo/).
- private static final String CONNECTION_TYPE_BLUETOOTH = "bluetooth";
- private static final String CONNECTION_TYPE_CELLULAR = "cellular";
- private static final String CONNECTION_TYPE_ETHERNET = "ethernet";
- private static final String CONNECTION_TYPE_NONE = "none";
- private static final String CONNECTION_TYPE_UNKNOWN = "unknown";
- private static final String CONNECTION_TYPE_WIFI = "wifi";
- private static final String CONNECTION_TYPE_WIMAX = "wimax";
-
- // Based on the EffectiveConnectionType enum described in the W3C Network Information API spec
- // (https://wicg.github.io/netinfo/).
- private static final String EFFECTIVE_CONNECTION_TYPE_UNKNOWN = "unknown";
- private static final String EFFECTIVE_CONNECTION_TYPE_2G = "2g";
- private static final String EFFECTIVE_CONNECTION_TYPE_3G = "3g";
- private static final String EFFECTIVE_CONNECTION_TYPE_4G = "4g";
-
- private static final String CONNECTION_TYPE_NONE_DEPRECATED = "NONE";
- private static final String CONNECTION_TYPE_UNKNOWN_DEPRECATED = "UNKNOWN";
-
- private static final String MISSING_PERMISSION_MESSAGE =
- "To use NetInfo on Android, add the following to your AndroidManifest.xml:\n" +
- "";
-
- private static final String ERROR_MISSING_PERMISSION = "E_MISSING_PERMISSION";
- public static final String NAME = "NetInfo";
-
- private final ConnectivityManager mConnectivityManager;
- private final ConnectivityBroadcastReceiver mConnectivityBroadcastReceiver;
- private boolean mNoNetworkPermission = false;
-
- private String mConnectivityDeprecated = CONNECTION_TYPE_UNKNOWN_DEPRECATED;
- private String mConnectionType = CONNECTION_TYPE_UNKNOWN;
- private String mEffectiveConnectionType = EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
-
- public NetInfoModule(ReactApplicationContext reactContext) {
- super(reactContext);
- mConnectivityManager =
- (ConnectivityManager) reactContext.getSystemService(Context.CONNECTIVITY_SERVICE);
- mConnectivityBroadcastReceiver = new ConnectivityBroadcastReceiver();
- }
-
- @Override
- public void onHostResume() {
- registerReceiver();
- }
-
- @Override
- public void onHostPause() {
- unregisterReceiver();
- }
-
- @Override
- public void onHostDestroy() {
- }
-
- @Override
- public void initialize() {
- getReactApplicationContext().addLifecycleEventListener(this);
- }
-
- @Override
- public String getName() {
- return NAME;
- }
-
- @ReactMethod
- public void getCurrentConnectivity(Promise promise) {
- if (mNoNetworkPermission) {
- promise.reject(ERROR_MISSING_PERMISSION, MISSING_PERMISSION_MESSAGE);
- return;
- }
- promise.resolve(createConnectivityEventMap());
- }
-
- @ReactMethod
- public void isConnectionMetered(Promise promise) {
- if (mNoNetworkPermission) {
- promise.reject(ERROR_MISSING_PERMISSION, MISSING_PERMISSION_MESSAGE);
- return;
- }
- promise.resolve(ConnectivityManagerCompat.isActiveNetworkMetered(mConnectivityManager));
- }
-
- private void registerReceiver() {
- IntentFilter filter = new IntentFilter();
- filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
- getReactApplicationContext().registerReceiver(mConnectivityBroadcastReceiver, filter);
- mConnectivityBroadcastReceiver.setRegistered(true);
- updateAndSendConnectionType();
- }
-
- private void unregisterReceiver() {
- if (mConnectivityBroadcastReceiver.isRegistered()) {
- getReactApplicationContext().unregisterReceiver(mConnectivityBroadcastReceiver);
- mConnectivityBroadcastReceiver.setRegistered(false);
- }
- }
-
- private void updateAndSendConnectionType() {
- String connectionType = CONNECTION_TYPE_UNKNOWN;
- String effectiveConnectionType = EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
-
- try {
- NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo();
- if (networkInfo == null || !networkInfo.isConnected()) {
- connectionType = CONNECTION_TYPE_NONE;
- } else {
- int networkType = networkInfo.getType();
- switch (networkType) {
- case ConnectivityManager.TYPE_BLUETOOTH:
- connectionType = CONNECTION_TYPE_BLUETOOTH;
- break;
- case ConnectivityManager.TYPE_ETHERNET:
- connectionType = CONNECTION_TYPE_ETHERNET;
- break;
- case ConnectivityManager.TYPE_MOBILE:
- case ConnectivityManager.TYPE_MOBILE_DUN:
- connectionType = CONNECTION_TYPE_CELLULAR;
- effectiveConnectionType = getEffectiveConnectionType(networkInfo);
- break;
- case ConnectivityManager.TYPE_WIFI:
- connectionType = CONNECTION_TYPE_WIFI;
- break;
- case ConnectivityManager.TYPE_WIMAX:
- connectionType = CONNECTION_TYPE_WIMAX;
- break;
- default:
- connectionType = CONNECTION_TYPE_UNKNOWN;
- break;
- }
- }
- } catch (SecurityException e) {
- mNoNetworkPermission = true;
- connectionType = CONNECTION_TYPE_UNKNOWN;
- }
-
- String currentConnectivity = getCurrentConnectionType();
- // It is possible to get multiple broadcasts for the same connectivity change, so we only
- // update and send an event when the connectivity has indeed changed.
- if (!connectionType.equalsIgnoreCase(mConnectionType) ||
- !effectiveConnectionType.equalsIgnoreCase(mEffectiveConnectionType) ||
- !currentConnectivity.equalsIgnoreCase(mConnectivityDeprecated)) {
- mConnectionType = connectionType;
- mEffectiveConnectionType = effectiveConnectionType;
- mConnectivityDeprecated = currentConnectivity;
- sendConnectivityChangedEvent();
- }
- }
-
- private String getCurrentConnectionType() {
- try {
- NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo();
- if (networkInfo == null || !networkInfo.isConnected()) {
- return CONNECTION_TYPE_NONE_DEPRECATED;
- } else if (ConnectivityManager.isNetworkTypeValid(networkInfo.getType())) {
- return networkInfo.getTypeName().toUpperCase();
- } else {
- return CONNECTION_TYPE_UNKNOWN_DEPRECATED;
- }
- } catch (SecurityException e) {
- mNoNetworkPermission = true;
- return CONNECTION_TYPE_UNKNOWN_DEPRECATED;
- }
- }
-
- private String getEffectiveConnectionType(NetworkInfo networkInfo) {
- switch (networkInfo.getSubtype()) {
- case TelephonyManager.NETWORK_TYPE_1xRTT:
- case TelephonyManager.NETWORK_TYPE_CDMA:
- case TelephonyManager.NETWORK_TYPE_EDGE:
- case TelephonyManager.NETWORK_TYPE_GPRS:
- case TelephonyManager.NETWORK_TYPE_IDEN:
- return EFFECTIVE_CONNECTION_TYPE_2G;
- case TelephonyManager.NETWORK_TYPE_EHRPD:
- case TelephonyManager.NETWORK_TYPE_EVDO_0:
- case TelephonyManager.NETWORK_TYPE_EVDO_A:
- case TelephonyManager.NETWORK_TYPE_EVDO_B:
- case TelephonyManager.NETWORK_TYPE_HSDPA:
- case TelephonyManager.NETWORK_TYPE_HSPA:
- case TelephonyManager.NETWORK_TYPE_HSUPA:
- case TelephonyManager.NETWORK_TYPE_UMTS:
- return EFFECTIVE_CONNECTION_TYPE_3G;
- case TelephonyManager.NETWORK_TYPE_HSPAP:
- case TelephonyManager.NETWORK_TYPE_LTE:
- return EFFECTIVE_CONNECTION_TYPE_4G;
- case TelephonyManager.NETWORK_TYPE_UNKNOWN:
- default:
- return EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
- }
- }
-
- private void sendConnectivityChangedEvent() {
- getReactApplicationContext().getJSModule(RCTDeviceEventEmitter.class)
- .emit("networkStatusDidChange", createConnectivityEventMap());
- }
-
- private WritableMap createConnectivityEventMap() {
- WritableMap event = new WritableNativeMap();
- event.putString("network_info", mConnectivityDeprecated);
- event.putString("connectionType", mConnectionType);
- event.putString("effectiveConnectionType", mEffectiveConnectionType);
- return event;
- }
-
- /**
- * Class that receives intents whenever the connection type changes.
- * NB: It is possible on some devices to receive certain connection type changes multiple times.
- */
- private class ConnectivityBroadcastReceiver extends BroadcastReceiver {
-
- //TODO: Remove registered check when source of crash is found. t9846865
- private boolean isRegistered = false;
-
- public void setRegistered(boolean registered) {
- isRegistered = registered;
- }
-
- public boolean isRegistered() {
- return isRegistered;
- }
-
- @Override
- public void onReceive(Context context, Intent intent) {
- if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
- updateAndSendConnectionType();
- }
- }
- }
-}
diff --git a/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK b/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK
index fc134a5af2d..ddd632a1b4f 100644
--- a/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK
+++ b/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK
@@ -38,7 +38,6 @@ rn_android_library(
react_native_target("java/com/facebook/react/modules/i18nmanager:i18nmanager"),
react_native_target("java/com/facebook/react/modules/image:image"),
react_native_target("java/com/facebook/react/modules/intent:intent"),
- react_native_target("java/com/facebook/react/modules/netinfo:netinfo"),
react_native_target("java/com/facebook/react/modules/network:network"),
react_native_target("java/com/facebook/react/modules/permissions:permissions"),
react_native_target("java/com/facebook/react/modules/share:share"),
diff --git a/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java b/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java
index 3d1c17ae4dc..cf1f81113f8 100644
--- a/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java
+++ b/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java
@@ -28,7 +28,6 @@ import com.facebook.react.modules.fresco.FrescoModule;
import com.facebook.react.modules.i18nmanager.I18nManagerModule;
import com.facebook.react.modules.image.ImageLoaderModule;
import com.facebook.react.modules.intent.IntentModule;
-import com.facebook.react.modules.netinfo.NetInfoModule;
import com.facebook.react.modules.network.NetworkingModule;
import com.facebook.react.modules.permissions.PermissionsModule;
import com.facebook.react.modules.share.ShareModule;
@@ -87,7 +86,6 @@ import javax.inject.Provider;
IntentModule.class,
NativeAnimatedModule.class,
NetworkingModule.class,
- NetInfoModule.class,
PermissionsModule.class,
ShareModule.class,
StatusBarModule.class,
@@ -251,14 +249,6 @@ public class MainReactPackage extends LazyReactPackage {
return new NetworkingModule(context);
}
}),
- ModuleSpec.nativeModuleSpec(
- NetInfoModule.class,
- new Provider() {
- @Override
- public NativeModule get() {
- return new NetInfoModule(context);
- }
- }),
ModuleSpec.nativeModuleSpec(
PermissionsModule.class,
new Provider() {