Initial commit
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
package com.bumptech.glide.manager;
|
||||
|
||||
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 android.util.Log;
|
||||
import com.bumptech.glide.manager.ConnectivityMonitor;
|
||||
import com.bumptech.glide.util.Preconditions;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class DefaultConnectivityMonitor implements ConnectivityMonitor {
|
||||
private final Context a;
|
||||
final ConnectivityMonitor.ConnectivityListener b;
|
||||
boolean c;
|
||||
private boolean d;
|
||||
private final BroadcastReceiver e = new BroadcastReceiver() { // from class: com.bumptech.glide.manager.DefaultConnectivityMonitor.1
|
||||
@Override // android.content.BroadcastReceiver
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
DefaultConnectivityMonitor defaultConnectivityMonitor = DefaultConnectivityMonitor.this;
|
||||
boolean z = defaultConnectivityMonitor.c;
|
||||
defaultConnectivityMonitor.c = defaultConnectivityMonitor.a(context);
|
||||
if (z != DefaultConnectivityMonitor.this.c) {
|
||||
if (Log.isLoggable("ConnectivityMonitor", 3)) {
|
||||
Log.d("ConnectivityMonitor", "connectivity changed, isConnected: " + DefaultConnectivityMonitor.this.c);
|
||||
}
|
||||
DefaultConnectivityMonitor defaultConnectivityMonitor2 = DefaultConnectivityMonitor.this;
|
||||
defaultConnectivityMonitor2.b.a(defaultConnectivityMonitor2.c);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
DefaultConnectivityMonitor(Context context, ConnectivityMonitor.ConnectivityListener connectivityListener) {
|
||||
this.a = context.getApplicationContext();
|
||||
this.b = connectivityListener;
|
||||
}
|
||||
|
||||
private void c() {
|
||||
if (this.d) {
|
||||
return;
|
||||
}
|
||||
this.c = a(this.a);
|
||||
try {
|
||||
this.a.registerReceiver(this.e, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
|
||||
this.d = true;
|
||||
} catch (SecurityException e) {
|
||||
if (Log.isLoggable("ConnectivityMonitor", 5)) {
|
||||
Log.w("ConnectivityMonitor", "Failed to register", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void d() {
|
||||
if (this.d) {
|
||||
this.a.unregisterReceiver(this.e);
|
||||
this.d = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.manager.LifecycleListener
|
||||
public void a() {
|
||||
}
|
||||
|
||||
@SuppressLint({"MissingPermission"})
|
||||
boolean a(Context context) {
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
|
||||
Preconditions.a(connectivityManager);
|
||||
try {
|
||||
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
|
||||
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
|
||||
} catch (RuntimeException e) {
|
||||
if (Log.isLoggable("ConnectivityMonitor", 5)) {
|
||||
Log.w("ConnectivityMonitor", "Failed to determine connectivity status when connectivity changed", e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.manager.LifecycleListener
|
||||
public void b() {
|
||||
d();
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.manager.LifecycleListener
|
||||
public void onStart() {
|
||||
c();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user