Bug 983856 - Message when syncing is disabled by Android. r=rnewman

This commit is contained in:
Nick Alexander 2014-03-26 22:11:05 -07:00
Родитель 4e04effddf
Коммит 0108f912d1
7 изменённых файлов: 106 добавлений и 30 удалений

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

@ -51,6 +51,8 @@ public class FxAccountStatusFragment extends PreferenceFragment implements OnPre
protected Preference needsPasswordPreference;
protected Preference needsUpgradePreference;
protected Preference needsVerificationPreference;
protected Preference needsMasterSyncAutomaticallyEnabledPreference;
protected Preference needsAccountEnabledPreference;
protected PreferenceCategory syncCategory;
@ -87,6 +89,8 @@ public class FxAccountStatusFragment extends PreferenceFragment implements OnPre
needsPasswordPreference = ensureFindPreference("needs_credentials");
needsUpgradePreference = ensureFindPreference("needs_upgrade");
needsVerificationPreference = ensureFindPreference("needs_verification");
needsMasterSyncAutomaticallyEnabledPreference = ensureFindPreference("needs_master_sync_automatically_enabled");
needsAccountEnabledPreference = ensureFindPreference("needs_account_enabled");
syncCategory = (PreferenceCategory) ensureFindPreference("sync_category");
@ -103,6 +107,7 @@ public class FxAccountStatusFragment extends PreferenceFragment implements OnPre
needsPasswordPreference.setOnPreferenceClickListener(this);
needsVerificationPreference.setOnPreferenceClickListener(this);
needsAccountEnabledPreference.setOnPreferenceClickListener(this);
bookmarksPreference.setOnPreferenceClickListener(this);
historyPreference.setOnPreferenceClickListener(this);
@ -143,6 +148,13 @@ public class FxAccountStatusFragment extends PreferenceFragment implements OnPre
return true;
}
if (preference == needsAccountEnabledPreference) {
fxAccount.enableSyncing();
refresh();
return true;
}
if (preference == bookmarksPreference ||
preference == historyPreference ||
preference == passwordsPreference ||
@ -171,7 +183,10 @@ public class FxAccountStatusFragment extends PreferenceFragment implements OnPre
final Preference[] errorPreferences = new Preference[] {
this.needsPasswordPreference,
this.needsUpgradePreference,
this.needsVerificationPreference };
this.needsVerificationPreference,
this.needsMasterSyncAutomaticallyEnabledPreference,
this.needsAccountEnabledPreference,
};
for (Preference errorPreference : errorPreferences) {
final boolean currentlyShown = null != findPreference(errorPreference.getKey());
final boolean shouldBeShown = errorPreference == errorPreferenceToShow;
@ -204,6 +219,18 @@ public class FxAccountStatusFragment extends PreferenceFragment implements OnPre
setCheckboxesEnabled(false);
}
protected void showNeedsMasterSyncAutomaticallyEnabled() {
syncCategory.setTitle(R.string.fxaccount_status_sync);
showOnlyOneErrorPreference(needsMasterSyncAutomaticallyEnabledPreference);
setCheckboxesEnabled(false);
}
protected void showNeedsAccountEnabled() {
syncCategory.setTitle(R.string.fxaccount_status_sync);
showOnlyOneErrorPreference(needsAccountEnabledPreference);
setCheckboxesEnabled(false);
}
protected void showConnected() {
syncCategory.setTitle(R.string.fxaccount_status_sync_enabled);
showOnlyOneErrorPreference(null);
@ -245,23 +272,49 @@ public class FxAccountStatusFragment extends PreferenceFragment implements OnPre
emailPreference.setTitle(fxAccount.getEmail());
// Interrogate the Firefox Account's state.
State state = fxAccount.getState();
switch (state.getNeededAction()) {
case NeedsUpgrade:
showNeedsUpgrade();
break;
case NeedsPassword:
showNeedsPassword();
break;
case NeedsVerification:
showNeedsVerification();
break;
default:
showConnected();
}
try {
// There are error states determined by Android, not the login state
// machine, and we have a chance to present these states here. We handle
// them specially, since we can't surface these states as part of syncing,
// because they generally stop syncs from happening regularly.
updateSelectedEngines();
// The action to enable syncing the Firefox Account doesn't require
// leaving this activity, so let's present it first.
final boolean isSyncing = fxAccount.isSyncing();
if (!isSyncing) {
showNeedsAccountEnabled();
return;
}
// Interrogate the Firefox Account's state.
State state = fxAccount.getState();
switch (state.getNeededAction()) {
case NeedsUpgrade:
showNeedsUpgrade();
break;
case NeedsPassword:
showNeedsPassword();
break;
case NeedsVerification:
showNeedsVerification();
break;
default:
showConnected();
}
// We check for the master setting last, since it is not strictly
// necessary for the user to address this error state: it's really a
// warning state. We surface it for the user's convenience, and to prevent
// confused folks wondering why Sync is not working at all.
final boolean masterSyncAutomatically = ContentResolver.getMasterSyncAutomatically();
if (!masterSyncAutomatically) {
showNeedsMasterSyncAutomaticallyEnabled();
return;
}
} finally {
// No matter our state, we should update the checkboxes.
updateSelectedEngines();
}
}
/**

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

@ -97,7 +97,7 @@ public class AccountPickler {
o.put(KEY_PROFILE, account.getProfile());
o.put(KEY_IDP_SERVER_URI, account.getAccountServerURI());
o.put(KEY_TOKEN_SERVER_URI, account.getTokenServerURI());
o.put(KEY_IS_SYNCING_ENABLED, account.isSyncingEnabled());
o.put(KEY_IS_SYNCING_ENABLED, account.isSyncing());
// TODO: If prefs version changes under us, SyncPrefsPath will change, "clearing" prefs.

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

@ -380,17 +380,21 @@ public class AndroidFxAccount {
getSyncPrefs().edit().clear().commit();
}
public boolean isSyncingEnabled() {
// TODO: Authority will be static in PR 426.
final int result = ContentResolver.getIsSyncable(account, BrowserContract.AUTHORITY);
if (result > 0) {
return true;
} else if (result == 0) {
return false;
} else {
// This should not happen.
throw new IllegalStateException("Sync enabled state unknown.");
/**
* Return true if the underlying Android account is currently set to sync automatically.
* <p>
* This is, confusingly, not the same thing as "being syncable": that refers
* to whether this account can be synced, ever; this refers to whether Android
* will try to sync the account at appropriate times.
*
* @return true if the account is set to sync automatically.
*/
public boolean isSyncing() {
boolean isSyncEnabled = true;
for (String authority : new String[] { BrowserContract.AUTHORITY }) {
isSyncEnabled &= ContentResolver.getSyncAutomatically(account, authority);
}
return isSyncEnabled;
}
public void enableSyncing() {

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

@ -178,6 +178,8 @@
<!ENTITY fxaccount_status_needs_verification2 'Your account needs to be verified. Tap to resend verification email.'>
<!ENTITY fxaccount_status_needs_credentials 'Cannot connect. Tap to sign in.'>
<!ENTITY fxaccount_status_needs_upgrade 'You need to upgrade &brandShortName; to sign in.'>
<!ENTITY fxaccount_status_needs_master_sync_automatically_enabled '&syncBrand.shortName.label; is set up, but not syncing automatically. Toggle “Auto-sync data” in Android Settings &gt; Data Usage.'>
<!ENTITY fxaccount_status_needs_account_enabled '&syncBrand.shortName.label; is set up, but not syncing automatically. Tap to start syncing.'>
<!ENTITY fxaccount_status_bookmarks 'Bookmarks'>
<!ENTITY fxaccount_status_history 'History'>
<!ENTITY fxaccount_status_passwords 'Passwords'>

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

@ -35,6 +35,20 @@
android:layout="@layout/fxaccount_status_error_preference"
android:persistent="false"
android:title="@string/fxaccount_status_needs_verification" />
<Preference
android:editable="false"
android:icon="@drawable/fxaccount_sync_error"
android:key="needs_master_sync_automatically_enabled"
android:layout="@layout/fxaccount_status_error_preference"
android:persistent="false"
android:title="@string/fxaccount_status_needs_master_sync_automatically_enabled" />
<Preference
android:editable="false"
android:icon="@drawable/fxaccount_sync_error"
android:key="needs_account_enabled"
android:layout="@layout/fxaccount_status_error_preference"
android:persistent="false"
android:title="@string/fxaccount_status_needs_account_enabled" />
<CheckBoxPreference
android:key="bookmarks"

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

@ -172,6 +172,8 @@
<string name="fxaccount_status_needs_verification">&fxaccount_status_needs_verification2;</string>
<string name="fxaccount_status_needs_credentials">&fxaccount_status_needs_credentials;</string>
<string name="fxaccount_status_needs_upgrade">&fxaccount_status_needs_upgrade;</string>
<string name="fxaccount_status_needs_master_sync_automatically_enabled">&fxaccount_status_needs_master_sync_automatically_enabled;</string>
<string name="fxaccount_status_needs_account_enabled">&fxaccount_status_needs_account_enabled;</string>
<string name="fxaccount_status_bookmarks">&fxaccount_status_bookmarks;</string>
<string name="fxaccount_status_history">&fxaccount_status_history;</string>
<string name="fxaccount_status_passwords">&fxaccount_status_passwords;</string>

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

@ -4,12 +4,12 @@
package org.mozilla.gecko.background.fxa.authenticator;
import org.mozilla.gecko.background.helpers.AndroidSyncTestCase;
import org.mozilla.gecko.background.sync.TestSyncAccounts;
import org.mozilla.gecko.fxa.FxAccountConstants;
import org.mozilla.gecko.fxa.authenticator.AccountPickler;
import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
import org.mozilla.gecko.fxa.login.Separated;
import org.mozilla.gecko.fxa.login.State;
import org.mozilla.gecko.background.sync.TestSyncAccounts;
import org.mozilla.gecko.sync.Utils;
import android.accounts.Account;
@ -34,6 +34,7 @@ public class TestAccountPickler extends AndroidSyncTestCase {
this.accountManager = AccountManager.get(context);
}
@Override
public void tearDown() {
if (this.account != null) {
deleteAccount(this, this.accountManager, this.account);
@ -104,7 +105,7 @@ public class TestAccountPickler extends AndroidSyncTestCase {
assertEquals(expected.getAudience(), actual.getAudience());
assertEquals(expected.getTokenServerURI(), actual.getTokenServerURI());
assertEquals(expected.getSyncPrefsPath(), actual.getSyncPrefsPath());
assertEquals(expected.isSyncingEnabled(), actual.isSyncingEnabled());
assertEquals(expected.isSyncing(), actual.isSyncing());
assertEquals(expected.getEmail(), actual.getEmail());
assertStateEquals(expected.getState(), actual.getState());
}