Bug 989105 - Redirect Send Tab to Status activity when the Firefox Account definitely cannot send a tab. r=rnewman

--HG--
extra : rebase_source : fa924a2d14147041604c67758270c85603a43acb
This commit is contained in:
Nick Alexander 2014-03-27 17:15:55 -07:00
parent 741780aca6
commit fd06d64df3
2 changed files with 47 additions and 15 deletions

View File

@ -398,7 +398,7 @@ public class AndroidFxAccount {
}
public void enableSyncing() {
Logger.info(LOG_TAG, "Enabling sync for account named like " + Utils.obfuscateEmail(getEmail()));
Logger.info(LOG_TAG, "Enabling sync for account named like " + getObfuscatedEmail());
for (String authority : new String[] { BrowserContract.AUTHORITY }) {
ContentResolver.setSyncAutomatically(account, authority, true);
ContentResolver.setIsSyncable(account, authority, 1);
@ -406,14 +406,14 @@ public class AndroidFxAccount {
}
public void disableSyncing() {
Logger.info(LOG_TAG, "Disabling sync for account named like " + Utils.obfuscateEmail(getEmail()));
Logger.info(LOG_TAG, "Disabling sync for account named like " + getObfuscatedEmail());
for (String authority : new String[] { BrowserContract.AUTHORITY }) {
ContentResolver.setSyncAutomatically(account, authority, false);
}
}
public void requestSync(Bundle extras) {
Logger.info(LOG_TAG, "Requesting sync for account named like " + Utils.obfuscateEmail(getEmail()) +
Logger.info(LOG_TAG, "Requesting sync for account named like " + getObfuscatedEmail() +
(extras.isEmpty() ? "." : "; has extras."));
for (String authority : new String[] { BrowserContract.AUTHORITY }) {
ContentResolver.requestSync(account, authority, extras);
@ -424,7 +424,7 @@ public class AndroidFxAccount {
if (state == null) {
throw new IllegalArgumentException("state must not be null");
}
Logger.info(LOG_TAG, "Moving account named like " + Utils.obfuscateEmail(getEmail()) +
Logger.info(LOG_TAG, "Moving account named like " + getObfuscatedEmail() +
" to state " + state.getStateLabel().toString());
updateBundleValue(BUNDLE_KEY_STATE_LABEL, state.getStateLabel().name());
updateBundleValue(BUNDLE_KEY_STATE, state.toJSONObject().toJSONString());
@ -475,6 +475,17 @@ public class AndroidFxAccount {
return account.name;
}
/**
* Return the Firefox Account's local email address, obfuscated.
* <p>
* Use this when logging.
*
* @return local email address, obfuscated.
*/
public String getObfuscatedEmail() {
return Utils.obfuscateEmail(account.name);
}
/**
* Create an intent announcing that a Firefox account will be deleted.
*

View File

@ -14,7 +14,9 @@ import org.mozilla.gecko.R;
import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.fxa.FxAccountConstants;
import org.mozilla.gecko.fxa.activities.FxAccountGetStartedActivity;
import org.mozilla.gecko.fxa.activities.FxAccountStatusActivity;
import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
import org.mozilla.gecko.fxa.login.State.Action;
import org.mozilla.gecko.sync.CommandProcessor;
import org.mozilla.gecko.sync.CommandRunner;
import org.mozilla.gecko.sync.GlobalSession;
@ -58,17 +60,17 @@ public class SendTabActivity extends Activity {
void syncClientsStage();
}
public class FxAccountTabSender implements TabSender {
private final AndroidFxAccount account;
private static class FxAccountTabSender implements TabSender {
private final AndroidFxAccount fxAccount;
public FxAccountTabSender(Context context, Account account) {
this.account = new AndroidFxAccount(context, account);
public FxAccountTabSender(Context context, AndroidFxAccount fxAccount) {
this.fxAccount = fxAccount;
}
@Override
public String getAccountGUID() {
try {
final SharedPreferences prefs = this.account.getSyncPrefs();
final SharedPreferences prefs = this.fxAccount.getSyncPrefs();
return prefs.getString(SyncConfiguration.PREF_ACCOUNT_GUID, null);
} catch (Exception e) {
Logger.warn(LOG_TAG, "Could not get Firefox Account parameters or preferences; aborting.");
@ -81,7 +83,7 @@ public class SendTabActivity extends Activity {
final Bundle extras = new Bundle();
Utils.putStageNamesToSync(extras, CLIENTS_STAGE, null);
extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
this.account.requestSync(extras);
this.fxAccount.requestSync(extras);
}
}
@ -89,6 +91,7 @@ public class SendTabActivity extends Activity {
private final Account account;
private final AccountManager accountManager;
private final Context context;
private Sync11TabSender(Context context, Account syncAccount, AccountManager accountManager) {
this.context = context;
this.account = syncAccount;
@ -224,7 +227,17 @@ public class SendTabActivity extends Activity {
final Account[] fxAccounts = accountManager.getAccountsByType(FxAccountConstants.ACCOUNT_TYPE);
if (fxAccounts.length > 0) {
this.tabSender = new FxAccountTabSender(applicationContext, fxAccounts[0]);
final AndroidFxAccount fxAccount = new AndroidFxAccount(applicationContext, fxAccounts[0]);
if (fxAccount.getState().getNeededAction() != Action.None) {
// We have a Firefox Account, but it's definitely not able to send a tab
// right now. Redirect to the status activity.
Logger.warn(LOG_TAG, "Firefox Account named like " + fxAccount.getObfuscatedEmail() +
" needs action before it can send a tab; redirecting to status activity.");
redirectToNewTask(FxAccountStatusActivity.class, false);
return;
}
this.tabSender = new FxAccountTabSender(applicationContext, fxAccount);
Logger.info(LOG_TAG, "Allowing tab send for Firefox Account.");
registerDisplayURICommand();
@ -241,10 +254,7 @@ public class SendTabActivity extends Activity {
}
// Offer to set up a Firefox Account, and finish this activity.
final Intent intent = new Intent(applicationContext, FxAccountGetStartedActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
redirectToNewTask(FxAccountGetStartedActivity.class, false);
}
private static void registerDisplayURICommand() {
@ -379,4 +389,15 @@ public class SendTabActivity extends Activity {
}
return out;
}
// Adapted from FxAccountAbstractActivity.
protected void redirectToNewTask(Class<? extends Activity> activityClass, boolean success) {
Intent intent = new Intent(this, activityClass);
// Per http://stackoverflow.com/a/8992365, this triggers a known bug with
// the soft keyboard not being shown for the started activity. Why, Android, why?
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
notifyAndFinish(success);
}
}