Bug 1335110 - Catch security exceptions while getting a GCM token to fail gracefully r=eoger
authorGrigory Kruglov <gkruglov@mozilla.com>
Fri, 08 Sep 2017 13:56:31 -0400
changeset 379774 33804f5a3451b67020f421f6d0722c6c7df3ce6b
parent 379773 e5e5c095a5eb86fea7ebe6aa28d566b794cf4c51
child 379775 bc6fec121cc69d7c8b971037ad6cabea1e3d2040
push id50794
push usergkruglov@mozilla.com
push dateFri, 08 Sep 2017 18:09:15 +0000
treeherderautoland@33804f5a3451 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerseoger
bugs1335110
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1335110 - Catch security exceptions while getting a GCM token to fail gracefully r=eoger Exception handling upstream is already in place, and will ensure that we degrade gracefully. Push won't work, but we won't crash either. MozReview-Commit-ID: EfDNoJu46zg
mobile/android/base/java/org/mozilla/gecko/gcm/GcmTokenClient.java
--- a/mobile/android/base/java/org/mozilla/gecko/gcm/GcmTokenClient.java
+++ b/mobile/android/base/java/org/mozilla/gecko/gcm/GcmTokenClient.java
@@ -79,17 +79,23 @@ public class GcmTokenClient {
                 Log.i(LOG_TAG, "Cached GCM token exists.");
             }
             return new Fetched(token, timestamp);
         }
 
         Log.i(LOG_TAG, "Cached GCM token does not exist; requesting new token with sender ID: " + senderID);
 
         final InstanceID instanceID = InstanceID.getInstance(context);
-        token = instanceID.getToken(senderID, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
+        try {
+            token = instanceID.getToken(senderID, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
+        } catch (SecurityException e) {
+            // Degrade gracefully (see upstream exception handling) if we couldn't get the token.
+            // See Bug 1335110.
+            throw new IOException("Could not get token due to a security exception", e);
+        }
         timestamp = System.currentTimeMillis();
 
         if (debug) {
             Log.i(LOG_TAG, "Got fresh GCM token; caching: " + token);
         } else {
             Log.i(LOG_TAG, "Got fresh GCM token; caching.");
         }
         sharedPrefs