summaryrefslogtreecommitdiff
path: root/keystore/java/android/security/Authorization.java
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2021-02-20 19:26:58 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-02-20 19:26:58 +0000
commit08bf2e8f49fb54d5377c8432cc41ccdf0f75ab41 (patch)
tree1f3693834a8320132c35e025c0b2e3baf37d0064 /keystore/java/android/security/Authorization.java
parent3237216211a63d59c090c154257746bc2cf4a58f (diff)
parent377370cce8f7452d01d493d682d7de84e4fd622e (diff)
Merge "Keystore 2.0: Revisite Authorization.java"
Diffstat (limited to 'keystore/java/android/security/Authorization.java')
-rw-r--r--keystore/java/android/security/Authorization.java22
1 files changed, 7 insertions, 15 deletions
diff --git a/keystore/java/android/security/Authorization.java b/keystore/java/android/security/Authorization.java
index 21d23b1b2575..50a90820117d 100644
--- a/keystore/java/android/security/Authorization.java
+++ b/keystore/java/android/security/Authorization.java
@@ -33,20 +33,12 @@ import android.util.Log;
*/
public class Authorization {
private static final String TAG = "KeystoreAuthorization";
- private static IKeystoreAuthorization sIKeystoreAuthorization;
public static final int SYSTEM_ERROR = ResponseCode.SYSTEM_ERROR;
- public Authorization() {
- sIKeystoreAuthorization = null;
- }
-
- private static synchronized IKeystoreAuthorization getService() {
- if (sIKeystoreAuthorization == null) {
- sIKeystoreAuthorization = IKeystoreAuthorization.Stub.asInterface(
+ private static IKeystoreAuthorization getService() {
+ return IKeystoreAuthorization.Stub.asInterface(
ServiceManager.checkService("android.security.authorization"));
- }
- return sIKeystoreAuthorization;
}
/**
@@ -55,12 +47,12 @@ public class Authorization {
* @param authToken created by Android authenticators.
* @return 0 if successful or {@code ResponseCode.SYSTEM_ERROR}.
*/
- public int addAuthToken(@NonNull HardwareAuthToken authToken) {
+ public static int addAuthToken(@NonNull HardwareAuthToken authToken) {
if (!android.security.keystore2.AndroidKeyStoreProvider.isInstalled()) return 0;
try {
getService().addAuthToken(authToken);
return 0;
- } catch (RemoteException e) {
+ } catch (RemoteException | NullPointerException e) {
Log.w(TAG, "Can not connect to keystore", e);
return SYSTEM_ERROR;
} catch (ServiceSpecificException e) {
@@ -73,7 +65,7 @@ public class Authorization {
* @param authToken
* @return 0 if successful or a {@code ResponseCode}.
*/
- public int addAuthToken(@NonNull byte[] authToken) {
+ public static int addAuthToken(@NonNull byte[] authToken) {
return addAuthToken(AuthTokenUtils.toHardwareAuthToken(authToken));
}
@@ -86,7 +78,7 @@ public class Authorization {
*
* @return 0 if successful or a {@code ResponseCode}.
*/
- public int onLockScreenEvent(@NonNull boolean locked, @NonNull int userId,
+ public static int onLockScreenEvent(@NonNull boolean locked, @NonNull int userId,
@Nullable byte[] syntheticPassword) {
if (!android.security.keystore2.AndroidKeyStoreProvider.isInstalled()) return 0;
try {
@@ -96,7 +88,7 @@ public class Authorization {
getService().onLockScreenEvent(LockScreenEvent.UNLOCK, userId, syntheticPassword);
}
return 0;
- } catch (RemoteException e) {
+ } catch (RemoteException | NullPointerException e) {
Log.w(TAG, "Can not connect to keystore", e);
return SYSTEM_ERROR;
} catch (ServiceSpecificException e) {