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

Commit 734d1df6 authored by Xin Guan's avatar Xin Guan Committed by Android (Google) Code Review
Browse files

Merge "JobScheduler: Update the evaluation for the media backup exemption policy" into main

parents 13f54f31 c21d5137
Loading
Loading
Loading
Loading
+14 −11
Original line number Diff line number Diff line
@@ -2567,18 +2567,21 @@ public final class JobStatus {
    }

    private boolean hasMediaBackupExemption() {
        if (Flags.updateMediaBackupExemptionPolicy()) {
            return getEffectivePriority() == JobInfo.PRIORITY_HIGH
                    && sourcePackageName.equals(
                            mJobSchedulerInternal.getCloudMediaProviderPackage(sourceUserId));
        } else {
            return mHasExemptedMediaUrisOnly
        // Check the legacy policy first.
        if (mHasExemptedMediaUrisOnly
                && !job.hasLateConstraint()
                && job.getRequiredNetwork() != null
                && getEffectivePriority() >= JobInfo.PRIORITY_DEFAULT
                && sourcePackageName.equals(
                            mJobSchedulerInternal.getCloudMediaProviderPackage(sourceUserId));
                        mJobSchedulerInternal.getCloudMediaProviderPackage(sourceUserId))) {
            return true;
        }

        // Check the new policy.
        return Flags.updateMediaBackupExemptionPolicy()
                && getEffectivePriority() == JobInfo.PRIORITY_HIGH
                && sourcePackageName.equals(
                        mJobSchedulerInternal.getCloudMediaProviderPackage(sourceUserId));
    }

    /**
+39 −20
Original line number Diff line number Diff line
@@ -376,35 +376,50 @@ public class JobStatusTest {
    }

    @Test
    @DisableFlags(Flags.FLAG_UPDATE_MEDIA_BACKUP_EXEMPTION_POLICY)
    public void testMediaBackupExemption_lateConstraint() {
        final JobInfo triggerContentJob = new JobInfo.Builder(42, TEST_JOB_COMPONENT)
        final JobInfo.Builder triggerContentJobBuilder = new JobInfo.Builder(42, TEST_JOB_COMPONENT)
                .addTriggerContentUri(new JobInfo.TriggerContentUri(IMAGES_MEDIA_URI, 0))
                .setOverrideDeadline(HOUR_IN_MILLIS)
                .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                .build();
                .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
        when(mJobSchedulerInternal.getCloudMediaProviderPackage(eq(0))).thenReturn(TEST_PACKAGE);
        assertEffectiveBucketForMediaExemption(createJobStatus(triggerContentJob), false);
        assertEffectiveBucketForMediaExemption(
                createJobStatus(triggerContentJobBuilder.build()), false);

        mSetFlagsRule.enableFlags(Flags.FLAG_UPDATE_MEDIA_BACKUP_EXEMPTION_POLICY);
        // High priority job from the cloud media package should be exempted.
        triggerContentJobBuilder.setPriority(JobInfo.PRIORITY_HIGH);
        assertEffectiveBucketForMediaExemption(
                createJobStatus(triggerContentJobBuilder.build()), true);
    }

    @Test
    @DisableFlags(Flags.FLAG_UPDATE_MEDIA_BACKUP_EXEMPTION_POLICY)
    public void testMediaBackupExemption_noConnectivityConstraint() {
        final JobInfo triggerContentJob = new JobInfo.Builder(42, TEST_JOB_COMPONENT)
                .addTriggerContentUri(new JobInfo.TriggerContentUri(IMAGES_MEDIA_URI, 0))
                .build();
        final JobInfo.Builder triggerContentJobBuilder = new JobInfo.Builder(42, TEST_JOB_COMPONENT)
                .addTriggerContentUri(new JobInfo.TriggerContentUri(IMAGES_MEDIA_URI, 0));

        when(mJobSchedulerInternal.getCloudMediaProviderPackage(eq(0))).thenReturn(TEST_PACKAGE);
        assertEffectiveBucketForMediaExemption(createJobStatus(triggerContentJob), false);
        assertEffectiveBucketForMediaExemption(
                createJobStatus(triggerContentJobBuilder.build()), false);

        mSetFlagsRule.enableFlags(Flags.FLAG_UPDATE_MEDIA_BACKUP_EXEMPTION_POLICY);
        triggerContentJobBuilder.setPriority(JobInfo.PRIORITY_HIGH);
        // High priority job from the cloud media package should be exempted.
        assertEffectiveBucketForMediaExemption(
                createJobStatus(triggerContentJobBuilder.setPriority(JobInfo.PRIORITY_HIGH)
                        .build()), true);
    }

    @Test
    @DisableFlags(Flags.FLAG_UPDATE_MEDIA_BACKUP_EXEMPTION_POLICY)
    public void testMediaBackupExemption_noContentTriggerConstraint() {
        final JobInfo networkJob = new JobInfo.Builder(42, TEST_JOB_COMPONENT)
                .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                .build();
        final JobInfo.Builder networkJobBuilder = new JobInfo.Builder(42, TEST_JOB_COMPONENT)
                .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
        when(mJobSchedulerInternal.getCloudMediaProviderPackage(eq(0))).thenReturn(TEST_PACKAGE);
        assertEffectiveBucketForMediaExemption(createJobStatus(networkJob), false);

        assertEffectiveBucketForMediaExemption(createJobStatus(networkJobBuilder.build()), false);
        mSetFlagsRule.enableFlags(Flags.FLAG_UPDATE_MEDIA_BACKUP_EXEMPTION_POLICY);
        networkJobBuilder.setPriority(JobInfo.PRIORITY_HIGH);
        // High priority job from the cloud media package should be exempted.
        assertEffectiveBucketForMediaExemption(createJobStatus(networkJobBuilder.build()), true);
    }

    @Test
@@ -431,17 +446,21 @@ public class JobStatusTest {
    }

    @Test
    @DisableFlags(Flags.FLAG_UPDATE_MEDIA_BACKUP_EXEMPTION_POLICY)
    public void testMediaBackupExemption_nonEligibleUri() {
        final Uri nonEligibleUri = MediaStore.AUTHORITY_URI.buildUpon()
                .appendPath("any_path").build();
        final JobInfo networkContentJob = new JobInfo.Builder(42, TEST_JOB_COMPONENT)
        final JobInfo.Builder networkContentJobBuilder = new JobInfo.Builder(42, TEST_JOB_COMPONENT)
                .addTriggerContentUri(new JobInfo.TriggerContentUri(IMAGES_MEDIA_URI, 0))
                .addTriggerContentUri(new JobInfo.TriggerContentUri(nonEligibleUri, 0))
                .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                .build();
                .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
        when(mJobSchedulerInternal.getCloudMediaProviderPackage(eq(0))).thenReturn(TEST_PACKAGE);
        assertEffectiveBucketForMediaExemption(createJobStatus(networkContentJob), false);

        assertEffectiveBucketForMediaExemption(
                createJobStatus(networkContentJobBuilder.build()), false);
        mSetFlagsRule.enableFlags(Flags.FLAG_UPDATE_MEDIA_BACKUP_EXEMPTION_POLICY);
        networkContentJobBuilder.setPriority(JobInfo.PRIORITY_HIGH);
        assertEffectiveBucketForMediaExemption(
                createJobStatus(networkContentJobBuilder.build()), true);
    }

    @Test