summaryrefslogtreecommitdiff
path: root/keystore/java
diff options
context:
space:
mode:
authorHasini Gunasinghe <hasinitg@google.com>2021-02-05 20:21:01 +0000
committerJanis Danisevskis <jdanis@google.com>2021-02-19 15:34:10 -0800
commit13dd61336fe7b5d6eea4e82c4881c9f3b2b58ce8 (patch)
tree65b43e42fb666d9942e282460335599803d0ed34 /keystore/java
parent355753053cf8c6c573a4640d6c1047180e7494f9 (diff)
Integrate IKeystoreUserManager aidl with LockSettingsService.
This CL introduces the client side for IKeystoreUserManager aidl and integrates it with the LockSettingsService. Bug: 171305115 Test: TBD Change-Id: I7560e98f95aaec6b85cdcfc01ba83aea0ccc52ae
Diffstat (limited to 'keystore/java')
-rw-r--r--keystore/java/android/security/AndroidKeyStoreMaintenance.java105
1 files changed, 105 insertions, 0 deletions
diff --git a/keystore/java/android/security/AndroidKeyStoreMaintenance.java b/keystore/java/android/security/AndroidKeyStoreMaintenance.java
new file mode 100644
index 000000000000..c81c8c54d88a
--- /dev/null
+++ b/keystore/java/android/security/AndroidKeyStoreMaintenance.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.security;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.os.ServiceManager;
+import android.os.ServiceSpecificException;
+import android.security.usermanager.IKeystoreUserManager;
+import android.system.keystore2.ResponseCode;
+import android.util.Log;
+
+/**
+ * @hide This is the client side for IKeystoreUserManager AIDL.
+ * It shall only be used by the LockSettingsService.
+ */
+public class AndroidKeyStoreMaintenance {
+ private static final String TAG = "AndroidKeyStoreMaintenance";
+
+ public static final int SYSTEM_ERROR = ResponseCode.SYSTEM_ERROR;
+
+ private static IKeystoreUserManager getService() {
+ return IKeystoreUserManager.Stub.asInterface(
+ ServiceManager.checkService("android.security.usermanager"));
+ }
+
+ /**
+ * Informs keystore2 about adding a user
+ *
+ * @param userId - Android user id of the user being added
+ * @return 0 if successful or a {@code ResponseCode}
+ * @hide
+ */
+ public static int onUserAdded(@NonNull int userId) {
+ if (!android.security.keystore2.AndroidKeyStoreProvider.isInstalled()) return 0;
+ try {
+ getService().onUserAdded(userId);
+ return 0;
+ } catch (ServiceSpecificException e) {
+ Log.e(TAG, "onUserAdded failed", e);
+ return e.errorCode;
+ } catch (Exception e) {
+ Log.e(TAG, "Can not connect to keystore", e);
+ return SYSTEM_ERROR;
+ }
+ }
+
+ /**
+ * Informs keystore2 about removing a usergit mer
+ *
+ * @param userId - Android user id of the user being removed
+ * @return 0 if successful or a {@code ResponseCode}
+ * @hide
+ */
+ public static int onUserRemoved(int userId) {
+ if (!android.security.keystore2.AndroidKeyStoreProvider.isInstalled()) return 0;
+ try {
+ getService().onUserRemoved(userId);
+ return 0;
+ } catch (ServiceSpecificException e) {
+ Log.e(TAG, "onUserRemoved failed", e);
+ return e.errorCode;
+ } catch (Exception e) {
+ Log.e(TAG, "Can not connect to keystore", e);
+ return SYSTEM_ERROR;
+ }
+ }
+
+ /**
+ * Informs keystore2 about changing user's password
+ *
+ * @param userId - Android user id of the user
+ * @param password - a secret derived from the synthetic password provided by the
+ * LockSettingService
+ * @return 0 if successful or a {@code ResponseCode}
+ * @hide
+ */
+ public static int onUserPasswordChanged(int userId, @Nullable byte[] password) {
+ if (!android.security.keystore2.AndroidKeyStoreProvider.isInstalled()) return 0;
+ try {
+ getService().onUserPasswordChanged(userId, password);
+ return 0;
+ } catch (ServiceSpecificException e) {
+ Log.e(TAG, "onUserPasswordChanged failed", e);
+ return e.errorCode;
+ } catch (Exception e) {
+ Log.e(TAG, "Can not connect to keystore", e);
+ return SYSTEM_ERROR;
+ }
+ }
+}