Merge "Use AppOpsManager#setUidMode instead of #setMode" into rvc-dev
diff --git a/src/com/android/settings/applications/AppStateManageExternalStorageBridge.java b/src/com/android/settings/applications/AppStateManageExternalStorageBridge.java
index 5a69035..7933062 100644
--- a/src/com/android/settings/applications/AppStateManageExternalStorageBridge.java
+++ b/src/com/android/settings/applications/AppStateManageExternalStorageBridge.java
@@ -22,20 +22,25 @@
import com.android.settingslib.applications.ApplicationsState;
+import java.util.List;
+
/**
* 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 APP_OP_STR = AppOpsManager.OPSTR_MANAGE_EXTERNAL_STORAGE;
private static final String[] PERMISSIONS = {
Manifest.permission.MANAGE_EXTERNAL_STORAGE
};
+ private final AppOpsManager mAppOpsManager;
+
public AppStateManageExternalStorageBridge(Context context, ApplicationsState appState,
Callback callback) {
- super(context, appState, callback, APP_OPS_OP_CODE, PERMISSIONS);
+ super(context, appState, callback, AppOpsManager.strOpToOp(APP_OP_STR), PERMISSIONS);
+ mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
}
@Override
@@ -43,6 +48,25 @@
app.extraInfo = getManageExternalStoragePermState(pkg, uid);
}
+ @Override
+ protected void loadAllExtraInfo() {
+ super.loadAllExtraInfo();
+ List<ApplicationsState.AppEntry> apps = mAppSession.getAllApps();
+ for (ApplicationsState.AppEntry app : apps) {
+ if (app.extraInfo instanceof PermissionState) {
+ ((PermissionState) app.extraInfo).appOpMode = mAppOpsManager.unsafeCheckOpNoThrow(
+ APP_OP_STR, app.info.uid, app.info.packageName);
+ }
+ }
+ }
+
+ @Override
+ public PermissionState getPermissionInfo(String pkg, int uid) {
+ PermissionState ps = super.getPermissionInfo(pkg, uid);
+ ps.appOpMode = mAppOpsManager.unsafeCheckOpNoThrow(APP_OP_STR, uid, pkg);
+ return ps;
+ }
+
/**
* Returns the MANAGE_EXTERNAL_STORAGE {@link AppStateAppOpsBridge.PermissionState} object
* associated with the given package and user.
diff --git a/src/com/android/settings/applications/appinfo/ManageExternalStorageDetails.java b/src/com/android/settings/applications/appinfo/ManageExternalStorageDetails.java
index 63ce440..6c840d5 100644
--- a/src/com/android/settings/applications/appinfo/ManageExternalStorageDetails.java
+++ b/src/com/android/settings/applications/appinfo/ManageExternalStorageDetails.java
@@ -23,7 +23,6 @@
import android.view.View;
import android.view.ViewGroup;
-import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference;
import androidx.preference.Preference.OnPreferenceChangeListener;
@@ -110,8 +109,8 @@
*/
private void setManageExternalStorageState(boolean newState) {
logSpecialPermissionChange(newState, mPackageName);
- mAppOpsManager.setMode(AppOpsManager.OP_MANAGE_EXTERNAL_STORAGE,
- mPackageInfo.applicationInfo.uid, mPackageName, newState
+ mAppOpsManager.setUidMode(AppOpsManager.OP_MANAGE_EXTERNAL_STORAGE,
+ mPackageInfo.applicationInfo.uid, newState
? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_ERRORED);
}