From 3e7cf168a547982676f18d3308b83381abc95f06 Mon Sep 17 00:00:00 2001 From: Robin Lee Date: Sat, 25 Feb 2017 01:28:25 +0000 Subject: [PATCH] Make IKeyChainAliasCallback oneway So it can be sent from devicepolicymanager (system_server) to keychain (a system_app) without waiting on the response and having to do everything in a background thread. Side-effect: the regular keychain => app callback is slightly more efficient now too. in case anyone particularly needs blazing fast private key user selections. Fix: 35675253 Test: cts-tradefed run cts --abi=arm64-v8a --skip-device-info --module CtsDevicePolicyManagerTestCases --test 'com.android.cts.devicepolicy.DeviceOwnerTest#testKeyManagement' &1 Change-Id: I6e9d96ca3c42e6489d879d8cfb0507eb94838bf1 --- .../security/IKeyChainAliasCallback.aidl | 2 +- .../DevicePolicyManagerService.java | 22 ++++++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/keystore/java/android/security/IKeyChainAliasCallback.aidl b/keystore/java/android/security/IKeyChainAliasCallback.aidl index 1ea952166009e..b9d37533de80d 100644 --- a/keystore/java/android/security/IKeyChainAliasCallback.aidl +++ b/keystore/java/android/security/IKeyChainAliasCallback.aidl @@ -20,7 +20,7 @@ package android.security; * * @hide */ -interface IKeyChainAliasCallback { +oneway interface IKeyChainAliasCallback { void alias(String alias); } diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 14b1741346b9b..5cd1427e07018 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -4828,19 +4828,15 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { private void sendPrivateKeyAliasResponse(final String alias, final IBinder responseBinder) { final IKeyChainAliasCallback keyChainAliasResponse = IKeyChainAliasCallback.Stub.asInterface(responseBinder); - new AsyncTask() { - @Override - protected Void doInBackground(Void... unused) { - try { - keyChainAliasResponse.alias(alias); - } catch (Exception e) { - // Catch everything (not just RemoteException): caller could throw a - // RuntimeException back across processes. - Log.e(LOG_TAG, "error while responding to callback", e); - } - return null; - } - }.execute(); + // Send the response. It's OK to do this from the main thread because IKeyChainAliasCallback + // is oneway, which means it won't block if the recipient lives in another process. + try { + keyChainAliasResponse.alias(alias); + } catch (Exception e) { + // Caller could throw RuntimeException or RemoteException back across processes. Catch + // everything just to be sure. + Log.e(LOG_TAG, "error while responding to callback", e); + } } /**