Felipe Leme | 0486d20 | 2018-12-04 09:47:39 -0800 | [diff] [blame] | 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; |
Felipe Leme | 0486d20 | 2018-12-04 09:47:39 -0800 | [diff] [blame] | 34 | |
| 35 | @NonNull |
| 36 | private final String mProperty; |
| 37 | |
Felipe Leme | c28711c | 2018-12-20 11:17:02 -0800 | [diff] [blame] | 38 | public SecureSettingsServiceNameResolver(@NonNull Context context, @NonNull String property) { |
Felipe Leme | 0486d20 | 2018-12-04 09:47:39 -0800 | [diff] [blame] | 39 | mContext = context; |
Felipe Leme | 0486d20 | 2018-12-04 09:47:39 -0800 | [diff] [blame] | 40 | mProperty = property; |
| 41 | } |
| 42 | |
| 43 | @Override |
Felipe Leme | c28711c | 2018-12-20 11:17:02 -0800 | [diff] [blame] | 44 | public String getDefaultServiceName(@UserIdInt int userId) { |
| 45 | return Settings.Secure.getStringForUser(mContext.getContentResolver(), mProperty, userId); |
Felipe Leme | 0486d20 | 2018-12-04 09:47:39 -0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | // TODO(b/117779333): support proto |
| 49 | @Override |
Felipe Leme | c28711c | 2018-12-20 11:17:02 -0800 | [diff] [blame] | 50 | public void dumpShort(@NonNull PrintWriter pw) { |
Felipe Leme | 0486d20 | 2018-12-04 09:47:39 -0800 | [diff] [blame] | 51 | pw.print("SecureSettingsServiceNamer: prop="); pw.print(mProperty); |
Felipe Leme | c28711c | 2018-12-20 11:17:02 -0800 | [diff] [blame] | 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)); |
Felipe Leme | 0486d20 | 2018-12-04 09:47:39 -0800 | [diff] [blame] | 58 | } |
Felipe Leme | 18a9a4a | 2019-01-08 15:53:42 -0800 | [diff] [blame^] | 59 | |
| 60 | @Override |
| 61 | public String toString() { |
| 62 | return "SecureSettingsServiceNameResolver[" + mProperty + "]"; |
| 63 | } |
Felipe Leme | 0486d20 | 2018-12-04 09:47:39 -0800 | [diff] [blame] | 64 | } |