Bug 895146 - Remove Android Sync support for profile migration. r=rnewman

This commit is contained in:
Nick Alexander 2013-07-18 11:45:09 -07:00
parent b50b560f85
commit 8461a557cb
7 changed files with 7 additions and 260 deletions

View File

@ -1565,10 +1565,6 @@ abstract public class GeckoApp
rec.recordJavaStartupTime(javaDuration);
}
// Sync settings need Gecko to be loaded, so
// no hurry in starting this.
checkMigrateSync();
// Record our launch time for the announcements service
// to use in assessing inactivity.
final Context context = GeckoApp.this;
@ -2262,17 +2258,6 @@ abstract public class GeckoApp
protected void finishProfileMigration() {
}
private void checkMigrateSync() {
final File profileDir = getProfile().getDir();
if (!GeckoApp.sIsUsingCustomProfile && profileDir != null) {
final GeckoApp app = GeckoApp.sAppContext;
ProfileMigrator profileMigrator = new ProfileMigrator(app);
if (!profileMigrator.hasSyncMigrated()) {
profileMigrator.launchSyncPrefs();
}
}
}
public PromptService getPromptService() {
return mPromptService;
}

View File

@ -12,8 +12,6 @@ import org.mozilla.gecko.db.LocalBrowserDB;
import org.mozilla.gecko.mozglue.GeckoLoader;
import org.mozilla.gecko.sqlite.SQLiteBridge;
import org.mozilla.gecko.sqlite.SQLiteBridgeException;
import org.mozilla.gecko.sync.setup.SyncAccounts;
import org.mozilla.gecko.sync.setup.SyncAccounts.SyncAccountParameters;
import org.mozilla.gecko.util.ThreadUtils;
import android.accounts.Account;
@ -76,7 +74,6 @@ public class ProfileMigrator {
private static final String PREFS_MIGRATE_HISTORY_DONE = "history_done";
// Number of history entries already migrated.
private static final String PREFS_MIGRATE_HISTORY_COUNT = "history_count";
private static final String PREFS_MIGRATE_SYNC_DONE = "sync_done";
// Profile has been moved to internal storage?
private static final String PREFS_MIGRATE_MOVE_PROFILE_DONE
@ -268,27 +265,6 @@ public class ProfileMigrator {
private static final String HISTORY_DATE = "h_date";
private static final String HISTORY_VISITS = "h_visits";
/*
Sync settings to get from prefs.js.
*/
private static final String[] SYNC_SETTINGS_LIST = new String[] {
"services.sync.account",
"services.sync.client.name",
"services.sync.client.GUID",
"services.sync.serverURL",
"services.sync.clusterURL"
};
/*
Sync settings to get from password manager.
*/
private static final String SYNC_HOST_NAME = "chrome://weave";
private static final String[] SYNC_REALM_LIST = new String[] {
"Mozilla Services Password",
"Mozilla Services Encryption Passphrase"
};
public ProfileMigrator(Context context) {
mContext = context;
mCr = mContext.getContentResolver();
@ -337,11 +313,6 @@ public class ProfileMigrator {
new PlacesRunnable(profileDir, maxEntries).run();
}
public void launchSyncPrefs() {
// Sync settings will post a runnable, no need for a seperate thread.
new SyncTask().run();
}
public void launchMoveProfile() {
// Make sure the profile is on internal storage.
new MoveProfileTask().run();
@ -364,11 +335,6 @@ public class ProfileMigrator {
return getPreferences().getBoolean(PREFS_MIGRATE_HISTORY_DONE, false);
}
// Have Sync settings been transferred?
public boolean hasSyncMigrated() {
return getPreferences().getBoolean(PREFS_MIGRATE_SYNC_DONE, false);
}
// Has the profile been moved from an SDcard to internal storage?
public boolean isProfileMoved() {
return getPreferences().getBoolean(PREFS_MIGRATE_MOVE_PROFILE_DONE,
@ -423,10 +389,6 @@ public class ProfileMigrator {
setBooleanPrefTrue(PREFS_MIGRATE_BOOKMARKS_DONE);
}
protected void setMigratedSync() {
setBooleanPrefTrue(PREFS_MIGRATE_SYNC_DONE);
}
protected void setMovedProfile() {
setBooleanPrefTrue(PREFS_MIGRATE_MOVE_PROFILE_DONE);
}
@ -543,146 +505,6 @@ public class ProfileMigrator {
}
}
private class SyncTask implements Runnable {
private Map<String, String> mSyncSettingsMap;
protected void requestValues() {
mSyncSettingsMap = new HashMap<String, String>();
PrefsHelper.getPrefs(SYNC_SETTINGS_LIST, new PrefsHelper.PrefHandlerBase() {
@Override public void prefValue(String pref, boolean value) {
mSyncSettingsMap.put(pref, value ? "1" : "0");
}
@Override public void prefValue(String pref, String value) {
if (!TextUtils.isEmpty(value)) {
mSyncSettingsMap.put(pref, value);
} else {
Log.w(LOGTAG, "Could not recover setting for = " + pref);
mSyncSettingsMap.put(pref, null);
}
}
@Override public void finish() {
// Now call the password provider to fill in the rest.
for (String location: SYNC_REALM_LIST) {
Log.d(LOGTAG, "Checking: " + location);
String passwd = getPassword(location);
if (!TextUtils.isEmpty(passwd)) {
Log.d(LOGTAG, "Got password");
mSyncSettingsMap.put(location, passwd);
} else {
Log.d(LOGTAG, "No password found");
mSyncSettingsMap.put(location, null);
}
}
// Call Sync and transfer settings.
configureSync();
}
});
}
protected String getPassword(String realm) {
Cursor cursor = null;
String result = null;
try {
cursor = mCr.query(Passwords.CONTENT_URI,
null,
Passwords.HOSTNAME + " = ? AND "
+ Passwords.HTTP_REALM + " = ?",
new String[] { SYNC_HOST_NAME, realm },
null);
if (cursor != null) {
final int userCol =
cursor.getColumnIndexOrThrow(Passwords.ENCRYPTED_USERNAME);
final int passCol =
cursor.getColumnIndexOrThrow(Passwords.ENCRYPTED_PASSWORD);
if (cursor.moveToFirst()) {
String user = cursor.getString(userCol);
String pass = cursor.getString(passCol);
result = pass;
} else {
Log.i(LOGTAG, "No password found for realm = " + realm);
}
}
} finally {
if (cursor != null)
cursor.close();
}
return result;
}
protected void configureSync() {
final String userName = mSyncSettingsMap.get("services.sync.account");
final String syncKey = mSyncSettingsMap.get("Mozilla Services Encryption Passphrase");
final String syncPass = mSyncSettingsMap.get("Mozilla Services Password");
final String serverURL = mSyncSettingsMap.get("services.sync.serverURL");
final String clusterURL = mSyncSettingsMap.get("services.sync.clusterURL");
final String clientName = mSyncSettingsMap.get("services.sync.client.name");
final String clientGuid = mSyncSettingsMap.get("services.sync.client.GUID");
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
if (userName == null || syncKey == null || syncPass == null) {
// This isn't going to work. Give up.
Log.e(LOGTAG, "Profile has incomplete Sync config. Not migrating.");
setMigratedSync();
return;
}
final SyncAccountParameters params =
new SyncAccountParameters(mContext, null,
userName, syncKey,
syncPass, serverURL, clusterURL,
clientName, clientGuid);
final Account account = SyncAccounts.createSyncAccount(params);
if (account == null) {
Log.e(LOGTAG, "Failed to migrate Sync account.");
} else {
Log.i(LOGTAG, "Migrating Sync account succeeded.");
}
setMigratedSync();
}
});
}
protected void registerAndRequest() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
requestValues();
}
});
}
@Override
public void run() {
// Run only if no Sync accounts exist.
new SyncAccounts.AccountsExistTask() {
@Override
protected void onPostExecute(Boolean result) {
if (result.booleanValue()) {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
Log.i(LOGTAG, "Sync account already configured, skipping.");
setMigratedSync();
}
});
} else {
// No account configured, fire up.
registerAndRequest();
}
}
}.execute(mContext);
}
}
private class MiscTask implements Runnable {
protected void cleanupXULLibCache() {
File cacheFile = GeckoLoader.getCacheDir(mContext);

View File

@ -169,7 +169,6 @@ SYNC_JAVA_FILES := \
sync/repositories/android/CachedSQLiteOpenHelper.java \
sync/repositories/android/ClientsDatabase.java \
sync/repositories/android/ClientsDatabaseAccessor.java \
sync/repositories/android/FennecControlHelper.java \
sync/repositories/android/FennecTabsRepository.java \
sync/repositories/android/FormHistoryRepositorySession.java \
sync/repositories/android/PasswordsRepositorySession.java \

View File

@ -8,13 +8,13 @@ import java.io.File;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import org.mozilla.gecko.background.common.GlobalConstants;
import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.sync.CredentialException;
import org.mozilla.gecko.sync.ExtendedJSONObject;
import org.mozilla.gecko.background.common.GlobalConstants;
import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.sync.SyncConstants;
import org.mozilla.gecko.sync.SyncConfiguration;
import org.mozilla.gecko.sync.SyncConstants;
import org.mozilla.gecko.sync.ThreadPool;
import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.config.AccountPickler;
@ -28,7 +28,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
@ -83,20 +82,6 @@ public class SyncAccounts {
return (account != null);
}
/**
* This class provides background-thread abstracted access to whether a
* Firefox Sync account has been set up on this device.
* <p>
* Subclass this task and override `onPostExecute` to act on the result.
*/
public static class AccountsExistTask extends AsyncTask<Context, Void, Boolean> {
@Override
protected Boolean doInBackground(Context... params) {
Context c = params[0];
return syncAccountsExist(c);
}
}
/**
* This class encapsulates the parameters needed to create a new Firefox Sync
* account.
@ -196,37 +181,6 @@ public class SyncAccounts {
}
}
/**
* This class provides background-thread abstracted access to creating a
* Firefox Sync account.
* <p>
* Subclass this task and override `onPostExecute` to act on the result. The
* <code>Result</code> (of type <code>Account</code>) is null if an error
* occurred and the account could not be added.
*/
public static class CreateSyncAccountTask extends AsyncTask<SyncAccountParameters, Void, Account> {
protected final boolean syncAutomatically;
public CreateSyncAccountTask() {
this(true);
}
public CreateSyncAccountTask(final boolean syncAutomically) {
this.syncAutomatically = syncAutomically;
}
@Override
protected Account doInBackground(SyncAccountParameters... params) {
SyncAccountParameters syncAccount = params[0];
try {
return createSyncAccount(syncAccount, syncAutomatically);
} catch (Exception e) {
Log.e(SyncConstants.GLOBAL_LOG_TAG, "Unable to create account.", e);
return null;
}
}
}
/**
* Create a sync account, clearing any existing preferences, and set it to
* sync automatically.

View File

@ -6,13 +6,11 @@ package org.mozilla.gecko.sync.stage;
import java.net.URISyntaxException;
import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.sync.JSONRecordFetcher;
import org.mozilla.gecko.sync.MetaGlobalException;
import org.mozilla.gecko.sync.repositories.RecordFactory;
import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.android.AndroidBrowserBookmarksRepository;
import org.mozilla.gecko.sync.repositories.android.FennecControlHelper;
import org.mozilla.gecko.sync.repositories.domain.BookmarkRecordFactory;
import org.mozilla.gecko.sync.repositories.domain.VersionConstants;
@ -65,13 +63,9 @@ public class AndroidBrowserBookmarksServerSyncStage extends ServerSyncStage {
@Override
protected boolean isEnabled() throws MetaGlobalException {
if (session.getContext() == null) {
if (session == null || session.getContext() == null) {
return false;
}
boolean migrated = FennecControlHelper.areBookmarksMigrated(session.getContext());
if (!migrated) {
Logger.warn(LOG_TAG, "Not enabling bookmarks engine since Fennec bookmarks are not migrated.");
}
return super.isEnabled() && migrated;
return super.isEnabled();
}
}
}

View File

@ -6,13 +6,11 @@ package org.mozilla.gecko.sync.stage;
import java.net.URISyntaxException;
import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.sync.MetaGlobalException;
import org.mozilla.gecko.sync.repositories.ConstrainedServer11Repository;
import org.mozilla.gecko.sync.repositories.RecordFactory;
import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.android.AndroidBrowserHistoryRepository;
import org.mozilla.gecko.sync.repositories.android.FennecControlHelper;
import org.mozilla.gecko.sync.repositories.domain.HistoryRecordFactory;
import org.mozilla.gecko.sync.repositories.domain.VersionConstants;
@ -64,10 +62,6 @@ public class AndroidBrowserHistoryServerSyncStage extends ServerSyncStage {
if (session == null || session.getContext() == null) {
return false;
}
boolean migrated = FennecControlHelper.isHistoryMigrated(session.getContext());
if (!migrated) {
Logger.warn(LOG_TAG, "Not enabling history engine since Fennec history is not migrated.");
}
return super.isEnabled() && migrated;
return super.isEnabled();
}
}

View File

@ -156,7 +156,6 @@ sync/repositories/android/BrowserContractHelpers.java
sync/repositories/android/CachedSQLiteOpenHelper.java
sync/repositories/android/ClientsDatabase.java
sync/repositories/android/ClientsDatabaseAccessor.java
sync/repositories/android/FennecControlHelper.java
sync/repositories/android/FennecTabsRepository.java
sync/repositories/android/FormHistoryRepositorySession.java
sync/repositories/android/PasswordsRepositorySession.java