Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit da0acdf9 authored by Svet Ganov's avatar Svet Ganov
Browse files

Auto-grant background execution and data access

Companion apps can declare they want background access and
background execution exceptions via dedicated permissions
in their manifest. If such a permission is requested we
auto-grant the corresponding exception after the user has
chosen a device from the companion UI. These permissions
are appop ones allowing us to use the app ops for gauging
whether the user has made a change after we auto-granted
the permission since we would like to revoke these special
privileges when the app disassociates itself from the
companion device if the user did not make an excplicit
choice otherwise.

While at this auto-grant fixed location permission to the
companion device discovery service.

Test: manual

Change-Id: I46ee4291e5e5a8f7613f0dd75eb61d6b9341f306
parent 3d52f79b
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -295,9 +295,9 @@ LOCAL_SRC_FILES += \
	core/java/android/printservice/IPrintService.aidl \
	core/java/android/printservice/IPrintServiceClient.aidl \
	core/java/android/companion/ICompanionDeviceManager.aidl \
	core/java/android/companion/ICompanionDeviceManagerService.aidl \
	core/java/android/companion/ICompanionDeviceManagerServiceCallback.aidl \
	core/java/android/companion/IOnAssociateCallback.aidl \
	core/java/android/companion/ICompanionDeviceDiscoveryService.aidl \
	core/java/android/companion/ICompanionDeviceDiscoveryServiceCallback.aidl \
	core/java/android/companion/IFindDeviceCallback.aidl \
	core/java/android/service/dreams/IDreamManager.aidl \
	core/java/android/service/dreams/IDreamService.aidl \
	core/java/android/service/persistentdata/IPersistentDataBlockService.aidl \
+2 −0
Original line number Diff line number Diff line
@@ -121,6 +121,7 @@ package android {
    field public static final java.lang.String REQUEST_INSTALL_PACKAGES = "android.permission.REQUEST_INSTALL_PACKAGES";
    field public static final deprecated java.lang.String RESTART_PACKAGES = "android.permission.RESTART_PACKAGES";
    field public static final java.lang.String RESTRICTED_VR_ACCESS = "android.permission.RESTRICTED_VR_ACCESS";
    field public static final java.lang.String RUN_IN_BACKGROUND = "android.permission.RUN_IN_BACKGROUND";
    field public static final java.lang.String SEND_RESPOND_VIA_MESSAGE = "android.permission.SEND_RESPOND_VIA_MESSAGE";
    field public static final java.lang.String SEND_SMS = "android.permission.SEND_SMS";
    field public static final java.lang.String SET_ALARM = "com.android.alarm.permission.SET_ALARM";
@@ -139,6 +140,7 @@ package android {
    field public static final java.lang.String TRANSMIT_IR = "android.permission.TRANSMIT_IR";
    field public static final java.lang.String UNINSTALL_SHORTCUT = "com.android.launcher.permission.UNINSTALL_SHORTCUT";
    field public static final java.lang.String UPDATE_DEVICE_STATS = "android.permission.UPDATE_DEVICE_STATS";
    field public static final java.lang.String USE_DATA_IN_BACKGROUND = "android.permission.USE_DATA_IN_BACKGROUND";
    field public static final java.lang.String USE_FINGERPRINT = "android.permission.USE_FINGERPRINT";
    field public static final java.lang.String USE_SIP = "android.permission.USE_SIP";
    field public static final java.lang.String VIBRATE = "android.permission.VIBRATE";
+2 −0
Original line number Diff line number Diff line
@@ -211,6 +211,7 @@ package android {
    field public static final java.lang.String RESTRICTED_VR_ACCESS = "android.permission.RESTRICTED_VR_ACCESS";
    field public static final java.lang.String RETRIEVE_WINDOW_CONTENT = "android.permission.RETRIEVE_WINDOW_CONTENT";
    field public static final java.lang.String REVOKE_RUNTIME_PERMISSIONS = "android.permission.REVOKE_RUNTIME_PERMISSIONS";
    field public static final java.lang.String RUN_IN_BACKGROUND = "android.permission.RUN_IN_BACKGROUND";
    field public static final java.lang.String SCORE_NETWORKS = "android.permission.SCORE_NETWORKS";
    field public static final java.lang.String SEND_RESPOND_VIA_MESSAGE = "android.permission.SEND_RESPOND_VIA_MESSAGE";
    field public static final java.lang.String SEND_SMS = "android.permission.SEND_SMS";
@@ -248,6 +249,7 @@ package android {
    field public static final java.lang.String UPDATE_DEVICE_STATS = "android.permission.UPDATE_DEVICE_STATS";
    field public static final java.lang.String UPDATE_LOCK = "android.permission.UPDATE_LOCK";
    field public static final java.lang.String USER_ACTIVITY = "android.permission.USER_ACTIVITY";
    field public static final java.lang.String USE_DATA_IN_BACKGROUND = "android.permission.USE_DATA_IN_BACKGROUND";
    field public static final java.lang.String USE_FINGERPRINT = "android.permission.USE_FINGERPRINT";
    field public static final java.lang.String USE_SIP = "android.permission.USE_SIP";
    field public static final java.lang.String VIBRATE = "android.permission.VIBRATE";
+2 −0
Original line number Diff line number Diff line
@@ -121,6 +121,7 @@ package android {
    field public static final java.lang.String REQUEST_INSTALL_PACKAGES = "android.permission.REQUEST_INSTALL_PACKAGES";
    field public static final deprecated java.lang.String RESTART_PACKAGES = "android.permission.RESTART_PACKAGES";
    field public static final java.lang.String RESTRICTED_VR_ACCESS = "android.permission.RESTRICTED_VR_ACCESS";
    field public static final java.lang.String RUN_IN_BACKGROUND = "android.permission.RUN_IN_BACKGROUND";
    field public static final java.lang.String SEND_RESPOND_VIA_MESSAGE = "android.permission.SEND_RESPOND_VIA_MESSAGE";
    field public static final java.lang.String SEND_SMS = "android.permission.SEND_SMS";
    field public static final java.lang.String SET_ALARM = "com.android.alarm.permission.SET_ALARM";
@@ -139,6 +140,7 @@ package android {
    field public static final java.lang.String TRANSMIT_IR = "android.permission.TRANSMIT_IR";
    field public static final java.lang.String UNINSTALL_SHORTCUT = "com.android.launcher.permission.UNINSTALL_SHORTCUT";
    field public static final java.lang.String UPDATE_DEVICE_STATS = "android.permission.UPDATE_DEVICE_STATS";
    field public static final java.lang.String USE_DATA_IN_BACKGROUND = "android.permission.USE_DATA_IN_BACKGROUND";
    field public static final java.lang.String USE_FINGERPRINT = "android.permission.USE_FINGERPRINT";
    field public static final java.lang.String USE_SIP = "android.permission.USE_SIP";
    field public static final java.lang.String VIBRATE = "android.permission.VIBRATE";
+18 −11
Original line number Diff line number Diff line
@@ -357,7 +357,8 @@ public class AppOpsManager {
    public static final String OPSTR_INSTANT_APP_START_FOREGROUND
            = "android:instant_app_start_foreground";

    private static final int[] RUNTIME_PERMISSIONS_OPS = {
    private static final int[] RUNTIME_AND_APPOP_PERMISSIONS_OPS = {
            // RUNTIME PERMISSIONS
            // Contacts
            OP_READ_CONTACTS,
            OP_WRITE_CONTACTS,
@@ -392,7 +393,13 @@ public class AppOpsManager {
            // Camera
            OP_CAMERA,
            // Body sensors
            OP_BODY_SENSORS
            OP_BODY_SENSORS,

            // APPOP PERMISSIONS
            OP_ACCESS_NOTIFICATIONS,
            OP_SYSTEM_ALERT_WINDOW,
            OP_WRITE_SETTINGS,
            OP_REQUEST_INSTALL_PACKAGES,
    };

    /**
@@ -1018,7 +1025,7 @@ public class AppOpsManager {
    /**
     * Mapping from a permission to the corresponding app op.
     */
    private static HashMap<String, Integer> sRuntimePermToOp = new HashMap<>();
    private static HashMap<String, Integer> sPermToOp = new HashMap<>();

    static {
        if (sOpToSwitch.length != _NUM_OP) {
@@ -1058,9 +1065,9 @@ public class AppOpsManager {
                sOpStrToOp.put(sOpToString[i], i);
            }
        }
        for (int op : RUNTIME_PERMISSIONS_OPS) {
        for (int op : RUNTIME_AND_APPOP_PERMISSIONS_OPS) {
            if (sOpPerms[op] != null) {
                sRuntimePermToOp.put(sOpPerms[op], op);
                sPermToOp.put(sOpPerms[op], op);
            }
        }
    }
@@ -1112,12 +1119,12 @@ public class AppOpsManager {

    /**
     * Retrieve the app op code for a permission, or null if there is not one.
     * This API is intended to be used for mapping runtime permissions to the
     * corresponding app op.
     * This API is intended to be used for mapping runtime or appop permissions
     * to the corresponding app op.
     * @hide
     */
    public static int permissionToOpCode(String permission) {
        Integer boxedOpCode = sRuntimePermToOp.get(permission);
        Integer boxedOpCode = sPermToOp.get(permission);
        return boxedOpCode != null ? boxedOpCode : OP_NONE;
    }

@@ -1462,7 +1469,7 @@ public class AppOpsManager {
     * @return The app op associated with the permission or null.
     */
    public static String permissionToOp(String permission) {
        final Integer opCode = sRuntimePermToOp.get(permission);
        final Integer opCode = sPermToOp.get(permission);
        if (opCode == null) {
            return null;
        }
Loading