From 299e609756584de1646fb4b378fa2c211a307c99 Mon Sep 17 00:00:00 2001 From: Sam Judd Date: Sat, 18 Nov 2017 17:43:45 -0800 Subject: [PATCH] Catch SecurityException registering receiver in ConnectivityMonitor. Fixes #1417 --- .../glide/manager/DefaultConnectivityMonitor.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/bumptech/glide/manager/DefaultConnectivityMonitor.java b/library/src/main/java/com/bumptech/glide/manager/DefaultConnectivityMonitor.java index 63c569ec04..0065ddc575 100644 --- a/library/src/main/java/com/bumptech/glide/manager/DefaultConnectivityMonitor.java +++ b/library/src/main/java/com/bumptech/glide/manager/DefaultConnectivityMonitor.java @@ -7,6 +7,7 @@ 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; @@ -14,6 +15,7 @@ * 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; @@ -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() {