1 /*
2  * Copyright (C) 2022 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 android.car.builtin.app;
18 
19 import android.annotation.SystemApi;
20 import android.app.AppOpsManager;
21 import android.content.Context;
22 
23 /**
24  * Helper for AppOpsManagerHelper related operations.
25  *
26  * @hide
27  */
28 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
29 public final class AppOpsManagerHelper {
30 
AppOpsManagerHelper()31     private AppOpsManagerHelper() {
32         throw new UnsupportedOperationException("contains only static members");
33     }
34 
35     /**
36      * Sets whether the app associated with the given {@code packageName} is allowed to turn the
37      * screen on.
38      *
39      * @param context Context to use.
40      * @param uid The user id of the application whose mode will be changed.
41      * @param packageName The name of the application package name whose mode will be changed.
42      * @param isAllowed Whether to allow or disallow.
43      */
setTurnScreenOnAllowed(Context context, int uid, String packageName, boolean isAllowed)44     public static void setTurnScreenOnAllowed(Context context, int uid, String packageName,
45             boolean isAllowed) {
46         int mode = isAllowed ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_ERRORED;
47         AppOpsManager appOpsManager = context.getSystemService(AppOpsManager.class);
48         appOpsManager.setMode(AppOpsManager.OP_TURN_SCREEN_ON, uid, packageName, mode);
49     }
50 }
51