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

Commit a4dbb590 authored by Rupesh Bansal's avatar Rupesh Bansal Committed by Android (Google) Code Review
Browse files

Merge "Add support for disabling autobrightness when stylus under use" into main

parents 49a44426 b9133e23
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -454,6 +454,11 @@ public abstract class DisplayManagerInternal {
     */
    public abstract void onPresentation(int displayId, boolean isShown);

    /**
     * Called upon the usage of stylus.
     */
    public abstract void stylusGestureStarted(long eventTime);

    /**
     * Describes the requested power state of the display.
     *
+28 −0
Original line number Diff line number Diff line
@@ -377,6 +377,7 @@ import javax.xml.datatype.DatatypeConfigurationException;
 *              </point>
 *            </map>
 *          </luxToBrightnessMapping>
 *          <idleStylusTimeoutMillis>10000</idleStylusTimeoutMillis>
 *      </autoBrightness>
 *
 *      <screenBrightnessRampFastDecrease>0.01</screenBrightnessRampFastDecrease>
@@ -708,6 +709,10 @@ public class DisplayDeviceConfig {

    private static final int KEEP_CURRENT_BRIGHTNESS = -1;

    // The default value to 0 which will signify that the stylus usage immediately stopped
    // after it was started. This will make the system behave as if the stylus was never used
    private static final int DEFAULT_IDLE_STYLUS_TIMEOUT_MILLIS = 0;

    private final Context mContext;

    // The details of the ambient light sensor associated with this display.
@@ -754,6 +759,9 @@ public class DisplayDeviceConfig {
    @Nullable
    private DisplayBrightnessMappingConfig mDisplayBrightnessMapping;

    private int mIdleStylusTimeoutMillis =
            DEFAULT_IDLE_STYLUS_TIMEOUT_MILLIS;

    private float mBacklightMinimum = Float.NaN;
    private float mBacklightMaximum = Float.NaN;
    private float mBrightnessDefault = Float.NaN;
@@ -1730,6 +1738,7 @@ public class DisplayDeviceConfig {
                + ", mDisplayBrightnessMapping= " + mDisplayBrightnessMapping
                + ", mDdcAutoBrightnessAvailable= " + mDdcAutoBrightnessAvailable
                + ", mAutoBrightnessAvailable= " + mAutoBrightnessAvailable
                + ", mIdleStylusTimeoutMillis= " + mIdleStylusTimeoutMillis
                + "\n"
                + "mDefaultLowBlockingZoneRefreshRate= " + mDefaultLowBlockingZoneRefreshRate
                + ", mDefaultHighBlockingZoneRefreshRate= " + mDefaultHighBlockingZoneRefreshRate
@@ -2389,9 +2398,18 @@ public class DisplayDeviceConfig {
        loadAutoBrightnessDarkeningLightDebounceIdle(autoBrightness);
        mDisplayBrightnessMapping = new DisplayBrightnessMappingConfig(mContext, mFlags,
                autoBrightness, getBacklightToBrightnessSpline());
        loadIdleStylusTimeoutMillis(autoBrightness);
        loadEnableAutoBrightness(autoBrightness);
    }

    /**
     * Gets the timeout post the stylus usage after which the automatic brightness will be enabled
     * again
     */
    public int getIdleStylusTimeoutMillis() {
        return mIdleStylusTimeoutMillis;
    }

    /**
     * Loads the auto-brightness brightening light debounce. Internally, this takes care of loading
     * the value from the display config, and if not present, falls back to config.xml.
@@ -2923,6 +2941,16 @@ public class DisplayDeviceConfig {
        return levels;
    }

    private void loadIdleStylusTimeoutMillis(AutoBrightness autoBrightness) {
        if (autoBrightness == null) {
            return;
        }
        BigInteger idleStylusTimeoutMillis = autoBrightness.getIdleStylusTimeoutMillis();
        if (idleStylusTimeoutMillis != null) {
            mIdleStylusTimeoutMillis = idleStylusTimeoutMillis.intValue();
        }
    }

    private void loadEnableAutoBrightness(AutoBrightness autobrightness) {
        // mDdcAutoBrightnessAvailable is initialised to true, so that we fallback to using the
        // config.xml values if the autobrightness tag is not defined in the ddc file.
+15 −0
Original line number Diff line number Diff line
@@ -5646,6 +5646,21 @@ public final class DisplayManagerService extends SystemService {
        public void onPresentation(int displayId, boolean isShown) {
            mExternalDisplayPolicy.onPresentation(displayId, isShown);
        }

        @Override
        public void stylusGestureStarted(long eventTime) {
            if (mFlags.isBlockAutobrightnessChangesOnStylusUsage()) {
                DisplayPowerController displayPowerController;
                synchronized (mSyncRoot) {
                    displayPowerController = mDisplayPowerControllers.get(
                            Display.DEFAULT_DISPLAY);
                }
                // We assume that the stylus is being used on the default display. This should
                // be changed to the displayId on which it is being used once we start getting this
                // information from the input manager service
                displayPowerController.stylusGestureStarted(eventTime);
            }
        }
    }

    class DesiredDisplayModeSpecsObserver
+39 −3
Original line number Diff line number Diff line
@@ -167,12 +167,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    private static final int MSG_SET_DWBC_LOGGING_ENABLED = 16;
    private static final int MSG_SET_BRIGHTNESS_FROM_OFFLOAD = 17;
    private static final int MSG_OFFLOADING_SCREEN_ON_UNBLOCKED = 18;


    private static final int MSG_SET_STYLUS_BEING_USED = 19;
    private static final int MSG_SET_STYLUS_USE_ENDED = 20;

    private static final int BRIGHTNESS_CHANGE_STATSD_REPORT_INTERVAL_MS = 500;


    // State machine constants for tracking initial brightness ramp skipping when enabled.
    private static final int RAMP_STATE_SKIP_NONE = 0;
    private static final int RAMP_STATE_SKIP_INITIAL = 1;
@@ -191,6 +190,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80,
        90, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200,
        1400, 1600, 1800, 2000, 2250, 2500, 2750, 3000};

    private static final int STYLUS_USAGE_DEBOUNCE_TIME  = 1000;
    private static final int NANO_SECONDS_TO_MILLI_SECONDS_RATIO  = 1_000_000;

    private static final int[] BRIGHTNESS_RANGE_INDEX = {
        FrameworkStatsLog.DISPLAY_BRIGHTNESS_CHANGED__BUCKET_INDEX__RANGE_UNKNOWN,
        FrameworkStatsLog.DISPLAY_BRIGHTNESS_CHANGED__BUCKET_INDEX__RANGE_0_1,
@@ -498,6 +501,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    @GuardedBy("mLock")
    private int mPendingOverrideDozeScreenStateLocked;

    private long mLastStylusUsageEventTime = -1;

    // The time of inactivity after which the stylus can be assumed to be no longer in use.
    private long mIdleStylusTimeoutMillisConfig = 0;

    /**
     * Creates the display power controller.
     */
@@ -518,6 +526,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        mSensorManager = sensorManager;
        mHandler = new DisplayControllerHandler(handler.getLooper());
        mDisplayDeviceConfig = mDisplayDevice.getDisplayDeviceConfig();
        mIdleStylusTimeoutMillisConfig = mDisplayDeviceConfig.getIdleStylusTimeoutMillis();
        mIsEnabled = logicalDisplay.isEnabledLocked();
        mIsInTransition = logicalDisplay.isInTransitionLocked();
        mIsDisplayInternal = displayDeviceInfo.type == Display.TYPE_INTERNAL;
@@ -893,6 +902,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                mPhysicalDisplayName = displayName;
                mDisplayStatsId = mUniqueDisplayId.hashCode();
                mDisplayDeviceConfig = config;
                mIdleStylusTimeoutMillisConfig = mDisplayDeviceConfig.getIdleStylusTimeoutMillis();
                mThermalBrightnessThrottlingDataId = thermalBrightnessThrottlingDataId;
                loadFromDisplayDeviceConfig(token, info, hbmMetadata);
                mDisplayPowerProximityStateController.notifyDisplayDeviceChanged(config);
@@ -2971,6 +2981,18 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        return mDisplayId == Display.DEFAULT_DISPLAY || mBootCompleted;
    }

    public void stylusGestureStarted(long eventTimeNanoSeconds) {
        long eventTimeMs = eventTimeNanoSeconds / NANO_SECONDS_TO_MILLI_SECONDS_RATIO;
        if (mLastStylusUsageEventTime == -1
                || eventTimeMs > mLastStylusUsageEventTime + STYLUS_USAGE_DEBOUNCE_TIME) {
            synchronized (mLock) {
                // Add a message to notify the stylus usage has started
                mHandler.sendEmptyMessageAtTime(MSG_SET_STYLUS_BEING_USED, mClock.uptimeMillis());
            }
            mLastStylusUsageEventTime = eventTimeMs;
        }
    }

    private final class DisplayControllerHandler extends Handler {
        DisplayControllerHandler(Looper looper) {
            super(looper, null, true /*async*/);
@@ -3087,6 +3109,20 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                        updatePowerState();
                    }
                    break;
                case MSG_SET_STYLUS_BEING_USED:
                    // Remove any MSG_SET_STYLUS_USE_ENDED message from the handler queue and
                    // post a delayed MSG_SET_STYLUS_USE_ENDED message to delay the stylus
                    // usage ended event processing
                    mHandler.removeMessages(MSG_SET_STYLUS_USE_ENDED);
                    Message message = mHandler.obtainMessage(MSG_SET_STYLUS_USE_ENDED);
                    mHandler.sendMessageAtTime(message,
                            mClock.uptimeMillis() + mIdleStylusTimeoutMillisConfig);
                    mDisplayBrightnessController.setStylusBeingUsed(true);
                    break;
                case MSG_SET_STYLUS_USE_ENDED:
                    mDisplayBrightnessController.setStylusBeingUsed(false);
                    updatePowerState();
                    break;
            }
        }
    }
+7 −0
Original line number Diff line number Diff line
@@ -501,6 +501,13 @@ public final class DisplayBrightnessController {
        return true;
    }

    /**
     * Notifies if the stylus is currently being used or not.
     */
    public void setStylusBeingUsed(boolean isEnabled) {
        // Todo(b/369977976) - Disable the auto-brightness strategy
    }

    @VisibleForTesting
    static class Injector {
        DisplayBrightnessStrategySelector getDisplayBrightnessStrategySelector(Context context,
Loading