blob: cac7f53aad664e7b1f69d6e7d617fdb2a16fe730 [file] [log] [blame]
Felipe Leme0486d202018-12-04 09:47:39 -08001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.server.infra;
17
18import android.annotation.NonNull;
19import android.annotation.UserIdInt;
20import android.content.Context;
21import android.provider.Settings;
22
23import java.io.PrintWriter;
24
25/**
26 * Gets the service name using a property from the {@link android.provider.Settings.Secure}
27 * provider.
28 *
29 * @hide
30 */
31public final class SecureSettingsServiceNameResolver implements ServiceNameResolver {
32
33 private final @NonNull Context mContext;
Felipe Leme0486d202018-12-04 09:47:39 -080034
35 @NonNull
36 private final String mProperty;
37
Felipe Lemec28711c2018-12-20 11:17:02 -080038 public SecureSettingsServiceNameResolver(@NonNull Context context, @NonNull String property) {
Felipe Leme0486d202018-12-04 09:47:39 -080039 mContext = context;
Felipe Leme0486d202018-12-04 09:47:39 -080040 mProperty = property;
41 }
42
43 @Override
Felipe Lemec28711c2018-12-20 11:17:02 -080044 public String getDefaultServiceName(@UserIdInt int userId) {
45 return Settings.Secure.getStringForUser(mContext.getContentResolver(), mProperty, userId);
Felipe Leme0486d202018-12-04 09:47:39 -080046 }
47
48 // TODO(b/117779333): support proto
49 @Override
Felipe Lemec28711c2018-12-20 11:17:02 -080050 public void dumpShort(@NonNull PrintWriter pw) {
Felipe Leme0486d202018-12-04 09:47:39 -080051 pw.print("SecureSettingsServiceNamer: prop="); pw.print(mProperty);
Felipe Lemec28711c2018-12-20 11:17:02 -080052 }
53
54 // TODO(b/117779333): support proto
55 @Override
56 public void dumpShort(@NonNull PrintWriter pw, @UserIdInt int userId) {
57 pw.print("defaultService="); pw.print(getDefaultServiceName(userId));
Felipe Leme0486d202018-12-04 09:47:39 -080058 }
Felipe Leme18a9a4a2019-01-08 15:53:42 -080059
60 @Override
61 public String toString() {
62 return "SecureSettingsServiceNameResolver[" + mProperty + "]";
63 }
Felipe Leme0486d202018-12-04 09:47:39 -080064}