Add settings UI for MANAGE_EXTERNAL_STORAGE
Adds a Special App Access setting for the app-op
OP_MANAGE_EXTERNAL_STORAGE. All apps requesting the corresponding
permission will be displayed in the settings page. Toggling the
preference switch for an app will grant/revoke the app-op.
All of the external references to the permission, app-op and their
corresponding activities and logic use the name "Manage External
Storage". All of the external displays and strings use the name "All
files access"
Test: * Install app with uses-permission MANAGE_EXTERNAL_STORAGE
* Observe it appearing the All files access page
* Toggle the switch and observe the change in
'adb shell dumpsys appops'
Bug: 146425146
Change-Id: If5c9c5daa3616a3310c090283acfda933bf9df26
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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 com.android.settingslib.applications.ApplicationsState;
|
||||
|
||||
/**
|
||||
* Retrieves information from {@link AppOpsManager} and {@link android.content.pm.PackageManager}
|
||||
* regarding {@link AppOpsManager#OP_MANAGE_EXTERNAL_STORAGE} and
|
||||
* {@link Manifest.permission#MANAGE_EXTERNAL_STORAGE}.
|
||||
*/
|
||||
public class AppStateManageExternalStorageBridge extends AppStateAppOpsBridge {
|
||||
private static final int APP_OPS_OP_CODE = AppOpsManager.OP_MANAGE_EXTERNAL_STORAGE;
|
||||
private static final String[] PERMISSIONS = {
|
||||
Manifest.permission.MANAGE_EXTERNAL_STORAGE
|
||||
};
|
||||
|
||||
public AppStateManageExternalStorageBridge(Context context, ApplicationsState appState,
|
||||
Callback callback) {
|
||||
super(context, appState, callback, APP_OPS_OP_CODE, PERMISSIONS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateExtraInfo(ApplicationsState.AppEntry app, String pkg, int uid) {
|
||||
app.extraInfo = getManageExternalStoragePermState(pkg, uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the MANAGE_EXTERNAL_STORAGE {@link AppStateAppOpsBridge.PermissionState} object
|
||||
* associated with the given package and user.
|
||||
*/
|
||||
public PermissionState getManageExternalStoragePermState(String pkg, int uid) {
|
||||
return getPermissionInfo(pkg, uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by {@link com.android.settings.applications.manageapplications.AppFilterRegistry} to
|
||||
* determine which apps get to appear on the Special App Access list.
|
||||
*/
|
||||
public static final ApplicationsState.AppFilter FILTER_MANAGE_EXTERNAL_STORAGE =
|
||||
new ApplicationsState.AppFilter() {
|
||||
@Override
|
||||
public void init() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean filterApp(ApplicationsState.AppEntry info) {
|
||||
// If extraInfo != null, it means that the app has declared
|
||||
// Manifest.permission.MANAGE_EXTERNAL_STORAGE and therefore it should appear on our
|
||||
// list
|
||||
return info.extraInfo != null;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user