mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-13 09:27:16 +01:00
107 lines
4.6 KiB
Java
107 lines
4.6 KiB
Java
package com.reactnativecommunity.netinfo;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.net.NetworkInfo;
|
|
import androidx.biometric.ErrorUtils$$ExternalSyntheticOutline0;
|
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
import com.reactnativecommunity.netinfo.types.CellularGeneration;
|
|
import com.reactnativecommunity.netinfo.types.ConnectionType;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes9.dex */
|
|
public class BroadcastReceiverConnectivityReceiver extends ConnectivityReceiver {
|
|
public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
|
|
private final ConnectivityBroadcastReceiver mConnectivityBroadcastReceiver;
|
|
|
|
public BroadcastReceiverConnectivityReceiver(ReactApplicationContext reactApplicationContext) {
|
|
super(reactApplicationContext);
|
|
this.mConnectivityBroadcastReceiver = new ConnectivityBroadcastReceiver(this, 0);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
@SuppressLint({"MissingPermission"})
|
|
public void updateAndSendConnectionType() {
|
|
NetworkInfo activeNetworkInfo;
|
|
ConnectionType connectionType = ConnectionType.UNKNOWN;
|
|
CellularGeneration cellularGeneration = null;
|
|
boolean z = false;
|
|
try {
|
|
activeNetworkInfo = getConnectivityManager().getActiveNetworkInfo();
|
|
} catch (SecurityException unused) {
|
|
connectionType = ConnectionType.UNKNOWN;
|
|
}
|
|
if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) {
|
|
z = activeNetworkInfo.isConnected();
|
|
int type = activeNetworkInfo.getType();
|
|
if (type != 0) {
|
|
if (type == 1) {
|
|
connectionType = ConnectionType.WIFI;
|
|
} else if (type != 4) {
|
|
if (type == 9) {
|
|
connectionType = ConnectionType.ETHERNET;
|
|
} else if (type == 17) {
|
|
connectionType = ConnectionType.VPN;
|
|
} else if (type == 6) {
|
|
connectionType = ConnectionType.WIMAX;
|
|
} else if (type == 7) {
|
|
connectionType = ConnectionType.BLUETOOTH;
|
|
}
|
|
}
|
|
updateConnectivity(connectionType, cellularGeneration, z);
|
|
}
|
|
connectionType = ConnectionType.CELLULAR;
|
|
cellularGeneration = CellularGeneration.fromNetworkInfo(activeNetworkInfo);
|
|
updateConnectivity(connectionType, cellularGeneration, z);
|
|
}
|
|
connectionType = ConnectionType.NONE;
|
|
updateConnectivity(connectionType, cellularGeneration, z);
|
|
}
|
|
|
|
@Override // com.reactnativecommunity.netinfo.ConnectivityReceiver
|
|
public void register() {
|
|
NetInfoUtils.compatRegisterReceiver(getReactContext(), this.mConnectivityBroadcastReceiver, ErrorUtils$$ExternalSyntheticOutline0.m(CONNECTIVITY_ACTION), false);
|
|
this.mConnectivityBroadcastReceiver.setRegistered(true);
|
|
updateAndSendConnectionType();
|
|
}
|
|
|
|
@Override // com.reactnativecommunity.netinfo.ConnectivityReceiver
|
|
public void unregister() {
|
|
if (this.mConnectivityBroadcastReceiver.isRegistered()) {
|
|
getReactContext().unregisterReceiver(this.mConnectivityBroadcastReceiver);
|
|
this.mConnectivityBroadcastReceiver.setRegistered(false);
|
|
}
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public class ConnectivityBroadcastReceiver extends BroadcastReceiver {
|
|
private boolean isRegistered;
|
|
|
|
private ConnectivityBroadcastReceiver() {
|
|
this.isRegistered = false;
|
|
}
|
|
|
|
public boolean isRegistered() {
|
|
return this.isRegistered;
|
|
}
|
|
|
|
@Override // android.content.BroadcastReceiver
|
|
public void onReceive(Context context, Intent intent) {
|
|
String action = intent.getAction();
|
|
if (action == null || !action.equals(BroadcastReceiverConnectivityReceiver.CONNECTIVITY_ACTION)) {
|
|
return;
|
|
}
|
|
BroadcastReceiverConnectivityReceiver.this.updateAndSendConnectionType();
|
|
}
|
|
|
|
public void setRegistered(boolean z) {
|
|
this.isRegistered = z;
|
|
}
|
|
|
|
public /* synthetic */ ConnectivityBroadcastReceiver(BroadcastReceiverConnectivityReceiver broadcastReceiverConnectivityReceiver, int i) {
|
|
this();
|
|
}
|
|
}
|
|
}
|