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

Commit dee0f3ba authored by Xin Guan's avatar Xin Guan
Browse files

JobScheduler: Fix FlexibilityControllerTest test failures

Mock the JobSchedulerInternal object as well since the tests
need to create JobStatus objects.

Bug: 437416813
Test: atest
FrameworksMockingServicesTests:com.android.server.job.controllers
Flag: EXEMPT test fix
Change-Id: I210548632beb7de9351d16b7f3dd94aad080bdc9
parent 4df9595f
Loading
Loading
Loading
Loading
+4 −3
Original line number Original line Diff line number Diff line
@@ -1426,9 +1426,6 @@ public final class JobStatus {
     * @return true if the exemption status changed
     * @return true if the exemption status changed
     */
     */
    public boolean updateMediaBackupExemptionStatus() {
    public boolean updateMediaBackupExemptionStatus() {
        if (mJobSchedulerInternal == null) {
            mJobSchedulerInternal = LocalServices.getService(JobSchedulerInternal.class);
        }
        final boolean hasMediaExemption = hasMediaBackupExemption();
        final boolean hasMediaExemption = hasMediaBackupExemption();
        if (mHasMediaBackupExemption == hasMediaExemption) {
        if (mHasMediaBackupExemption == hasMediaExemption) {
            return false;
            return false;
@@ -2567,6 +2564,10 @@ public final class JobStatus {
    }
    }


    private boolean hasMediaBackupExemption() {
    private boolean hasMediaBackupExemption() {
        if (mJobSchedulerInternal == null) {
            mJobSchedulerInternal = LocalServices.getService(JobSchedulerInternal.class);
        }

        // Check the legacy policy first.
        // Check the legacy policy first.
        if (mHasExemptedMediaUrisOnly
        if (mHasExemptedMediaUrisOnly
                && !job.hasLateConstraint()
                && !job.hasLateConstraint()
+5 −0
Original line number Original line Diff line number Diff line
@@ -93,6 +93,7 @@ import android.util.SparseArray;
import com.android.server.AppSchedulingModuleThread;
import com.android.server.AppSchedulingModuleThread;
import com.android.server.DeviceIdleInternal;
import com.android.server.DeviceIdleInternal;
import com.android.server.LocalServices;
import com.android.server.LocalServices;
import com.android.server.job.JobSchedulerInternal;
import com.android.server.job.JobSchedulerService;
import com.android.server.job.JobSchedulerService;
import com.android.server.job.JobStore;
import com.android.server.job.JobStore;


@@ -196,6 +197,10 @@ public class FlexibilityControllerTest {
        doReturn(mJobStore).when(mJobSchedulerService).getJobStore();
        doReturn(mJobStore).when(mJobSchedulerService).getJobStore();
        // Used in JobStatus.
        // Used in JobStatus.
        doReturn(mIPackageManager).when(AppGlobals::getPackageManager);
        doReturn(mIPackageManager).when(AppGlobals::getPackageManager);
        // Used in JobStatus.
        doReturn(mock(JobSchedulerInternal.class))
                .when(() -> LocalServices.getService(JobSchedulerInternal.class));

        // Freeze the clocks at a moment in time
        // Freeze the clocks at a moment in time
        JobSchedulerService.sSystemClock =
        JobSchedulerService.sSystemClock =
                Clock.fixed(Instant.ofEpochMilli(FROZEN_TIME), ZoneOffset.UTC);
                Clock.fixed(Instant.ofEpochMilli(FROZEN_TIME), ZoneOffset.UTC);