Bug 1335110 - Catch security exceptions while getting a GCM token to fail gracefully r=eoger draft
authorGrigory Kruglov <gkruglov@mozilla.com>
Fri, 08 Sep 2017 13:56:31 -0400
changeset 661530 fab5546108b8da29b3b2e3c8ee02e6459e6fc6dc
parent 661528 6d0288c291650ab619dc4ff92cb0b60e3b6e7b3b
child 730618 0e8529d4923d859a2a02dbc1d5e84c4b3487407f
push id78812
push userbmo:gkruglov@mozilla.com
push dateFri, 08 Sep 2017 17:57:07 +0000
reviewerseoger
bugs1335110
milestone57.0a1
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