1 /*
2  * Copyright (C) 2024 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 
17 package com.android.settings
18 
19 import android.app.Application
20 import android.content.Intent
21 import com.android.settings.flags.Flags
22 import com.android.settingslib.graph.PreferenceGetterRequest
23 import com.android.settingslib.graph.PreferenceSetterRequest
24 import com.android.settingslib.ipc.ApiPermissionChecker
25 import com.android.settingslib.service.PreferenceService
26 
27 /** Service to expose settings APIs. */
28 class SettingsService :
29     PreferenceService(
30         graphPermissionChecker = ApiPermissionChecker.alwaysAllow(),
31         setterPermissionChecker = SetterPermissionChecker(),
32         getterPermissionChecker = GetterPermissionChecker(),
33     ) {
34 
onBindnull35     override fun onBind(intent: Intent) =
36         if (Flags.catalystService()) super.onBind(intent) else null
37 }
38 
39 /** Permission checker for external setter API. */
40 private class SetterPermissionChecker : ApiPermissionChecker<PreferenceSetterRequest> {
41 
42     override fun hasPermission(
43         application: Application,
44         myUid: Int,
45         callingUid: Int,
46         request: PreferenceSetterRequest,
47     ) = true
48 }
49 
50 /** Permission checker for external getter API. */
51 private class GetterPermissionChecker : ApiPermissionChecker<PreferenceGetterRequest> {
52 
hasPermissionnull53     override fun hasPermission(
54         application: Application,
55         myUid: Int,
56         callingUid: Int,
57         request: PreferenceGetterRequest,
58     ) = true
59 }
60