Merge "Use KeyChain instead of Credentials to delete certs" into nyc-dev am: 34ecc000ae
am: 23e5801a3b
* commit '23e5801a3bad0a5f4c30eafdc49400e8d479eee3':
Use KeyChain instead of Credentials to delete certs
This commit is contained in:
@@ -27,8 +27,13 @@ import android.os.AsyncTask;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
import android.os.RemoteException;
|
||||||
import android.security.Credentials;
|
import android.security.Credentials;
|
||||||
|
import android.security.IKeyChainService;
|
||||||
|
import android.security.KeyChain;
|
||||||
|
import android.security.KeyChain.KeyChainConnection;
|
||||||
import android.security.KeyStore;
|
import android.security.KeyStore;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -120,21 +125,49 @@ public class UserCredentialsSettings extends InstrumentedFragment implements OnI
|
|||||||
.setNegativeButton(R.string.trusted_credentials_remove_label,
|
.setNegativeButton(R.string.trusted_credentials_remove_label,
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
@Override public void onClick(DialogInterface dialog, int id) {
|
@Override public void onClick(DialogInterface dialog, int id) {
|
||||||
final KeyStore ks = KeyStore.getInstance();
|
new RemoveCredentialsTask(getContext(), getTargetFragment())
|
||||||
Credentials.deleteAllTypesForAlias(ks, item.alias);
|
.execute(item.alias);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.create();
|
.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class RemoveCredentialsTask extends AsyncTask<String, Void, Void> {
|
||||||
public void onDismiss(DialogInterface dialog) {
|
private Context context;
|
||||||
final Fragment target = getTargetFragment();
|
private Fragment targetFragment;
|
||||||
if (target instanceof UserCredentialsSettings) {
|
|
||||||
((UserCredentialsSettings) target).refreshItems();
|
public RemoveCredentialsTask(Context context, Fragment targetFragment) {
|
||||||
|
this.context = context;
|
||||||
|
this.targetFragment = targetFragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(String... aliases) {
|
||||||
|
try {
|
||||||
|
final KeyChainConnection conn = KeyChain.bind(getContext());
|
||||||
|
try {
|
||||||
|
IKeyChainService keyChain = conn.getService();
|
||||||
|
for (String alias : aliases) {
|
||||||
|
keyChain.removeKeyPair(alias);
|
||||||
|
}
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.w(TAG, "Removing credentials", e);
|
||||||
|
} finally {
|
||||||
|
conn.close();
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Log.w(TAG, "Connecting to keychain", e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void result) {
|
||||||
|
if (targetFragment instanceof UserCredentialsSettings) {
|
||||||
|
((UserCredentialsSettings) targetFragment).refreshItems();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
super.onDismiss(dialog);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user