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

Commit 4a22aeef authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Log global JobScheduler state changes."

parents 8fdf92ef 367e535e
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -69,6 +69,11 @@ public final class BatteryController extends RestrictingController {
     */
    private final ArraySet<JobStatus> mChangedJobs = new ArraySet<>();

    @GuardedBy("mLock")
    private Boolean mLastReportedStatsdBatteryNotLow = null;
    @GuardedBy("mLock")
    private Boolean mLastReportedStatsdStablePower = null;

    public BatteryController(JobSchedulerService service,
            FlexibilityController flexibilityController) {
        super(service);
@@ -176,6 +181,19 @@ public final class BatteryController extends RestrictingController {
            Slog.d(TAG, "maybeReportNewChargingStateLocked: "
                    + powerConnected + "/" + stablePower + "/" + batteryNotLow);
        }

        if (mLastReportedStatsdStablePower == null
                || mLastReportedStatsdStablePower != stablePower) {
            logDeviceWideConstraintStateToStatsd(JobStatus.CONSTRAINT_CHARGING, stablePower);
            mLastReportedStatsdStablePower = stablePower;
        }
        if (mLastReportedStatsdBatteryNotLow == null
                || mLastReportedStatsdBatteryNotLow != stablePower) {
            logDeviceWideConstraintStateToStatsd(JobStatus.CONSTRAINT_BATTERY_NOT_LOW,
                    batteryNotLow);
            mLastReportedStatsdBatteryNotLow = batteryNotLow;
        }

        final long nowElapsed = sElapsedRealtimeClock.millis();

        mFlexibilityController.setConstraintSatisfied(
+2 −0
Original line number Diff line number Diff line
@@ -153,6 +153,8 @@ public final class DeviceIdleJobsController extends StateController {
                changed = true;
            }
            mDeviceIdleMode = enabled;
            logDeviceWideConstraintStateToStatsd(JobStatus.CONSTRAINT_DEVICE_NOT_DOZING,
                    !mDeviceIdleMode);
            if (DEBUG) Slog.d(TAG, "mDeviceIdleMode=" + mDeviceIdleMode);
            mDeviceIdleUpdateFunctor.prepare();
            if (enabled) {
+2 −0
Original line number Diff line number Diff line
@@ -96,6 +96,8 @@ public final class IdleController extends RestrictingController implements Idlen
    @Override
    public void reportNewIdleState(boolean isIdle) {
        synchronized (mLock) {
            logDeviceWideConstraintStateToStatsd(JobStatus.CONSTRAINT_IDLE, isIdle);

            final long nowElapsed = sElapsedRealtimeClock.millis();
            mFlexibilityController.setConstraintSatisfied(
                    JobStatus.CONSTRAINT_IDLE, isIdle, nowElapsed);
+8 −3
Original line number Diff line number Diff line
@@ -170,13 +170,12 @@ public final class JobStatus {
     */
    private static final int STATSD_CONSTRAINTS_TO_LOG = CONSTRAINT_CONTENT_TRIGGER
            | CONSTRAINT_DEADLINE
            | CONSTRAINT_IDLE
            | CONSTRAINT_PREFETCH
            | CONSTRAINT_TARE_WEALTH
            | CONSTRAINT_TIMING_DELAY
            | CONSTRAINT_WITHIN_QUOTA;

    // TODO(b/129954980)
    // TODO(b/129954980): ensure this doesn't spam statsd, especially at boot
    private static final boolean STATS_LOG_ENABLED = false;

    // No override.
@@ -1982,7 +1981,7 @@ public final class JobStatus {
    }

    /** Returns a {@link JobServerProtoEnums.Constraint} enum value for the given constraint. */
    private int getProtoConstraint(int constraint) {
    static int getProtoConstraint(int constraint) {
        switch (constraint) {
            case CONSTRAINT_BACKGROUND_NOT_RESTRICTED:
                return JobServerProtoEnums.CONSTRAINT_BACKGROUND_NOT_RESTRICTED;
@@ -1998,10 +1997,16 @@ public final class JobStatus {
                return JobServerProtoEnums.CONSTRAINT_DEADLINE;
            case CONSTRAINT_DEVICE_NOT_DOZING:
                return JobServerProtoEnums.CONSTRAINT_DEVICE_NOT_DOZING;
            case CONSTRAINT_FLEXIBLE:
                return JobServerProtoEnums.CONSTRAINT_FLEXIBILITY;
            case CONSTRAINT_IDLE:
                return JobServerProtoEnums.CONSTRAINT_IDLE;
            case CONSTRAINT_PREFETCH:
                return JobServerProtoEnums.CONSTRAINT_PREFETCH;
            case CONSTRAINT_STORAGE_NOT_LOW:
                return JobServerProtoEnums.CONSTRAINT_STORAGE_NOT_LOW;
            case CONSTRAINT_TARE_WEALTH:
                return JobServerProtoEnums.CONSTRAINT_TARE_WEALTH;
            case CONSTRAINT_TIMING_DELAY:
                return JobServerProtoEnums.CONSTRAINT_TIMING_DELAY;
            case CONSTRAINT_WITHIN_QUOTA:
+10 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.util.Slog;
import android.util.proto.ProtoOutputStream;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.FrameworkStatsLog;
import com.android.server.job.JobSchedulerService;
import com.android.server.job.JobSchedulerService.Constants;
import com.android.server.job.StateChangedListener;
@@ -165,6 +166,15 @@ public abstract class StateController {
        return mService.areComponentsInPlaceLocked(jobStatus);
    }

    protected void logDeviceWideConstraintStateToStatsd(int constraint, boolean satisfied) {
        FrameworkStatsLog.write(
                FrameworkStatsLog.DEVICE_WIDE_JOB_CONSTRAINT_CHANGED,
                JobStatus.getProtoConstraint(constraint),
                satisfied
                        ? FrameworkStatsLog.DEVICE_WIDE_JOB_CONSTRAINT_CHANGED__STATE__SATISFIED
                        : FrameworkStatsLog.DEVICE_WIDE_JOB_CONSTRAINT_CHANGED__STATE__UNSATISFIED);
    }

    public abstract void dumpControllerStateLocked(IndentingPrintWriter pw,
            Predicate<JobStatus> predicate);
    public void dumpControllerStateLocked(ProtoOutputStream proto, long fieldId,