Bug 1287643 - Add Push crypto params to FxAccountDevice. r?nalexander
MozReview-Commit-ID: LFnbpA0zjjj
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/FxAccountDevice.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/FxAccountDevice.java
@@ -7,51 +7,75 @@ package org.mozilla.gecko.fxa;
import org.mozilla.gecko.sync.ExtendedJSONObject;
public class FxAccountDevice {
public static final String JSON_KEY_NAME = "name";
public static final String JSON_KEY_ID = "id";
public static final String JSON_KEY_TYPE = "type";
public static final String JSON_KEY_ISCURRENTDEVICE = "isCurrentDevice";
+ public static final String JSON_KEY_PUSH_CALLBACK = "pushCallback";
+ public static final String JSON_KEY_PUSH_PUBLICKEY = "pushPublicKey";
+ public static final String JSON_KEY_PUSH_AUTHKEY = "pushAuthKey";
- public String id;
- public String name;
- public String type;
- public Boolean isCurrentDevice;
+ public final String id;
+ public final String name;
+ public final String type;
+ public final Boolean isCurrentDevice;
+ public final String pushCallback;
+ public final String pushPublicKey;
+ public final String pushAuthKey;
- public FxAccountDevice(String name, String id, String type, Boolean isCurrentDevice) {
+ public FxAccountDevice(String name, String id, String type, Boolean isCurrentDevice,
+ String pushCallback, String pushPublicKey, String pushAuthKey) {
this.name = name;
this.id = id;
this.type = type;
this.isCurrentDevice = isCurrentDevice;
+ this.pushCallback = pushCallback;
+ this.pushPublicKey = pushPublicKey;
+ this.pushAuthKey = pushAuthKey;
}
- public static FxAccountDevice forRegister(String name, String type) {
- return new FxAccountDevice(name, null, type, null);
+ public static FxAccountDevice forRegister(String name, String type, String pushCallback,
+ String pushPublicKey, String pushAuthKey) {
+ return new FxAccountDevice(name, null, type, null, pushCallback, pushPublicKey, pushAuthKey);
}
- public static FxAccountDevice forUpdate(String id, String name) {
- return new FxAccountDevice(name, id, null, null);
+ public static FxAccountDevice forUpdate(String id, String name, String pushCallback,
+ String pushPublicKey, String pushAuthKey) {
+ return new FxAccountDevice(name, id, null, null, pushCallback, pushPublicKey, pushAuthKey);
}
public static FxAccountDevice fromJson(ExtendedJSONObject json) {
String name = json.getString(JSON_KEY_NAME);
String id = json.getString(JSON_KEY_ID);
String type = json.getString(JSON_KEY_TYPE);
Boolean isCurrentDevice = json.getBoolean(JSON_KEY_ISCURRENTDEVICE);
- return new FxAccountDevice(name, id, type, isCurrentDevice);
+ String pushCallback = json.getString(JSON_KEY_PUSH_CALLBACK);
+ String pushPublicKey = json.getString(JSON_KEY_PUSH_PUBLICKEY);
+ String pushAuthKey = json.getString(JSON_KEY_PUSH_AUTHKEY);
+ return new FxAccountDevice(name, id, type, isCurrentDevice, pushCallback, pushPublicKey, pushAuthKey);
}
public ExtendedJSONObject toJson() {
final ExtendedJSONObject body = new ExtendedJSONObject();
if (this.name != null) {
body.put(JSON_KEY_NAME, this.name);
}
if (this.id != null) {
body.put(JSON_KEY_ID, this.id);
}
if (this.type != null) {
body.put(JSON_KEY_TYPE, this.type);
}
+ if (this.pushCallback != null) {
+ body.put(JSON_KEY_PUSH_CALLBACK, this.pushCallback);
+ }
+ if (this.pushPublicKey != null) {
+ body.put(JSON_KEY_PUSH_PUBLICKEY, this.pushPublicKey);
+ }
+ if (this.pushAuthKey != null) {
+ body.put(JSON_KEY_PUSH_AUTHKEY, this.pushAuthKey);
+ }
return body;
}
}
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/MockFxAccountClient.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/MockFxAccountClient.java
@@ -173,30 +173,33 @@ public class MockFxAccountClient impleme
if (!user.verified) {
handleFailure(requestDelegate, HttpStatus.SC_BAD_REQUEST, FxAccountRemoteError.ATTEMPT_TO_OPERATE_ON_AN_UNVERIFIED_ACCOUNT, "user is unverified");
return;
}
try {
String deviceId = deviceToRegister.id;
if (TextUtils.isEmpty(deviceId)) { // Create
deviceId = UUID.randomUUID().toString();
- FxAccountDevice device = new FxAccountDevice(deviceToRegister.name, deviceId, deviceToRegister.type, null);
- deviceToRegister.id = deviceId;
+ FxAccountDevice device = new FxAccountDevice(deviceToRegister.name, deviceId, deviceToRegister.type, null, null, null, null);
+ requestDelegate.handleSuccess(device);
} else { // Update
FxAccountDevice existingDevice = user.devices.get(deviceId);
if (existingDevice != null) {
+ String deviceName = existingDevice.name;
if (!TextUtils.isEmpty(deviceToRegister.name)) {
- existingDevice.name = deviceToRegister.name;
+ deviceName = deviceToRegister.name;
} // We could also update the other fields..
+ FxAccountDevice device = new FxAccountDevice(deviceName, existingDevice.id, existingDevice.type,
+ existingDevice.isCurrentDevice, existingDevice.pushCallback, existingDevice.pushPublicKey,existingDevice.pushAuthKey);
+ requestDelegate.handleSuccess(device);
} else { // Device unknown
handleFailure(requestDelegate, HttpStatus.SC_BAD_REQUEST, FxAccountRemoteError.UNKNOWN_DEVICE, "device is unknown");
return;
}
}
- requestDelegate.handleSuccess(deviceToRegister);
} catch (Exception e) {
requestDelegate.handleError(e);
}
}
@Override
public void deviceList(byte[] sessionToken, RequestDelegate<FxAccountDevice[]> requestDelegate) {
String email = sessionTokens.get(Utils.byte2Hex(sessionToken));