Bug 1497977 p3 - Retry a device registration immediately after recovering from a unknown device error. r=nalexander
authorEdouard Oger <eoger@fastmail.com>
Wed, 17 Oct 2018 18:23:07 +0000
changeset 497556 5238702906f63d95d2fae62f33aa53cb61de7e49
parent 497555 e720c16aa7c6da10135d26da34cd4030b2c83713
child 497557 ea10b0217cec23ce84efefcf437e9a81c33e31fd
push id9996
push userarchaeopteryx@coole-files.de
push dateThu, 18 Oct 2018 18:37:15 +0000
treeherdermozilla-beta@8efe26839243 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs1497977
milestone64.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 1497977 p3 - Retry a device registration immediately after recovering from a unknown device error. r=nalexander Depends on D8607 Differential Revision: https://phabricator.services.mozilla.com/D8609
mobile/android/services/src/main/java/org/mozilla/gecko/fxa/devices/FxAccountDeviceRegistrator.java
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/devices/FxAccountDeviceRegistrator.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/devices/FxAccountDeviceRegistrator.java
@@ -216,26 +216,25 @@ public class FxAccountDeviceRegistrator 
       @Override
       public void handleFailure(FxAccountClientRemoteException error) {
         Log.e(LOG_TAG, "Error while updating a device registration: ", error);
 
         fxAccount.setDeviceRegistrationTimestamp(0L);
 
         if (error.httpStatusCode == 400) {
           if (error.apiErrorNumber == FxAccountRemoteError.UNKNOWN_DEVICE) {
-            recoverFromUnknownDevice(fxAccount);
+            recoverFromUnknownDevice(context, fxAccount, device);
           } else if (error.apiErrorNumber == FxAccountRemoteError.DEVICE_SESSION_CONFLICT) {
             // This can happen if a device was already registered using our session token, and we
             // tried to create a new one (no id field).
             recoverFromDeviceSessionConflict(error, fxAccountClient, sessionToken, fxAccount, device,
                     context, allowRecursion);
           }
-        } else
-        if (error.httpStatusCode == 401
-                && error.apiErrorNumber == FxAccountRemoteError.INVALID_AUTHENTICATION_TOKEN) {
+        } else if (error.httpStatusCode == 401
+                   && error.apiErrorNumber == FxAccountRemoteError.INVALID_AUTHENTICATION_TOKEN) {
           handleTokenError(error, fxAccountClient, fxAccount);
         } else {
           logErrorAndResetDeviceRegistrationVersionAndTimestamp(error, fxAccount);
         }
       }
 
       @Override
       public void handleSuccess(FxAccountDevice result) {
@@ -325,19 +324,25 @@ public class FxAccountDeviceRegistrator 
           return;
         }
         Log.e(LOG_TAG, "sessionToken invalid");
         fxAccount.setState(doghouseState);
       }
     });
   }
 
-  private static void recoverFromUnknownDevice(final AndroidFxAccount fxAccount) {
+  private static void recoverFromUnknownDevice(final Context context, final AndroidFxAccount fxAccount, final FxAccountDevice device) {
     Log.i(LOG_TAG, "unknown device id, clearing the cached device id");
     fxAccount.setDeviceId(null);
+    // Same device but without a device ID.
+    final FxAccountDevice newDevice = new FxAccountDevice(device.name, null, device.type,
+            null, null,
+            device.pushCallback, device.pushPublicKey,
+            device.pushAuthKey, null);
+    doFxaRegistration(context, fxAccount, newDevice, true);
   }
 
   /**
    * Will call delegate#complete in all cases
    */
   private static void recoverFromDeviceSessionConflict(final FxAccountClientRemoteException error,
                                                        final FxAccountClient fxAccountClient,
                                                        final byte[] sessionToken,