summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Carlstrom <bdc@google.com>2011-05-17 10:37:54 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-05-17 10:37:54 -0700
commit2c1e9c784641cc0e6b68f25951c1abae2eb186dc (patch)
tree863894a8a2675841dede7cc7855438f56798f92d
parent6019c7dcba103a42fd1b4085f00863f558ff40fd (diff)
parent9815429821832c204eaf8edebb37f4e2ff7636f0 (diff)
downloadpackages_apps_settings-2c1e9c784641cc0e6b68f25951c1abae2eb186dc.zip
packages_apps_settings-2c1e9c784641cc0e6b68f25951c1abae2eb186dc.tar.gz
packages_apps_settings-2c1e9c784641cc0e6b68f25951c1abae2eb186dc.tar.bz2
Merge "Make CertInstaller installed CA certs trusted by applications via default TrustManager (5 of 6)"
-rw-r--r--res/values/strings.xml2
-rw-r--r--src/com/android/settings/CredentialStorage.java78
2 files changed, 72 insertions, 8 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 4da3ca4..e3250be 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3053,6 +3053,8 @@ found in the list of installed applications.</string>
<!-- Toast message [CHAR LIMIT=30] -->
<string name="credentials_erased">Credential storage is erased.</string>
<!-- Toast message [CHAR LIMIT=30] -->
+ <string name="credentials_not_erased">Credential could not be erased.</string>
+ <!-- Toast message [CHAR LIMIT=30] -->
<string name="credentials_enabled">Credential storage is enabled.</string>
<!-- Sound settings screen, setting check box label -->
diff --git a/src/com/android/settings/CredentialStorage.java b/src/com/android/settings/CredentialStorage.java
index 9d5a603..b2d0a3a 100644
--- a/src/com/android/settings/CredentialStorage.java
+++ b/src/com/android/settings/CredentialStorage.java
@@ -18,9 +18,16 @@ package com.android.settings;
import android.app.Activity;
import android.app.AlertDialog;
+import android.content.ComponentName;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.AsyncTask;
import android.os.Bundle;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.security.IKeyChainService;
import android.security.KeyStore;
import android.text.Editable;
import android.text.TextWatcher;
@@ -30,6 +37,8 @@ import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
import java.io.UnsupportedEncodingException;
public class CredentialStorage extends Activity implements TextWatcher,
@@ -43,7 +52,8 @@ public class CredentialStorage extends Activity implements TextWatcher,
private static final String TAG = "CredentialStorage";
private KeyStore mKeyStore = KeyStore.getInstance();
- private boolean mSubmit = false;
+ private boolean mPositive = false;
+ private boolean mNeutral = false;
private Bundle mBundle;
private TextView mOldPassword;
@@ -177,16 +187,13 @@ public class CredentialStorage extends Activity implements TextWatcher,
}
public void onClick(DialogInterface dialog, int button) {
- mSubmit = (button == DialogInterface.BUTTON_POSITIVE);
- if (button == DialogInterface.BUTTON_NEUTRAL) {
- mKeyStore.reset();
- Toast.makeText(this, R.string.credentials_erased, Toast.LENGTH_SHORT).show();
- }
+ mPositive = (button == DialogInterface.BUTTON_POSITIVE);
+ mNeutral = (button == DialogInterface.BUTTON_NEUTRAL);
}
public void onDismiss(DialogInterface dialog) {
- if (mSubmit) {
- mSubmit = false;
+ if (mPositive) {
+ mPositive = false;
mError.setVisibility(View.VISIBLE);
if (mNewPassword == null) {
@@ -225,6 +232,61 @@ public class CredentialStorage extends Activity implements TextWatcher,
return;
}
}
+ if (mNeutral) {
+ mNeutral = false;
+ new ResetKeyStoreAndKeyChain().execute();
+ return;
+ }
finish();
}
+
+ private class ResetKeyStoreAndKeyChain extends AsyncTask<Void, Void, Boolean> {
+
+ @Override protected Boolean doInBackground(Void... unused) {
+
+ mKeyStore.reset();
+
+ final BlockingQueue<IKeyChainService> q = new LinkedBlockingQueue<IKeyChainService>(1);
+ ServiceConnection keyChainServiceConnection = new ServiceConnection() {
+ @Override public void onServiceConnected(ComponentName name, IBinder service) {
+ try {
+ q.put(IKeyChainService.Stub.asInterface(service));
+ } catch (InterruptedException e) {
+ throw new AssertionError(e);
+ }
+ }
+ @Override public void onServiceDisconnected(ComponentName name) {}
+ };
+ boolean isBound = bindService(new Intent(IKeyChainService.class.getName()),
+ keyChainServiceConnection,
+ Context.BIND_AUTO_CREATE);
+ if (!isBound) {
+ Log.w(TAG, "could not bind to KeyChainService");
+ return false;
+ }
+ IKeyChainService keyChainService;
+ try {
+ keyChainService = q.take();
+ return keyChainService.reset();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ return false;
+ } catch (RemoteException e) {
+ return false;
+ } finally {
+ unbindService(keyChainServiceConnection);
+ }
+ }
+
+ @Override protected void onPostExecute(Boolean success) {
+ if (success) {
+ Toast.makeText(CredentialStorage.this,
+ R.string.credentials_erased, Toast.LENGTH_SHORT).show();
+ } else {
+ Toast.makeText(CredentialStorage.this,
+ R.string.credentials_not_erased, Toast.LENGTH_SHORT).show();
+ }
+ finish();
+ }
+ }
}