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

Commit 3b7af776 authored by Evan Severson's avatar Evan Severson Committed by Android (Google) Code Review
Browse files

Merge changes from topic "BackgroundMicCamera"

* changes:
  Do not show rationale when permission is restricted
  Add role allowlist for restricted permissions
  Add documentation to APIs using non-inclusive lanuage
  Treat background mic/camera normally
  Introduce new permissionFlag
  Split camera and microphone for background modes
  Add background microphone and camera permission
parents a5260751 234009fb
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ package android {
    field public static final String ACTIVITY_RECOGNITION = "android.permission.ACTIVITY_RECOGNITION";
    field public static final String ADD_VOICEMAIL = "com.android.voicemail.permission.ADD_VOICEMAIL";
    field public static final String ANSWER_PHONE_CALLS = "android.permission.ANSWER_PHONE_CALLS";
    field public static final String BACKGROUND_CAMERA = "android.permission.BACKGROUND_CAMERA";
    field public static final String BATTERY_STATS = "android.permission.BATTERY_STATS";
    field public static final String BIND_ACCESSIBILITY_SERVICE = "android.permission.BIND_ACCESSIBILITY_SERVICE";
    field public static final String BIND_APPWIDGET = "android.permission.BIND_APPWIDGET";
@@ -129,6 +130,7 @@ package android {
    field public static final String RECEIVE_SMS = "android.permission.RECEIVE_SMS";
    field public static final String RECEIVE_WAP_PUSH = "android.permission.RECEIVE_WAP_PUSH";
    field public static final String RECORD_AUDIO = "android.permission.RECORD_AUDIO";
    field public static final String RECORD_BACKGROUND_AUDIO = "android.permission.RECORD_BACKGROUND_AUDIO";
    field public static final String REORDER_TASKS = "android.permission.REORDER_TASKS";
    field public static final String REQUEST_COMPANION_RUN_IN_BACKGROUND = "android.permission.REQUEST_COMPANION_RUN_IN_BACKGROUND";
    field public static final String REQUEST_COMPANION_USE_DATA_IN_BACKGROUND = "android.permission.REQUEST_COMPANION_USE_DATA_IN_BACKGROUND";
@@ -12235,6 +12237,7 @@ package android.content.pm {
    field public static final String FEATURE_WIFI_DIRECT = "android.hardware.wifi.direct";
    field public static final String FEATURE_WIFI_PASSPOINT = "android.hardware.wifi.passpoint";
    field public static final String FEATURE_WIFI_RTT = "android.hardware.wifi.rtt";
    field public static final int FLAG_PERMISSION_ALLOWLIST_ROLE = 8; // 0x8
    field public static final int FLAG_PERMISSION_WHITELIST_INSTALLER = 2; // 0x2
    field public static final int FLAG_PERMISSION_WHITELIST_SYSTEM = 1; // 0x1
    field public static final int FLAG_PERMISSION_WHITELIST_UPGRADE = 4; // 0x4
@@ -12344,6 +12347,7 @@ package android.content.pm {
    field public static final int FLAG_HARD_RESTRICTED = 4; // 0x4
    field public static final int FLAG_IMMUTABLY_RESTRICTED = 16; // 0x10
    field public static final int FLAG_INSTALLED = 1073741824; // 0x40000000
    field public static final int FLAG_INSTALLER_EXEMPT_IGNORED = 32; // 0x20
    field public static final int FLAG_SOFT_RESTRICTED = 8; // 0x8
    field public static final int PROTECTION_DANGEROUS = 1; // 0x1
    field public static final int PROTECTION_FLAG_APPOP = 64; // 0x40
+1 −0
Original line number Diff line number Diff line
@@ -2157,6 +2157,7 @@ package android.content.pm {
    field public static final int FLAG_PERMISSION_ONE_TIME = 65536; // 0x10000
    field public static final int FLAG_PERMISSION_POLICY_FIXED = 4; // 0x4
    field public static final int FLAG_PERMISSION_RESTRICTION_INSTALLER_EXEMPT = 2048; // 0x800
    field public static final int FLAG_PERMISSION_RESTRICTION_ROLE_EXEMPT = 262144; // 0x40000
    field public static final int FLAG_PERMISSION_RESTRICTION_SYSTEM_EXEMPT = 4096; // 0x1000
    field public static final int FLAG_PERMISSION_RESTRICTION_UPGRADE_EXEMPT = 8192; // 0x2000
    field public static final int FLAG_PERMISSION_REVIEW_REQUIRED = 64; // 0x40
+1 −0
Original line number Diff line number Diff line
@@ -1037,6 +1037,7 @@ package android.content.pm {
    field public static final int FLAG_PERMISSION_ONE_TIME = 65536; // 0x10000
    field public static final int FLAG_PERMISSION_POLICY_FIXED = 4; // 0x4
    field public static final int FLAG_PERMISSION_RESTRICTION_INSTALLER_EXEMPT = 2048; // 0x800
    field public static final int FLAG_PERMISSION_RESTRICTION_ROLE_EXEMPT = 262144; // 0x40000
    field public static final int FLAG_PERMISSION_RESTRICTION_SYSTEM_EXEMPT = 4096; // 0x1000
    field public static final int FLAG_PERMISSION_RESTRICTION_UPGRADE_EXEMPT = 8192; // 0x2000
    field public static final int FLAG_PERMISSION_REVIEW_REQUIRED = 64; // 0x40
+114 −8
Original line number Diff line number Diff line
@@ -866,6 +866,12 @@ public abstract class PackageManager {
     * is set the restricted permissions will be whitelisted for all users, otherwise
     * only to the owner.
     *
     * <p>
     * <strong>Note: </strong>In retrospect it would have been preferred to use
     * more inclusive terminology when naming this API. Similar APIs added will
     * refrain from using the term "whitelist".
     * </p>
     *
     * @hide
     */
    public static final int INSTALL_ALL_WHITELIST_RESTRICTED_PERMISSIONS = 0x00400000;
@@ -3504,6 +3510,17 @@ public abstract class PackageManager {
    @SystemApi
    public static final int FLAG_PERMISSION_AUTO_REVOKED = 1 << 17;

    /**
     * Permission flag: The permission is restricted but the app is exempt
     * from the restriction and is allowed to hold this permission in its
     * full form and the exemption is provided by the held roles.
     *
     * @hide
     */
    @TestApi
    @SystemApi
    public static final int FLAG_PERMISSION_RESTRICTION_ROLE_EXEMPT =  1 << 18;

    /**
     * Permission flags: Reserved for use by the permission controller. The platform and any
     * packages besides the permission controller should not assume any definition about these
@@ -3522,7 +3539,8 @@ public abstract class PackageManager {
    public static final int FLAGS_PERMISSION_RESTRICTION_ANY_EXEMPT =
            FLAG_PERMISSION_RESTRICTION_INSTALLER_EXEMPT
                    | FLAG_PERMISSION_RESTRICTION_SYSTEM_EXEMPT
                    | FLAG_PERMISSION_RESTRICTION_UPGRADE_EXEMPT;
                    | FLAG_PERMISSION_RESTRICTION_UPGRADE_EXEMPT
                    | FLAG_PERMISSION_RESTRICTION_ROLE_EXEMPT;

    /**
     * Mask for all permission flags.
@@ -3568,13 +3586,27 @@ public abstract class PackageManager {

    /**
     * Permission whitelist flag: permissions whitelisted by the system.
     * Permissions can also be whitelisted by the installer or on upgrade.
     * Permissions can also be whitelisted by the installer, on upgrade, or on
     * role grant.
     *
     * <p>
     * <strong>Note: </strong>In retrospect it would have been preferred to use
     * more inclusive terminology when naming this API. Similar APIs added will
     * refrain from using the term "whitelist".
     * </p>
     */
    public static final int FLAG_PERMISSION_WHITELIST_SYSTEM = 1 << 0;

    /**
     * Permission whitelist flag: permissions whitelisted by the installer.
     * Permissions can also be whitelisted by the system or on upgrade.
     * Permissions can also be whitelisted by the system, on upgrade, or on role
     * grant.
     *
     * <p>
     * <strong>Note: </strong>In retrospect it would have been preferred to use
     * more inclusive terminology when naming this API. Similar APIs added will
     * refrain from using the term "whitelist".
     * </p>
     */
    public static final int FLAG_PERMISSION_WHITELIST_INSTALLER = 1 << 1;

@@ -3582,15 +3614,31 @@ public abstract class PackageManager {
     * Permission whitelist flag: permissions whitelisted by the system
     * when upgrading from an OS version where the permission was not
     * restricted to an OS version where the permission is restricted.
     * Permissions can also be whitelisted by the installer or the system.
     * Permissions can also be whitelisted by the installer, the system, or on
     * role grant.
     *
     * <p>
     * <strong>Note: </strong>In retrospect it would have been preferred to use
     * more inclusive terminology when naming this API. Similar APIs added will
     * refrain from using the term "whitelist".
     * </p>
     */
    public static final int FLAG_PERMISSION_WHITELIST_UPGRADE = 1 << 2;

    /**
     * Permission allowlist flag: permissions exempted by the system
     * when being granted a role.
     * Permissions can also be exempted by the installer, the system, or on
     * upgrade.
     */
    public static final int FLAG_PERMISSION_ALLOWLIST_ROLE = 1 << 3;

    /** @hide */
    @IntDef(flag = true, prefix = {"FLAG_PERMISSION_WHITELIST_"}, value = {
            FLAG_PERMISSION_WHITELIST_SYSTEM,
            FLAG_PERMISSION_WHITELIST_INSTALLER,
            FLAG_PERMISSION_WHITELIST_UPGRADE
            FLAG_PERMISSION_WHITELIST_UPGRADE,
            FLAG_PERMISSION_ALLOWLIST_ROLE
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface PermissionWhitelistFlags {}
@@ -4536,7 +4584,7 @@ public abstract class PackageManager {
     * allows for the to hold that permission and whitelisting a soft restricted
     * permission allows the app to hold the permission in its full, unrestricted form.
     *
     * <p><ol>There are three whitelists:
     * <p><ol>There are four allowlists:
     *
     * <li>one for cases where the system permission policy whitelists a permission
     * This list corresponds to the{@link #FLAG_PERMISSION_WHITELIST_SYSTEM} flag.
@@ -4553,6 +4601,17 @@ public abstract class PackageManager {
     * Can be accessed by pre-installed holders of a dedicated permission or the
     * installer on record.
     *
     * <li>one for cases where the system exempts the permission when granting a role.
     * This list corresponds to the {@link #FLAG_PERMISSION_ALLOWLIST_ROLE} flag. Can
     * be accessed by pre-installed holders of a dedicated permission.
     * </ol>
     *
     * <p>
     * <strong>Note: </strong>In retrospect it would have been preferred to use
     * more inclusive terminology when naming this API. Similar APIs added will
     * refrain from using the term "whitelist".
     * </p>
     *
     * @param packageName The app for which to get whitelisted permissions.
     * @param whitelistFlag The flag to determine which whitelist to query. Only one flag
     * can be passed.s
@@ -4563,6 +4622,7 @@ public abstract class PackageManager {
     * @see #FLAG_PERMISSION_WHITELIST_SYSTEM
     * @see #FLAG_PERMISSION_WHITELIST_UPGRADE
     * @see #FLAG_PERMISSION_WHITELIST_INSTALLER
     * @see #FLAG_PERMISSION_ALLOWLIST_ROLE
     *
     * @throws SecurityException if you try to access a whitelist that you have no access to.
     */
@@ -4584,7 +4644,7 @@ public abstract class PackageManager {
     * allows for the to hold that permission and whitelisting a soft restricted
     * permission allows the app to hold the permission in its full, unrestricted form.
     *
     * <p><ol>There are three whitelists:
     * <p><ol>There are four whitelists:
     *
     * <li>one for cases where the system permission policy whitelists a permission
     * This list corresponds to the {@link #FLAG_PERMISSION_WHITELIST_SYSTEM} flag.
@@ -4602,10 +4662,21 @@ public abstract class PackageManager {
     * Can be modified by pre-installed holders of a dedicated permission or the installer
     * on record.
     *
     * <li>one for cases where the system exempts the permission when permission when
     * granting a role. This list corresponds to the {@link #FLAG_PERMISSION_ALLOWLIST_ROLE}
     * flag. Can be modified by pre-installed holders of a dedicated permission.
     * </ol>
     *
     * <p>You need to specify the whitelists for which to set the whitelisted permissions
     * which will clear the previous whitelisted permissions and replace them with the
     * provided ones.
     *
     * <p>
     * <strong>Note: </strong>In retrospect it would have been preferred to use
     * more inclusive terminology when naming this API. Similar APIs added will
     * refrain from using the term "whitelist".
     * </p>
     *
     * @param packageName The app for which to get whitelisted permissions.
     * @param permName The whitelisted permission to add.
     * @param whitelistFlags The whitelists to which to add. Passing multiple flags
@@ -4617,6 +4688,7 @@ public abstract class PackageManager {
     * @see #FLAG_PERMISSION_WHITELIST_SYSTEM
     * @see #FLAG_PERMISSION_WHITELIST_UPGRADE
     * @see #FLAG_PERMISSION_WHITELIST_INSTALLER
     * @see #FLAG_PERMISSION_ALLOWLIST_ROLE
     *
     * @throws SecurityException if you try to modify a whitelist that you have no access to.
     */
@@ -4638,7 +4710,7 @@ public abstract class PackageManager {
     * allows for the to hold that permission and whitelisting a soft restricted
     * permission allows the app to hold the permission in its full, unrestricted form.
     *
     * <p><ol>There are three whitelists:
     * <p><ol>There are four whitelists:
     *
     * <li>one for cases where the system permission policy whitelists a permission
     * This list corresponds to the {@link #FLAG_PERMISSION_WHITELIST_SYSTEM} flag.
@@ -4656,10 +4728,24 @@ public abstract class PackageManager {
     * Can be modified by pre-installed holders of a dedicated permission or the installer
     * on record.
     *
     * <li>one for cases where the system exempts the permission when upgrading
     * from an OS version in which the permission was not restricted to an OS version
     * in which the permission is restricted. This list corresponds to the {@link
     * #FLAG_PERMISSION_WHITELIST_UPGRADE} flag. Can be modified by pre-installed
     * holders of a dedicated permission. The installer on record can only remove
     * permissions from this allowlist.
     * </ol>
     *
     * <p>You need to specify the whitelists for which to set the whitelisted permissions
     * which will clear the previous whitelisted permissions and replace them with the
     * provided ones.
     *
     * <p>
     * <strong>Note: </strong>In retrospect it would have been preferred to use
     * more inclusive terminology when naming this API. Similar APIs added will
     * refrain from using the term "whitelist".
     * </p>
     *
     * @param packageName The app for which to get whitelisted permissions.
     * @param permName The whitelisted permission to remove.
     * @param whitelistFlags The whitelists from which to remove. Passing multiple flags
@@ -4671,6 +4757,7 @@ public abstract class PackageManager {
     * @see #FLAG_PERMISSION_WHITELIST_SYSTEM
     * @see #FLAG_PERMISSION_WHITELIST_UPGRADE
     * @see #FLAG_PERMISSION_WHITELIST_INSTALLER
     * @see #FLAG_PERMISSION_ALLOWLIST_ROLE
     *
     * @throws SecurityException if you try to modify a whitelist that you have no access to.
     */
@@ -4691,6 +4778,12 @@ public abstract class PackageManager {
     * un-whitelist the packages it installs, unless auto-revoking permissions from that package
     * would cause breakages beyond having to re-request the permission(s).
     *
     * <p>
     * <strong>Note: </strong>In retrospect it would have been preferred to use
     * more inclusive terminology when naming this API. Similar APIs added will
     * refrain from using the term "whitelist".
     * </p>
     *
     * @param packageName The app for which to set exemption.
     * @param whitelisted Whether the app should be whitelisted.
     *
@@ -4712,6 +4805,13 @@ public abstract class PackageManager {
     *
     * Only the installer on record that installed the given package, or a holder of
     * {@code WHITELIST_AUTO_REVOKE_PERMISSIONS} is allowed to call this.
     *
     * <p>
     * <strong>Note: </strong>In retrospect it would have been preferred to use
     * more inclusive terminology when naming this API. Similar APIs added will
     * refrain from using the term "whitelist".
     * </p>
     *
     * @param packageName The app for which to set exemption.
     *
     * @return Whether the app is whitelisted.
@@ -8026,6 +8126,12 @@ public abstract class PackageManager {
    }

    /**
     * <p>
     * <strong>Note: </strong>In retrospect it would have been preferred to use
     * more inclusive terminology when naming this API. Similar APIs added will
     * refrain from using the term "whitelist".
     * </p>
     *
     * @return whether this package is whitelisted from having its runtime permission be
     *         auto-revoked if unused for an extended period of time.
     */
+13 −0
Original line number Diff line number Diff line
@@ -376,6 +376,14 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
     */
    public static final int FLAG_IMMUTABLY_RESTRICTED = 1<<4;

    /**
     * Flag for {@link #flags}, corresponding to <code>installerExemptIgnored</code>
     * value of {@link android.R.attr#permissionFlags}.
     *
     * <p> Modifier for permission restriction. This permission cannot be exempted by the installer.
     */
    public static final int FLAG_INSTALLER_EXEMPT_IGNORED = 1 << 5;

    /**
     * Flag for {@link #flags}, indicating that this permission has been
     * installed into the system's globally defined permissions.
@@ -655,6 +663,11 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
        return isHardRestricted() || isSoftRestricted();
    }

    /** @hide */
    public boolean isInstallerExemptIgnored() {
        return (flags & PermissionInfo.FLAG_INSTALLER_EXEMPT_IGNORED) != 0;
    }

    /** @hide */
    public boolean isAppOp() {
        return (protectionLevel & PermissionInfo.PROTECTION_FLAG_APPOP) != 0;
Loading