Skip to content

Commit 40047fa

Browse files
fredquintanaAndroid Git Automerger
authored andcommitted
am 272101b: Merge "Fix a bug in the account chooser where relaunching an in-progress flow results in a blank screen." into ics-factoryrom
* commit '272101b308c7eb0a4639bed0106830a8d6b0f2a1': Fix a bug in the account chooser where relaunching an in-progress flow results in a blank screen.
2 parents 55b039f + 272101b commit 40047fa

File tree

2 files changed

+56
-45
lines changed

2 files changed

+56
-45
lines changed

core/java/android/accounts/ChooseAccountTypeActivity.java

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import android.widget.TextView;
3434
import com.android.internal.R;
3535

36-
import java.io.IOException;
3736
import java.util.ArrayList;
3837
import java.util.HashMap;
3938
import java.util.HashSet;
@@ -43,7 +42,7 @@
4342
/**
4443
* @hide
4544
*/
46-
public class ChooseAccountTypeActivity extends Activity implements AccountManagerCallback<Bundle> {
45+
public class ChooseAccountTypeActivity extends Activity {
4746
private static final String TAG = "AccountManager";
4847

4948
private HashMap<String, AuthInfo> mTypeToAuthenticatorInfo = new HashMap<String, AuthInfo>();
@@ -52,7 +51,6 @@ public class ChooseAccountTypeActivity extends Activity implements AccountManage
5251
@Override
5352
public void onCreate(Bundle savedInstanceState) {
5453
super.onCreate(savedInstanceState);
55-
setContentView(R.layout.choose_account_type);
5654

5755
// Read the validAccountTypes, if present, and add them to the setOfAllowableAccountTypes
5856
Set<String> setOfAllowableAccountTypes = null;
@@ -90,10 +88,11 @@ public void onCreate(Bundle savedInstanceState) {
9088
}
9189

9290
if (mAuthenticatorInfosToDisplay.size() == 1) {
93-
runAddAccountForAuthenticator(mAuthenticatorInfosToDisplay.get(0));
91+
setResultAndFinish(mAuthenticatorInfosToDisplay.get(0).desc.type);
9492
return;
9593
}
9694

95+
setContentView(R.layout.choose_account_type);
9796
// Setup the list
9897
ListView list = (ListView) findViewById(android.R.id.list);
9998
// Use an existing ListAdapter that will map an array of strings to TextViews
@@ -103,11 +102,20 @@ public void onCreate(Bundle savedInstanceState) {
103102
list.setTextFilterEnabled(false);
104103
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
105104
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
106-
runAddAccountForAuthenticator(mAuthenticatorInfosToDisplay.get(position));
105+
setResultAndFinish(mAuthenticatorInfosToDisplay.get(position).desc.type);
107106
}
108107
});
109108
}
110109

110+
private void setResultAndFinish(final String type) {
111+
Bundle bundle = new Bundle();
112+
bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, type);
113+
setResult(Activity.RESULT_OK, new Intent().putExtras(bundle));
114+
Log.d(TAG, "ChooseAccountTypeActivity.setResultAndFinish: "
115+
+ "selected account type " + type);
116+
finish();
117+
}
118+
111119
private void buildTypeToAuthDescriptionMap() {
112120
for(AuthenticatorDescription desc : AccountManager.get(this).getAuthenticatorTypes()) {
113121
String name = null;
@@ -136,42 +144,6 @@ private void buildTypeToAuthDescriptionMap() {
136144
}
137145
}
138146

139-
protected void runAddAccountForAuthenticator(AuthInfo authInfo) {
140-
Log.d(TAG, "selected account type " + authInfo.name);
141-
final Bundle options = getIntent().getBundleExtra(
142-
ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE);
143-
final String[] requiredFeatures = getIntent().getStringArrayExtra(
144-
ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_REQUIRED_FEATURES_STRING_ARRAY);
145-
final String authTokenType = getIntent().getStringExtra(
146-
ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_AUTH_TOKEN_TYPE_STRING);
147-
AccountManager.get(this).addAccount(authInfo.desc.type, authTokenType, requiredFeatures,
148-
options, this, this, null /* Handler */);
149-
}
150-
151-
public void run(final AccountManagerFuture<Bundle> accountManagerFuture) {
152-
try {
153-
Bundle accountManagerResult = accountManagerFuture.getResult();
154-
Bundle bundle = new Bundle();
155-
bundle.putString(AccountManager.KEY_ACCOUNT_NAME,
156-
accountManagerResult.getString(AccountManager.KEY_ACCOUNT_NAME));
157-
bundle.putString(AccountManager.KEY_ACCOUNT_TYPE,
158-
accountManagerResult.getString(AccountManager.KEY_ACCOUNT_TYPE));
159-
setResult(Activity.RESULT_OK, new Intent().putExtras(bundle));
160-
finish();
161-
return;
162-
} catch (OperationCanceledException e) {
163-
setResult(Activity.RESULT_CANCELED);
164-
finish();
165-
return;
166-
} catch (IOException e) {
167-
} catch (AuthenticatorException e) {
168-
}
169-
Bundle bundle = new Bundle();
170-
bundle.putString(AccountManager.KEY_ERROR_MESSAGE, "error communicating with server");
171-
setResult(Activity.RESULT_OK, new Intent().putExtras(bundle));
172-
finish();
173-
}
174-
175147
private static class AuthInfo {
176148
final AuthenticatorDescription desc;
177149
final String name;

core/java/android/accounts/ChooseTypeAndAccountActivity.java

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import android.widget.TextView;
3737
import com.android.internal.R;
3838

39+
import java.io.IOException;
3940
import java.util.ArrayList;
4041
import java.util.HashMap;
4142
import java.util.HashSet;
@@ -44,7 +45,8 @@
4445
/**
4546
* @hide
4647
*/
47-
public class ChooseTypeAndAccountActivity extends Activity {
48+
public class ChooseTypeAndAccountActivity extends Activity
49+
implements AccountManagerCallback<Bundle> {
4850
private static final String TAG = "AccountManager";
4951

5052
/**
@@ -211,10 +213,9 @@ public void onClick(final View v) {
211213
protected void onActivityResult(final int requestCode, final int resultCode,
212214
final Intent data) {
213215
if (resultCode == RESULT_OK && data != null) {
214-
String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
215216
String accountType = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE);
216-
if (accountName != null && accountType != null) {
217-
setResultAndFinish(accountName, accountType);
217+
if (accountType != null) {
218+
runAddAccountForAuthenticator(accountType);
218219
return;
219220
}
220221
}
@@ -223,6 +224,43 @@ protected void onActivityResult(final int requestCode, final int resultCode,
223224
finish();
224225
}
225226

227+
protected void runAddAccountForAuthenticator(String type) {
228+
Log.d(TAG, "selected account type " + type);
229+
final Bundle options = getIntent().getBundleExtra(
230+
ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE);
231+
final String[] requiredFeatures = getIntent().getStringArrayExtra(
232+
ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_REQUIRED_FEATURES_STRING_ARRAY);
233+
final String authTokenType = getIntent().getStringExtra(
234+
ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_AUTH_TOKEN_TYPE_STRING);
235+
AccountManager.get(this).addAccount(type, authTokenType, requiredFeatures,
236+
options, this, this, null /* Handler */);
237+
}
238+
239+
public void run(final AccountManagerFuture<Bundle> accountManagerFuture) {
240+
try {
241+
final Bundle accountManagerResult = accountManagerFuture.getResult();
242+
final String name = accountManagerResult.getString(AccountManager.KEY_ACCOUNT_NAME);
243+
final String type = accountManagerResult.getString(AccountManager.KEY_ACCOUNT_TYPE);
244+
if (name != null && type != null) {
245+
final Bundle bundle = new Bundle();
246+
bundle.putString(AccountManager.KEY_ACCOUNT_NAME, name);
247+
bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, type);
248+
setResult(Activity.RESULT_OK, new Intent().putExtras(bundle));
249+
finish();
250+
return;
251+
}
252+
} catch (OperationCanceledException e) {
253+
setResult(Activity.RESULT_CANCELED);
254+
finish();
255+
return;
256+
} catch (IOException e) {
257+
} catch (AuthenticatorException e) {
258+
}
259+
Bundle bundle = new Bundle();
260+
bundle.putString(AccountManager.KEY_ERROR_MESSAGE, "error communicating with server");
261+
setResult(Activity.RESULT_OK, new Intent().putExtras(bundle));
262+
finish();
263+
}
226264

227265
private Drawable getDrawableForType(
228266
final HashMap<String, AuthenticatorDescription> typeToAuthDescription,
@@ -266,6 +304,7 @@ private void setResultAndFinish(final String accountName, final String accountTy
266304

267305
private void startChooseAccountTypeActivity() {
268306
final Intent intent = new Intent(this, ChooseAccountTypeActivity.class);
307+
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
269308
intent.putExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY,
270309
getIntent().getStringArrayExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY));
271310
intent.putExtra(EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE,

0 commit comments

Comments
 (0)