Add initial skeleton implementation of Credential Manager
Test: built and tested locally
Change-Id: Ide7a4b586929b4175001ed02fce2f7245f9e31f2
diff --git a/core/java/android/credentials/ICredentialManager.aidl b/core/java/android/credentials/ICredentialManager.aidl
new file mode 100644
index 0000000..a281cd5
--- /dev/null
+++ b/core/java/android/credentials/ICredentialManager.aidl
@@ -0,0 +1,10 @@
+package android.credentials;
+
+/**
+ * Mediator between apps and credential manager service implementations.
+ *
+ * {@hide}
+ */
+oneway interface ICredentialManager {
+ void getCredential();
+}
\ No newline at end of file
diff --git a/services/credentials/Android.bp b/services/credentials/Android.bp
new file mode 100644
index 0000000..5fa4442
--- /dev/null
+++ b/services/credentials/Android.bp
@@ -0,0 +1,22 @@
+package {
+ // See: http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // all of the 'license_kinds' from "frameworks_base_license"
+ // to get the below license kinds:
+ // SPDX-license-identifier-Apache-2.0
+ default_applicable_licenses: ["frameworks_base_license"],
+}
+
+filegroup {
+ name: "services.credentials-sources",
+ srcs: ["java/**/*.java"],
+ path: "java",
+ visibility: ["//frameworks/base/services"],
+}
+
+java_library_static {
+ name: "services.credentials",
+ defaults: ["platform_service_defaults"],
+ srcs: [":services.credentials-sources"],
+ libs: ["services.core"],
+}
diff --git a/services/credentials/java/com/android/server/credentials/CredentialManagerService.java b/services/credentials/java/com/android/server/credentials/CredentialManagerService.java
new file mode 100644
index 0000000..76ed2b3
--- /dev/null
+++ b/services/credentials/java/com/android/server/credentials/CredentialManagerService.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2022 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 com.android.server.credentials;
+
+import android.annotation.NonNull;
+import android.annotation.UserIdInt;
+import android.content.Context;
+import android.credentials.ICredentialManager;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.util.Log;
+
+import com.android.server.infra.AbstractMasterSystemService;
+import com.android.server.infra.SecureSettingsServiceNameResolver;
+
+/**
+ * Entry point service for credential management.
+ *
+ * <p>This service provides the {@link ICredentialManager} implementation and keeps a list of
+ * {@link CredentialManagerServiceImpl} per user; the real work is done by
+ * {@link CredentialManagerServiceImpl} itself.
+ */
+public final class CredentialManagerService extends
+ AbstractMasterSystemService<CredentialManagerService, CredentialManagerServiceImpl> {
+
+ private static final String TAG = "CredManSysService";
+
+ public CredentialManagerService(@NonNull Context context) {
+ super(context,
+ new SecureSettingsServiceNameResolver(context, Settings.Secure.AUTOFILL_SERVICE),
+ null, PACKAGE_UPDATE_POLICY_REFRESH_EAGER);
+ }
+
+ @Override
+ protected String getServiceSettingsProperty() {
+ return Settings.Secure.AUTOFILL_SERVICE;
+ }
+
+ @Override // from AbstractMasterSystemService
+ protected CredentialManagerServiceImpl newServiceLocked(@UserIdInt int resolvedUserId,
+ boolean disabled) {
+ return new CredentialManagerServiceImpl(this, mLock, resolvedUserId);
+ }
+
+ @Override
+ public void onStart() {
+ Log.i(TAG, "onStart");
+ }
+
+ final class CredentialManagerServiceStub extends ICredentialManager.Stub {
+ @Override
+ public void getCredential() {
+ final int userId = UserHandle.getCallingUserId();
+ synchronized (mLock) {
+ final CredentialManagerServiceImpl service = peekServiceForUserLocked(userId);
+ if (service != null) {
+ Log.i(TAG, "Got service for : " + userId);
+ service.getCredential();
+ }
+ }
+ }
+ }
+}
diff --git a/services/credentials/java/com/android/server/credentials/CredentialManagerServiceImpl.java b/services/credentials/java/com/android/server/credentials/CredentialManagerServiceImpl.java
new file mode 100644
index 0000000..f45f626
--- /dev/null
+++ b/services/credentials/java/com/android/server/credentials/CredentialManagerServiceImpl.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2022 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 com.android.server.credentials;
+
+import android.annotation.NonNull;
+import android.util.Log;
+
+import com.android.server.infra.AbstractPerUserSystemService;
+
+/**
+ * Per-user implementation of {@link CredentialManagerService}
+ */
+public class CredentialManagerServiceImpl extends
+ AbstractPerUserSystemService<CredentialManagerServiceImpl, CredentialManagerService> {
+ private static final String TAG = "CredManSysServiceImpl";
+
+ protected CredentialManagerServiceImpl(
+ @NonNull CredentialManagerService master,
+ @NonNull Object lock, int userId) {
+ super(master, lock, userId);
+ }
+
+ /**
+ * Unimplemented getCredentials
+ */
+ public void getCredential() {
+ Log.i(TAG, "getCredential not implemented");
+ // TODO : Implement logic
+ }
+}