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.hardware.display.DisplayManagerInternal; 20 import android.os.PowerManager; 21 22 import com.android.server.display.DisplayBrightnessState; 23 import com.android.server.display.brightness.BrightnessReason; 24 import com.android.server.display.brightness.BrightnessUtils; 25 26 import java.io.PrintWriter; 27 28 /** 29 * Manages the brightness of the display when the system brightness is temporary 30 */ 31 public class TemporaryBrightnessStrategy implements DisplayBrightnessStrategy { 32 // The temporary screen brightness. Typically set when a user is interacting with the 33 // brightness slider but hasn't settled on a choice yet. Set to 34 // PowerManager.BRIGHTNESS_INVALID_FLOAT when there's no temporary brightness set. 35 private float mTemporaryScreenBrightness; 36 TemporaryBrightnessStrategy()37 public TemporaryBrightnessStrategy() { 38 mTemporaryScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT; 39 } 40 41 // Use the temporary screen brightness if there isn't an override, either from 42 // WindowManager or based on the display state. 43 @Override updateBrightness( DisplayManagerInternal.DisplayPowerRequest displayPowerRequest)44 public DisplayBrightnessState updateBrightness( 45 DisplayManagerInternal.DisplayPowerRequest displayPowerRequest) { 46 // Todo(b/241308599): Introduce a validator class and add validations before setting 47 // the brightness 48 DisplayBrightnessState displayBrightnessState = 49 BrightnessUtils.constructDisplayBrightnessState(BrightnessReason.REASON_TEMPORARY, 50 mTemporaryScreenBrightness, 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 */ dump(PrintWriter writer)71 public void dump(PrintWriter writer) { 72 writer.println("TemporaryBrightnessStrategy:"); 73 writer.println(" mTemporaryScreenBrightness:" + mTemporaryScreenBrightness); 74 } 75 } 76