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

Commit 53e84fae authored by Varun Shah's avatar Varun Shah
Browse files

Introduce the RUN_BACKUP_JOBS permission.

This is a new app-op permission which will be reserved for apps whose
primary purpose is to backup or sync content. Holding this permission
will allow the app to run longer backup-related jobs.

This permission will be denied by default and users will have to
navigate to the relevant Special App Access page in Settings to grant an
app the permission.

Bug: 318731461
Test: atest AppOpsTest
Change-Id: I2b1257fa557b5b7fb0acf6046f912611a99f7d14
parent ac9f7236
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -13,3 +13,10 @@ flag {
    description: "Add APIs to let apps attach debug information to jobs"
    bug: "293491637"
}

flag {
    name: "backup_jobs_exemption"
    namespace: "backstage_power"
    description: "Introduce a new RUN_BACKUP_JOBS permission and exemption logic allowing for longer running jobs for apps whose primary purpose is to backup or sync content."
    bug: "318731461"
}
+3 −0
Original line number Diff line number Diff line
@@ -5444,6 +5444,9 @@ public class JobSchedulerService extends com.android.server.SystemService
            pw.print(Flags.FLAG_THROW_ON_UNSUPPORTED_BIAS_USAGE,
                    Flags.throwOnUnsupportedBiasUsage());
            pw.println();
            pw.print(android.app.job.Flags.FLAG_BACKUP_JOBS_EXEMPTION,
                    android.app.job.Flags.backupJobsExemption());
            pw.println();
            pw.decreaseIndent();
            pw.println();

+3 −0
Original line number Diff line number Diff line
@@ -353,6 +353,9 @@ public final class JobSchedulerShellCommand extends BasicShellCommandHandler {
            case com.android.server.job.Flags.FLAG_THROW_ON_UNSUPPORTED_BIAS_USAGE:
                pw.println(com.android.server.job.Flags.throwOnUnsupportedBiasUsage());
                break;
            case android.app.job.Flags.FLAG_BACKUP_JOBS_EXEMPTION:
                pw.println(android.app.job.Flags.backupJobsExemption());
                break;
            default:
                pw.println("Unknown flag: " + flagName);
                break;
+1 −0
Original line number Diff line number Diff line
@@ -277,6 +277,7 @@ package android {
    field @FlaggedApi("android.companion.flags.device_presence") public static final String REQUEST_OBSERVE_DEVICE_UUID_PRESENCE = "android.permission.REQUEST_OBSERVE_DEVICE_UUID_PRESENCE";
    field public static final String REQUEST_PASSWORD_COMPLEXITY = "android.permission.REQUEST_PASSWORD_COMPLEXITY";
    field @Deprecated public static final String RESTART_PACKAGES = "android.permission.RESTART_PACKAGES";
    field @FlaggedApi("android.app.job.backup_jobs_exemption") public static final String RUN_BACKUP_JOBS = "android.permission.RUN_BACKUP_JOBS";
    field public static final String RUN_USER_INITIATED_JOBS = "android.permission.RUN_USER_INITIATED_JOBS";
    field public static final String SCHEDULE_EXACT_ALARM = "android.permission.SCHEDULE_EXACT_ALARM";
    field public static final String SEND_RESPOND_VIA_MESSAGE = "android.permission.SEND_RESPOND_VIA_MESSAGE";
+19 −1
Original line number Diff line number Diff line
@@ -1548,9 +1548,16 @@ public class AppOpsManager {
    public static final int OP_READ_SYSTEM_GRAMMATICAL_GENDER =
            AppProtoEnums.APP_OP_READ_SYSTEM_GRAMMATICAL_GENDER;

    /**
     * Allows an app whose primary use case is to backup or sync content to run longer jobs.
     *
     * @hide
     */
    public static final int OP_RUN_BACKUP_JOBS = AppProtoEnums.APP_OP_RUN_BACKUP_JOBS;

    /** @hide */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public static final int _NUM_OP = 144;
    public static final int _NUM_OP = 145;

    /**
     * All app ops represented as strings.
@@ -1700,6 +1707,7 @@ public class AppOpsManager {
            OPSTR_ENABLE_MOBILE_DATA_BY_USER,
            OPSTR_RESERVED_FOR_TESTING,
            OPSTR_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER,
            OPSTR_RUN_BACKUP_JOBS,
    })
    public @interface AppOpString {}

@@ -2392,6 +2400,13 @@ public class AppOpsManager {
    public static final String OPSTR_READ_SYSTEM_GRAMMATICAL_GENDER =
            "android:read_system_grammatical_gender";

    /**
     * Allows an app whose primary use case is to backup or sync content to run longer jobs.
     *
     * @hide
     */
    public static final String OPSTR_RUN_BACKUP_JOBS = "android:run_backup_jobs";

    /** {@link #sAppOpsToNote} not initialized yet for this op */
    private static final byte SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED = 0;
    /** Should not collect noting of this app-op in {@link #sAppOpsToNote} */
@@ -2504,6 +2519,7 @@ public class AppOpsManager {
            OP_RECEIVE_SANDBOXED_DETECTION_TRAINING_DATA,
            OP_MEDIA_ROUTING_CONTROL,
            OP_READ_SYSTEM_GRAMMATICAL_GENDER,
            OP_RUN_BACKUP_JOBS,
    };

    static final AppOpInfo[] sAppOpInfos = new AppOpInfo[]{
@@ -2960,6 +2976,8 @@ public class AppOpsManager {
                OPSTR_READ_SYSTEM_GRAMMATICAL_GENDER, "READ_SYSTEM_GRAMMATICAL_GENDER")
                .setPermission(Manifest.permission.READ_SYSTEM_GRAMMATICAL_GENDER)
                .build(),
        new AppOpInfo.Builder(OP_RUN_BACKUP_JOBS, OPSTR_RUN_BACKUP_JOBS, "RUN_BACKUP_JOBS")
                .setPermission(Manifest.permission.RUN_BACKUP_JOBS).build(),
    };

    // The number of longs needed to form a full bitmask of app ops
Loading