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 private static final int APP_OPS_OP_CODE = AppOpsManager.OP_WRITE_SETTINGS; 33 private static final String PM_WRITE_SETTINGS = Manifest.permission.WRITE_SETTINGS; 34 35 private static final String[] PM_PERMISSIONS = { 36 PM_WRITE_SETTINGS 37 }; 38 AppStateWriteSettingsBridge(Context context, ApplicationsState appState, Callback callback)39 public AppStateWriteSettingsBridge(Context context, ApplicationsState appState, Callback 40 callback) { 41 super(context, appState, callback, APP_OPS_OP_CODE, PM_PERMISSIONS); 42 } 43 44 @Override updateExtraInfo(AppEntry app, String pkg, int uid)45 protected void updateExtraInfo(AppEntry app, String pkg, int uid) { 46 app.extraInfo = getWriteSettingsInfo(pkg, uid); 47 } 48 getWriteSettingsInfo(String pkg, int uid)49 public WriteSettingsState getWriteSettingsInfo(String pkg, int uid) { 50 PermissionState permissionState = super.getPermissionInfo(pkg, uid); 51 return new WriteSettingsState(permissionState); 52 } 53 54 public static class WriteSettingsState extends AppStateAppOpsBridge.PermissionState { WriteSettingsState(PermissionState permissionState)55 public WriteSettingsState(PermissionState permissionState) { 56 super(permissionState.packageName, permissionState.userHandle); 57 this.packageInfo = permissionState.packageInfo; 58 this.appOpMode = permissionState.appOpMode; 59 this.permissionDeclared = permissionState.permissionDeclared; 60 this.staticPermissionGranted = permissionState.staticPermissionGranted; 61 } 62 } 63 64 public static final AppFilter FILTER_WRITE_SETTINGS = new AppFilter() { 65 @Override 66 public void init() { 67 } 68 69 @Override 70 public boolean filterApp(AppEntry info) { 71 return info.extraInfo != null; 72 } 73 }; 74 } 75