Moved logic that gets the service name to a separate set of classes.

Such refactoring will allow a system service to connect to more than one
AbstractRemoteService.

Bug: 117779333
Test: atest CtsContentCaptureServiceTestCases CtsAutoFillServiceTestCases

Change-Id: Ib14d80fa117893126d190f07b67228d29e0dcc76
diff --git a/services/core/java/com/android/server/infra/SecureSettingsServiceNameResolver.java b/services/core/java/com/android/server/infra/SecureSettingsServiceNameResolver.java
new file mode 100644
index 0000000..7af8f60
--- /dev/null
+++ b/services/core/java/com/android/server/infra/SecureSettingsServiceNameResolver.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2018 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.infra;
+
+import android.annotation.NonNull;
+import android.annotation.UserIdInt;
+import android.content.Context;
+import android.provider.Settings;
+
+import java.io.PrintWriter;
+
+/**
+ * Gets the service name using a property from the {@link android.provider.Settings.Secure}
+ * provider.
+ *
+ * @hide
+ */
+public final class SecureSettingsServiceNameResolver implements ServiceNameResolver {
+
+    private final @NonNull Context mContext;
+    private final @NonNull @UserIdInt int mUserId;
+
+    @NonNull
+    private final String mProperty;
+
+    public SecureSettingsServiceNameResolver(@NonNull Context context, @UserIdInt int userId,
+            @NonNull String property) {
+        mContext = context;
+        mUserId = userId;
+        mProperty = property;
+    }
+
+    @Override
+    public String getDefaultServiceName() {
+        return Settings.Secure.getStringForUser(mContext.getContentResolver(), mProperty, mUserId);
+    }
+
+    // TODO(b/117779333): support proto
+    @Override
+    public void dumpShortLocked(@NonNull PrintWriter pw) {
+        pw.print("SecureSettingsServiceNamer: prop="); pw.print(mProperty);
+        pw.print(", value="); pw.println(getDefaultServiceName());
+    }
+}