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