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

Commit 06642218 authored by Eugene Susla's avatar Eugene Susla
Browse files

Rename Companion permissions

Test: ensure permission check still works
Fixes: 37721270
Change-Id: I1ff5c2924ee837c8b4a6e2825dce171e6a2e00cb
parent b9a2e321
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -116,12 +116,13 @@ package android {
    field public static final java.lang.String RECEIVE_WAP_PUSH = "android.permission.RECEIVE_WAP_PUSH";
    field public static final java.lang.String RECORD_AUDIO = "android.permission.RECORD_AUDIO";
    field public static final java.lang.String REORDER_TASKS = "android.permission.REORDER_TASKS";
    field public static final java.lang.String REQUEST_COMPANION_RUN_IN_BACKGROUND = "android.permission.REQUEST_COMPANION_RUN_IN_BACKGROUND";
    field public static final java.lang.String REQUEST_COMPANION_USE_DATA_IN_BACKGROUND = "android.permission.REQUEST_COMPANION_USE_DATA_IN_BACKGROUND";
    field public static final java.lang.String REQUEST_DELETE_PACKAGES = "android.permission.REQUEST_DELETE_PACKAGES";
    field public static final java.lang.String REQUEST_IGNORE_BATTERY_OPTIMIZATIONS = "android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS";
    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";
@@ -140,7 +141,6 @@ 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 −2
Original line number Diff line number Diff line
@@ -211,6 +211,8 @@ package android {
    field public static final java.lang.String REGISTER_SIM_SUBSCRIPTION = "android.permission.REGISTER_SIM_SUBSCRIPTION";
    field public static final java.lang.String REMOVE_DRM_CERTIFICATES = "android.permission.REMOVE_DRM_CERTIFICATES";
    field public static final java.lang.String REORDER_TASKS = "android.permission.REORDER_TASKS";
    field public static final java.lang.String REQUEST_COMPANION_RUN_IN_BACKGROUND = "android.permission.REQUEST_COMPANION_RUN_IN_BACKGROUND";
    field public static final java.lang.String REQUEST_COMPANION_USE_DATA_IN_BACKGROUND = "android.permission.REQUEST_COMPANION_USE_DATA_IN_BACKGROUND";
    field public static final java.lang.String REQUEST_DELETE_PACKAGES = "android.permission.REQUEST_DELETE_PACKAGES";
    field public static final java.lang.String REQUEST_IGNORE_BATTERY_OPTIMIZATIONS = "android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS";
    field public static final java.lang.String REQUEST_INSTALL_PACKAGES = "android.permission.REQUEST_INSTALL_PACKAGES";
@@ -218,7 +220,6 @@ 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";
@@ -256,7 +257,6 @@ 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 −2
Original line number Diff line number Diff line
@@ -116,12 +116,13 @@ package android {
    field public static final java.lang.String RECEIVE_WAP_PUSH = "android.permission.RECEIVE_WAP_PUSH";
    field public static final java.lang.String RECORD_AUDIO = "android.permission.RECORD_AUDIO";
    field public static final java.lang.String REORDER_TASKS = "android.permission.REORDER_TASKS";
    field public static final java.lang.String REQUEST_COMPANION_RUN_IN_BACKGROUND = "android.permission.REQUEST_COMPANION_RUN_IN_BACKGROUND";
    field public static final java.lang.String REQUEST_COMPANION_USE_DATA_IN_BACKGROUND = "android.permission.REQUEST_COMPANION_USE_DATA_IN_BACKGROUND";
    field public static final java.lang.String REQUEST_DELETE_PACKAGES = "android.permission.REQUEST_DELETE_PACKAGES";
    field public static final java.lang.String REQUEST_IGNORE_BATTERY_OPTIMIZATIONS = "android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS";
    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";
@@ -140,7 +141,6 @@ 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";
+22 −4
Original line number Diff line number Diff line
@@ -1860,22 +1860,40 @@
        android:description="@string/permdesc_systemAlertWindow"
        android:protectionLevel="signature|preinstalled|appop|pre23|development" />

    <!-- Allows an app to run in the background.
         <p>Protection level: signature
    <!-- @deprecated Use {@link android.Manifest.permission#REQUEST_COMPANION_RUN_IN_BACKGROUND}
         @hide
    -->
    <permission android:name="android.permission.RUN_IN_BACKGROUND"
        android:label="@string/permlab_runInBackground"
        android:description="@string/permdesc_runInBackground"
        android:protectionLevel="signature" />

    <!-- Allows an app to use data in the background.
         <p>Protection level: signature
    <!-- @deprecated Use
        {@link android.Manifest.permission#REQUEST_COMPANION_USE_DATA_IN_BACKGROUND}
         @hide
    -->
    <permission android:name="android.permission.USE_DATA_IN_BACKGROUND"
        android:label="@string/permlab_useDataInBackground"
        android:description="@string/permdesc_useDataInBackground"
        android:protectionLevel="signature" />

    <!-- Allows a companion app to run in the background.
         <p>Protection level: signature
    -->
    <permission android:name="android.permission.REQUEST_COMPANION_RUN_IN_BACKGROUND"
                android:label="@string/permlab_runInBackground"
                android:description="@string/permdesc_runInBackground"
                android:protectionLevel="signature" />

    <!-- Allows a companion app to use data in the background.
         <p>Protection level: signature
    -->
    <permission android:name="android.permission.REQUEST_COMPANION_USE_DATA_IN_BACKGROUND"
                android:label="@string/permlab_useDataInBackground"
                android:description="@string/permdesc_useDataInBackground"
                android:protectionLevel="signature" />


    <!-- ================================== -->
    <!-- Permissions affecting the system wallpaper -->
    <!-- ================================== -->
+10 −4
Original line number Diff line number Diff line
@@ -414,8 +414,9 @@ public class CompanionDeviceManagerService extends SystemService implements Bind

        Binder.withCleanCallingIdentity(() -> {
            try {
                if (ArrayUtils.contains(packageInfo.requestedPermissions,
                        Manifest.permission.RUN_IN_BACKGROUND)) {
                if (containsEither(packageInfo.requestedPermissions,
                        Manifest.permission.RUN_IN_BACKGROUND,
                        Manifest.permission.REQUEST_COMPANION_RUN_IN_BACKGROUND)) {
                    mIdleController.addPowerSaveWhitelistApp(packageInfo.packageName);
                } else {
                    mIdleController.removePowerSaveWhitelistApp(packageInfo.packageName);
@@ -425,8 +426,9 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
            }

            NetworkPolicyManager networkPolicyManager = NetworkPolicyManager.from(getContext());
            if (ArrayUtils.contains(packageInfo.requestedPermissions,
                    Manifest.permission.USE_DATA_IN_BACKGROUND)) {
            if (containsEither(packageInfo.requestedPermissions,
                    Manifest.permission.USE_DATA_IN_BACKGROUND,
                    Manifest.permission.REQUEST_COMPANION_USE_DATA_IN_BACKGROUND)) {
                networkPolicyManager.addUidPolicy(
                        packageInfo.applicationInfo.uid,
                        NetworkPolicyManager.POLICY_ALLOW_METERED_BACKGROUND);
@@ -438,6 +440,10 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
        });
    }

    private static <T> boolean containsEither(T[] array, T a, T b) {
        return ArrayUtils.contains(array, a) || ArrayUtils.contains(array, b);
    }

    @Nullable
    private PackageInfo getPackageInfo(String packageName, int userId) {
        return Binder.withCleanCallingIdentity(() -> {