• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.BrightnessUtils;
24 import com.android.server.display.brightness.StrategyExecutionRequest;
25 import com.android.server.display.brightness.StrategySelectionNotifyRequest;
26 
27 import java.io.PrintWriter;
28 
29 /**
30  * Manages the brightness of the display when the system brightness is temporary
31  */
32 public class TemporaryBrightnessStrategy implements DisplayBrightnessStrategy {
33     // The temporary screen brightness. Typically set when a user is interacting with the
34     // brightness slider but hasn't settled on a choice yet. Set to
35     // PowerManager.BRIGHTNESS_INVALID_FLOAT when there's no temporary brightness set.
36     private float mTemporaryScreenBrightness;
37 
TemporaryBrightnessStrategy()38     public TemporaryBrightnessStrategy() {
39         mTemporaryScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
40     }
41 
42     // Use the temporary screen brightness if there isn't an override, either from
43     // WindowManager or based on the display state.
44     @Override
updateBrightness( StrategyExecutionRequest strategyExecutionRequest)45     public DisplayBrightnessState updateBrightness(
46             StrategyExecutionRequest strategyExecutionRequest) {
47         // Todo(b/241308599): Introduce a validator class and add validations before setting
48         // the brightness
49         DisplayBrightnessState displayBrightnessState =
50                 BrightnessUtils.constructDisplayBrightnessState(BrightnessReason.REASON_TEMPORARY,
51                         mTemporaryScreenBrightness, getName());
52         return displayBrightnessState;
53     }
54 
55     @Override
getName()56     public String getName() {
57         return "TemporaryBrightnessStrategy";
58     }
59 
getTemporaryScreenBrightness()60     public float getTemporaryScreenBrightness() {
61         return mTemporaryScreenBrightness;
62     }
63 
setTemporaryScreenBrightness(float temporaryScreenBrightness)64     public void setTemporaryScreenBrightness(float temporaryScreenBrightness) {
65         mTemporaryScreenBrightness = temporaryScreenBrightness;
66     }
67 
68     /**
69      * Dumps the state of this class.
70      */
71     @Override
dump(PrintWriter writer)72     public void dump(PrintWriter writer) {
73         writer.println("TemporaryBrightnessStrategy:");
74         writer.println("  mTemporaryScreenBrightness:" + mTemporaryScreenBrightness);
75     }
76 
77     @Override
strategySelectionPostProcessor( StrategySelectionNotifyRequest strategySelectionNotifyRequest)78     public void strategySelectionPostProcessor(
79             StrategySelectionNotifyRequest strategySelectionNotifyRequest) {
80         // DO NOTHING
81     }
82 
83     @Override
getReason()84     public int getReason() {
85         return BrightnessReason.REASON_TEMPORARY;
86     }
87 }
88