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; 18 19 import android.content.pm.ParceledListSlice; 20 import android.hardware.display.AmbientBrightnessDayStats; 21 import android.hardware.display.BrightnessChangeEvent; 22 import android.hardware.display.BrightnessConfiguration; 23 import android.hardware.display.BrightnessInfo; 24 import android.hardware.display.DisplayManagerInternal; 25 26 import java.io.PrintWriter; 27 28 /** 29 * An interface to manage the display's power state and brightness 30 */ 31 public interface DisplayPowerControllerInterface { 32 int DEFAULT_USER_SERIAL = -1; 33 /** 34 * Notified when the display is changed. 35 * 36 * We use this to apply any changes that might be needed when displays get swapped on foldable 37 * devices, when layouts change, etc. 38 * 39 * Must be called while holding the SyncRoot lock. 40 * 41 * @param hbmInfo The high brightness mode metadata, like 42 * remaining time and hbm events, for the corresponding 43 * physical display, to make sure we stay within the safety margins. 44 * @param leadDisplayId The display who is considered our "leader" for things like brightness. 45 */ onDisplayChanged(HighBrightnessModeMetadata hbmInfo, int leadDisplayId)46 void onDisplayChanged(HighBrightnessModeMetadata hbmInfo, int leadDisplayId); 47 48 /** 49 * Unregisters all listeners and interrupts all running threads; halting future work. 50 * 51 * This method should be called when the DisplayPowerController is no longer in use; i.e. when 52 * the display has been removed. 53 */ stop()54 void stop(); 55 56 /** 57 * Used to update the display's BrightnessConfiguration 58 * @param config The new BrightnessConfiguration 59 */ setBrightnessConfiguration(BrightnessConfiguration config, boolean shouldResetShortTermModel)60 void setBrightnessConfiguration(BrightnessConfiguration config, 61 boolean shouldResetShortTermModel); 62 63 /** 64 * Used to set the ambient color temperature of the Display 65 * @param ambientColorTemperature The target ambientColorTemperature 66 */ setAmbientColorTemperatureOverride(float ambientColorTemperature)67 void setAmbientColorTemperatureOverride(float ambientColorTemperature); 68 69 /** 70 * Used to decide the associated AutomaticBrightnessController's BrightnessMode 71 * @param isIdle Flag which represents if the Idle BrightnessMode is to be set 72 */ setAutomaticScreenBrightnessMode(boolean isIdle)73 void setAutomaticScreenBrightnessMode(boolean isIdle); 74 75 /** 76 * Used to enable/disable the logging of the WhileBalance associated entities 77 * @param enabled Flag which represents if the logging is the be enabled 78 */ setDisplayWhiteBalanceLoggingEnabled(boolean enabled)79 void setDisplayWhiteBalanceLoggingEnabled(boolean enabled); 80 81 /** 82 * Used to dump the state. 83 * @param writer The PrintWriter used to dump the state. 84 */ dump(PrintWriter writer)85 void dump(PrintWriter writer); 86 87 /** 88 * Used to get the ambient brightness stats 89 */ getAmbientBrightnessStats(int userId)90 ParceledListSlice<AmbientBrightnessDayStats> getAmbientBrightnessStats(int userId); 91 92 /** 93 * Get the default brightness configuration 94 */ getDefaultBrightnessConfiguration()95 BrightnessConfiguration getDefaultBrightnessConfiguration(); 96 97 /** 98 * Set the screen brightness of the associated display 99 * @param brightness The value to which the brightness is to be set 100 */ setBrightness(float brightness)101 default void setBrightness(float brightness) { 102 setBrightness(brightness, DEFAULT_USER_SERIAL); 103 } 104 105 /** 106 * Set the screen brightness of the associated display 107 * @param brightness The value to which the brightness is to be set 108 * @param userSerial The user for which the brightness value is to be set. Use userSerial = -1, 109 * if brightness needs to be updated for the current user. 110 */ setBrightness(float brightness, int userSerial)111 void setBrightness(float brightness, int userSerial); 112 113 /** 114 * Checks if the proximity sensor is available 115 */ isProximitySensorAvailable()116 boolean isProximitySensorAvailable(); 117 118 /** 119 * Persist the brightness slider events and ambient brightness stats to disk. 120 */ persistBrightnessTrackerState()121 void persistBrightnessTrackerState(); 122 123 /** 124 * Ignores the proximity sensor until the sensor state changes, but only if the sensor is 125 * currently enabled and forcing the screen to be dark. 126 */ ignoreProximitySensorUntilChanged()127 void ignoreProximitySensorUntilChanged(); 128 129 /** 130 * Requests a new power state. 131 * 132 * @param request The requested power state. 133 * @param waitForNegativeProximity If true, issues a request to wait for 134 * negative proximity before turning the screen back on, 135 * assuming the screen was turned off by the proximity sensor. 136 * @return True if display is ready, false if there are important changes that must 137 * be made asynchronously. 138 */ requestPowerState(DisplayManagerInternal.DisplayPowerRequest request, boolean waitForNegativeProximity)139 boolean requestPowerState(DisplayManagerInternal.DisplayPowerRequest request, 140 boolean waitForNegativeProximity); 141 142 /** 143 * Sets up the temporary autobrightness adjustment when the user is yet to settle down to a 144 * value. 145 */ setTemporaryAutoBrightnessAdjustment(float adjustment)146 void setTemporaryAutoBrightnessAdjustment(float adjustment); 147 148 /** 149 * Gets the screen brightness setting 150 */ getScreenBrightnessSetting()151 float getScreenBrightnessSetting(); 152 153 /** 154 * Sets up the temporary brightness for the associated display 155 */ setTemporaryBrightness(float brightness)156 void setTemporaryBrightness(float brightness); 157 158 /** 159 * Gets the associated {@link BrightnessInfo} 160 */ getBrightnessInfo()161 BrightnessInfo getBrightnessInfo(); 162 163 /** 164 * Get the {@link BrightnessChangeEvent}s for the specified user. 165 */ getBrightnessEvents(int userId, boolean hasUsageStats)166 ParceledListSlice<BrightnessChangeEvent> getBrightnessEvents(int userId, boolean hasUsageStats); 167 168 /** 169 * Sets up the logging for the associated {@link AutomaticBrightnessController} 170 * @param enabled Flag to represent if the logging is to be enabled 171 */ setAutoBrightnessLoggingEnabled(boolean enabled)172 void setAutoBrightnessLoggingEnabled(boolean enabled); 173 174 /** 175 * Handles the changes to be done to update the brightness when the user is changed 176 * @param newUserId The new userId 177 */ onSwitchUser(int newUserId)178 void onSwitchUser(int newUserId); 179 180 /** 181 * Get the ID of the display associated with this DPC. 182 * @return The display ID 183 */ getDisplayId()184 int getDisplayId(); 185 186 /** 187 * Get the ID of the display that is the leader of this DPC. 188 * 189 * Note that this is different than the display associated with the DPC. The leader is another 190 * display which we follow for things like brightness. 191 * 192 * Must be called while holding the SyncRoot lock. 193 */ getLeadDisplayId()194 int getLeadDisplayId(); 195 196 /** 197 * Set the brightness to follow if this is an additional display in a set of concurrent 198 * displays. 199 * @param leadDisplayBrightness The brightness of the lead display in the set of concurrent 200 * displays 201 * @param nits The brightness value in nits if the device supports nits. Set to a negative 202 * number otherwise. 203 * @param ambientLux The lux value that will be passed to {@link HighBrightnessModeController} 204 * @param slowChange Indicates whether we should slowly animate to the given brightness value. 205 */ setBrightnessToFollow(float leadDisplayBrightness, float nits, float ambientLux, boolean slowChange)206 void setBrightnessToFollow(float leadDisplayBrightness, float nits, float ambientLux, 207 boolean slowChange); 208 209 /** 210 * Add an additional display that will copy the brightness value from this display. This is used 211 * when the device is in concurrent displays mode. 212 * @param follower The DPC that should copy the brightness value from this DPC 213 */ addDisplayBrightnessFollower(DisplayPowerControllerInterface follower)214 void addDisplayBrightnessFollower(DisplayPowerControllerInterface follower); 215 216 /** 217 * Removes the given display from the list of brightness followers. 218 * @param follower The DPC to remove from the followers list 219 */ removeDisplayBrightnessFollower(DisplayPowerControllerInterface follower)220 void removeDisplayBrightnessFollower(DisplayPowerControllerInterface follower); 221 222 /** 223 * Indicate that boot has been completed and the screen is ready to update. 224 */ onBootCompleted()225 void onBootCompleted(); 226 } 227