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

Commit b1b591f3 authored by Rupesh Bansal's avatar Rupesh Bansal
Browse files

Added support to reset offload brightness in post processor

Bug: 335310897
Test: atest OffloadBrightnessStrategyTest
Change-Id: Ie3e793b2ddfb559f47ed720ee0b095c3708c48ba
parent 1dd4c8fc
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -1404,7 +1404,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            if (mScreenOffBrightnessSensorController != null) {
                mScreenOffBrightnessSensorController.setLightSensorEnabled(false);
            }
            setBrightnessFromOffload(PowerManager.BRIGHTNESS_INVALID_FLOAT);
        }
        // AutomaticBrightnessStrategy has higher priority than OffloadBrightnessStrategy
        if (!mFlags.isRefactorDisplayPowerControllerEnabled() && (Float.isNaN(brightnessState)
+5 −3
Original line number Diff line number Diff line
@@ -121,7 +121,8 @@ public class DisplayBrightnessStrategySelector {
                (mDisplayManagerFlags.isRefactorDisplayPowerControllerEnabled())
                        ? mAutomaticBrightnessStrategy1 : mAutomaticBrightnessStrategy2;
        if (flags.isDisplayOffloadEnabled()) {
            mOffloadBrightnessStrategy = injector.getOffloadBrightnessStrategy();
            mOffloadBrightnessStrategy = injector
                    .getOffloadBrightnessStrategy(mDisplayManagerFlags);
        } else {
            mOffloadBrightnessStrategy = null;
        }
@@ -314,8 +315,9 @@ public class DisplayBrightnessStrategySelector {
            return new AutomaticBrightnessStrategy2(context, displayId);
        }

        OffloadBrightnessStrategy getOffloadBrightnessStrategy() {
            return new OffloadBrightnessStrategy();
        OffloadBrightnessStrategy getOffloadBrightnessStrategy(
                DisplayManagerFlags displayManagerFlags) {
            return new OffloadBrightnessStrategy(displayManagerFlags);
        }
    }
}
+21 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.display.brightness.strategy;

public class DisplayBrightnessStrategyConstants {
    static final String INVALID_BRIGHTNESS_STRATEGY_NAME = "InvalidBrightnessStrategy";
}
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ public class InvalidBrightnessStrategy implements DisplayBrightnessStrategy {

    @Override
    public String getName() {
        return "InvalidBrightnessStrategy";
        return DisplayBrightnessStrategyConstants.INVALID_BRIGHTNESS_STRATEGY_NAME;
    }

    @Override
+23 −4
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.PowerManager;
import com.android.server.display.DisplayBrightnessState;
import com.android.server.display.brightness.BrightnessReason;
import com.android.server.display.brightness.StrategySelectionNotifyRequest;
import com.android.server.display.feature.DisplayManagerFlags;

import java.io.PrintWriter;

@@ -32,19 +33,29 @@ import java.io.PrintWriter;
public class OffloadBrightnessStrategy implements DisplayBrightnessStrategy {

    private float mOffloadScreenBrightness;
    private final DisplayManagerFlags mDisplayManagerFlags;

    public OffloadBrightnessStrategy() {
    public OffloadBrightnessStrategy(DisplayManagerFlags displayManagerFlags) {
        mDisplayManagerFlags = displayManagerFlags;
        mOffloadScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
    }

    @Override
    public DisplayBrightnessState updateBrightness(
            DisplayManagerInternal.DisplayPowerRequest displayPowerRequest) {
        float offloadBrightness = mOffloadScreenBrightness;
        if (mDisplayManagerFlags.isRefactorDisplayPowerControllerEnabled()) {
            // We reset the offload brightness to invalid so that there is no stale value lingering
            // around. After this request is processed, the current brightness will be set to
            // offload brightness. Hence even if the lux values don't become valid for the next
            // request, we will fallback to the current brightness anyways.
            mOffloadScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
        }
        BrightnessReason brightnessReason = new BrightnessReason();
        brightnessReason.setReason(BrightnessReason.REASON_OFFLOAD);
        return new DisplayBrightnessState.Builder()
                .setBrightness(mOffloadScreenBrightness)
                .setSdrBrightness(mOffloadScreenBrightness)
                .setBrightness(offloadBrightness)
                .setSdrBrightness(offloadBrightness)
                .setBrightnessReason(brightnessReason)
                .setDisplayBrightnessStrategyName(getName())
                .setIsSlowChange(false)
@@ -77,7 +88,15 @@ public class OffloadBrightnessStrategy implements DisplayBrightnessStrategy {
    @Override
    public void strategySelectionPostProcessor(
            StrategySelectionNotifyRequest strategySelectionNotifyRequest) {
        // DO NOTHING
        // We reset the offload brightness only if the selected strategy is not offload or invalid,
        // as we are yet to use the brightness to evaluate the brightness state.
        if (!strategySelectionNotifyRequest.getSelectedDisplayBrightnessStrategy().getName()
                .equals(getName())
                && !strategySelectionNotifyRequest.getSelectedDisplayBrightnessStrategy().getName()
                .equals(
                DisplayBrightnessStrategyConstants.INVALID_BRIGHTNESS_STRATEGY_NAME)) {
            mOffloadScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
        }
    }

    @Override
Loading