17f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau/* 27f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau * Copyright (C) 2015 The Android Open Source Project 37f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau * 47f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau * Licensed under the Apache License, Version 2.0 (the "License"); 57f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau * you may not use this file except in compliance with the License. 67f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau * You may obtain a copy of the License at 77f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau * 87f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau * http://www.apache.org/licenses/LICENSE-2.0 97f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau * 107f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau * Unless required by applicable law or agreed to in writing, software 117f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau * distributed under the License is distributed on an "AS IS" BASIS, 127f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau * See the License for the specific language governing permissions and 147f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau * limitations under the License. 157f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau */ 167f70ba18e6760c2539704c16cf3865bf49953d50Billy Laupackage com.android.settings.applications; 177f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 187f70ba18e6760c2539704c16cf3865bf49953d50Billy Lauimport android.Manifest; 197f70ba18e6760c2539704c16cf3865bf49953d50Billy Lauimport android.app.AppOpsManager; 207f70ba18e6760c2539704c16cf3865bf49953d50Billy Lauimport android.content.Context; 217f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 227f70ba18e6760c2539704c16cf3865bf49953d50Billy Lauimport com.android.settingslib.applications.ApplicationsState; 237f70ba18e6760c2539704c16cf3865bf49953d50Billy Lauimport com.android.settingslib.applications.ApplicationsState.AppEntry; 247f70ba18e6760c2539704c16cf3865bf49953d50Billy Lauimport com.android.settingslib.applications.ApplicationsState.AppFilter; 257f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 267f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau/* 277f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau * Connects info of apps that draw overlay to the ApplicationsState. Wraps around the generic 287f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau * AppStateAppOpsBridge class to tailor to the semantics of SYSTEM_ALERT_WINDOW. Also provides app 297f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau * filters that can use the info. 307f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau */ 317f70ba18e6760c2539704c16cf3865bf49953d50Billy Laupublic class AppStateOverlayBridge extends AppStateAppOpsBridge { 327f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 337f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau private static final String TAG = "AppStateOverlayBridge"; 347f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau private static final int APP_OPS_OP_CODE = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; 357f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau private static final String PM_SYSTEM_ALERT_WINDOW = Manifest.permission.SYSTEM_ALERT_WINDOW; 363d9c7fc9982ddd513bc1bebdce76a12eecb61c88Billy Lau private static final String[] PM_PERMISSION = { 373d9c7fc9982ddd513bc1bebdce76a12eecb61c88Billy Lau PM_SYSTEM_ALERT_WINDOW 383d9c7fc9982ddd513bc1bebdce76a12eecb61c88Billy Lau }; 397f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 407f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau public AppStateOverlayBridge(Context context, ApplicationsState appState, Callback callback) { 413d9c7fc9982ddd513bc1bebdce76a12eecb61c88Billy Lau super(context, appState, callback, APP_OPS_OP_CODE, PM_PERMISSION); 427f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau } 437f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 447f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau @Override 457f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau protected void updateExtraInfo(AppEntry app, String pkg, int uid) { 467f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau app.extraInfo = getOverlayInfo(pkg, uid); 477f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau } 487f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 497f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau public OverlayState getOverlayInfo(String pkg, int uid) { 507f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau PermissionState permissionState = super.getPermissionInfo(pkg, uid); 517f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau return new OverlayState(permissionState); 527f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau } 537f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 547f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau // TODO: figure out how to filter out system apps for this method 557f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau public int getNumberOfPackagesWithPermission() { 567f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau return super.getNumPackagesDeclaredPermission(); 577f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau } 587f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 597f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau // TODO: figure out how to filter out system apps for this method 607f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau public int getNumberOfPackagesCanDrawOverlay() { 617f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau return super.getNumPackagesAllowedByAppOps(); 627f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau } 637f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 64f8f98021040e325b07f96ca93a9171c9cc7625d1Billy Lau public static class OverlayState extends AppStateAppOpsBridge.PermissionState { 657f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 667f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau public OverlayState(PermissionState permissionState) { 67f8f98021040e325b07f96ca93a9171c9cc7625d1Billy Lau super(permissionState.packageName, permissionState.userHandle); 68f8f98021040e325b07f96ca93a9171c9cc7625d1Billy Lau this.packageInfo = permissionState.packageInfo; 69f8f98021040e325b07f96ca93a9171c9cc7625d1Billy Lau this.appOpMode = permissionState.appOpMode; 70f8f98021040e325b07f96ca93a9171c9cc7625d1Billy Lau this.permissionDeclared = permissionState.permissionDeclared; 71fee785645b57c519a31ed403e60e8f76dcc8abbbBilly Lau this.staticPermissionGranted = permissionState.staticPermissionGranted; 727f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau } 737f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau } 747f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 757f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau public static final AppFilter FILTER_SYSTEM_ALERT_WINDOW = new AppFilter() { 767f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau @Override 777f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau public void init() { 787f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau } 797f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 807f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau @Override 817f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau public boolean filterApp(AppEntry info) { 827f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau return info.extraInfo != null; 837f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau } 847f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau }; 857f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau} 86