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 an additional display that copies the brightness value from the lead 31 * display when the device is using concurrent displays. 32 */ 33 public class FollowerBrightnessStrategy implements DisplayBrightnessStrategy { 34 35 // The ID of the LogicalDisplay using this strategy. 36 private final int mDisplayId; 37 38 // Set to PowerManager.BRIGHTNESS_INVALID_FLOAT when there's no brightness to follow set. 39 private float mBrightnessToFollow; 40 41 // Indicates whether we should ramp slowly to the brightness value to follow. 42 private boolean mBrightnessToFollowSlowChange; 43 FollowerBrightnessStrategy(int displayId)44 public FollowerBrightnessStrategy(int displayId) { 45 mDisplayId = displayId; 46 mBrightnessToFollow = PowerManager.BRIGHTNESS_INVALID_FLOAT; 47 mBrightnessToFollowSlowChange = false; 48 } 49 50 @Override updateBrightness( StrategyExecutionRequest strategyExecutionRequest)51 public DisplayBrightnessState updateBrightness( 52 StrategyExecutionRequest strategyExecutionRequest) { 53 // Todo(b/241308599): Introduce a validator class and add validations before setting 54 // the brightness 55 return BrightnessUtils.constructDisplayBrightnessState(BrightnessReason.REASON_FOLLOWER, 56 mBrightnessToFollow, mBrightnessToFollow, getName(), mBrightnessToFollowSlowChange); 57 } 58 59 @Override getName()60 public String getName() { 61 return "FollowerBrightnessStrategy"; 62 } 63 getBrightnessToFollow()64 public float getBrightnessToFollow() { 65 return mBrightnessToFollow; 66 } 67 68 /** 69 * Updates brightness value and brightness slowChange flag 70 **/ setBrightnessToFollow(float brightnessToFollow, boolean slowChange)71 public void setBrightnessToFollow(float brightnessToFollow, boolean slowChange) { 72 mBrightnessToFollow = brightnessToFollow; 73 mBrightnessToFollowSlowChange = slowChange; 74 } 75 76 /** 77 * Dumps the state of this class. 78 */ 79 @Override dump(PrintWriter writer)80 public void dump(PrintWriter writer) { 81 writer.println("FollowerBrightnessStrategy:"); 82 writer.println(" mDisplayId=" + mDisplayId); 83 writer.println(" mBrightnessToFollow:" + mBrightnessToFollow); 84 writer.println(" mBrightnessToFollowSlowChange:" + mBrightnessToFollowSlowChange); 85 } 86 87 @Override strategySelectionPostProcessor( StrategySelectionNotifyRequest strategySelectionNotifyRequest)88 public void strategySelectionPostProcessor( 89 StrategySelectionNotifyRequest strategySelectionNotifyRequest) { 90 // DO NOTHING 91 } 92 93 @Override getReason()94 public int getReason() { 95 return BrightnessReason.REASON_FOLLOWER; 96 } 97 } 98