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

Commit 188bbbf1 authored by Michael Wright's avatar Michael Wright
Browse files

Log the requested display policy.

This way we can track what the general desire for the display is. Note
that this is different than tracking the actual display state since, for
example, you may be applying POLICY_DOZE but the DozeService actually
has the display in the ON state.

Bug: 122949636
Test: manual inspection
Change-Id: I65b7e26937f6fbb40057a49c4ebe4aed7380100b
parent f54473a8
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -7132,6 +7132,12 @@ message MetricsEvent {
    // OS: Q
    FIELD_SCREEN_SLEEP_REASON = 1695;

    // UPDATE: The screen changed policy
    //   SUBTYPE: The applied policy. One of the DISPLAY_POLICY_* constants in
    //   DisplayManagerInternal.
    // OS: Q
    DISPLAY_POLICY = 1696;

    // ---- End Q Constants, all Q constants go above this line ----
    // Add new aosp constants above this line.
    // END OF AOSP CONSTANTS
+21 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.hardware.display.BrightnessChangeEvent;
import android.hardware.display.BrightnessConfiguration;
import android.hardware.display.DisplayManagerInternal.DisplayPowerCallbacks;
import android.hardware.display.DisplayManagerInternal.DisplayPowerRequest;
import android.metrics.LogMaker;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
@@ -51,6 +52,8 @@ import android.util.TimeUtils;
import android.view.Display;

import com.android.internal.app.IBatteryStats;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.server.LocalServices;
import com.android.server.am.BatteryStatsService;
import com.android.server.display.whitebalance.DisplayWhiteBalanceController;
@@ -731,6 +734,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    private void updatePowerState() {
        // Update the power state request.
        final boolean mustNotify;
        final int previousPolicy;
        boolean mustInitialize = false;

        synchronized (mLock) {
@@ -745,12 +749,18 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                mPendingWaitForNegativeProximityLocked = false;
                mPendingRequestChangedLocked = false;
                mustInitialize = true;
                // Assume we're on and bright until told otherwise, since that's the state we turn
                // on in.
                previousPolicy = DisplayPowerRequest.POLICY_BRIGHT;
            } else if (mPendingRequestChangedLocked) {
                previousPolicy = mPowerRequest.policy;
                mPowerRequest.copyFrom(mPendingRequestLocked);
                mWaitingForNegativeProximity |= mPendingWaitForNegativeProximityLocked;
                mPendingWaitForNegativeProximityLocked = false;
                mPendingRequestChangedLocked = false;
                mDisplayReadyLocked = false;
            } else {
                previousPolicy = mPowerRequest.policy;
            }

            mustNotify = !mDisplayReadyLocked;
@@ -1103,6 +1113,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call

        // Record if dozing for future comparison.
        mDozing = state != Display.STATE_ON;

        if (previousPolicy != mPowerRequest.policy) {
            logDisplayPolicyChanged(mPowerRequest.policy);
        }
    }

    @Override
@@ -1523,6 +1537,13 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        mHandler.post(mOnStateChangedRunnable);
    }

    private void logDisplayPolicyChanged(int newPolicy) {
        LogMaker log = new LogMaker(MetricsEvent.DISPLAY_POLICY);
        log.setType(MetricsEvent.TYPE_UPDATE);
        log.setSubtype(newPolicy);
        MetricsLogger.action(log);
    }

    private void handleSettingsChange(boolean userSwitch) {
        mPendingScreenBrightnessSetting = getScreenBrightnessSetting();
        if (userSwitch) {