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 if (strategyExecutionRequest.isStylusBeingUsed()) { 41 brightnessReason.setModifier(BrightnessReason.MODIFIER_STYLUS_UNDER_USE); 42 } 43 return new DisplayBrightnessState.Builder() 44 .setBrightness(strategyExecutionRequest.getCurrentScreenBrightness()) 45 .setBrightnessReason(brightnessReason) 46 .setDisplayBrightnessStrategyName(getName()) 47 // The fallback brightness might change due to clamping. Make sure we tell the rest 48 // of the system by updating the setting 49 .setShouldUpdateScreenBrightnessSetting(true) 50 .setIsUserInitiatedChange(strategyExecutionRequest.isUserSetBrightnessChanged()) 51 .build(); 52 } 53 54 @NonNull 55 @Override getName()56 public String getName() { 57 return DisplayBrightnessStrategyConstants.FALLBACK_BRIGHTNESS_STRATEGY_NAME; 58 } 59 60 @Override getReason()61 public int getReason() { 62 return BrightnessReason.REASON_MANUAL; 63 } 64 65 @Override dump(PrintWriter writer)66 public void dump(PrintWriter writer) { 67 68 } 69 70 @Override strategySelectionPostProcessor( StrategySelectionNotifyRequest strategySelectionNotifyRequest)71 public void strategySelectionPostProcessor( 72 StrategySelectionNotifyRequest strategySelectionNotifyRequest) { 73 74 } 75 } 76