Bug 1250782 - Include fxaDeviceId in sync client records. r=mcomella, nalexander
authorEdouard Oger <eoger@fastmail.com>
Wed, 18 May 2016 13:43:10 -0700
changeset 304076 5013e7bb1c9fb049cfeb8546caf5cd504a57114e
parent 304075 2b40afc365695b8ee407c46dea9ea5c89ada8beb
child 304077 5ee8820711c14c560dea339529f8e42d6033a671
push id30411
push userkwierso@gmail.com
push dateFri, 08 Jul 2016 00:26:45 +0000
treeherdermozilla-central@23dc78b7b57e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella, nalexander
bugs1250782
milestone50.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 1250782 - Include fxaDeviceId in sync client records. r=mcomella, nalexander MozReview-Commit-ID: BjTKTN5XX4w
mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/domain/ClientRecord.java
mobile/android/services/src/main/java/org/mozilla/gecko/sync/stage/SyncClientsEngineStage.java
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/domain/ClientRecord.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/domain/ClientRecord.java
@@ -45,16 +45,17 @@ public class ClientRecord extends Record
   // See <https://github.com/mozilla-services/docs/blob/master/source/sync/objectformats.rst#user-content-clients>
   // for full formats.
   // If a value isn't known, the field is omitted.
   public String formfactor;          // "phone", "largetablet", "smalltablet", "desktop", "laptop", "tv".
   public String os;                  // One of "Android", "Darwin", "WINNT", "Linux", "iOS", "Firefox OS".
   public String application;         // Display name, E.g., "Firefox Beta"
   public String appPackage;          // E.g., "org.mozilla.firefox_beta"
   public String device;              // E.g., "HTC One"
+  public String fxaDeviceId;         // E.g., "525b624eaaf1e40d21ec8997c3116ad8"
 
   public ClientRecord(String guid, String collection, long lastModified, boolean deleted) {
     super(guid, collection, lastModified, deleted);
     this.ttl = CLIENTS_TTL;
   }
 
   public ClientRecord(String guid, String collection, long lastModified) {
     this(guid, collection, lastModified, false);
@@ -110,16 +111,20 @@ public class ClientRecord extends Record
 
     if (payload.containsKey("appPackage")) {
       this.appPackage = payload.getString("appPackage");
     }
 
     if (payload.containsKey("device")) {
       this.device = payload.getString("device");
     }
+
+    if (payload.containsKey("fxaDeviceId")) {
+      this.fxaDeviceId = payload.getString("fxaDeviceId");
+    }
   }
 
   @Override
   protected void populatePayload(ExtendedJSONObject payload) {
     putPayload(payload, "id",   this.guid);
     putPayload(payload, "name", this.name);
     putPayload(payload, "type", this.type);
     putPayload(payload, "version", this.version);
@@ -127,17 +132,16 @@ public class ClientRecord extends Record
     if (this.commands != null) {
       payload.put("commands",  this.commands);
     }
 
     if (this.protocols != null) {
       payload.put("protocols",  this.protocols);
     }
 
-
     if (this.formfactor != null) {
       payload.put("formfactor", this.formfactor);
     }
 
     if (this.os != null) {
       payload.put("os", this.os);
     }
 
@@ -147,16 +151,20 @@ public class ClientRecord extends Record
 
     if (this.appPackage != null) {
       payload.put("appPackage", this.appPackage);
     }
 
     if (this.device != null) {
       payload.put("device", this.device);
     }
+
+    if (this.fxaDeviceId != null) {
+      payload.put("fxaDeviceId", this.fxaDeviceId);
+    }
   }
 
   @Override
   public boolean equals(Object o) {
     if (!(o instanceof ClientRecord) || !super.equals(o)) {
       return false;
     }
 
@@ -196,16 +204,17 @@ public class ClientRecord extends Record
     out.version = this.version;
     out.protocols = this.protocols;
 
     out.formfactor = this.formfactor;
     out.os = this.os;
     out.application = this.application;
     out.appPackage = this.appPackage;
     out.device = this.device;
+    out.fxaDeviceId = this.fxaDeviceId;
 
     return out;
   }
 
 /*
 Example record:
 
 {id:"relf31w7B4F1",
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/stage/SyncClientsEngineStage.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/stage/SyncClientsEngineStage.java
@@ -1,25 +1,31 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.sync.stage;
 
+import android.accounts.Account;
+import android.content.Context;
+import android.text.TextUtils;
+
 import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.background.common.log.Logger;
+import org.mozilla.gecko.fxa.FirefoxAccounts;
+import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
 import org.mozilla.gecko.sync.CommandProcessor;
 import org.mozilla.gecko.sync.CommandProcessor.Command;
 import org.mozilla.gecko.sync.CryptoRecord;
 import org.mozilla.gecko.sync.ExtendedJSONObject;
 import org.mozilla.gecko.sync.HTTPFailureException;
 import org.mozilla.gecko.sync.NoCollectionKeysSetException;
 import org.mozilla.gecko.sync.Utils;
 import org.mozilla.gecko.sync.crypto.CryptoException;
@@ -380,16 +386,26 @@ public class SyncClientsEngineStage exte
     r.protocols = getLocalClientProtocols();
 
     r.os = "Android";
     r.application = AppConstants.MOZ_APP_DISPLAYNAME;
     r.appPackage = AppConstants.ANDROID_PACKAGE_NAME;
     r.device = android.os.Build.MODEL;
     r.formfactor = delegate.getFormFactor();
 
+    Context context = session.getContext();
+    final Account account = FirefoxAccounts.getFirefoxAccount(context);
+    if (account != null) {
+      final AndroidFxAccount fxAccount = new AndroidFxAccount(context, account);
+      final String deviceId = fxAccount.getDeviceId();
+      if (!TextUtils.isEmpty(deviceId)) {
+        r.fxaDeviceId = deviceId;
+      }
+    }
+
     return r;
   }
 
   // TODO: Bug 726055 - More considered handling of when to sync.
   protected boolean shouldDownload() {
     // Ask info/collections whether a download is needed.
     return true;
   }