Bug 772645 - part 2/2: Make Android Sync account type depend on Fennec shared user ID. r=rnewman

This commit is contained in:
Nick Alexander 2012-07-26 08:47:25 -07:00
Родитель 47cd37d786
Коммит fd23bc31f2
13 изменённых файлов: 45 добавлений и 39 удалений

Просмотреть файл

@ -23,9 +23,6 @@ class SyncPreference extends Preference {
@Override
protected void onClick() {
// Make sure we use the same account type as our bundled version of Sync!
final String accountType = org.mozilla.gecko.sync.setup.Constants.ACCOUNTTYPE_SYNC;
// Show Sync setup if no accounts exist; otherwise, show account settings.
if (SyncAccounts.syncAccountsExist(mContext)) {
SyncAccounts.openSyncSettings(mContext);

Просмотреть файл

@ -12,3 +12,5 @@ SYNC_RES_DRAWABLE_MDPI :=
SYNC_RES_DRAWABLE_HDPI :=
SYNC_RES_LAYOUT := res/layout/sync_account.xml res/layout/sync_list_item.xml res/layout/sync_redirect_to_setup.xml res/layout/sync_send_tab.xml res/layout/sync_setup.xml res/layout/sync_setup_failure.xml res/layout/sync_setup_jpake_waiting.xml res/layout/sync_setup_nointernet.xml res/layout/sync_setup_pair.xml res/layout/sync_setup_success.xml
SYNC_RES_VALUES := res/values/sync_styles.xml
SYNC_RES_XML :=
SYNC_PP_RES_XML := res/xml/sync_syncadapter.xml res/xml/sync_options.xml res/xml/sync_authenticator.xml

Просмотреть файл

@ -1,10 +1,11 @@
#filter substitution
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="org.mozilla.firefox_sync"
android:accountType="@MOZ_ANDROID_SHARED_ACCOUNT_TYPE@"
android:icon="@drawable/icon"
android:smallIcon="@drawable/icon"
android:label="@string/sync_account_label"

Просмотреть файл

@ -6,7 +6,7 @@
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:contentAuthority="@ANDROID_PACKAGE_NAME@.db.browser"
android:accountType="org.mozilla.firefox_sync"
android:accountType="@MOZ_ANDROID_SHARED_ACCOUNT_TYPE@"
android:supportsUploading="true"
android:userVisible="true"
/>

Просмотреть файл

@ -16,4 +16,6 @@ public class GlobalConstants {
" (" + PRODUCT_NAME + ")";
public static final String BROWSER_INTENT_PACKAGE = "@ANDROID_PACKAGE_NAME@";
public static final String BROWSER_INTENT_CLASS = BROWSER_INTENT_PACKAGE + ".App";
public static final String ACCOUNTTYPE_SYNC = "@MOZ_ANDROID_SHARED_ACCOUNT_TYPE@";
}

Просмотреть файл

@ -41,7 +41,8 @@ public class Logger {
final Set<LogWriter> defaultLogWriters = new LinkedHashSet<LogWriter>();
LogWriter log = new AndroidLogWriter();
LogWriter cache = new AndroidLevelCachingLogWriter(log);
LogWriter single = new SingleTagLogWriter(GLOBAL_LOG_TAG, cache);
final String processedPackage = GlobalConstants.BROWSER_INTENT_PACKAGE.replace("org.mozilla.", "");
LogWriter single = new SingleTagLogWriter(processedPackage, new SingleTagLogWriter(GLOBAL_LOG_TAG, cache));
defaultLogWriters.add(single);
return defaultLogWriters;
}

Просмотреть файл

@ -8,7 +8,6 @@ import android.content.Intent;
public class Constants {
// Constants for Firefox Sync SyncAdapter Accounts.
public static final String ACCOUNTTYPE_SYNC = "org.mozilla.firefox_sync";
public static final String OPTION_SYNCKEY = "option.synckey";
public static final String OPTION_USERNAME = "option.username";
public static final String AUTHTOKEN_TYPE_PLAIN = "auth.plain";

Просмотреть файл

@ -8,6 +8,7 @@ import java.io.File;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.sync.ExtendedJSONObject;
import org.mozilla.gecko.sync.GlobalConstants;
import org.mozilla.gecko.sync.Logger;
import org.mozilla.gecko.sync.SyncConfiguration;
import org.mozilla.gecko.sync.Utils;
@ -50,7 +51,7 @@ public class SyncAccounts {
* Do not call this method from the main thread.
*/
public static boolean syncAccountsExist(Context c) {
final boolean accountsExist = AccountManager.get(c).getAccountsByType(Constants.ACCOUNTTYPE_SYNC).length > 0;
final boolean accountsExist = AccountManager.get(c).getAccountsByType(GlobalConstants.ACCOUNTTYPE_SYNC).length > 0;
if (accountsExist) {
return true;
}
@ -286,13 +287,13 @@ public class SyncAccounts {
Logger.info(LOG_TAG, "Setting explicit server URL: " + serverURL);
}
final Account account = new Account(username, Constants.ACCOUNTTYPE_SYNC);
final Account account = new Account(username, GlobalConstants.ACCOUNTTYPE_SYNC);
final Bundle userbundle = new Bundle();
// Add sync key and server URL.
userbundle.putString(Constants.OPTION_SYNCKEY, syncKey);
userbundle.putString(Constants.OPTION_SERVER, serverURL);
Logger.debug(LOG_TAG, "Adding account for " + Constants.ACCOUNTTYPE_SYNC);
Logger.debug(LOG_TAG, "Adding account for " + GlobalConstants.ACCOUNTTYPE_SYNC);
boolean result = false;
try {
result = accountManager.addAccountExplicitly(account, password, userbundle);

Просмотреть файл

@ -7,6 +7,7 @@ package org.mozilla.gecko.sync.setup;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import org.mozilla.gecko.sync.GlobalConstants;
import org.mozilla.gecko.sync.Logger;
import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.config.AccountPickler;
@ -63,7 +64,7 @@ public class SyncAuthenticatorService extends Service {
final Intent intent = new Intent(mContext, SetupSyncActivity.class);
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE,
response);
intent.putExtra("accountType", Constants.ACCOUNTTYPE_SYNC);
intent.putExtra("accountType", GlobalConstants.ACCOUNTTYPE_SYNC);
intent.putExtra(Constants.INTENT_EXTRA_IS_SETUP, true);
final Bundle result = new Bundle();
@ -107,7 +108,7 @@ public class SyncAuthenticatorService extends Service {
final Bundle result = new Bundle();
// This is a Sync account.
result.putString(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNTTYPE_SYNC);
result.putString(AccountManager.KEY_ACCOUNT_TYPE, GlobalConstants.ACCOUNTTYPE_SYNC);
// Server.
String serverURL = am.getUserData(account, Constants.OPTION_SERVER);

Просмотреть файл

@ -7,6 +7,7 @@ package org.mozilla.gecko.sync.setup.activities;
import java.util.Locale;
import org.mozilla.gecko.R;
import org.mozilla.gecko.sync.GlobalConstants;
import org.mozilla.gecko.sync.Logger;
import org.mozilla.gecko.sync.ThreadPool;
import org.mozilla.gecko.sync.setup.Constants;
@ -264,8 +265,8 @@ public class AccountActivity extends AccountAuthenticatorActivity {
Bundle resultBundle = new Bundle();
resultBundle.putString(AccountManager.KEY_ACCOUNT_NAME, syncAccount.username);
resultBundle.putString(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNTTYPE_SYNC);
resultBundle.putString(AccountManager.KEY_AUTHTOKEN, Constants.ACCOUNTTYPE_SYNC);
resultBundle.putString(AccountManager.KEY_ACCOUNT_TYPE, GlobalConstants.ACCOUNTTYPE_SYNC);
resultBundle.putString(AccountManager.KEY_AUTHTOKEN, GlobalConstants.ACCOUNTTYPE_SYNC);
setAccountAuthenticatorResult(resultBundle);
setResult(RESULT_OK);

Просмотреть файл

@ -9,6 +9,7 @@ import java.util.List;
import org.mozilla.gecko.R;
import org.mozilla.gecko.sync.CommandProcessor;
import org.mozilla.gecko.sync.CommandRunner;
import org.mozilla.gecko.sync.GlobalConstants;
import org.mozilla.gecko.sync.GlobalSession;
import org.mozilla.gecko.sync.Logger;
import org.mozilla.gecko.sync.repositories.NullCursorException;
@ -87,7 +88,7 @@ public class SendTabActivity extends Activity {
private void redirectIfNoSyncAccount() {
accountManager = AccountManager.get(getApplicationContext());
Account[] accts = accountManager.getAccountsByType(Constants.ACCOUNTTYPE_SYNC);
Account[] accts = accountManager.getAccountsByType(GlobalConstants.ACCOUNTTYPE_SYNC);
// A Sync account exists.
if (accts.length > 0) {

Просмотреть файл

@ -8,6 +8,7 @@ import java.util.HashMap;
import org.json.simple.JSONObject;
import org.mozilla.gecko.R;
import org.mozilla.gecko.sync.GlobalConstants;
import org.mozilla.gecko.sync.Logger;
import org.mozilla.gecko.sync.ThreadPool;
import org.mozilla.gecko.sync.jpake.JPakeClient;
@ -99,7 +100,7 @@ public class SetupSyncActivity extends AccountAuthenticatorActivity {
ThreadPool.run(new Runnable() {
@Override
public void run() {
Account[] accts = mAccountManager.getAccountsByType(Constants.ACCOUNTTYPE_SYNC);
Account[] accts = mAccountManager.getAccountsByType(GlobalConstants.ACCOUNTTYPE_SYNC);
finishResume(accts);
}
});
@ -337,7 +338,7 @@ public class SetupSyncActivity extends AccountAuthenticatorActivity {
*/
public void onPaired() {
// Extract Sync account data.
Account[] accts = mAccountManager.getAccountsByType(Constants.ACCOUNTTYPE_SYNC);
Account[] accts = mAccountManager.getAccountsByType(GlobalConstants.ACCOUNTTYPE_SYNC);
if (accts.length == 0) {
// Error, no account present.
Logger.error(LOG_TAG, "No accounts present.");
@ -421,8 +422,8 @@ public class SetupSyncActivity extends AccountAuthenticatorActivity {
if (isSuccess) {
Bundle resultBundle = new Bundle();
resultBundle.putString(AccountManager.KEY_ACCOUNT_NAME, syncAccount.username);
resultBundle.putString(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNTTYPE_SYNC);
resultBundle.putString(AccountManager.KEY_AUTHTOKEN, Constants.ACCOUNTTYPE_SYNC);
resultBundle.putString(AccountManager.KEY_ACCOUNT_TYPE, GlobalConstants.ACCOUNTTYPE_SYNC);
resultBundle.putString(AccountManager.KEY_AUTHTOKEN, GlobalConstants.ACCOUNTTYPE_SYNC);
setAccountAuthenticatorResult(resultBundle);
}
displayResultAndFinish(isSuccess);

Просмотреть файл

@ -49,7 +49,6 @@ import android.database.sqlite.SQLiteConstraintException;
import android.database.sqlite.SQLiteException;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSessionCallback, ClientsDataDelegate {
private static final String LOG_TAG = "SyncAdapter";
@ -126,32 +125,32 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe
setShouldInvalidateAuthToken();
try {
if (e instanceof SQLiteConstraintException) {
Log.e(LOG_TAG, "Constraint exception. Aborting sync.", e);
Logger.error(LOG_TAG, "Constraint exception. Aborting sync.", e);
syncResult.stats.numParseExceptions++; // This is as good as we can do.
return;
}
if (e instanceof SQLiteException) {
Log.e(LOG_TAG, "Couldn't open database (locked?). Aborting sync.", e);
Logger.error(LOG_TAG, "Couldn't open database (locked?). Aborting sync.", e);
syncResult.stats.numIoExceptions++;
return;
}
if (e instanceof OperationCanceledException) {
Log.e(LOG_TAG, "Operation canceled. Aborting sync.", e);
Logger.error(LOG_TAG, "Operation canceled. Aborting sync.", e);
return;
}
if (e instanceof AuthenticatorException) {
syncResult.stats.numParseExceptions++;
Log.e(LOG_TAG, "AuthenticatorException. Aborting sync.", e);
Logger.error(LOG_TAG, "AuthenticatorException. Aborting sync.", e);
return;
}
if (e instanceof IOException) {
syncResult.stats.numIoExceptions++;
Log.e(LOG_TAG, "IOException. Aborting sync.", e);
Logger.error(LOG_TAG, "IOException. Aborting sync.", e);
e.printStackTrace();
return;
}
syncResult.stats.numIoExceptions++;
Log.e(LOG_TAG, "Unknown exception. Aborting sync.", e);
Logger.error(LOG_TAG, "Unknown exception. Aborting sync.", e);
} finally {
notifyMonitor();
}
@ -168,7 +167,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe
String token;
try {
token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN);
mAccountManager.invalidateAuthToken(Constants.ACCOUNTTYPE_SYNC, token);
mAccountManager.invalidateAuthToken(GlobalConstants.ACCOUNTTYPE_SYNC, token);
} catch (Exception e) {
Logger.error(LOG_TAG, "Couldn't invalidate auth token: " + e);
}
@ -263,7 +262,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe
this.syncResult = syncResult;
this.localAccount = account;
Log.i(LOG_TAG,
Logger.info(LOG_TAG,
"Syncing account named " + account.name +
" for client named '" + getClientName() +
"' with client guid " + getAccountGUID() +
@ -273,9 +272,9 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe
long delay = delayMilliseconds();
if (delay > 0) {
if (thisSyncIsForced) {
Log.i(LOG_TAG, "Forced sync: overruling remaining backoff of " + delay + "ms.");
Logger.info(LOG_TAG, "Forced sync: overruling remaining backoff of " + delay + "ms.");
} else {
Log.i(LOG_TAG, "Not syncing: must wait another " + delay + "ms.");
Logger.info(LOG_TAG, "Not syncing: must wait another " + delay + "ms.");
long remainingSeconds = delay / 1000;
syncResult.delayUntil = remainingSeconds + BACKOFF_PAD_SECONDS;
return;
@ -299,7 +298,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe
try {
Bundle bundle = future.getResult(60L, TimeUnit.SECONDS);
if (bundle.containsKey("KEY_INTENT")) {
Log.w(LOG_TAG, "KEY_INTENT included in AccountManagerFuture bundle. Problem?");
Logger.warn(LOG_TAG, "KEY_INTENT included in AccountManagerFuture bundle. Problem?");
}
String username = bundle.getString(Constants.OPTION_USERNAME);
String syncKey = bundle.getString(Constants.OPTION_SYNCKEY);
@ -332,14 +331,14 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe
// Now catch the individual cases.
if (password == null) {
Log.e(LOG_TAG, "No password: aborting sync.");
Logger.error(LOG_TAG, "No password: aborting sync.");
syncResult.stats.numAuthExceptions++;
notifyMonitor();
return;
}
if (syncKey == null) {
Log.e(LOG_TAG, "No Sync Key: aborting sync.");
Logger.error(LOG_TAG, "No Sync Key: aborting sync.");
syncResult.stats.numAuthExceptions++;
notifyMonitor();
return;
@ -379,11 +378,11 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe
syncMonitor.wait();
long interval = getSyncInterval();
long next = System.currentTimeMillis() + interval;
Log.i(LOG_TAG, "Setting minimum next sync time to " + next + " (" + interval + "ms from now).");
Logger.info(LOG_TAG, "Setting minimum next sync time to " + next + " (" + interval + "ms from now).");
extendEarliestNextSync(next);
Log.i(LOG_TAG, "Sync took " + Utils.formatDuration(syncStartTimestamp, System.currentTimeMillis()) + ".");
Logger.info(LOG_TAG, "Sync took " + Utils.formatDuration(syncStartTimestamp, System.currentTimeMillis()) + ".");
} catch (InterruptedException e) {
Log.w(LOG_TAG, "Waiting on sync monitor interrupted.", e);
Logger.warn(LOG_TAG, "Waiting on sync monitor interrupted.", e);
} finally {
// And we're done with HTTP stuff.
stale.shutdown();
@ -489,7 +488,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe
// Implementing GlobalSession callbacks.
@Override
public void handleError(GlobalSession globalSession, Exception ex) {
Log.i(LOG_TAG, "GlobalSession indicated error. Flagging auth token as invalid, just in case.");
Logger.info(LOG_TAG, "GlobalSession indicated error. Flagging auth token as invalid, just in case.");
setShouldInvalidateAuthToken();
this.updateStats(globalSession, ex);
notifyMonitor();
@ -497,7 +496,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe
@Override
public void handleAborted(GlobalSession globalSession, String reason) {
Log.w(LOG_TAG, "Sync aborted: " + reason);
Logger.warn(LOG_TAG, "Sync aborted: " + reason);
notifyMonitor();
}
@ -519,7 +518,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe
@Override
public void handleSuccess(GlobalSession globalSession) {
Log.i(LOG_TAG, "GlobalSession indicated success.");
Logger.info(LOG_TAG, "GlobalSession indicated success.");
Logger.debug(LOG_TAG, "Prefs target: " + globalSession.config.prefsPath);
globalSession.config.persistToPrefs();
notifyMonitor();