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