Backed out changeset 53e599ac1ed7 (bug 1359279) for android linting failure. r=backout

This commit is contained in:
Sebastian Hengst 2017-09-21 00:07:06 +02:00
parent b98981f4a0
commit 8d0a582563
6 changed files with 14 additions and 90 deletions

View File

@ -15,8 +15,7 @@ public class FxAccountDevice {
private static final String JSON_KEY_PUSH_CALLBACK = "pushCallback";
private static final String JSON_KEY_PUSH_PUBLICKEY = "pushPublicKey";
private static final String JSON_KEY_PUSH_AUTHKEY = "pushAuthKey";
private static final String JSON_KEY_LAST_ACCESS_TIME = "lastAccessTime";
private static final String JSON_KEY_PUSH_ENDPOINT_EXPIRED = "pushEndpointExpired";
private static final String JSON_LAST_ACCESS_TIME = "lastAccessTime";
public final String id;
public final String name;
@ -26,11 +25,10 @@ public class FxAccountDevice {
public final String pushCallback;
public final String pushPublicKey;
public final String pushAuthKey;
public final Boolean pushEndpointExpired;
public FxAccountDevice(String name, String id, String type, Boolean isCurrentDevice,
Long lastAccessTime, String pushCallback, String pushPublicKey,
String pushAuthKey, Boolean pushEndpointExpired) {
String pushAuthKey) {
this.name = name;
this.id = id;
this.type = type;
@ -39,7 +37,6 @@ public class FxAccountDevice {
this.pushCallback = pushCallback;
this.pushPublicKey = pushPublicKey;
this.pushAuthKey = pushAuthKey;
this.pushEndpointExpired = pushEndpointExpired;
}
public static FxAccountDevice fromJson(ExtendedJSONObject json) {
@ -47,24 +44,12 @@ public class FxAccountDevice {
final String id = json.getString(JSON_KEY_ID);
final String type = json.getString(JSON_KEY_TYPE);
final Boolean isCurrentDevice = json.getBoolean(JSON_KEY_ISCURRENTDEVICE);
final Long lastAccessTime = json.getLong(JSON_KEY_LAST_ACCESS_TIME);
final Long lastAccessTime = json.getLong(JSON_LAST_ACCESS_TIME);
final String pushCallback = json.getString(JSON_KEY_PUSH_CALLBACK);
final String pushPublicKey = json.getString(JSON_KEY_PUSH_PUBLICKEY);
final String pushAuthKey = json.getString(JSON_KEY_PUSH_AUTHKEY);
// The FxA server sends this boolean as a number (bug):
// https://github.com/mozilla/fxa-auth-server/pull/2122
// Use getBoolean directly once the fix is deployed (probably ~Oct-Nov 2017).
final Object pushEndpointExpiredRaw = json.get(JSON_KEY_PUSH_ENDPOINT_EXPIRED);
final Boolean pushEndpointExpired;
if (pushEndpointExpiredRaw instanceof Number) {
pushEndpointExpired = ((Number) pushEndpointExpiredRaw).intValue() == 1;
} else if (pushEndpointExpiredRaw instanceof Boolean) {
pushEndpointExpired = (Boolean) pushEndpointExpiredRaw;
} else {
pushEndpointExpired = false;
}
return new FxAccountDevice(name, id, type, isCurrentDevice, lastAccessTime, pushCallback,
pushPublicKey, pushAuthKey, pushEndpointExpired);
pushPublicKey, pushAuthKey);
}
public ExtendedJSONObject toJson() {
@ -124,7 +109,7 @@ public class FxAccountDevice {
public FxAccountDevice build() {
return new FxAccountDevice(this.name, this.id, this.type, null, null,
this.pushCallback, this.pushPublicKey, this.pushAuthKey, null);
this.pushCallback, this.pushPublicKey, this.pushAuthKey);
}
}
}

View File

@ -6,8 +6,6 @@ package org.mozilla.gecko.fxa.devices;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
@ -21,12 +19,7 @@ import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.BrowserContract.RemoteDevices;
import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
import org.mozilla.gecko.fxa.login.State;
import org.mozilla.gecko.util.ThreadUtils;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.GeneralSecurityException;
import java.util.concurrent.Executor;
public class FxAccountDeviceListUpdater implements FxAccountClient20.RequestDelegate<FxAccountDevice[]> {
@ -34,10 +27,6 @@ public class FxAccountDeviceListUpdater implements FxAccountClient20.RequestDele
private final AndroidFxAccount fxAccount;
private final ContentResolver contentResolver;
private boolean localDevicePushEndpointExpired = false;
private final static String SYNC_PREFS_PUSH_LAST_RENEW_REGISTRATION_MS = "push.lastRenewRegistration";
private final static long TIME_BETWEEN_RENEW_REGISTRATION_MS = 2 * 7 * 24 * 3600 * 1000;
public FxAccountDeviceListUpdater(final AndroidFxAccount fxAccount, final ContentResolver cr) {
this.fxAccount = fxAccount;
@ -57,9 +46,6 @@ public class FxAccountDeviceListUpdater implements FxAccountClient20.RequestDele
final long now = System.currentTimeMillis();
for (int i = 0; i < result.length; i++) {
final FxAccountDevice fxADevice = result[i];
if (fxADevice.isCurrentDevice && fxADevice.pushEndpointExpired) {
this.localDevicePushEndpointExpired = true;
}
final ContentValues deviceValues = new ContentValues();
deviceValues.put(RemoteDevices.GUID, fxADevice.id);
deviceValues.put(RemoteDevices.TYPE, fxADevice.type);
@ -67,7 +53,9 @@ public class FxAccountDeviceListUpdater implements FxAccountClient20.RequestDele
deviceValues.put(RemoteDevices.IS_CURRENT_DEVICE, fxADevice.isCurrentDevice);
deviceValues.put(RemoteDevices.DATE_CREATED, now);
deviceValues.put(RemoteDevices.DATE_MODIFIED, now);
deviceValues.put(RemoteDevices.LAST_ACCESS_TIME, fxADevice.lastAccessTime);
// TODO: Remove that line once FxA sends lastAccessTime all the time.
final Long lastAccessTime = fxADevice.lastAccessTime != null ? fxADevice.lastAccessTime : 0;
deviceValues.put(RemoteDevices.LAST_ACCESS_TIME, lastAccessTime);
insertValues[i] = deviceValues;
}
valuesBundle.putParcelableArray(BrowserContract.METHOD_PARAM_DATA, insertValues);
@ -120,53 +108,4 @@ public class FxAccountDeviceListUpdater implements FxAccountClient20.RequestDele
final FxAccountClient fxaClient = getSynchronousFxaClient();
fxaClient.deviceList(sessionToken, this);
}
// Updates the list of remote devices, and also renews our push registration if the list provider
// tells us it's expired.
public void updateAndMaybeRenewRegistration(final Context context) {
// Synchronous operation, the re-registration will happen right after the refresh if necessary.
this.update();
if (!this.localDevicePushEndpointExpired) {
return;
}
final SharedPreferences syncPrefs;
try {
syncPrefs = fxAccount.getSyncPrefs();
} catch (UnsupportedEncodingException | GeneralSecurityException e) {
Log.e(LOG_TAG, "Could not get sync preferences, skipping push endpoint re-registration.");
return;
}
final long lastTryMs = syncPrefs.getLong(SYNC_PREFS_PUSH_LAST_RENEW_REGISTRATION_MS, 0);
final long nowMs = System.currentTimeMillis();
if (nowMs - lastTryMs < TIME_BETWEEN_RENEW_REGISTRATION_MS) {
Log.w(LOG_TAG, "Last renew registration too close, skipping.");
return;
}
final SharedPreferences.Editor syncPrefsEditor = syncPrefs.edit();
syncPrefsEditor.putLong(SYNC_PREFS_PUSH_LAST_RENEW_REGISTRATION_MS, nowMs);
syncPrefsEditor.commit();
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
try {
FxAccountDeviceListUpdater.this.renewPushRegistration(context);
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
Log.e(LOG_TAG, "Could not renew push registration, continuing anyway", e);
}
FxAccountDeviceRegistrator.renewRegistration(context);
}
});
}
private void renewPushRegistration(Context context) throws ClassNotFoundException, NoSuchMethodException,
InvocationTargetException, IllegalAccessException {
final Class<?> pushService = Class.forName("org.mozilla.gecko.push.PushService");
final Method getInstance = pushService.getMethod("getInstance", Context.class);
final Object instance = getInstance.invoke(null, context);
final Method onRefresh = pushService.getMethod("onRefresh");
onRefresh.invoke(instance);
}
}

View File

@ -380,7 +380,7 @@ public class FxAccountDeviceRegistrator implements BundleEventListener {
final FxAccountDevice updatedDevice = new FxAccountDevice(device.name, fxaDevice.id, device.type,
null, null,
device.pushCallback, device.pushPublicKey,
device.pushAuthKey, null);
device.pushAuthKey);
doFxaRegistration(context, fxAccount, updatedDevice, false);
return;
}

View File

@ -484,7 +484,7 @@ public class FxAccountSyncAdapter extends AbstractThreadedSyncAdapter {
FxAccountDeviceListUpdater deviceListUpdater = new FxAccountDeviceListUpdater(fxAccount, context.getContentResolver());
// Since the clients stage requires a fresh list of remote devices, we update the device list synchronously.
deviceListUpdater.updateAndMaybeRenewRegistration(context);
deviceListUpdater.update();
}
/**

View File

@ -81,9 +81,9 @@ public class TestFxAccountDeviceListUpdater {
public void testSuccessHandler() throws Throwable {
FxAccountDevice[] result = new FxAccountDevice[2];
FxAccountDevice device1 = new FxAccountDevice("Current device", "deviceid1", "mobile", true, System.currentTimeMillis(),
"https://localhost/push/callback1", "abc123", "321cba", false);
"https://localhost/push/callback1", "abc123", "321cba");
FxAccountDevice device2 = new FxAccountDevice("Desktop PC", "deviceid2", "desktop", true, System.currentTimeMillis(),
"https://localhost/push/callback2", "abc123", "321cba", false);
"https://localhost/push/callback2", "abc123", "321cba");
result[0] = device1;
result[1] = device2;

View File

@ -180,7 +180,7 @@ public class MockFxAccountClient implements FxAccountClient {
String deviceId = deviceToRegister.id;
if (TextUtils.isEmpty(deviceId)) { // Create
deviceId = UUID.randomUUID().toString();
FxAccountDevice device = new FxAccountDevice(deviceToRegister.name, deviceId, deviceToRegister.type, null, null, null, null, null, false);
FxAccountDevice device = new FxAccountDevice(deviceToRegister.name, deviceId, deviceToRegister.type, null, null, null, null, null);
requestDelegate.handleSuccess(device);
} else { // Update
FxAccountDevice existingDevice = user.devices.get(deviceId);
@ -190,7 +190,7 @@ public class MockFxAccountClient implements FxAccountClient {
deviceName = deviceToRegister.name;
} // We could also update the other fields..
FxAccountDevice device = new FxAccountDevice(deviceName, existingDevice.id, existingDevice.type, existingDevice.isCurrentDevice,
existingDevice.lastAccessTime, existingDevice.pushCallback, existingDevice.pushPublicKey,existingDevice.pushAuthKey, false);
existingDevice.lastAccessTime, existingDevice.pushCallback, existingDevice.pushPublicKey,existingDevice.pushAuthKey);
requestDelegate.handleSuccess(device);
} else { // Device unknown
handleFailure(requestDelegate, HttpStatus.SC_BAD_REQUEST, FxAccountRemoteError.UNKNOWN_DEVICE, "device is unknown");