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

Commit 7c243dd6 authored by Rupesh Bansal's avatar Rupesh Bansal
Browse files

Dont select automatic strategy when stylus is in use

To stop the brightness from changing when stylus is being used, we will
not select the automatic brightness strategy. This way, the selector
will falkback to the next valid strategy(FallbackBrightnessStrategy)
which will select the current brightness

Bug: 352411468
Test: atest com.android.server.display
Flag: com.android.server.display.feature.flags.block_autobrightness_changes_on_stylus_usage
Change-Id: I3014ea0b1e6b71378a1cdfd402b4b37df70f5a20
parent 550054fb
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -50,8 +50,10 @@ public final class BrightnessReason {
    public static final int MODIFIER_THROTTLED = 0x8;
    public static final int MODIFIER_MIN_LUX = 0x10;
    public static final int MODIFIER_MIN_USER_SET_LOWER_BOUND = 0x20;
    public static final int MODIFIER_STYLUS_UNDER_USE = 0x40;
    public static final int MODIFIER_MASK = MODIFIER_DIMMED | MODIFIER_LOW_POWER | MODIFIER_HDR
            | MODIFIER_THROTTLED | MODIFIER_MIN_LUX | MODIFIER_MIN_USER_SET_LOWER_BOUND;
            | MODIFIER_THROTTLED | MODIFIER_MIN_LUX | MODIFIER_MIN_USER_SET_LOWER_BOUND
            | MODIFIER_STYLUS_UNDER_USE;

    // ADJUSTMENT_*
    // These things can happen at any point, even if the main brightness reason doesn't
@@ -158,6 +160,9 @@ public final class BrightnessReason {
        if ((mModifier & MODIFIER_MIN_USER_SET_LOWER_BOUND) != 0) {
            sb.append(" user_min_pref");
        }
        if ((mModifier & MODIFIER_STYLUS_UNDER_USE) != 0) {
            sb.append(" stylus_under_use");
        }
        int strlen = sb.length();
        if (sb.charAt(strlen - 1) == '[') {
            sb.setLength(strlen - 2);
+14 −3
Original line number Diff line number Diff line
@@ -110,6 +110,9 @@ public final class DisplayBrightnessController {
    @VisibleForTesting
    AutomaticBrightnessController mAutomaticBrightnessController;

    // True if the stylus is being used
    private boolean mIsStylusBeingUsed;

    /**
     * The constructor of DisplayBrightnessController.
     */
@@ -460,6 +463,8 @@ public final class DisplayBrightnessController {
        writer.println("  mScreenBrightnessDefault=" + mScreenBrightnessDefault);
        writer.println("  mPersistBrightnessNitsForDefaultDisplay="
                + mPersistBrightnessNitsForDefaultDisplay);
        writer.println("  mIsStylusBeingUsed="
                + mIsStylusBeingUsed);
        synchronized (mLock) {
            writer.println("  mPendingScreenBrightness=" + mPendingScreenBrightness);
            writer.println("  mCurrentScreenBrightness=" + mCurrentScreenBrightness);
@@ -505,7 +510,12 @@ public final class DisplayBrightnessController {
     * Notifies if the stylus is currently being used or not.
     */
    public void setStylusBeingUsed(boolean isEnabled) {
        // Todo(b/369977976) - Disable the auto-brightness strategy
        mIsStylusBeingUsed = isEnabled;
    }

    @VisibleForTesting
    boolean isStylusBeingUsed() {
        return mIsStylusBeingUsed;
    }

    @VisibleForTesting
@@ -626,13 +636,14 @@ public final class DisplayBrightnessController {
            lastUserSetScreenBrightness = mLastUserSetScreenBrightness;
        }
        return new StrategySelectionRequest(displayPowerRequest, targetDisplayState,
                lastUserSetScreenBrightness, userSetBrightnessChanged, displayOffloadSession);
                lastUserSetScreenBrightness, userSetBrightnessChanged, displayOffloadSession,
                mIsStylusBeingUsed);
    }

    private StrategyExecutionRequest constructStrategyExecutionRequest(
            DisplayManagerInternal.DisplayPowerRequest displayPowerRequest) {
        float currentScreenBrightness = getCurrentBrightness();
        return new StrategyExecutionRequest(displayPowerRequest, currentScreenBrightness,
                mUserSetScreenBrightnessUpdated);
                mUserSetScreenBrightnessUpdated, mIsStylusBeingUsed);
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -306,7 +306,8 @@ public class DisplayBrightnessStrategySelector {
                strategySelectionRequest.getDisplayPowerRequest().useNormalBrightnessForDoze,
                strategySelectionRequest.getLastUserSetScreenBrightness(),
                strategySelectionRequest.isUserSetBrightnessChanged());
        return mAutomaticBrightnessStrategy1.isAutoBrightnessValid();
        return !strategySelectionRequest.isStylusBeingUsed()
                && mAutomaticBrightnessStrategy1.isAutoBrightnessValid();
    }

    private StrategySelectionNotifyRequest constructStrategySelectionNotifyRequest(
+12 −3
Original line number Diff line number Diff line
@@ -32,11 +32,15 @@ public final class StrategyExecutionRequest {
    // Represents if the user set screen brightness was changed or not.
    private boolean mUserSetBrightnessChanged;

    private boolean mIsStylusBeingUsed;

    public StrategyExecutionRequest(DisplayManagerInternal.DisplayPowerRequest displayPowerRequest,
            float currentScreenBrightness, boolean userSetBrightnessChanged) {
            float currentScreenBrightness, boolean userSetBrightnessChanged,
            boolean isStylusBeingUsed) {
        mDisplayPowerRequest = displayPowerRequest;
        mCurrentScreenBrightness = currentScreenBrightness;
        mUserSetBrightnessChanged = userSetBrightnessChanged;
        mIsStylusBeingUsed = isStylusBeingUsed;
    }

    public DisplayManagerInternal.DisplayPowerRequest getDisplayPowerRequest() {
@@ -51,6 +55,10 @@ public final class StrategyExecutionRequest {
        return mUserSetBrightnessChanged;
    }

    public boolean isStylusBeingUsed() {
        return mIsStylusBeingUsed;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof StrategyExecutionRequest)) {
@@ -59,12 +67,13 @@ public final class StrategyExecutionRequest {
        StrategyExecutionRequest other = (StrategyExecutionRequest) obj;
        return Objects.equals(mDisplayPowerRequest, other.getDisplayPowerRequest())
                && mCurrentScreenBrightness == other.getCurrentScreenBrightness()
                && mUserSetBrightnessChanged == other.isUserSetBrightnessChanged();
                && mUserSetBrightnessChanged == other.isUserSetBrightnessChanged()
                && mIsStylusBeingUsed == other.isStylusBeingUsed();
    }

    @Override
    public int hashCode() {
        return Objects.hash(mDisplayPowerRequest, mCurrentScreenBrightness,
                mUserSetBrightnessChanged);
                mUserSetBrightnessChanged, mIsStylusBeingUsed);
    }
}
+13 −3
Original line number Diff line number Diff line
@@ -40,15 +40,19 @@ public final class StrategySelectionRequest {

    private DisplayManagerInternal.DisplayOffloadSession mDisplayOffloadSession;

    private boolean mIsStylusBeingUsed;

    public StrategySelectionRequest(DisplayManagerInternal.DisplayPowerRequest displayPowerRequest,
            int targetDisplayState, float lastUserSetScreenBrightness,
            boolean userSetBrightnessChanged,
            DisplayManagerInternal.DisplayOffloadSession displayOffloadSession) {
            DisplayManagerInternal.DisplayOffloadSession displayOffloadSession,
            boolean isStylusBeingUsed) {
        mDisplayPowerRequest = displayPowerRequest;
        mTargetDisplayState = targetDisplayState;
        mLastUserSetScreenBrightness = lastUserSetScreenBrightness;
        mUserSetBrightnessChanged = userSetBrightnessChanged;
        mDisplayOffloadSession = displayOffloadSession;
        mIsStylusBeingUsed = isStylusBeingUsed;
    }

    public DisplayManagerInternal.DisplayPowerRequest getDisplayPowerRequest() {
@@ -72,6 +76,10 @@ public final class StrategySelectionRequest {
        return mDisplayOffloadSession;
    }

    public boolean isStylusBeingUsed() {
        return mIsStylusBeingUsed;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof StrategySelectionRequest)) {
@@ -82,12 +90,14 @@ public final class StrategySelectionRequest {
                && mTargetDisplayState == other.getTargetDisplayState()
                && mLastUserSetScreenBrightness == other.getLastUserSetScreenBrightness()
                && mUserSetBrightnessChanged == other.isUserSetBrightnessChanged()
                && mDisplayOffloadSession.equals(other.getDisplayOffloadSession());
                && mDisplayOffloadSession.equals(other.getDisplayOffloadSession())
                && mIsStylusBeingUsed == other.isStylusBeingUsed();
    }

    @Override
    public int hashCode() {
        return Objects.hash(mDisplayPowerRequest, mTargetDisplayState,
                mLastUserSetScreenBrightness, mUserSetBrightnessChanged, mDisplayOffloadSession);
                mLastUserSetScreenBrightness, mUserSetBrightnessChanged, mDisplayOffloadSession,
                mIsStylusBeingUsed);
    }
}
Loading