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

Commit 619c5a46 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Implement requestForegroundServiceExemption, without enabling it

Bug: 187429663
Test: Checked ApplicationInfo.hasRequestForegroundServiceExemption()
  of a test app, with and without the new attribute set.

Change-Id: I98342a35a82e44327db896c9820806eb3eda5b4c
parent 88385cc1
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -338,6 +338,9 @@ public class PowerExemptionManager {
     */
     */
    public static final int REASON_MEDIA_SESSION_CALLBACK = 317;
    public static final int REASON_MEDIA_SESSION_CALLBACK = 317;


    /** @hide The app requests out-out. */
    public static final int REASON_OPT_OUT_REQUESTED = 1000;

    /**
    /**
     * The list of BG-FGS-Launch and temp-allow-list reason code.
     * The list of BG-FGS-Launch and temp-allow-list reason code.
     * @hide
     * @hide
@@ -404,6 +407,7 @@ public class PowerExemptionManager {
            REASON_EVENT_MMS,
            REASON_EVENT_MMS,
            REASON_SHELL,
            REASON_SHELL,
            REASON_MEDIA_SESSION_CALLBACK,
            REASON_MEDIA_SESSION_CALLBACK,
            REASON_OPT_OUT_REQUESTED,
    })
    })
    @Retention(RetentionPolicy.SOURCE)
    @Retention(RetentionPolicy.SOURCE)
    public @interface ReasonCode {}
    public @interface ReasonCode {}
@@ -700,6 +704,8 @@ public class PowerExemptionManager {
                return "SHELL";
                return "SHELL";
            case REASON_MEDIA_SESSION_CALLBACK:
            case REASON_MEDIA_SESSION_CALLBACK:
                return "MEDIA_SESSION_CALLBACK";
                return "MEDIA_SESSION_CALLBACK";
            case REASON_OPT_OUT_REQUESTED:
                return "REASON_OPT_OUT_REQUESTED";
            default:
            default:
                return "(unknown:" + reasonCode + ")";
                return "(unknown:" + reasonCode + ")";
        }
        }
+5 −0
Original line number Original line Diff line number Diff line
@@ -50,6 +50,10 @@ package android {
    field public static final String UNDEFINED = "android.permission-group.UNDEFINED";
    field public static final String UNDEFINED = "android.permission-group.UNDEFINED";
  }
  }


  public static final class R.attr {
    field public static final int requestForegroundServiceExemption;
  }

  public static final class R.bool {
  public static final class R.bool {
    field public static final int config_assistantOnTopOfDream = 17891333; // 0x1110005
    field public static final int config_assistantOnTopOfDream = 17891333; // 0x1110005
    field public static final int config_perDisplayFocusEnabled = 17891332; // 0x1110004
    field public static final int config_perDisplayFocusEnabled = 17891332; // 0x1110004
@@ -806,6 +810,7 @@ package android.content.pm {
  }
  }


  public class ApplicationInfo extends android.content.pm.PackageItemInfo implements android.os.Parcelable {
  public class ApplicationInfo extends android.content.pm.PackageItemInfo implements android.os.Parcelable {
    method public boolean hasRequestForegroundServiceExemption();
    method public boolean isPrivilegedApp();
    method public boolean isPrivilegedApp();
    method public boolean isSystemApp();
    method public boolean isSystemApp();
    field public static final int PRIVATE_FLAG_PRIVILEGED = 8; // 0x8
    field public static final int PRIVATE_FLAG_PRIVILEGED = 8; // 0x8
+20 −0
Original line number Original line Diff line number Diff line
@@ -778,9 +778,18 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
     */
     */
    public static final int PRIVATE_FLAG_EXT_PROFILEABLE = 1 << 0;
    public static final int PRIVATE_FLAG_EXT_PROFILEABLE = 1 << 0;


    /**
     * Value for {@link #privateFlagsExt}: whether this application has requested
     * exemption from the foreground service restriction introduced in S
     * (https://developer.android.com/about/versions/12/foreground-services).
     * @hide
     */
    public static final int PRIVATE_FLAG_EXT_REQUEST_FOREGROUND_SERVICE_EXEMPTION = 1 << 1;

    /** @hide */
    /** @hide */
    @IntDef(flag = true, prefix = { "PRIVATE_FLAG_EXT_" }, value = {
    @IntDef(flag = true, prefix = { "PRIVATE_FLAG_EXT_" }, value = {
            PRIVATE_FLAG_EXT_PROFILEABLE,
            PRIVATE_FLAG_EXT_PROFILEABLE,
            PRIVATE_FLAG_EXT_REQUEST_FOREGROUND_SERVICE_EXEMPTION,
    })
    })
    @Retention(RetentionPolicy.SOURCE)
    @Retention(RetentionPolicy.SOURCE)
    public @interface ApplicationInfoPrivateFlagsExt {}
    public @interface ApplicationInfoPrivateFlagsExt {}
@@ -2444,6 +2453,17 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        return (privateFlags & ApplicationInfo.PRIVATE_FLAG_IS_RESOURCE_OVERLAY) != 0;
        return (privateFlags & ApplicationInfo.PRIVATE_FLAG_IS_RESOURCE_OVERLAY) != 0;
    }
    }


    /**
     * @return whether the app has requested exemption from the foreground service restrictions.
     * This does not take any affect for now.
     * @hide
     */
    @TestApi
    public boolean hasRequestForegroundServiceExemption() {
        return (privateFlagsExt
                & ApplicationInfo.PRIVATE_FLAG_EXT_REQUEST_FOREGROUND_SERVICE_EXEMPTION) != 0;
    }

    /**
    /**
     * @hide
     * @hide
     */
     */
+3 −1
Original line number Original line Diff line number Diff line
@@ -806,7 +806,9 @@ public class PackageInfoWithoutStateUtils {
    public static int appInfoPrivateFlagsExt(ParsingPackageRead pkg) {
    public static int appInfoPrivateFlagsExt(ParsingPackageRead pkg) {
        // @formatter:off
        // @formatter:off
        int privateFlagsExt =
        int privateFlagsExt =
                flag(pkg.isProfileable(), ApplicationInfo.PRIVATE_FLAG_EXT_PROFILEABLE);
                flag(pkg.isProfileable(), ApplicationInfo.PRIVATE_FLAG_EXT_PROFILEABLE)
                | flag(pkg.hasRequestForegroundServiceExemption(),
                        ApplicationInfo.PRIVATE_FLAG_EXT_REQUEST_FOREGROUND_SERVICE_EXEMPTION);
        // @formatter:on
        // @formatter:on
        return privateFlagsExt;
        return privateFlagsExt;
    }
    }
+2 −0
Original line number Original line Diff line number Diff line
@@ -338,6 +338,8 @@ public interface ParsingPackage extends ParsingPackageRead {


    ParsingPackage setTheme(int theme);
    ParsingPackage setTheme(int theme);


    ParsingPackage setRequestForegroundServiceExemption(boolean requestForegroundServiceExemption);

    ParsingPackage setUpgradeKeySets(@NonNull Set<String> upgradeKeySets);
    ParsingPackage setUpgradeKeySets(@NonNull Set<String> upgradeKeySets);


    ParsingPackage setUse32BitAbi(boolean use32BitAbi);
    ParsingPackage setUse32BitAbi(boolean use32BitAbi);
Loading