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

Commit 7b14a664 authored by Eric Jeong's avatar Eric Jeong
Browse files

Change idleness according to screen status

- Unlike DeviceIdlenessTracker, CarIdlenessTracker didn't listen to
screen status change.
- android.jobscheduler.cts.DeviceStatesTest#testDeviceChangeIdleActiveState
fails due to the above reason.
- It is natural to exit idle when screen is turned on, unless forced idle
is set or car is in garage mode.

Bug: 130662327
Test: Run CtsJobSchedulerTestCases
Change-Id: I8c04c619b34b9e72027914e080aa0f4ef7519422
parent 34bc57f7
Loading
Loading
Loading
Loading
+23 −3
Original line number Diff line number Diff line
@@ -20,9 +20,9 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import android.util.Log;
import android.util.Slog;

import com.android.server.am.ActivityManagerService;
import com.android.server.job.JobSchedulerService;

@@ -67,6 +67,9 @@ public final class CarIdlenessTracker extends BroadcastReceiver implements Idlen

        IntentFilter filter = new IntentFilter();

        // Screen state
        filter.addAction(Intent.ACTION_SCREEN_ON);

        // State of GarageMode
        filter.addAction(ACTION_GARAGE_MODE_ON);
        filter.addAction(ACTION_GARAGE_MODE_OFF);
@@ -97,6 +100,9 @@ public final class CarIdlenessTracker extends BroadcastReceiver implements Idlen
        } else if (action.equals(ACTION_UNFORCE_IDLE)) {
            logIfDebug("Unforcing idle...");
            setForceIdleState(false);
        } else if (action.equals(Intent.ACTION_SCREEN_ON)) {
            logIfDebug("Screen is on...");
            handleScreenOn();
        } else if (action.equals(ACTION_GARAGE_MODE_ON)) {
            logIfDebug("GarageMode is on...");
            mGarageModeOn = true;
@@ -147,7 +153,21 @@ public final class CarIdlenessTracker extends BroadcastReceiver implements Idlen
        }
    }

    private void logIfDebug(String msg) {
    private void handleScreenOn() {
        if (mForced || mGarageModeOn) {
            // Even though screen is on, the device remains idle
            logIfDebug("Screen is on, but device cannot exit idle");
        } else if (mIdle) {
            // Exiting idle
            logIfDebug("Device is exiting idle");
            mIdle = false;
        } else {
            // Already in non-idle state. Nothing to do
            logIfDebug("Device is already non-idle");
        }
    }

    private static void logIfDebug(String msg) {
        if (DEBUG) {
            Slog.v(TAG, msg);
        }