1 /* 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 */ 16 package com.android.server.infra; 17 18 import android.annotation.NonNull; 19 import android.annotation.UserIdInt; 20 import android.content.Context; 21 import android.provider.Settings; 22 23 import 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 */ 31 public final class SecureSettingsServiceNameResolver implements ServiceNameResolver { 32 33 private final @NonNull Context mContext; 34 35 @NonNull 36 private final String mProperty; 37 38 public SecureSettingsServiceNameResolver(@NonNull Context context, @NonNull String property) { 39 mContext = context; 40 mProperty = property; 41 } 42 43 @Override 44 public String getDefaultServiceName(@UserIdInt int userId) { 45 return Settings.Secure.getStringForUser(mContext.getContentResolver(), mProperty, userId); 46 } 47 48 // TODO(b/117779333): support proto 49 @Override 50 public void dumpShort(@NonNull PrintWriter pw) { 51 pw.print("SecureSettingsServiceNamer: prop="); pw.print(mProperty); 52 } 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)); 58 } 59 60 @Override 61 public String toString() { 62 return "SecureSettingsServiceNameResolver[" + mProperty + "]"; 63 } 64 } 65