Skip to content

Commit

Permalink
Catch SecurityException registering receiver in ConnectivityMonitor.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjudd committed Nov 19, 2017
1 parent b227776 commit 299e609
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import com.bumptech.glide.util.Preconditions;
import com.bumptech.glide.util.Synthetic;

/**
* Uses {@link android.net.ConnectivityManager} to identify connectivity changes.
*/
class DefaultConnectivityMonitor implements ConnectivityMonitor {
private static final String TAG = "ConnectivityMonitor";
private final Context context;
@SuppressWarnings("WeakerAccess") @Synthetic final ConnectivityListener listener;

Expand Down Expand Up @@ -44,9 +46,16 @@ private void register() {
}

isConnected = isConnected(context);
context.registerReceiver(connectivityReceiver,
new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
isRegistered = true;
try {
context.registerReceiver(connectivityReceiver,
new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
isRegistered = true;
} catch (SecurityException e) {
// See #1417.
if (Log.isLoggable(TAG, Log.WARN)) {
Log.w(TAG, "Failed to register", e);
}
}
}

private void unregister() {
Expand Down

0 comments on commit 299e609

Please sign in to comment.