summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrian Carlstrom <bdc@google.com>2011-06-28 20:37:31 -0700
committerBrian Carlstrom <bdc@google.com>2011-06-28 20:42:59 -0700
commit91940e7fb9ac0eabfba7921173f1694a49a345fb (patch)
treedb5b65f8cceae1edabf7f957b7a7e46bd2763435 /src
parent43f5b77dbbff264f7f521dbf5361f07a5e253c70 (diff)
downloadandroid_packages_apps_KeyChain-91940e7fb9ac0eabfba7921173f1694a49a345fb.tar.gz
android_packages_apps_KeyChain-91940e7fb9ac0eabfba7921173f1694a49a345fb.tar.bz2
android_packages_apps_KeyChain-91940e7fb9ac0eabfba7921173f1694a49a345fb.zip
Support rotation in new dialog based KeyChainActivity
Using showDialog, the framework manged the dialog for me. So on rotation, it skiped onResume and right to onCreateDialog but then the mCertificateAdapter was null. I considered showing the list first, and filling in the content later, more like I do TrustedCredentialsSettings. However, here the dialog content is different if there are no entries. To fix, I just don't use showDialog. Then onResume is called and I recreate the dialog the same way in both cases. Bug: 4967378 Change-Id: I306e3a32069dce4e00864be79b50e081869851d5
Diffstat (limited to 'src')
-rw-r--r--src/com/android/keychain/KeyChainActivity.java40
1 files changed, 16 insertions, 24 deletions
diff --git a/src/com/android/keychain/KeyChainActivity.java b/src/com/android/keychain/KeyChainActivity.java
index 0702c3f..80b537a 100644
--- a/src/com/android/keychain/KeyChainActivity.java
+++ b/src/com/android/keychain/KeyChainActivity.java
@@ -59,8 +59,6 @@ public class KeyChainActivity extends Activity {
private static final int REQUEST_UNLOCK = 1;
- private static final int DIALOG_CERT_CHOOSER = 0;
-
private static enum State { INITIAL, UNLOCK_REQUESTED };
private State mState;
@@ -71,8 +69,6 @@ public class KeyChainActivity extends Activity {
// be done on the UI thread.
private KeyStore mKeyStore = KeyStore.getInstance();
- private CertificateAdapter mCertificateAdapter;
-
// the KeyStore.state operation is safe to do on the UI thread, it
// does not do a file operation.
private boolean isKeyStoreUnlocked() {
@@ -107,7 +103,7 @@ public class KeyChainActivity extends Activity {
// onActivityResult is called with REQUEST_UNLOCK
return;
}
- new AliasLoader().execute();
+ showCertChooserDialog();
return;
case UNLOCK_REQUESTED:
// we've already asked, but have not heard back, probably just rotated.
@@ -118,6 +114,10 @@ public class KeyChainActivity extends Activity {
}
}
+ private void showCertChooserDialog() {
+ new AliasLoader().execute();
+ }
+
private class AliasLoader extends AsyncTask<Void, Void, CertificateAdapter> {
@Override protected CertificateAdapter doInBackground(Void... params) {
String[] aliasArray = mKeyStore.saw(Credentials.USER_PRIVATE_KEY);
@@ -127,26 +127,18 @@ public class KeyChainActivity extends Activity {
Collections.sort(aliasList);
return new CertificateAdapter(aliasList);
}
- @Override protected void onPostExecute(CertificateAdapter result) {
- mCertificateAdapter = result;
- showDialog(DIALOG_CERT_CHOOSER);
- }
- }
-
- @Override protected Dialog onCreateDialog(int id, Bundle args) {
- if (id == DIALOG_CERT_CHOOSER) {
- return createCertChooserDialog();
+ @Override protected void onPostExecute(CertificateAdapter adapter) {
+ displayCertChooserDialog(adapter);
}
- throw new AssertionError();
}
- private Dialog createCertChooserDialog() {
+ private void displayCertChooserDialog(final CertificateAdapter adapter) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = View.inflate(this, R.layout.cert_chooser, null);
builder.setView(view);
- boolean empty = mCertificateAdapter.mAliases.isEmpty();
+ boolean empty = adapter.mAliases.isEmpty();
int negativeLabel = empty ? android.R.string.cancel : R.string.deny_button;
builder.setNegativeButton(negativeLabel, new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int id) {
@@ -161,10 +153,10 @@ public class KeyChainActivity extends Activity {
} else {
title = res.getString(R.string.title_select_cert);
final ListView lv = (ListView) view.findViewById(R.id.cert_chooser_cert_list);
- lv.setAdapter(mCertificateAdapter);
+ lv.setAdapter(adapter);
String alias = getIntent().getStringExtra(KeyChain.EXTRA_ALIAS);
if (alias != null) {
- int position = mCertificateAdapter.mAliases.indexOf(alias);
+ int position = adapter.mAliases.indexOf(alias);
if (position != -1) {
lv.setItemChecked(position, true);
}
@@ -174,7 +166,7 @@ public class KeyChainActivity extends Activity {
@Override public void onClick(DialogInterface dialog, int id) {
int pos = lv.getCheckedItemPosition();
String alias = ((pos != ListView.INVALID_POSITION)
- ? mCertificateAdapter.getItem(pos)
+ ? adapter.getItem(pos)
: null);
finish(alias);
}
@@ -183,6 +175,7 @@ public class KeyChainActivity extends Activity {
lv.setVisibility(View.VISIBLE);
}
builder.setTitle(title);
+ final Dialog dialog = builder.create();
PendingIntent sender = getIntent().getParcelableExtra(KeyChain.EXTRA_SENDER);
if (sender == null) {
@@ -234,18 +227,17 @@ public class KeyChainActivity extends Activity {
@Override public void onClick(View v) {
// remove dialog so that we will recreate with
// possibly new content after install returns
- removeDialog(DIALOG_CERT_CHOOSER);
+ dialog.dismiss();
Credentials.getInstance().install(KeyChainActivity.this);
}
});
- Dialog dialog = builder.create();
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override public void onCancel(DialogInterface dialog) {
finish(null);
}
});
- return dialog;
+ dialog.show();
}
private class CertificateAdapter extends BaseAdapter {
@@ -338,7 +330,7 @@ public class KeyChainActivity extends Activity {
switch (requestCode) {
case REQUEST_UNLOCK:
if (isKeyStoreUnlocked()) {
- showDialog(DIALOG_CERT_CHOOSER);
+ showCertChooserDialog();
} else {
// user must have canceled unlock, give up
finish(null);