1 /*
2  * Copyright (C) 2024 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.annotation.NonNull;
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 
26 import java.io.PrintWriter;
27 
28 /**
29  * Manages the brightness of the associated display when no other strategy qualifies for
30  * setting up the brightness state. This strategy is also being used for evaluating the
31  * display brightness state when we have a manually set brightness. This is a temporary state, and
32  * the logic for evaluating the manual brightness will be moved to a separate strategy
33  */
34 public class FallbackBrightnessStrategy implements DisplayBrightnessStrategy{
35     @Override
updateBrightness( StrategyExecutionRequest strategyExecutionRequest)36     public DisplayBrightnessState updateBrightness(
37             StrategyExecutionRequest strategyExecutionRequest) {
38         BrightnessReason brightnessReason = new BrightnessReason();
39         brightnessReason.setReason(BrightnessReason.REASON_MANUAL);
40         return new DisplayBrightnessState.Builder()
41                 .setBrightness(strategyExecutionRequest.getCurrentScreenBrightness())
42                 .setSdrBrightness(strategyExecutionRequest.getCurrentScreenBrightness())
43                 .setBrightnessReason(brightnessReason)
44                 .setDisplayBrightnessStrategyName(getName())
45                 // The fallback brightness might change due to clamping. Make sure we tell the rest
46                 // of the system by updating the setting
47                 .setShouldUpdateScreenBrightnessSetting(true)
48                 .setIsUserInitiatedChange(strategyExecutionRequest.isUserSetBrightnessChanged())
49                 .build();
50     }
51 
52     @NonNull
53     @Override
getName()54     public String getName() {
55         return DisplayBrightnessStrategyConstants.FALLBACK_BRIGHTNESS_STRATEGY_NAME;
56     }
57 
58     @Override
getReason()59     public int getReason() {
60         return BrightnessReason.REASON_MANUAL;
61     }
62 
63     @Override
dump(PrintWriter writer)64     public void dump(PrintWriter writer) {
65 
66     }
67 
68     @Override
strategySelectionPostProcessor( StrategySelectionNotifyRequest strategySelectionNotifyRequest)69     public void strategySelectionPostProcessor(
70             StrategySelectionNotifyRequest strategySelectionNotifyRequest) {
71 
72     }
73 }
74