diff options
author | Costin Manolache <costin@google.com> | 2011-07-21 10:38:15 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-07-21 10:38:15 -0700 |
commit | 554ad399a5f7114943e0f9d0725b36eafd8cc327 (patch) | |
tree | c881516e5ead0ae9e450672bcd347c87920e3b25 /src/com | |
parent | dac08e0f9c6e7aa65a22108f5e12b13f73681286 (diff) | |
parent | b22a242e0e87caf214d9a6139df09bbb2975990a (diff) | |
download | packages_apps_settings-554ad399a5f7114943e0f9d0725b36eafd8cc327.zip packages_apps_settings-554ad399a5f7114943e0f9d0725b36eafd8cc327.tar.gz packages_apps_settings-554ad399a5f7114943e0f9d0725b36eafd8cc327.tar.bz2 |
Merge "Add an extra parameter to identify the caller application. Fix the handling of 'suspend' - the callback will not be visible."
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/settings/accounts/AddAccountSettings.java | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/com/android/settings/accounts/AddAccountSettings.java b/src/com/android/settings/accounts/AddAccountSettings.java index 72ef130..382481e 100644 --- a/src/com/android/settings/accounts/AddAccountSettings.java +++ b/src/com/android/settings/accounts/AddAccountSettings.java @@ -22,6 +22,7 @@ import android.accounts.AccountManagerFuture; import android.accounts.AuthenticatorException; import android.accounts.OperationCanceledException; import android.app.Activity; +import android.app.PendingIntent; import android.content.Intent; import android.os.Bundle; import android.util.Log; @@ -44,18 +45,37 @@ import java.io.IOException; * when returning from each account setup, which doesn't look good. */ public class AddAccountSettings extends Activity { + /** + * + */ + private static final String KEY_ADD_CALLED = "AddAccountCalled"; + + /** + * Extra parameter to identify the caller. Applications may display a + * different UI if the calls is made from Settings or from a specific + * application. + */ + private static final String KEY_CALLER_IDENTITY = "pendingIntent"; + private static final String TAG = "AccountSettings"; /* package */ static final String EXTRA_SELECTED_ACCOUNT = "selected_account"; private static final int CHOOSE_ACCOUNT_REQUEST = 1; + private PendingIntent mPendingIntent; + private AccountManagerCallback<Bundle> mCallback = new AccountManagerCallback<Bundle>() { public void run(AccountManagerFuture<Bundle> future) { try { Bundle bundle = future.getResult(); bundle.keySet(); setResult(RESULT_OK); + + if (mPendingIntent != null) { + mPendingIntent.cancel(); + } + if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "account added: " + bundle); } catch (OperationCanceledException e) { if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "addAccount was canceled"); @@ -69,10 +89,22 @@ public class AddAccountSettings extends Activity { } }; + private boolean mAddAccountCalled = false; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + if (savedInstanceState != null) { + mAddAccountCalled = savedInstanceState.getBoolean(KEY_ADD_CALLED); + if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "restored"); + } + + if (mAddAccountCalled) { + // We already called add account - maybe the callback was lost. + finish(); + return; + } final String[] authorities = getIntent().getStringArrayExtra(AccountPreferenceBase.AUTHORITIES_FILTER_KEY); final String[] accountTypes = @@ -102,14 +134,24 @@ public class AddAccountSettings extends Activity { } } + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putBoolean(KEY_ADD_CALLED, mAddAccountCalled); + if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "saved"); + } + private void addAccount(String accountType) { + Bundle addAccountOptions = new Bundle(); + mPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(), 0); + addAccountOptions.putParcelable(KEY_CALLER_IDENTITY, mPendingIntent); AccountManager.get(this).addAccount( accountType, null, /* authTokenType */ null, /* requiredFeatures */ - null, /* addAccountOptions */ + addAccountOptions, this, mCallback, null /* handler */); + mAddAccountCalled = true; } } |