summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/accounts
diff options
context:
space:
mode:
authorCostin Manolache <costin@google.com>2011-07-18 16:30:36 -0700
committerCostin Manolache <costin@google.com>2011-07-21 10:37:12 -0700
commitb22a242e0e87caf214d9a6139df09bbb2975990a (patch)
tree469d0002d458ec48a1cb01b5c545682c60e490f0 /src/com/android/settings/accounts
parent6ba9e021d40b0232c5d46afb366cf986b3fa9ce4 (diff)
downloadpackages_apps_Settings-b22a242e0e87caf214d9a6139df09bbb2975990a.zip
packages_apps_Settings-b22a242e0e87caf214d9a6139df09bbb2975990a.tar.gz
packages_apps_Settings-b22a242e0e87caf214d9a6139df09bbb2975990a.tar.bz2
Add an extra parameter to identify the caller application. Fix the handling of 'suspend' - the callback will not be visible.
Change-Id: Ide8b841b6b57e31ac082678b27c314b9eeff8846
Diffstat (limited to 'src/com/android/settings/accounts')
-rw-r--r--src/com/android/settings/accounts/AddAccountSettings.java44
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;
}
}