mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2025-01-09 13:43:22 +00:00
282 lines
11 KiB
Java
282 lines
11 KiB
Java
package org.webrtc;
|
|
|
|
import android.content.Context;
|
|
import android.os.Build;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import org.webrtc.NetworkChangeDetector;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public class NetworkMonitor {
|
|
private static final String TAG = "NetworkMonitor";
|
|
private volatile NetworkChangeDetector.ConnectionType currentConnectionType;
|
|
private final ArrayList<Long> nativeNetworkObservers;
|
|
private NetworkChangeDetector networkChangeDetector;
|
|
private NetworkChangeDetectorFactory networkChangeDetectorFactory;
|
|
private final Object networkChangeDetectorLock;
|
|
private final ArrayList<NetworkObserver> networkObservers;
|
|
private int numObservers;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public interface NetworkObserver {
|
|
void onConnectionTypeChanged(NetworkChangeDetector.ConnectionType connectionType);
|
|
}
|
|
|
|
private static int androidSdkInt() {
|
|
return Build.VERSION.SDK_INT;
|
|
}
|
|
|
|
private NetworkChangeDetector.ConnectionType getCurrentConnectionType() {
|
|
return this.currentConnectionType;
|
|
}
|
|
|
|
@Deprecated
|
|
public static void init(Context context) {
|
|
}
|
|
|
|
private native void nativeNotifyConnectionTypeChanged(long j);
|
|
|
|
private native void nativeNotifyOfActiveNetworkList(long j, NetworkChangeDetector.NetworkInformation[] networkInformationArr);
|
|
|
|
private native void nativeNotifyOfNetworkConnect(long j, NetworkChangeDetector.NetworkInformation networkInformation);
|
|
|
|
private native void nativeNotifyOfNetworkDisconnect(long j, long j2);
|
|
|
|
private native void nativeNotifyOfNetworkPreference(long j, NetworkChangeDetector.ConnectionType connectionType, int i);
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
/* loaded from: classes3.dex */
|
|
public static class InstanceHolder {
|
|
static final NetworkMonitor instance = new NetworkMonitor();
|
|
|
|
private InstanceHolder() {
|
|
}
|
|
}
|
|
|
|
private NetworkMonitor() {
|
|
this.networkChangeDetectorFactory = new NetworkChangeDetectorFactory() { // from class: org.webrtc.NetworkMonitor.1
|
|
@Override // org.webrtc.NetworkChangeDetectorFactory
|
|
public NetworkChangeDetector create(NetworkChangeDetector.Observer observer, Context context) {
|
|
return new NetworkMonitorAutoDetect(observer, context);
|
|
}
|
|
};
|
|
this.networkChangeDetectorLock = new Object();
|
|
this.nativeNetworkObservers = new ArrayList<>();
|
|
this.networkObservers = new ArrayList<>();
|
|
this.numObservers = 0;
|
|
this.currentConnectionType = NetworkChangeDetector.ConnectionType.CONNECTION_UNKNOWN;
|
|
}
|
|
|
|
public void setNetworkChangeDetectorFactory(NetworkChangeDetectorFactory networkChangeDetectorFactory) {
|
|
assertIsTrue(this.numObservers == 0);
|
|
this.networkChangeDetectorFactory = networkChangeDetectorFactory;
|
|
}
|
|
|
|
public static NetworkMonitor getInstance() {
|
|
return InstanceHolder.instance;
|
|
}
|
|
|
|
private static void assertIsTrue(boolean z) {
|
|
if (!z) {
|
|
throw new AssertionError("Expected to be true");
|
|
}
|
|
}
|
|
|
|
public void startMonitoring(Context context) {
|
|
synchronized (this.networkChangeDetectorLock) {
|
|
this.numObservers++;
|
|
if (this.networkChangeDetector == null) {
|
|
this.networkChangeDetector = createNetworkChangeDetector(context);
|
|
}
|
|
this.currentConnectionType = this.networkChangeDetector.getCurrentConnectionType();
|
|
}
|
|
}
|
|
|
|
@Deprecated
|
|
public void startMonitoring() {
|
|
startMonitoring(ContextUtils.getApplicationContext());
|
|
}
|
|
|
|
private void startMonitoring(Context context, long j) {
|
|
Logging.d(TAG, "Start monitoring with native observer " + j);
|
|
if (context == null) {
|
|
context = ContextUtils.getApplicationContext();
|
|
}
|
|
startMonitoring(context);
|
|
synchronized (this.nativeNetworkObservers) {
|
|
this.nativeNetworkObservers.add(Long.valueOf(j));
|
|
}
|
|
updateObserverActiveNetworkList(j);
|
|
notifyObserversOfConnectionTypeChange(this.currentConnectionType);
|
|
}
|
|
|
|
public void stopMonitoring() {
|
|
synchronized (this.networkChangeDetectorLock) {
|
|
int i = this.numObservers - 1;
|
|
this.numObservers = i;
|
|
if (i == 0) {
|
|
this.networkChangeDetector.destroy();
|
|
this.networkChangeDetector = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void stopMonitoring(long j) {
|
|
Logging.d(TAG, "Stop monitoring with native observer " + j);
|
|
stopMonitoring();
|
|
synchronized (this.nativeNetworkObservers) {
|
|
this.nativeNetworkObservers.remove(Long.valueOf(j));
|
|
}
|
|
}
|
|
|
|
private boolean networkBindingSupported() {
|
|
boolean z;
|
|
synchronized (this.networkChangeDetectorLock) {
|
|
NetworkChangeDetector networkChangeDetector = this.networkChangeDetector;
|
|
z = networkChangeDetector != null && networkChangeDetector.supportNetworkCallback();
|
|
}
|
|
return z;
|
|
}
|
|
|
|
private NetworkChangeDetector createNetworkChangeDetector(Context context) {
|
|
return this.networkChangeDetectorFactory.create(new NetworkChangeDetector.Observer() { // from class: org.webrtc.NetworkMonitor.2
|
|
@Override // org.webrtc.NetworkChangeDetector.Observer
|
|
public void onConnectionTypeChanged(NetworkChangeDetector.ConnectionType connectionType) {
|
|
NetworkMonitor.this.updateCurrentConnectionType(connectionType);
|
|
}
|
|
|
|
@Override // org.webrtc.NetworkChangeDetector.Observer
|
|
public void onNetworkConnect(NetworkChangeDetector.NetworkInformation networkInformation) {
|
|
NetworkMonitor.this.notifyObserversOfNetworkConnect(networkInformation);
|
|
}
|
|
|
|
@Override // org.webrtc.NetworkChangeDetector.Observer
|
|
public void onNetworkDisconnect(long j) {
|
|
NetworkMonitor.this.notifyObserversOfNetworkDisconnect(j);
|
|
}
|
|
|
|
@Override // org.webrtc.NetworkChangeDetector.Observer
|
|
public void onNetworkPreference(List<NetworkChangeDetector.ConnectionType> list, int i) {
|
|
NetworkMonitor.this.notifyObserversOfNetworkPreference(list, i);
|
|
}
|
|
}, context);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void updateCurrentConnectionType(NetworkChangeDetector.ConnectionType connectionType) {
|
|
this.currentConnectionType = connectionType;
|
|
notifyObserversOfConnectionTypeChange(connectionType);
|
|
}
|
|
|
|
private void notifyObserversOfConnectionTypeChange(NetworkChangeDetector.ConnectionType connectionType) {
|
|
ArrayList arrayList;
|
|
Iterator<Long> it = getNativeNetworkObserversSync().iterator();
|
|
while (it.hasNext()) {
|
|
nativeNotifyConnectionTypeChanged(it.next().longValue());
|
|
}
|
|
synchronized (this.networkObservers) {
|
|
arrayList = new ArrayList(this.networkObservers);
|
|
}
|
|
Iterator it2 = arrayList.iterator();
|
|
while (it2.hasNext()) {
|
|
((NetworkObserver) it2.next()).onConnectionTypeChanged(connectionType);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void notifyObserversOfNetworkConnect(NetworkChangeDetector.NetworkInformation networkInformation) {
|
|
Iterator<Long> it = getNativeNetworkObserversSync().iterator();
|
|
while (it.hasNext()) {
|
|
nativeNotifyOfNetworkConnect(it.next().longValue(), networkInformation);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void notifyObserversOfNetworkDisconnect(long j) {
|
|
Iterator<Long> it = getNativeNetworkObserversSync().iterator();
|
|
while (it.hasNext()) {
|
|
nativeNotifyOfNetworkDisconnect(it.next().longValue(), j);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void notifyObserversOfNetworkPreference(List<NetworkChangeDetector.ConnectionType> list, int i) {
|
|
List<Long> nativeNetworkObserversSync = getNativeNetworkObserversSync();
|
|
for (NetworkChangeDetector.ConnectionType connectionType : list) {
|
|
Iterator<Long> it = nativeNetworkObserversSync.iterator();
|
|
while (it.hasNext()) {
|
|
nativeNotifyOfNetworkPreference(it.next().longValue(), connectionType, i);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void updateObserverActiveNetworkList(long j) {
|
|
List<NetworkChangeDetector.NetworkInformation> activeNetworkList;
|
|
synchronized (this.networkChangeDetectorLock) {
|
|
NetworkChangeDetector networkChangeDetector = this.networkChangeDetector;
|
|
activeNetworkList = networkChangeDetector == null ? null : networkChangeDetector.getActiveNetworkList();
|
|
}
|
|
if (activeNetworkList == null || activeNetworkList.size() == 0) {
|
|
return;
|
|
}
|
|
nativeNotifyOfActiveNetworkList(j, (NetworkChangeDetector.NetworkInformation[]) activeNetworkList.toArray(new NetworkChangeDetector.NetworkInformation[activeNetworkList.size()]));
|
|
}
|
|
|
|
private List<Long> getNativeNetworkObserversSync() {
|
|
ArrayList arrayList;
|
|
synchronized (this.nativeNetworkObservers) {
|
|
arrayList = new ArrayList(this.nativeNetworkObservers);
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
@Deprecated
|
|
public static void addNetworkObserver(NetworkObserver networkObserver) {
|
|
getInstance().addObserver(networkObserver);
|
|
}
|
|
|
|
public void addObserver(NetworkObserver networkObserver) {
|
|
synchronized (this.networkObservers) {
|
|
this.networkObservers.add(networkObserver);
|
|
}
|
|
}
|
|
|
|
@Deprecated
|
|
public static void removeNetworkObserver(NetworkObserver networkObserver) {
|
|
getInstance().removeObserver(networkObserver);
|
|
}
|
|
|
|
public void removeObserver(NetworkObserver networkObserver) {
|
|
synchronized (this.networkObservers) {
|
|
this.networkObservers.remove(networkObserver);
|
|
}
|
|
}
|
|
|
|
public static boolean isOnline() {
|
|
return getInstance().getCurrentConnectionType() != NetworkChangeDetector.ConnectionType.CONNECTION_NONE;
|
|
}
|
|
|
|
NetworkChangeDetector getNetworkChangeDetector() {
|
|
NetworkChangeDetector networkChangeDetector;
|
|
synchronized (this.networkChangeDetectorLock) {
|
|
networkChangeDetector = this.networkChangeDetector;
|
|
}
|
|
return networkChangeDetector;
|
|
}
|
|
|
|
int getNumObservers() {
|
|
int i;
|
|
synchronized (this.networkChangeDetectorLock) {
|
|
i = this.numObservers;
|
|
}
|
|
return i;
|
|
}
|
|
|
|
static NetworkMonitorAutoDetect createAndSetAutoDetectForTest(Context context) {
|
|
NetworkMonitor networkMonitor = getInstance();
|
|
NetworkChangeDetector createNetworkChangeDetector = networkMonitor.createNetworkChangeDetector(context);
|
|
networkMonitor.networkChangeDetector = createNetworkChangeDetector;
|
|
return (NetworkMonitorAutoDetect) createNetworkChangeDetector;
|
|
}
|
|
}
|