SetupWizard: Launch GMS account setup by intent
Fallback to AccountManager api if intent fails. Change-Id: I5ec06f452d12706a0f59e2f2a85bd9b4b5e4a965
This commit is contained in:
parent
9e6bebaabb
commit
30af327616
|
@ -37,8 +37,10 @@ public class SetupWizardApp extends Application {
|
||||||
public static final String EXTRA_ALLOW_SKIP = "allowSkip";
|
public static final String EXTRA_ALLOW_SKIP = "allowSkip";
|
||||||
public static final String EXTRA_AUTO_FINISH = "wifi_auto_finish_on_connect";
|
public static final String EXTRA_AUTO_FINISH = "wifi_auto_finish_on_connect";
|
||||||
public static final String EXTRA_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
|
public static final String EXTRA_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
|
||||||
|
public static final String EXTRA_USE_IMMERSIVE = "useImmersiveMode";
|
||||||
|
|
||||||
public static final int REQUEST_CODE_SETUP_WIFI = 0;
|
public static final int REQUEST_CODE_SETUP_WIFI = 0;
|
||||||
|
public static final int REQUEST_CODE_SETUP_GMS= 1;
|
||||||
|
|
||||||
private StatusBarManager mStatusBarManager;
|
private StatusBarManager mStatusBarManager;
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,12 @@ import android.accounts.AuthenticatorException;
|
||||||
import android.accounts.OperationCanceledException;
|
import android.accounts.OperationCanceledException;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import com.cyanogenmod.setupwizard.R;
|
import com.cyanogenmod.setupwizard.R;
|
||||||
import com.cyanogenmod.setupwizard.SetupWizardApp;
|
import com.cyanogenmod.setupwizard.SetupWizardApp;
|
||||||
|
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -62,30 +64,60 @@ public class GmsAccountPage extends SetupPage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_GMS) {
|
||||||
|
if (resultCode == Activity.RESULT_OK || resultCode == Activity.RESULT_FIRST_USER) {
|
||||||
|
if (SetupWizardUtils.accountExists(mContext, SetupWizardApp.ACCOUNT_TYPE_GMS)) {
|
||||||
|
setCompleted(true);
|
||||||
|
}
|
||||||
|
getCallbacks().onNextPage();
|
||||||
|
} else if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
|
getCallbacks().onPreviousPage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public void launchGmsAccountSetup(final Activity activity) {
|
public void launchGmsAccountSetup(final Activity activity) {
|
||||||
Bundle bundle = new Bundle();
|
/*
|
||||||
bundle.putBoolean(SetupWizardApp.EXTRA_FIRST_RUN, true);
|
* XXX: The AccountIntro intent is now public and therefore likely to change.
|
||||||
bundle.putBoolean(SetupWizardApp.EXTRA_ALLOW_SKIP, true);
|
* The only way to catch whether the user pressed skip of back if via
|
||||||
bundle.putBoolean("useImmersiveMode", true);
|
* startActivityForResult.
|
||||||
AccountManager
|
*
|
||||||
.get(activity).addAccount(SetupWizardApp.ACCOUNT_TYPE_GMS, null, null,
|
* If this fails, fall back to the old method, but it is not ideal because only a
|
||||||
bundle, activity, new AccountManagerCallback<Bundle>() {
|
* OperationCanceledException is thrown regardless of skipping or pressing back.
|
||||||
@Override
|
*/
|
||||||
public void run(AccountManagerFuture<Bundle> bundleAccountManagerFuture) {
|
try {
|
||||||
//There is a chance this activity has been torn down.
|
Intent intent = new Intent("com.google.android.accounts.AccountIntro");
|
||||||
if (activity == null) return;
|
intent.putExtra(SetupWizardApp.EXTRA_FIRST_RUN, true);
|
||||||
String token = null;
|
intent.putExtra(SetupWizardApp.EXTRA_ALLOW_SKIP, true);
|
||||||
try {
|
intent.putExtra(SetupWizardApp.EXTRA_USE_IMMERSIVE, true);
|
||||||
token = bundleAccountManagerFuture.getResult().getString(AccountManager.KEY_AUTHTOKEN);
|
activity.startActivityForResult(intent, SetupWizardApp.REQUEST_CODE_SETUP_GMS);
|
||||||
} catch (OperationCanceledException e) {
|
} catch (Exception e) {
|
||||||
} catch (IOException e) {
|
Bundle bundle = new Bundle();
|
||||||
} catch (AuthenticatorException e) {
|
bundle.putBoolean(SetupWizardApp.EXTRA_FIRST_RUN, true);
|
||||||
|
bundle.putBoolean(SetupWizardApp.EXTRA_ALLOW_SKIP, true);
|
||||||
|
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) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (token != null) {
|
}, null);
|
||||||
setCompleted(true);
|
}
|
||||||
}
|
|
||||||
getCallbacks().onNextPage();
|
|
||||||
}
|
|
||||||
}, null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue