Bug: 21589105 Rescoping SYSTEM_ALERT_WINDOW and WRITE_SETTINGS permission to an

explicit toggle to be enabled through Settings via Apps -> Advanced Apps.

Added new and refactored an old xml to define the UX for two new Preferences
in Advanced Settings. Modified the existing AdvancedAppSettings to add
control flow for two new settings. Also enriched ManageApplications to
handle these cases. Added additional strings in xml/values/strings.xml
to support these settings. Also defined new classes to handle these the
toggle of these permissions per app.

Refactored codes from AppStateUsageBridge to a generic AppStateAppOpsBridge so
that future usages related to AppOps can inherit from this class.

Change-Id: I43b81282a063e05844c7805556a6d05cfc02bcdb
This commit is contained in:
Billy Lau
2015-07-03 17:01:18 +01:00
parent 01ce80b574
commit 7f70ba18e6
14 changed files with 1146 additions and 230 deletions

View File

@@ -0,0 +1,84 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.applications;
import android.Manifest;
import android.app.AppOpsManager;
import android.content.Context;
import android.util.Log;
import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
import com.android.settingslib.applications.ApplicationsState.AppFilter;
/*
* Connects info of apps that draw overlay to the ApplicationsState. Wraps around the generic
* AppStateAppOpsBridge class to tailor to the semantics of SYSTEM_ALERT_WINDOW. Also provides app
* filters that can use the info.
*/
public class AppStateOverlayBridge extends AppStateAppOpsBridge {
private static final String TAG = "AppStateOverlayBridge";
private static final int APP_OPS_OP_CODE = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
private static final String PM_SYSTEM_ALERT_WINDOW = Manifest.permission.SYSTEM_ALERT_WINDOW;
public AppStateOverlayBridge(Context context, ApplicationsState appState, Callback callback) {
super(context, appState, callback, APP_OPS_OP_CODE, PM_SYSTEM_ALERT_WINDOW);
}
@Override
protected void updateExtraInfo(AppEntry app, String pkg, int uid) {
app.extraInfo = getOverlayInfo(pkg, uid);
}
public OverlayState getOverlayInfo(String pkg, int uid) {
PermissionState permissionState = super.getPermissionInfo(pkg, uid);
return new OverlayState(permissionState);
}
// TODO: figure out how to filter out system apps for this method
public int getNumberOfPackagesWithPermission() {
return super.getNumPackagesDeclaredPermission();
}
// TODO: figure out how to filter out system apps for this method
public int getNumberOfPackagesCanDrawOverlay() {
return super.getNumPackagesAllowedByAppOps();
}
public static class OverlayState {
PermissionState mPermissionState;
public OverlayState(PermissionState permissionState) {
mPermissionState = permissionState;
}
public boolean isAllowed() {
return mPermissionState.isPermissible();
}
}
public static final AppFilter FILTER_SYSTEM_ALERT_WINDOW = new AppFilter() {
@Override
public void init() {
}
@Override
public boolean filterApp(AppEntry info) {
return info.extraInfo != null;
}
};
}