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

Commit 4a6dff09 authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Allow permissions to have background permissions

Some permissions are getting split into foreground and background
variants. If an app only has the foreground version it can only access
the protected resource while the user is using it. Once the background
permission is added to the foreground permission the app can always
access the resource protected by the permission.

- Only having the background permission does grant anything.
- Mutliple foreground permission can share a single background permission,
  but a foreground permission can not have multiple background
  permissions.
- As the implementation of background permissions is based on AppOps
  only the system can declare such foreground/background permissions
- A CTS test enforce that the background is in the same group as the
  matching foreground permission.

Bug: 78788390
Test: Checked declared permission after boot and found new attributes
Change-Id: Ica7ba77b24345607c7467c41c982a58c39199024
parent fdc40f52
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1202,6 +1202,9 @@ package android.content.pm {
  }

  public class PermissionGroupInfo extends android.content.pm.PackageItemInfo implements android.os.Parcelable {
    field public int backgroundRequestDetailResourceId;
    field public int backgroundRequestResourceId;
    field public int requestDetailResourceId;
    field public int requestRes;
  }

@@ -1209,6 +1212,7 @@ package android.content.pm {
    field public static final int FLAG_REMOVED = 2; // 0x2
    field public static final int PROTECTION_FLAG_OEM = 16384; // 0x4000
    field public static final int PROTECTION_FLAG_SYSTEM_TEXT_CLASSIFIER = 65536; // 0x10000
    field public java.lang.String backgroundPermission;
    field public int requestRes;
  }

+1 −0
Original line number Diff line number Diff line
@@ -276,6 +276,7 @@ package android.content.pm {
  public class PermissionInfo extends android.content.pm.PackageItemInfo implements android.os.Parcelable {
    field public static final int PROTECTION_FLAG_SYSTEM_TEXT_CLASSIFIER = 65536; // 0x10000
    field public static final int PROTECTION_FLAG_VENDOR_PRIVILEGED = 32768; // 0x8000
    field public java.lang.String backgroundPermission;
  }

  public final class ShortcutInfo implements android.os.Parcelable {
+21 −0
Original line number Diff line number Diff line
@@ -3097,6 +3097,14 @@ public class PackageParser {
                0);
        perm.info.requestRes = sa.getResourceId(
                com.android.internal.R.styleable.AndroidManifestPermissionGroup_request, 0);
        perm.info.requestDetailResourceId = sa.getResourceId(
                com.android.internal.R.styleable.AndroidManifestPermissionGroup_requestDetail, 0);
        perm.info.backgroundRequestResourceId = sa.getResourceId(
                com.android.internal.R.styleable.AndroidManifestPermissionGroup_backgroundRequest,
                0);
        perm.info.backgroundRequestDetailResourceId = sa.getResourceId(
                com.android.internal.R.styleable
                        .AndroidManifestPermissionGroup_backgroundRequestDetail, 0);
        perm.info.flags = sa.getInt(
                com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0);
        perm.info.priority = sa.getInt(
@@ -3151,6 +3159,19 @@ public class PackageParser {
        perm.info.requestRes = sa.getResourceId(
                com.android.internal.R.styleable.AndroidManifestPermission_request, 0);

        if (sa.hasValue(
                com.android.internal.R.styleable.AndroidManifestPermission_backgroundPermission)) {
            if ("android".equals(owner.packageName)) {
                perm.info.backgroundPermission = sa.getNonResourceString(
                        com.android.internal.R.styleable
                                .AndroidManifestPermission_backgroundPermission);
            } else {
                Slog.w(TAG, owner.packageName + " defines permission '" + perm.info.name
                        + "' with a background permission. Only the 'android' package can do "
                        + "that.");
            }
        }

        perm.info.protectionLevel = sa.getInt(
                com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
                PermissionInfo.PROTECTION_NORMAL);
+45 −0
Original line number Diff line number Diff line
@@ -44,6 +44,42 @@ public class PermissionGroupInfo extends PackageItemInfo implements Parcelable {
    @SystemApi
    public @StringRes int requestRes;

    /**
     * A string resource identifier (in the package's resources) used as subtitle when requesting
     * only access while in the foreground.
     *
     * From the "requestDetail" attribute or, if not set, {@link
     * android.content.res.ResourceId#ID_NULL}.
     *
     * @hide
     */
    @SystemApi
    public @StringRes int requestDetailResourceId;

    /**
     * A string resource identifier (in the package's resources) used when requesting background
     * access. Also used when requesting both foreground and background access.
     *
     * From the "backgroundRequest" attribute or, if not set, {@link
     * android.content.res.ResourceId#ID_NULL}.
     *
     * @hide
     */
    @SystemApi
    public @StringRes int backgroundRequestResourceId;

    /**
     * A string resource identifier (in the package's resources) used as subtitle when requesting
     * background access.
     *
     * From the "backgroundRequestDetail" attribute or, if not set, {@link
     * android.content.res.ResourceId#ID_NULL}.
     *
     * @hide
     */
    @SystemApi
    public @StringRes int backgroundRequestDetailResourceId;

    /**
     * The description string provided in the AndroidManifest file, if any.  You
     * probably don't want to use this, since it will be null if the description
@@ -76,6 +112,9 @@ public class PermissionGroupInfo extends PackageItemInfo implements Parcelable {
        super(orig);
        descriptionRes = orig.descriptionRes;
        requestRes = orig.requestRes;
        requestDetailResourceId = orig.requestDetailResourceId;
        backgroundRequestResourceId = orig.backgroundRequestResourceId;
        backgroundRequestDetailResourceId = orig.backgroundRequestDetailResourceId;
        nonLocalizedDescription = orig.nonLocalizedDescription;
        flags = orig.flags;
        priority = orig.priority;
@@ -119,6 +158,9 @@ public class PermissionGroupInfo extends PackageItemInfo implements Parcelable {
        super.writeToParcel(dest, parcelableFlags);
        dest.writeInt(descriptionRes);
        dest.writeInt(requestRes);
        dest.writeInt(requestDetailResourceId);
        dest.writeInt(backgroundRequestResourceId);
        dest.writeInt(backgroundRequestDetailResourceId);
        TextUtils.writeToParcel(nonLocalizedDescription, dest, parcelableFlags);
        dest.writeInt(flags);
        dest.writeInt(priority);
@@ -138,6 +180,9 @@ public class PermissionGroupInfo extends PackageItemInfo implements Parcelable {
        super(source);
        descriptionRes = source.readInt();
        requestRes = source.readInt();
        requestDetailResourceId = source.readInt();
        backgroundRequestResourceId = source.readInt();
        backgroundRequestDetailResourceId = source.readInt();
        nonLocalizedDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
        flags = source.readInt();
        priority = source.readInt();
+18 −0
Original line number Diff line number Diff line
@@ -284,6 +284,21 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
    @SystemApi
    public int requestRes;

    /**
     * Some permissions only grant access while the app is in foreground. Some of these permissions
     * allow to add background capabilities by adding another permission.
     *
     * If this is such a permission, this is the name of the permission adding the background
     * access.
     *
     * From the "backgroundPermission" attribute or, if not set null
     *
     * @hide
     */
    @SystemApi
    @TestApi
    public String backgroundPermission;

    /**
     * The description string provided in the AndroidManifest file, if any.  You
     * probably don't want to use this, since it will be null if the description
@@ -373,6 +388,7 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
        protectionLevel = orig.protectionLevel;
        flags = orig.flags;
        group = orig.group;
        backgroundPermission = orig.backgroundPermission;
        descriptionRes = orig.descriptionRes;
        requestRes = orig.requestRes;
        nonLocalizedDescription = orig.nonLocalizedDescription;
@@ -436,6 +452,7 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
        dest.writeInt(protectionLevel);
        dest.writeInt(flags);
        dest.writeString(group);
        dest.writeString(backgroundPermission);
        dest.writeInt(descriptionRes);
        dest.writeInt(requestRes);
        TextUtils.writeToParcel(nonLocalizedDescription, dest, parcelableFlags);
@@ -475,6 +492,7 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
        protectionLevel = source.readInt();
        flags = source.readInt();
        group = source.readString();
        backgroundPermission = source.readString();
        descriptionRes = source.readInt();
        requestRes = source.readInt();
        nonLocalizedDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
Loading