• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.server.display.brightness.strategy;
18 
19 import android.os.PowerManager;
20 
21 import com.android.server.display.DisplayBrightnessState;
22 import com.android.server.display.brightness.BrightnessReason;
23 import com.android.server.display.brightness.StrategyExecutionRequest;
24 import com.android.server.display.brightness.StrategySelectionNotifyRequest;
25 import com.android.server.display.feature.DisplayManagerFlags;
26 
27 import java.io.PrintWriter;
28 
29 /**
30  * Manages the brightness of the display when auto-brightness is on, the screen has just turned on
31  * and there is no available lux reading yet. The brightness value is read from the offload chip.
32  */
33 public class OffloadBrightnessStrategy implements DisplayBrightnessStrategy {
34 
35     private float mOffloadScreenBrightness;
36     private final DisplayManagerFlags mDisplayManagerFlags;
37 
OffloadBrightnessStrategy(DisplayManagerFlags displayManagerFlags)38     public OffloadBrightnessStrategy(DisplayManagerFlags displayManagerFlags) {
39         mDisplayManagerFlags = displayManagerFlags;
40         mOffloadScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
41     }
42 
43     @Override
updateBrightness( StrategyExecutionRequest strategyExecutionRequest)44     public DisplayBrightnessState updateBrightness(
45             StrategyExecutionRequest strategyExecutionRequest) {
46         float offloadBrightness = mOffloadScreenBrightness;
47         if (mDisplayManagerFlags.isRefactorDisplayPowerControllerEnabled()) {
48             // We reset the offload brightness to invalid so that there is no stale value lingering
49             // around. After this request is processed, the current brightness will be set to
50             // offload brightness. Hence even if the lux values don't become valid for the next
51             // request, we will fallback to the current brightness anyways.
52             mOffloadScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
53         }
54         BrightnessReason brightnessReason = new BrightnessReason();
55         brightnessReason.setReason(BrightnessReason.REASON_OFFLOAD);
56         return new DisplayBrightnessState.Builder()
57                 .setBrightness(offloadBrightness)
58                 .setBrightnessReason(brightnessReason)
59                 .setDisplayBrightnessStrategyName(getName())
60                 .setIsSlowChange(false)
61                 .setShouldUpdateScreenBrightnessSetting(true)
62                 .build();
63     }
64 
65     @Override
getName()66     public String getName() {
67         return "OffloadBrightnessStrategy";
68     }
69 
getOffloadScreenBrightness()70     public float getOffloadScreenBrightness() {
71         return mOffloadScreenBrightness;
72     }
73 
setOffloadScreenBrightness(float offloadScreenBrightness)74     public void setOffloadScreenBrightness(float offloadScreenBrightness) {
75         mOffloadScreenBrightness = offloadScreenBrightness;
76     }
77 
78     /**
79      * Dumps the state of this class.
80      */
81     @Override
dump(PrintWriter writer)82     public void dump(PrintWriter writer) {
83         writer.println("OffloadBrightnessStrategy:");
84         writer.println("  mOffloadScreenBrightness:" + mOffloadScreenBrightness);
85     }
86 
87     @Override
strategySelectionPostProcessor( StrategySelectionNotifyRequest strategySelectionNotifyRequest)88     public void strategySelectionPostProcessor(
89             StrategySelectionNotifyRequest strategySelectionNotifyRequest) {
90         // We reset the offload brightness only if the selected strategy is not offload or invalid,
91         // as we are yet to use the brightness to evaluate the brightness state.
92         if (!strategySelectionNotifyRequest.getSelectedDisplayBrightnessStrategy().getName()
93                 .equals(getName())
94                 && !strategySelectionNotifyRequest.getSelectedDisplayBrightnessStrategy().getName()
95                 .equals(
96                 DisplayBrightnessStrategyConstants.INVALID_BRIGHTNESS_STRATEGY_NAME)) {
97             mOffloadScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
98         }
99     }
100 
101     @Override
getReason()102     public int getReason() {
103         return BrightnessReason.REASON_OFFLOAD;
104     }
105 }
106