• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.settings.applications;
17 
18 import android.Manifest;
19 import android.app.AppOpsManager;
20 import android.content.Context;
21 
22 import com.android.settingslib.applications.ApplicationsState;
23 import com.android.settingslib.applications.ApplicationsState.AppEntry;
24 import com.android.settingslib.applications.ApplicationsState.AppFilter;
25 
26 /*
27  * Connects info of apps that draw overlay to the ApplicationsState. Wraps around the generic
28  * AppStateAppOpsBridge class to tailor to the semantics of SYSTEM_ALERT_WINDOW. Also provides app
29  * filters that can use the info.
30  */
31 public class AppStateWriteSettingsBridge extends AppStateAppOpsBridge {
32 
33     private static final String TAG = "AppStateWriteSettingsBridge";
34     private static final int APP_OPS_OP_CODE = AppOpsManager.OP_WRITE_SETTINGS;
35     private static final String PM_WRITE_SETTINGS = Manifest.permission.WRITE_SETTINGS;
36 
37     private static final String[] PM_PERMISSIONS = {
38             PM_WRITE_SETTINGS
39     };
40 
AppStateWriteSettingsBridge(Context context, ApplicationsState appState, Callback callback)41     public AppStateWriteSettingsBridge(Context context, ApplicationsState appState, Callback
42             callback) {
43         super(context, appState, callback, APP_OPS_OP_CODE, PM_PERMISSIONS);
44     }
45 
46     @Override
updateExtraInfo(AppEntry app, String pkg, int uid)47     protected void updateExtraInfo(AppEntry app, String pkg, int uid) {
48         app.extraInfo = getWriteSettingsInfo(pkg, uid);
49     }
50 
getWriteSettingsInfo(String pkg, int uid)51     public WriteSettingsState getWriteSettingsInfo(String pkg, int uid) {
52         PermissionState permissionState = super.getPermissionInfo(pkg, uid);
53         return new WriteSettingsState(permissionState);
54     }
55 
56     // TODO: figure out how to filter out system apps for this method
getNumberOfPackagesWithPermission()57     public int getNumberOfPackagesWithPermission() {
58         return super.getNumPackagesDeclaredPermission();
59     }
60 
61     // TODO: figure out how to filter out system apps for this method
getNumberOfPackagesCanWriteSettings()62     public int getNumberOfPackagesCanWriteSettings() {
63         return super.getNumPackagesAllowedByAppOps();
64     }
65 
66     public static class WriteSettingsState extends AppStateAppOpsBridge.PermissionState {
WriteSettingsState(PermissionState permissionState)67         public WriteSettingsState(PermissionState permissionState) {
68             super(permissionState.packageName, permissionState.userHandle);
69             this.packageInfo = permissionState.packageInfo;
70             this.appOpMode = permissionState.appOpMode;
71             this.permissionDeclared = permissionState.permissionDeclared;
72             this.staticPermissionGranted = permissionState.staticPermissionGranted;
73         }
74     }
75 
76     public static final AppFilter FILTER_WRITE_SETTINGS = new AppFilter() {
77         @Override
78         public void init() {
79         }
80 
81         @Override
82         public boolean filterApp(AppEntry info) {
83             return info.extraInfo != null;
84         }
85     };
86 }
87