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 Lauimport android.util.Log; 227f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 237f70ba18e6760c2539704c16cf3865bf49953d50Billy Lauimport com.android.settingslib.applications.ApplicationsState; 247f70ba18e6760c2539704c16cf3865bf49953d50Billy Lauimport com.android.settingslib.applications.ApplicationsState.AppEntry; 257f70ba18e6760c2539704c16cf3865bf49953d50Billy Lauimport com.android.settingslib.applications.ApplicationsState.AppFilter; 267f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 277f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau/* 287f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau * Connects info of apps that draw overlay to the ApplicationsState. Wraps around the generic 297f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau * AppStateAppOpsBridge class to tailor to the semantics of SYSTEM_ALERT_WINDOW. Also provides app 307f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau * filters that can use the info. 317f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau */ 327f70ba18e6760c2539704c16cf3865bf49953d50Billy Laupublic class AppStateOverlayBridge extends AppStateAppOpsBridge { 337f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 347f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau private static final String TAG = "AppStateOverlayBridge"; 357f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau private static final int APP_OPS_OP_CODE = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; 367f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau private static final String PM_SYSTEM_ALERT_WINDOW = Manifest.permission.SYSTEM_ALERT_WINDOW; 373d9c7fc9982ddd513bc1bebdce76a12eecb61c88Billy Lau private static final String[] PM_PERMISSION = { 383d9c7fc9982ddd513bc1bebdce76a12eecb61c88Billy Lau PM_SYSTEM_ALERT_WINDOW 393d9c7fc9982ddd513bc1bebdce76a12eecb61c88Billy Lau }; 407f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 417f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau public AppStateOverlayBridge(Context context, ApplicationsState appState, Callback callback) { 423d9c7fc9982ddd513bc1bebdce76a12eecb61c88Billy Lau super(context, appState, callback, APP_OPS_OP_CODE, PM_PERMISSION); 437f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau } 447f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 457f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau @Override 467f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau protected void updateExtraInfo(AppEntry app, String pkg, int uid) { 477f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau app.extraInfo = getOverlayInfo(pkg, uid); 487f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau } 497f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 507f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau public OverlayState getOverlayInfo(String pkg, int uid) { 517f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau PermissionState permissionState = super.getPermissionInfo(pkg, uid); 527f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau return new OverlayState(permissionState); 537f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau } 547f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 557f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau // TODO: figure out how to filter out system apps for this method 567f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau public int getNumberOfPackagesWithPermission() { 577f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau return super.getNumPackagesDeclaredPermission(); 587f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau } 597f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 607f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau // TODO: figure out how to filter out system apps for this method 617f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau public int getNumberOfPackagesCanDrawOverlay() { 627f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau return super.getNumPackagesAllowedByAppOps(); 637f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau } 647f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 65f8f98021040e325b07f96ca93a9171c9cc7625d1Billy Lau public static class OverlayState extends AppStateAppOpsBridge.PermissionState { 667f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 677f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau public OverlayState(PermissionState permissionState) { 68f8f98021040e325b07f96ca93a9171c9cc7625d1Billy Lau super(permissionState.packageName, permissionState.userHandle); 69f8f98021040e325b07f96ca93a9171c9cc7625d1Billy Lau this.packageInfo = permissionState.packageInfo; 70f8f98021040e325b07f96ca93a9171c9cc7625d1Billy Lau this.appOpMode = permissionState.appOpMode; 71f8f98021040e325b07f96ca93a9171c9cc7625d1Billy Lau this.permissionDeclared = permissionState.permissionDeclared; 72fee785645b57c519a31ed403e60e8f76dcc8abbbBilly Lau this.staticPermissionGranted = permissionState.staticPermissionGranted; 737f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau } 747f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau } 757f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 767f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau public static final AppFilter FILTER_SYSTEM_ALERT_WINDOW = new AppFilter() { 777f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau @Override 787f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau public void init() { 797f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau } 807f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau 817f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau @Override 827f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau public boolean filterApp(AppEntry info) { 837f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau return info.extraInfo != null; 847f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau } 857f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau }; 867f70ba18e6760c2539704c16cf3865bf49953d50Billy Lau} 87