SetupWizard: Use GMS AccountManager as intended

Change-Id: I1c2bac11745d0d6b9a9378e483d1b64b01f5df44
This commit is contained in:
cretin45 2015-01-23 11:46:39 -08:00
parent 61a331f403
commit b990a954a8

View File

@ -80,44 +80,26 @@ public class GmsAccountPage extends SetupPage {
} }
public void launchGmsAccountSetup(final Activity activity) { public void launchGmsAccountSetup(final Activity activity) {
/* Bundle bundle = new Bundle();
* XXX: The AccountIntro intent is now public and therefore likely to change. bundle.putBoolean(SetupWizardApp.EXTRA_FIRST_RUN, true);
* The only way to catch whether the user pressed skip of back if via bundle.putBoolean(SetupWizardApp.EXTRA_ALLOW_SKIP, true);
* startActivityForResult. bundle.putBoolean(SetupWizardApp.EXTRA_USE_IMMERSIVE, true);
* AccountManager
* If this fails, fall back to the old method, but it is not ideal because only a .get(activity).addAccount(SetupWizardApp.ACCOUNT_TYPE_GMS, null, null,
* OperationCanceledException is thrown regardless of skipping or pressing back. bundle, null, new AccountManagerCallback<Bundle>() {
*/ @Override
try { public void run(AccountManagerFuture<Bundle> future) {
Intent intent = new Intent("com.google.android.accounts.AccountIntro"); try {
intent.putExtra(SetupWizardApp.EXTRA_FIRST_RUN, true); Bundle result = future.getResult();
intent.putExtra(SetupWizardApp.EXTRA_ALLOW_SKIP, true); Intent intent = result
intent.putExtra(SetupWizardApp.EXTRA_USE_IMMERSIVE, true); .getParcelable(AccountManager.KEY_INTENT);
activity.startActivityForResult(intent, SetupWizardApp.REQUEST_CODE_SETUP_GMS); activity.startActivityForResult(intent,
} catch (Exception e) { SetupWizardApp.REQUEST_CODE_SETUP_GMS);
Bundle bundle = new Bundle(); } catch (OperationCanceledException e) {
bundle.putBoolean(SetupWizardApp.EXTRA_FIRST_RUN, true); } catch (IOException e) {
bundle.putBoolean(SetupWizardApp.EXTRA_ALLOW_SKIP, true); } catch (AuthenticatorException e) {
bundle.putBoolean(SetupWizardApp.EXTRA_USE_IMMERSIVE, true);
AccountManager
.get(activity).addAccount(SetupWizardApp.ACCOUNT_TYPE_GMS, null, null,
bundle, activity, new AccountManagerCallback<Bundle>() {
@Override
public void run(AccountManagerFuture<Bundle> bundleAccountManagerFuture) {
try {
if (bundleAccountManagerFuture.getResult()
.getString(AccountManager.KEY_AUTHTOKEN) != null) {
setCompleted(true);
}
} catch (OperationCanceledException e) {
if (activity != null && activity.isResumed()) {
getCallbacks().onNextPage();
}
} catch (IOException e) {
} catch (AuthenticatorException e) {
}
} }
}, null); }
} }, null);
} }
} }