From: Irina Dumitrescu Date: Fri, 8 Jun 2018 18:36:34 +0000 (+0100) Subject: Add Keystore get option that supresses caught exceptions warnings. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=203bd1b113a3998939005395f9fefe0a4798b1fb;p=android-x86%2Fframeworks-base.git Add Keystore get option that supresses caught exceptions warnings. This is useful when the caught exceptions are not informative and they act as a red herring in the adb logs. Bug:109791294 Test: call this method in the VpnSettings and manually navigate to adding a new VPN by searching for VPN in settings and then pressing '+'. Change-Id: I4bc86e3ea5b11027090fd3a27dc7455557cf66ab Merged-In: I4bc86e3ea5b11027090fd3a27dc7455557cf66ab --- diff --git a/keystore/java/android/security/KeyStore.java b/keystore/java/android/security/KeyStore.java index 25a6cdc4a7f4..a64ce83d91c4 100644 --- a/keystore/java/android/security/KeyStore.java +++ b/keystore/java/android/security/KeyStore.java @@ -219,6 +219,15 @@ public class KeyStore { } public byte[] get(String key, int uid) { + return get(key, uid, false); + } + + @UnsupportedAppUsage + public byte[] get(String key) { + return get(key, UID_SELF); + } + + public byte[] get(String key, int uid, boolean suppressKeyNotFoundWarning) { try { key = key != null ? key : ""; return mBinder.get(key, uid); @@ -226,16 +235,18 @@ public class KeyStore { Log.w(TAG, "Cannot connect to keystore", e); return null; } catch (android.os.ServiceSpecificException e) { - Log.w(TAG, "KeyStore exception", e); + if (!suppressKeyNotFoundWarning || e.errorCode != KEY_NOT_FOUND) { + Log.w(TAG, "KeyStore exception", e); + } return null; } } - @UnsupportedAppUsage - public byte[] get(String key) { - return get(key, UID_SELF); + public byte[] get(String key, boolean suppressKeyNotFoundWarning) { + return get(key, UID_SELF, suppressKeyNotFoundWarning); } + public boolean put(String key, byte[] value, int uid, int flags) { return insert(key, value, uid, flags) == NO_ERROR; }