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
--- 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