Move to KeyChain.bind
Change-Id: Ic12e84bdc2e391c4a08a0f854d0e0f7315fc31a3
This commit is contained in:
@@ -27,6 +27,8 @@ import android.os.AsyncTask;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.security.KeyChain;
|
||||||
|
import android.security.KeyChain.KeyChainConnection;
|
||||||
import android.security.IKeyChainService;
|
import android.security.IKeyChainService;
|
||||||
import android.security.KeyStore;
|
import android.security.KeyStore;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
@@ -246,35 +248,18 @@ public class CredentialStorage extends Activity implements TextWatcher,
|
|||||||
|
|
||||||
mKeyStore.reset();
|
mKeyStore.reset();
|
||||||
|
|
||||||
final BlockingQueue<IKeyChainService> q = new LinkedBlockingQueue<IKeyChainService>(1);
|
|
||||||
ServiceConnection keyChainServiceConnection = new ServiceConnection() {
|
|
||||||
@Override public void onServiceConnected(ComponentName name, IBinder service) {
|
|
||||||
try {
|
try {
|
||||||
q.put(IKeyChainService.Stub.asInterface(service));
|
KeyChainConnection keyChainConnection = KeyChain.bind(CredentialStorage.this);
|
||||||
} 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 {
|
try {
|
||||||
keyChainService = q.take();
|
return keyChainConnection.getService().reset();
|
||||||
return keyChainService.reset();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
return false;
|
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
unbindService(keyChainServiceConnection);
|
keyChainConnection.close();
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user