Initial commit
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package com.unity3d.ads.connectivity;
|
||||
|
||||
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 com.unity3d.ads.properties.ClientProperties;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class ConnectivityChangeReceiver extends BroadcastReceiver {
|
||||
private static ConnectivityChangeReceiver _receiver;
|
||||
|
||||
public static void register() {
|
||||
if (_receiver == null) {
|
||||
_receiver = new ConnectivityChangeReceiver();
|
||||
ClientProperties.getApplicationContext().registerReceiver(_receiver, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
|
||||
}
|
||||
}
|
||||
|
||||
public static void unregister() {
|
||||
if (_receiver != null) {
|
||||
ClientProperties.getApplicationContext().unregisterReceiver(_receiver);
|
||||
_receiver = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.content.BroadcastReceiver
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
NetworkInfo activeNetworkInfo;
|
||||
if (intent.getBooleanExtra("noConnectivity", false)) {
|
||||
ConnectivityMonitor.disconnected();
|
||||
return;
|
||||
}
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
|
||||
if (connectivityManager == null || (activeNetworkInfo = connectivityManager.getActiveNetworkInfo()) == null || !activeNetworkInfo.isConnected()) {
|
||||
return;
|
||||
}
|
||||
ConnectivityMonitor.connected();
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.unity3d.ads.connectivity;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public enum ConnectivityEvent {
|
||||
CONNECTED,
|
||||
DISCONNECTED,
|
||||
NETWORK_CHANGE
|
||||
}
|
197
sources/com/unity3d/ads/connectivity/ConnectivityMonitor.java
Normal file
197
sources/com/unity3d/ads/connectivity/ConnectivityMonitor.java
Normal file
@@ -0,0 +1,197 @@
|
||||
package com.unity3d.ads.connectivity;
|
||||
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Build;
|
||||
import android.telephony.TelephonyManager;
|
||||
import com.unity3d.ads.log.DeviceLog;
|
||||
import com.unity3d.ads.properties.ClientProperties;
|
||||
import com.unity3d.ads.webview.WebViewApp;
|
||||
import com.unity3d.ads.webview.WebViewEventCategory;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class ConnectivityMonitor {
|
||||
private static int _connected = -1;
|
||||
private static HashSet<IConnectivityListener> _listeners = null;
|
||||
private static boolean _listening = false;
|
||||
private static int _networkType = -1;
|
||||
private static boolean _webappMonitoring = false;
|
||||
private static boolean _wifi = false;
|
||||
|
||||
/* renamed from: com.unity3d.ads.connectivity.ConnectivityMonitor$1, reason: invalid class name */
|
||||
static /* synthetic */ class AnonymousClass1 {
|
||||
static final /* synthetic */ int[] $SwitchMap$com$unity3d$ads$connectivity$ConnectivityEvent = new int[ConnectivityEvent.values().length];
|
||||
|
||||
static {
|
||||
try {
|
||||
$SwitchMap$com$unity3d$ads$connectivity$ConnectivityEvent[ConnectivityEvent.CONNECTED.ordinal()] = 1;
|
||||
} catch (NoSuchFieldError unused) {
|
||||
}
|
||||
try {
|
||||
$SwitchMap$com$unity3d$ads$connectivity$ConnectivityEvent[ConnectivityEvent.DISCONNECTED.ordinal()] = 2;
|
||||
} catch (NoSuchFieldError unused2) {
|
||||
}
|
||||
try {
|
||||
$SwitchMap$com$unity3d$ads$connectivity$ConnectivityEvent[ConnectivityEvent.NETWORK_CHANGE.ordinal()] = 3;
|
||||
} catch (NoSuchFieldError unused3) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addListener(IConnectivityListener iConnectivityListener) {
|
||||
if (_listeners == null) {
|
||||
_listeners = new HashSet<>();
|
||||
}
|
||||
_listeners.add(iConnectivityListener);
|
||||
updateListeningStatus();
|
||||
}
|
||||
|
||||
public static void connected() {
|
||||
if (_connected == 1) {
|
||||
return;
|
||||
}
|
||||
DeviceLog.debug("Unity Ads connectivity change: connected");
|
||||
initConnectionStatus();
|
||||
HashSet<IConnectivityListener> hashSet = _listeners;
|
||||
if (hashSet != null) {
|
||||
Iterator<IConnectivityListener> it = hashSet.iterator();
|
||||
while (it.hasNext()) {
|
||||
it.next().onConnected();
|
||||
}
|
||||
}
|
||||
sendToWebview(ConnectivityEvent.CONNECTED, _wifi, _networkType);
|
||||
}
|
||||
|
||||
public static void connectionStatusChanged() {
|
||||
NetworkInfo activeNetworkInfo;
|
||||
if (_connected == 1 && (activeNetworkInfo = ((ConnectivityManager) ClientProperties.getApplicationContext().getSystemService("connectivity")).getActiveNetworkInfo()) != null && activeNetworkInfo.isConnected()) {
|
||||
boolean z = activeNetworkInfo.getType() == 1;
|
||||
int networkType = ((TelephonyManager) ClientProperties.getApplicationContext().getSystemService("phone")).getNetworkType();
|
||||
boolean z2 = _wifi;
|
||||
if (z == z2 && (networkType == _networkType || z2)) {
|
||||
return;
|
||||
}
|
||||
_wifi = z;
|
||||
_networkType = networkType;
|
||||
DeviceLog.debug("Unity Ads connectivity change: network change");
|
||||
sendToWebview(ConnectivityEvent.NETWORK_CHANGE, z, networkType);
|
||||
}
|
||||
}
|
||||
|
||||
public static void disconnected() {
|
||||
if (_connected == 0) {
|
||||
return;
|
||||
}
|
||||
_connected = 0;
|
||||
DeviceLog.debug("Unity Ads connectivity change: disconnected");
|
||||
HashSet<IConnectivityListener> hashSet = _listeners;
|
||||
if (hashSet != null) {
|
||||
Iterator<IConnectivityListener> it = hashSet.iterator();
|
||||
while (it.hasNext()) {
|
||||
it.next().onDisconnected();
|
||||
}
|
||||
}
|
||||
sendToWebview(ConnectivityEvent.DISCONNECTED, false, 0);
|
||||
}
|
||||
|
||||
private static void initConnectionStatus() {
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) ClientProperties.getApplicationContext().getSystemService("connectivity");
|
||||
if (connectivityManager == null) {
|
||||
return;
|
||||
}
|
||||
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
|
||||
if (activeNetworkInfo == null || !activeNetworkInfo.isConnected()) {
|
||||
_connected = 0;
|
||||
return;
|
||||
}
|
||||
_connected = 1;
|
||||
_wifi = activeNetworkInfo.getType() == 1;
|
||||
if (_wifi) {
|
||||
return;
|
||||
}
|
||||
_networkType = ((TelephonyManager) ClientProperties.getApplicationContext().getSystemService("phone")).getNetworkType();
|
||||
}
|
||||
|
||||
public static void removeListener(IConnectivityListener iConnectivityListener) {
|
||||
HashSet<IConnectivityListener> hashSet = _listeners;
|
||||
if (hashSet == null) {
|
||||
return;
|
||||
}
|
||||
hashSet.remove(iConnectivityListener);
|
||||
updateListeningStatus();
|
||||
}
|
||||
|
||||
private static void sendToWebview(ConnectivityEvent connectivityEvent, boolean z, int i) {
|
||||
WebViewApp currentApp;
|
||||
if (_webappMonitoring && (currentApp = WebViewApp.getCurrentApp()) != null && currentApp.isWebAppLoaded()) {
|
||||
int i2 = AnonymousClass1.$SwitchMap$com$unity3d$ads$connectivity$ConnectivityEvent[connectivityEvent.ordinal()];
|
||||
if (i2 == 1) {
|
||||
if (z) {
|
||||
currentApp.sendEvent(WebViewEventCategory.CONNECTIVITY, ConnectivityEvent.CONNECTED, Boolean.valueOf(z), 0);
|
||||
return;
|
||||
} else {
|
||||
currentApp.sendEvent(WebViewEventCategory.CONNECTIVITY, ConnectivityEvent.CONNECTED, Boolean.valueOf(z), Integer.valueOf(i));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (i2 == 2) {
|
||||
currentApp.sendEvent(WebViewEventCategory.CONNECTIVITY, ConnectivityEvent.DISCONNECTED, new Object[0]);
|
||||
} else {
|
||||
if (i2 != 3) {
|
||||
return;
|
||||
}
|
||||
if (z) {
|
||||
currentApp.sendEvent(WebViewEventCategory.CONNECTIVITY, ConnectivityEvent.NETWORK_CHANGE, Boolean.valueOf(z), 0);
|
||||
} else {
|
||||
currentApp.sendEvent(WebViewEventCategory.CONNECTIVITY, ConnectivityEvent.NETWORK_CHANGE, Boolean.valueOf(z), Integer.valueOf(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setConnectionMonitoring(boolean z) {
|
||||
_webappMonitoring = z;
|
||||
updateListeningStatus();
|
||||
}
|
||||
|
||||
private static void startListening() {
|
||||
if (_listening) {
|
||||
return;
|
||||
}
|
||||
_listening = true;
|
||||
initConnectionStatus();
|
||||
if (Build.VERSION.SDK_INT < 21) {
|
||||
ConnectivityChangeReceiver.register();
|
||||
} else {
|
||||
ConnectivityNetworkCallback.register();
|
||||
}
|
||||
}
|
||||
|
||||
public static void stopAll() {
|
||||
_listeners = null;
|
||||
_webappMonitoring = false;
|
||||
updateListeningStatus();
|
||||
}
|
||||
|
||||
private static void stopListening() {
|
||||
if (_listening) {
|
||||
_listening = false;
|
||||
if (Build.VERSION.SDK_INT < 21) {
|
||||
ConnectivityChangeReceiver.unregister();
|
||||
} else {
|
||||
ConnectivityNetworkCallback.unregister();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateListeningStatus() {
|
||||
HashSet<IConnectivityListener> hashSet;
|
||||
if (_webappMonitoring || !((hashSet = _listeners) == null || hashSet.isEmpty())) {
|
||||
startListening();
|
||||
} else {
|
||||
stopListening();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
package com.unity3d.ads.connectivity;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.LinkProperties;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkRequest;
|
||||
import com.unity3d.ads.properties.ClientProperties;
|
||||
|
||||
@TargetApi(21)
|
||||
/* loaded from: classes2.dex */
|
||||
public class ConnectivityNetworkCallback extends ConnectivityManager.NetworkCallback {
|
||||
private static ConnectivityNetworkCallback _impl;
|
||||
|
||||
public static void register() {
|
||||
if (_impl == null) {
|
||||
_impl = new ConnectivityNetworkCallback();
|
||||
((ConnectivityManager) ClientProperties.getApplicationContext().getSystemService("connectivity")).registerNetworkCallback(new NetworkRequest.Builder().build(), _impl);
|
||||
}
|
||||
}
|
||||
|
||||
public static void unregister() {
|
||||
if (_impl != null) {
|
||||
((ConnectivityManager) ClientProperties.getApplicationContext().getSystemService("connectivity")).unregisterNetworkCallback(_impl);
|
||||
_impl = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.net.ConnectivityManager.NetworkCallback
|
||||
public void onAvailable(Network network) {
|
||||
ConnectivityMonitor.connected();
|
||||
}
|
||||
|
||||
@Override // android.net.ConnectivityManager.NetworkCallback
|
||||
public void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) {
|
||||
ConnectivityMonitor.connectionStatusChanged();
|
||||
}
|
||||
|
||||
@Override // android.net.ConnectivityManager.NetworkCallback
|
||||
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
|
||||
ConnectivityMonitor.connectionStatusChanged();
|
||||
}
|
||||
|
||||
@Override // android.net.ConnectivityManager.NetworkCallback
|
||||
public void onLost(Network network) {
|
||||
ConnectivityMonitor.disconnected();
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.unity3d.ads.connectivity;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public interface IConnectivityListener {
|
||||
void onConnected();
|
||||
|
||||
void onDisconnected();
|
||||
}
|
Reference in New Issue
Block a user