1 /* 2 * Copyright (C) 2014 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 android.hardware.display; 18 19 import android.annotation.IntDef; 20 import android.annotation.Nullable; 21 import android.companion.virtual.IVirtualDevice; 22 import android.graphics.Point; 23 import android.hardware.SensorManager; 24 import android.hardware.input.HostUsiVersion; 25 import android.os.Handler; 26 import android.os.PowerManager; 27 import android.util.IntArray; 28 import android.util.SparseArray; 29 import android.view.Display; 30 import android.view.DisplayInfo; 31 import android.view.SurfaceControl; 32 import android.view.SurfaceControl.RefreshRateRange; 33 import android.view.SurfaceControl.Transaction; 34 import android.window.DisplayWindowPolicyController; 35 import android.window.ScreenCapture; 36 37 import java.lang.annotation.Retention; 38 import java.lang.annotation.RetentionPolicy; 39 import java.util.List; 40 import java.util.Objects; 41 import java.util.Set; 42 43 /** 44 * Display manager local system service interface. 45 * 46 * @hide Only for use within the system server. 47 */ 48 public abstract class DisplayManagerInternal { 49 50 @IntDef(prefix = {"REFRESH_RATE_LIMIT_"}, value = { 51 REFRESH_RATE_LIMIT_HIGH_BRIGHTNESS_MODE 52 }) 53 @Retention(RetentionPolicy.SOURCE) 54 public @interface RefreshRateLimitType {} 55 56 /** Refresh rate should be limited when High Brightness Mode is active. */ 57 public static final int REFRESH_RATE_LIMIT_HIGH_BRIGHTNESS_MODE = 1; 58 59 /** 60 * Called by the power manager to initialize power management facilities. 61 */ initPowerManagement(DisplayPowerCallbacks callbacks, Handler handler, SensorManager sensorManager)62 public abstract void initPowerManagement(DisplayPowerCallbacks callbacks, 63 Handler handler, SensorManager sensorManager); 64 65 /** 66 * Called by the VirtualDeviceManagerService to create a VirtualDisplay owned by a 67 * VirtualDevice. 68 */ createVirtualDisplay(VirtualDisplayConfig config, IVirtualDisplayCallback callback, IVirtualDevice virtualDevice, DisplayWindowPolicyController dwpc, String packageName)69 public abstract int createVirtualDisplay(VirtualDisplayConfig config, 70 IVirtualDisplayCallback callback, IVirtualDevice virtualDevice, 71 DisplayWindowPolicyController dwpc, String packageName); 72 73 /** 74 * Called by the power manager to request a new power state. 75 * <p> 76 * The display power controller makes a copy of the provided object and then 77 * begins adjusting the power state to match what was requested. 78 * </p> 79 * 80 * @param groupId The identifier for the display group being requested to change power state 81 * @param request The requested power state. 82 * @param waitForNegativeProximity If {@code true}, issues a request to wait for 83 * negative proximity before turning the screen back on, assuming the screen 84 * was turned off by the proximity sensor. 85 * @return {@code true} if display group is ready, {@code false} if there are important 86 * changes that must be made asynchronously (such as turning the screen on), in which case 87 * the caller should grab a wake lock, watch for {@link DisplayPowerCallbacks#onStateChanged} 88 * then try the request again later until the state converges. If the provided {@code groupId} 89 * cannot be found then {@code true} will be returned. 90 */ requestPowerState(int groupId, DisplayPowerRequest request, boolean waitForNegativeProximity)91 public abstract boolean requestPowerState(int groupId, DisplayPowerRequest request, 92 boolean waitForNegativeProximity); 93 94 /** 95 * Returns {@code true} if the proximity sensor screen-off function is available for the given 96 * display. 97 */ isProximitySensorAvailable(int displayId)98 public abstract boolean isProximitySensorAvailable(int displayId); 99 100 /** 101 * Registers a display group listener which will be informed of the addition, removal, or change 102 * of display groups. 103 * 104 * @param listener The listener to register. 105 */ registerDisplayGroupListener(DisplayGroupListener listener)106 public abstract void registerDisplayGroupListener(DisplayGroupListener listener); 107 108 /** 109 * Unregisters a display group listener which will be informed of the addition, removal, or 110 * change of display groups. 111 * 112 * @param listener The listener to unregister. 113 */ unregisterDisplayGroupListener(DisplayGroupListener listener)114 public abstract void unregisterDisplayGroupListener(DisplayGroupListener listener); 115 116 /** 117 * Screenshot for internal system-only use such as rotation, etc. This method includes 118 * secure layers and the result should never be exposed to non-system applications. 119 * This method does not apply any rotation and provides the output in natural orientation. 120 * 121 * @param displayId The display id to take the screenshot of. 122 * @return The buffer or null if we have failed. 123 */ systemScreenshot(int displayId)124 public abstract ScreenCapture.ScreenshotHardwareBuffer systemScreenshot(int displayId); 125 126 /** 127 * General screenshot functionality that excludes secure layers and applies appropriate 128 * rotation that the device is currently in. 129 * 130 * @param displayId The display id to take the screenshot of. 131 * @return The buffer or null if we have failed. 132 */ userScreenshot(int displayId)133 public abstract ScreenCapture.ScreenshotHardwareBuffer userScreenshot(int displayId); 134 135 /** 136 * Returns information about the specified logical display. 137 * 138 * @param displayId The logical display id. 139 * @return The logical display info, or null if the display does not exist. The 140 * returned object must be treated as immutable. 141 */ getDisplayInfo(int displayId)142 public abstract DisplayInfo getDisplayInfo(int displayId); 143 144 /** 145 * Returns a set of DisplayInfo, for the states that may be assumed by either the given display, 146 * or any other display within that display's group. 147 * 148 * @param displayId The logical display id to fetch DisplayInfo for. 149 */ getPossibleDisplayInfo(int displayId)150 public abstract Set<DisplayInfo> getPossibleDisplayInfo(int displayId); 151 152 /** 153 * Returns the position of the display's projection. 154 * 155 * @param displayId The logical display id. 156 * @return The x, y coordinates of the display, or null if the display does not exist. The 157 * return object must be treated as immutable. 158 */ 159 @Nullable getDisplayPosition(int displayId)160 public abstract Point getDisplayPosition(int displayId); 161 162 /** 163 * Registers a display transaction listener to provide the client a chance to 164 * update its surfaces within the same transaction as any display layout updates. 165 * 166 * @param listener The listener to register. 167 */ registerDisplayTransactionListener(DisplayTransactionListener listener)168 public abstract void registerDisplayTransactionListener(DisplayTransactionListener listener); 169 170 /** 171 * Unregisters a display transaction listener to provide the client a chance to 172 * update its surfaces within the same transaction as any display layout updates. 173 * 174 * @param listener The listener to unregister. 175 */ unregisterDisplayTransactionListener(DisplayTransactionListener listener)176 public abstract void unregisterDisplayTransactionListener(DisplayTransactionListener listener); 177 178 /** 179 * Overrides the display information of a particular logical display. 180 * This is used by the window manager to control the size and characteristics 181 * of the default display. It is expected to apply the requested change 182 * to the display information synchronously so that applications will immediately 183 * observe the new state. 184 * 185 * NOTE: This method must be the only entry point by which the window manager 186 * influences the logical configuration of displays. 187 * 188 * @param displayId The logical display id. 189 * @param info The new data to be stored. 190 */ setDisplayInfoOverrideFromWindowManager( int displayId, DisplayInfo info)191 public abstract void setDisplayInfoOverrideFromWindowManager( 192 int displayId, DisplayInfo info); 193 194 /** 195 * Get current display info without override from WindowManager. 196 * Current implementation of LogicalDisplay#getDisplayInfoLocked() always returns display info 197 * with overrides from WM if set. This method can be used for getting real display size without 198 * overrides to determine if real changes to display metrics happened. 199 * @param displayId Id of the target display. 200 * @param outInfo {@link DisplayInfo} to fill. 201 */ getNonOverrideDisplayInfo(int displayId, DisplayInfo outInfo)202 public abstract void getNonOverrideDisplayInfo(int displayId, DisplayInfo outInfo); 203 204 /** 205 * Called by the window manager to perform traversals while holding a 206 * surface flinger transaction. 207 * @param t The default transaction. 208 * @param displayTransactions The transactions mapped by display id. 209 */ performTraversal(Transaction t, SparseArray<SurfaceControl.Transaction> displayTransactions)210 public abstract void performTraversal(Transaction t, 211 SparseArray<SurfaceControl.Transaction> displayTransactions); 212 213 /** 214 * Tells the display manager about properties of the display that depend on the windows on it. 215 * This includes whether there is interesting unique content on the specified logical display, 216 * and whether the one of the windows has a preferred refresh rate. 217 * <p> 218 * If the display has unique content, then the display manager arranges for it 219 * to be presented on a physical display if appropriate. Otherwise, the display manager 220 * may choose to make the physical display mirror some other logical display. 221 * </p> 222 * 223 * <p> 224 * If one of the windows on the display has a preferred refresh rate that's supported by the 225 * display, then the display manager will request its use. 226 * </p> 227 * 228 * @param displayId The logical display id to update. 229 * @param hasContent True if the logical display has content. This is used to control automatic 230 * mirroring. 231 * @param requestedRefreshRate The preferred refresh rate for the top-most visible window that 232 * has a preference. 233 * @param requestedModeId The preferred mode id for the top-most visible window that has a 234 * preference. 235 * @param requestedMinRefreshRate The preferred lowest refresh rate for the top-most visible 236 * window that has a preference. 237 * @param requestedMaxRefreshRate The preferred highest refresh rate for the top-most visible 238 * window that has a preference. 239 * @param requestedMinimalPostProcessing The preferred minimal post processing setting for the 240 * display. This is true when there is at least one visible window that wants minimal post 241 * processng on. 242 * @param disableHdrConversion The preferred HDR conversion setting for the window. 243 * @param inTraversal True if called from WindowManagerService during a window traversal 244 * prior to call to performTraversalInTransactionFromWindowManager. 245 */ setDisplayProperties(int displayId, boolean hasContent, float requestedRefreshRate, int requestedModeId, float requestedMinRefreshRate, float requestedMaxRefreshRate, boolean requestedMinimalPostProcessing, boolean disableHdrConversion, boolean inTraversal)246 public abstract void setDisplayProperties(int displayId, boolean hasContent, 247 float requestedRefreshRate, int requestedModeId, float requestedMinRefreshRate, 248 float requestedMaxRefreshRate, boolean requestedMinimalPostProcessing, 249 boolean disableHdrConversion, boolean inTraversal); 250 251 /** 252 * Applies an offset to the contents of a display, for example to avoid burn-in. 253 * <p> 254 * TODO: Technically this should be associated with a physical rather than logical 255 * display but this is good enough for now. 256 * </p> 257 * 258 * @param displayId The logical display id to update. 259 * @param x The X offset by which to shift the contents of the display. 260 * @param y The Y offset by which to shift the contents of the display. 261 */ setDisplayOffsets(int displayId, int x, int y)262 public abstract void setDisplayOffsets(int displayId, int x, int y); 263 264 /** 265 * Disables scaling for a display. 266 * 267 * @param displayId The logical display id to disable scaling for. 268 * @param disableScaling {@code true} to disable scaling, 269 * {@code false} to use the default scaling behavior of the logical display. 270 */ setDisplayScalingDisabled(int displayId, boolean disableScaling)271 public abstract void setDisplayScalingDisabled(int displayId, boolean disableScaling); 272 273 /** 274 * Provide a list of UIDs that are present on the display and are allowed to access it. 275 * 276 * @param displayAccessUIDs Mapping displayId -> int array of UIDs. 277 */ setDisplayAccessUIDs(SparseArray<IntArray> displayAccessUIDs)278 public abstract void setDisplayAccessUIDs(SparseArray<IntArray> displayAccessUIDs); 279 280 /** 281 * Persist brightness slider events and ambient brightness stats. 282 */ persistBrightnessTrackerState()283 public abstract void persistBrightnessTrackerState(); 284 285 /** 286 * Notifies the display manager that resource overlays have changed. 287 */ onOverlayChanged()288 public abstract void onOverlayChanged(); 289 290 /** 291 * Get the attributes available for display color sampling. 292 * @param displayId id of the display to collect the sample from. 293 * 294 * @return The attributes the display supports, or null if sampling is not supported. 295 */ 296 @Nullable getDisplayedContentSamplingAttributes( int displayId)297 public abstract DisplayedContentSamplingAttributes getDisplayedContentSamplingAttributes( 298 int displayId); 299 300 /** 301 * Enable or disable the collection of color samples. 302 * 303 * @param displayId id of the display to collect the sample from. 304 * @param componentMask a bitmask of the color channels to collect samples for, or zero for all 305 * available. 306 * @param maxFrames maintain a ringbuffer of the last maxFrames. 307 * @param enable True to enable, False to disable. 308 * 309 * @return True if sampling was enabled, false if failure. 310 */ setDisplayedContentSamplingEnabled( int displayId, boolean enable, int componentMask, int maxFrames)311 public abstract boolean setDisplayedContentSamplingEnabled( 312 int displayId, boolean enable, int componentMask, int maxFrames); 313 314 /** 315 * Accesses the color histogram statistics of displayed frames on devices that support sampling. 316 * 317 * @param displayId id of the display to collect the sample from 318 * @param maxFrames limit the statistics to the last maxFrames number of frames. 319 * @param timestamp discard statistics that were collected prior to timestamp, where timestamp 320 * is given as CLOCK_MONOTONIC. 321 * @return The statistics representing a histogram of the color distribution of the frames 322 * displayed on-screen, or null if sampling is not supported. 323 */ 324 @Nullable getDisplayedContentSample( int displayId, long maxFrames, long timestamp)325 public abstract DisplayedContentSample getDisplayedContentSample( 326 int displayId, long maxFrames, long timestamp); 327 328 /** 329 * Temporarily ignore proximity-sensor-based display behavior until there is a change 330 * to the proximity sensor state. This allows the display to turn back on even if something 331 * is obstructing the proximity sensor. 332 */ ignoreProximitySensorUntilChanged()333 public abstract void ignoreProximitySensorUntilChanged(); 334 335 /** 336 * Returns the refresh rate switching type. 337 */ 338 @DisplayManager.SwitchingType getRefreshRateSwitchingType()339 public abstract int getRefreshRateSwitchingType(); 340 341 /** 342 * TODO: b/191384041 - Replace this with getRefreshRateLimitations() 343 * Return the refresh rate restriction for the specified display and sensor pairing. If the 344 * specified sensor is identified as an associated sensor in the specified display's 345 * display-device-config file, then return any refresh rate restrictions that it might define. 346 * If no restriction is specified, or the sensor is not associated with the display, then null 347 * will be returned. 348 * 349 * @param displayId The display to check against. 350 * @param name The name of the sensor. 351 * @param type The type of sensor. 352 * 353 * @return The min/max refresh-rate restriction as a {@link Pair} of floats, or null if not 354 * restricted. 355 */ getRefreshRateForDisplayAndSensor( int displayId, String name, String type)356 public abstract RefreshRateRange getRefreshRateForDisplayAndSensor( 357 int displayId, String name, String type); 358 359 /** 360 * Returns a list of various refresh rate limitations for the specified display. 361 * 362 * @param displayId The display to get limitations for. 363 * 364 * @return a list of {@link RefreshRateLimitation}s describing the various limits. 365 */ getRefreshRateLimitations(int displayId)366 public abstract List<RefreshRateLimitation> getRefreshRateLimitations(int displayId); 367 368 /** 369 * For the given displayId, updates if WindowManager is responsible for mirroring on that 370 * display. If {@code false}, then SurfaceFlinger performs no layer mirroring to the 371 * given display. 372 * Only used for mirroring started from MediaProjection. 373 */ setWindowManagerMirroring(int displayId, boolean isMirroring)374 public abstract void setWindowManagerMirroring(int displayId, boolean isMirroring); 375 376 /** 377 * Returns the default size of the surface associated with the display, or null if the surface 378 * is not provided for layer mirroring by SurfaceFlinger. Size is rotated to reflect the current 379 * display device orientation. 380 * Used for mirroring from MediaProjection, or a physical display based on display flags. 381 */ getDisplaySurfaceDefaultSize(int displayId)382 public abstract Point getDisplaySurfaceDefaultSize(int displayId); 383 384 /** 385 * Get a new displayId which represents the display you want to mirror. If mirroring is not 386 * enabled on the display, {@link Display#INVALID_DISPLAY} will be returned. 387 * 388 * @param displayId The id of the display. 389 * @return The displayId that should be mirrored or INVALID_DISPLAY if mirroring is not enabled. 390 */ getDisplayIdToMirror(int displayId)391 public abstract int getDisplayIdToMirror(int displayId); 392 393 /** 394 * Receives early interactivity changes from power manager. 395 * 396 * @param interactive The interactive state that the device is moving into. 397 */ onEarlyInteractivityChange(boolean interactive)398 public abstract void onEarlyInteractivityChange(boolean interactive); 399 400 /** 401 * Get {@link DisplayWindowPolicyController} associated to the {@link DisplayInfo#displayId} 402 * 403 * @param displayId The id of the display. 404 * @return The associated {@link DisplayWindowPolicyController}. 405 */ getDisplayWindowPolicyController(int displayId)406 public abstract DisplayWindowPolicyController getDisplayWindowPolicyController(int displayId); 407 408 /** 409 * Get DisplayPrimaries from SF for a particular display. 410 */ getDisplayNativePrimaries(int displayId)411 public abstract SurfaceControl.DisplayPrimaries getDisplayNativePrimaries(int displayId); 412 413 /** 414 * Get the version of the Universal Stylus Initiative (USI) Protocol supported by the display. 415 * @param displayId The id of the display. 416 * @return The USI version, or null if not supported 417 */ 418 @Nullable getHostUsiVersion(int displayId)419 public abstract HostUsiVersion getHostUsiVersion(int displayId); 420 421 /** 422 * Get the ALS data for a particular display. 423 * 424 * @param displayId The id of the display. 425 * @return {@link AmbientLightSensorData} 426 */ 427 @Nullable getAmbientLightSensorData(int displayId)428 public abstract AmbientLightSensorData getAmbientLightSensorData(int displayId); 429 430 /** 431 * Get all available DisplayGroupIds. 432 */ getDisplayGroupIds()433 public abstract IntArray getDisplayGroupIds(); 434 435 436 /** 437 * Get all display ids belonging to the display group with given id. 438 */ getDisplayIdsForGroup(int groupId)439 public abstract int[] getDisplayIdsForGroup(int groupId); 440 441 /** 442 * Get the mapping of display group ids to the display ids that belong to them. 443 */ getDisplayIdsByGroupsIds()444 public abstract SparseArray<int[]> getDisplayIdsByGroupsIds(); 445 446 /** 447 * Get all available display ids. 448 */ getDisplayIds()449 public abstract IntArray getDisplayIds(); 450 451 /** 452 * Get group id for given display id 453 */ getGroupIdForDisplay(int displayId)454 public abstract int getGroupIdForDisplay(int displayId); 455 456 /** 457 * Called upon presentation started/ended on the display. 458 * @param displayId the id of the display where presentation started. 459 * @param isShown whether presentation is shown. 460 */ onPresentation(int displayId, boolean isShown)461 public abstract void onPresentation(int displayId, boolean isShown); 462 463 /** 464 * Called upon the usage of stylus. 465 */ stylusGestureStarted(long eventTime)466 public abstract void stylusGestureStarted(long eventTime); 467 468 /** 469 * Called by {@link com.android.server.wm.ContentRecorder} to verify whether 470 * the display is allowed to mirror primary display's content. 471 * @param displayId the id of the display where we mirror to. 472 * @return true if the mirroring dialog is confirmed (display is enabled), or 473 * {@link com.android.server.display.ExternalDisplayPolicy#ENABLE_ON_CONNECT} 474 * system property is enabled. 475 */ isDisplayReadyForMirroring(int displayId)476 public abstract boolean isDisplayReadyForMirroring(int displayId); 477 478 /** 479 * Called by {@link com.android.server.wm.WindowManagerService} to notify whether a display 480 * should be in the topology. 481 * @param displayId The logical ID of the display 482 * @param inTopology Whether the display should be in the topology. This being true does not 483 * guarantee that the display will be in the topology - Display Manager might 484 * also check other parameters. 485 */ onDisplayBelongToTopologyChanged(int displayId, boolean inTopology)486 public abstract void onDisplayBelongToTopologyChanged(int displayId, boolean inTopology); 487 488 /** 489 * Called by {@link com.android.server.display.DisplayBackupHelper} when backup files were 490 * restored and are ready to be reloaded. 491 */ reloadTopologies(int userId)492 public abstract void reloadTopologies(int userId); 493 494 495 /** 496 * Used by the window manager to override the per-display screen brightness based on the 497 * current foreground activity. 498 * 499 * The key of the array is the displayId. If a displayId is missing from the array, this is 500 * equivalent to clearing any existing brightness overrides for that display. 501 * 502 * This method must only be called by the window manager. 503 */ setScreenBrightnessOverrideFromWindowManager( SparseArray<DisplayBrightnessOverrideRequest> brightnessOverrides)504 public abstract void setScreenBrightnessOverrideFromWindowManager( 505 SparseArray<DisplayBrightnessOverrideRequest> brightnessOverrides); 506 507 /** 508 * Describes a request for overriding the brightness of a single display. 509 */ 510 public static class DisplayBrightnessOverrideRequest { 511 // An override of the screen brightness. 512 // Set to PowerManager.BRIGHTNESS_INVALID if there's no override. 513 public float brightness = PowerManager.BRIGHTNESS_INVALID_FLOAT; 514 515 // Tag used to identify the app window requesting the brightness override. 516 public CharSequence tag; 517 } 518 519 /** 520 * Describes the requested power state of the display. 521 * 522 * This object is intended to describe the general characteristics of the 523 * power state, such as whether the screen should be on or off and the current 524 * brightness controls leaving the DisplayPowerController to manage the 525 * details of how the transitions between states should occur. The goal is for 526 * the PowerManagerService to focus on the global power state and not 527 * have to micro-manage screen off animations, auto-brightness and other effects. 528 */ 529 public static class DisplayPowerRequest { 530 // Policy: Turn screen off as if the user pressed the power button 531 // including playing a screen off animation if applicable. 532 public static final int POLICY_OFF = 0; 533 // Policy: Enable dozing and always-on display functionality. 534 public static final int POLICY_DOZE = 1; 535 // Policy: Make the screen dim when the user activity timeout is 536 // about to expire. 537 public static final int POLICY_DIM = 2; 538 // Policy: Make the screen bright as usual. 539 public static final int POLICY_BRIGHT = 3; 540 // The maximum policy constant. Useful for iterating through all constants in tests. 541 public static final int POLICY_MAX = POLICY_BRIGHT; 542 543 // The basic overall policy to apply: off, doze, dim or bright. 544 public int policy; 545 546 // The reason behind the current policy. 547 @Display.StateReason 548 public int policyReason; 549 550 // If true, the proximity sensor overrides the screen state when an object is 551 // nearby, turning it off temporarily until the object is moved away. 552 public boolean useProximitySensor; 553 554 // A global override of the screen brightness, applied to all displays. 555 // Set to PowerManager.BRIGHTNESS_INVALID if there's no override. 556 public float screenBrightnessOverride; 557 558 // Tag used to identify the reason for the global brightness override. 559 public CharSequence screenBrightnessOverrideTag; 560 561 // An override of the screen auto-brightness adjustment factor in the range -1 (dimmer) to 562 // 1 (brighter). Set to Float.NaN if there's no override. 563 public float screenAutoBrightnessAdjustmentOverride; 564 565 // If true, scales the brightness to a fraction of desired (as defined by 566 // screenLowPowerBrightnessFactor). 567 public boolean lowPowerMode; 568 569 // The factor to adjust the screen brightness in low power mode in the range 570 // 0 (screen off) to 1 (no change) 571 public float screenLowPowerBrightnessFactor; 572 573 // If true, applies a brightness boost. 574 public boolean boostScreenBrightness; 575 576 // If true, prevents the screen from completely turning on if it is currently off. 577 // The display does not enter a "ready" state if this flag is true and screen on is 578 // blocked. The window manager policy blocks screen on while it prepares the keyguard to 579 // prevent the user from seeing intermediate updates. 580 // 581 // Technically, we may not block the screen itself from turning on (because that introduces 582 // extra unnecessary latency) but we do prevent content on screen from becoming 583 // visible to the user. 584 public boolean blockScreenOn; 585 586 // Overrides the policy for adjusting screen brightness and state while dozing. 587 public int dozeScreenState; 588 public float dozeScreenBrightness; 589 public int dozeScreenStateReason; 590 591 // Override that makes display use normal brightness while dozing. 592 public boolean useNormalBrightnessForDoze; 593 DisplayPowerRequest()594 public DisplayPowerRequest() { 595 policy = POLICY_BRIGHT; 596 policyReason = Display.STATE_REASON_DEFAULT_POLICY; 597 useProximitySensor = false; 598 screenBrightnessOverride = PowerManager.BRIGHTNESS_INVALID_FLOAT; 599 screenAutoBrightnessAdjustmentOverride = Float.NaN; 600 screenLowPowerBrightnessFactor = 0.5f; 601 blockScreenOn = false; 602 dozeScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT; 603 dozeScreenState = Display.STATE_UNKNOWN; 604 dozeScreenStateReason = Display.STATE_REASON_UNKNOWN; 605 } 606 DisplayPowerRequest(DisplayPowerRequest other)607 public DisplayPowerRequest(DisplayPowerRequest other) { 608 copyFrom(other); 609 } 610 isBrightOrDim()611 public boolean isBrightOrDim() { 612 return policy == POLICY_BRIGHT || policy == POLICY_DIM; 613 } 614 copyFrom(DisplayPowerRequest other)615 public void copyFrom(DisplayPowerRequest other) { 616 policy = other.policy; 617 policyReason = other.policyReason; 618 useProximitySensor = other.useProximitySensor; 619 screenBrightnessOverride = other.screenBrightnessOverride; 620 screenBrightnessOverrideTag = other.screenBrightnessOverrideTag; 621 screenAutoBrightnessAdjustmentOverride = other.screenAutoBrightnessAdjustmentOverride; 622 screenLowPowerBrightnessFactor = other.screenLowPowerBrightnessFactor; 623 blockScreenOn = other.blockScreenOn; 624 lowPowerMode = other.lowPowerMode; 625 boostScreenBrightness = other.boostScreenBrightness; 626 dozeScreenBrightness = other.dozeScreenBrightness; 627 dozeScreenState = other.dozeScreenState; 628 dozeScreenStateReason = other.dozeScreenStateReason; 629 useNormalBrightnessForDoze = other.useNormalBrightnessForDoze; 630 } 631 632 @Override equals(@ullable Object o)633 public boolean equals(@Nullable Object o) { 634 return o instanceof DisplayPowerRequest 635 && equals((DisplayPowerRequest)o); 636 } 637 equals(DisplayPowerRequest other)638 public boolean equals(DisplayPowerRequest other) { 639 return other != null 640 && policy == other.policy 641 && useProximitySensor == other.useProximitySensor 642 && floatEquals(screenBrightnessOverride, other.screenBrightnessOverride) 643 && Objects.equals(screenBrightnessOverrideTag, 644 other.screenBrightnessOverrideTag) 645 && floatEquals(screenAutoBrightnessAdjustmentOverride, 646 other.screenAutoBrightnessAdjustmentOverride) 647 && screenLowPowerBrightnessFactor 648 == other.screenLowPowerBrightnessFactor 649 && blockScreenOn == other.blockScreenOn 650 && lowPowerMode == other.lowPowerMode 651 && boostScreenBrightness == other.boostScreenBrightness 652 && floatEquals(dozeScreenBrightness, other.dozeScreenBrightness) 653 && dozeScreenState == other.dozeScreenState 654 && dozeScreenStateReason == other.dozeScreenStateReason 655 && useNormalBrightnessForDoze == other.useNormalBrightnessForDoze; 656 } 657 floatEquals(float f1, float f2)658 private boolean floatEquals(float f1, float f2) { 659 return f1 == f2 || Float.isNaN(f1) && Float.isNaN(f2); 660 } 661 662 @Override hashCode()663 public int hashCode() { 664 return 0; // don't care 665 } 666 667 @Override toString()668 public String toString() { 669 return "policy=" + policyToString(policy) 670 + ", useProximitySensor=" + useProximitySensor 671 + ", screenBrightnessOverride=" + screenBrightnessOverride 672 + ", screenAutoBrightnessAdjustmentOverride=" 673 + screenAutoBrightnessAdjustmentOverride 674 + ", screenLowPowerBrightnessFactor=" + screenLowPowerBrightnessFactor 675 + ", blockScreenOn=" + blockScreenOn 676 + ", lowPowerMode=" + lowPowerMode 677 + ", boostScreenBrightness=" + boostScreenBrightness 678 + ", dozeScreenBrightness=" + dozeScreenBrightness 679 + ", dozeScreenState=" + Display.stateToString(dozeScreenState) 680 + ", dozeScreenStateReason=" 681 + Display.stateReasonToString(dozeScreenStateReason) 682 + ", useNormalBrightnessForDoze=" + useNormalBrightnessForDoze; 683 } 684 policyToString(int policy)685 public static String policyToString(int policy) { 686 switch (policy) { 687 case POLICY_OFF: 688 return "OFF"; 689 case POLICY_DOZE: 690 return "DOZE"; 691 case POLICY_DIM: 692 return "DIM"; 693 case POLICY_BRIGHT: 694 return "BRIGHT"; 695 default: 696 return Integer.toString(policy); 697 } 698 } 699 } 700 701 /** 702 * Asynchronous callbacks from the power controller to the power manager service. 703 */ 704 public interface DisplayPowerCallbacks { onStateChanged()705 void onStateChanged(); onProximityPositive()706 void onProximityPositive(); onProximityNegative()707 void onProximityNegative(); onDisplayStateChange(boolean allInactive, boolean allOff)708 void onDisplayStateChange(boolean allInactive, boolean allOff); 709 710 /** 711 * Acquires a suspend blocker with a specified label. 712 * 713 * @param id A logging label for the acquisition. 714 */ acquireSuspendBlocker(String id)715 void acquireSuspendBlocker(String id); 716 717 /** 718 * Releases a suspend blocker with a specified label. 719 * 720 * @param id A logging label for the release. 721 */ releaseSuspendBlocker(String id)722 void releaseSuspendBlocker(String id); 723 } 724 725 /** 726 * Called within a Surface transaction whenever the size or orientation of a 727 * display may have changed. Provides an opportunity for the client to 728 * update the position of its surfaces as part of the same transaction. 729 */ 730 public interface DisplayTransactionListener { onDisplayTransaction(Transaction t)731 void onDisplayTransaction(Transaction t); 732 } 733 734 /** 735 * Called when there are changes to {@link com.android.server.display.DisplayGroup 736 * DisplayGroups}. 737 */ 738 public interface DisplayGroupListener { 739 /** 740 * A new display group with the provided {@code groupId} was added. 741 * 742 * <ol> 743 * <li>The {@code groupId} is applied to all appropriate {@link Display displays}. 744 * <li>This method is called. 745 * <li>{@link android.hardware.display.DisplayManager.DisplayListener DisplayListeners} 746 * are informed of any corresponding changes. 747 * </ol> 748 */ onDisplayGroupAdded(int groupId)749 void onDisplayGroupAdded(int groupId); 750 751 /** 752 * The display group with the provided {@code groupId} was removed. 753 * 754 * <ol> 755 * <li>All affected {@link Display displays} have their group IDs updated appropriately. 756 * <li>{@link android.hardware.display.DisplayManager.DisplayListener DisplayListeners} 757 * are informed of any corresponding changes. 758 * <li>This method is called. 759 * </ol> 760 */ onDisplayGroupRemoved(int groupId)761 void onDisplayGroupRemoved(int groupId); 762 763 /** 764 * The display group with the provided {@code groupId} has changed. 765 * 766 * <ol> 767 * <li>All affected {@link Display displays} have their group IDs updated appropriately. 768 * <li>{@link android.hardware.display.DisplayManager.DisplayListener DisplayListeners} 769 * are informed of any corresponding changes. 770 * <li>This method is called. 771 * </ol> 772 */ onDisplayGroupChanged(int groupId)773 void onDisplayGroupChanged(int groupId); 774 } 775 776 /** 777 * Describes a limitation on a display's refresh rate. Includes the allowed refresh rate 778 * range as well as information about when it applies, such as high-brightness-mode. 779 */ 780 public static final class RefreshRateLimitation { 781 @RefreshRateLimitType public int type; 782 783 /** The range the that refresh rate should be limited to. */ 784 public RefreshRateRange range; 785 RefreshRateLimitation(@efreshRateLimitType int type, float min, float max)786 public RefreshRateLimitation(@RefreshRateLimitType int type, float min, float max) { 787 this(type, new RefreshRateRange(min, max)); 788 } 789 RefreshRateLimitation(@efreshRateLimitType int type, RefreshRateRange range)790 public RefreshRateLimitation(@RefreshRateLimitType int type, RefreshRateRange range) { 791 this.type = type; 792 this.range = range; 793 } 794 795 @Override toString()796 public String toString() { 797 return "RefreshRateLimitation(" + type + ": " + range + ")"; 798 } 799 } 800 801 /** 802 * Class to provide Ambient sensor data using the API 803 * {@link DisplayManagerInternal#getAmbientLightSensorData(int)} 804 */ 805 public static final class AmbientLightSensorData { 806 public String sensorName; 807 public String sensorType; 808 AmbientLightSensorData(String name, String type)809 public AmbientLightSensorData(String name, String type) { 810 sensorName = name; 811 sensorType = type; 812 } 813 814 @Override toString()815 public String toString() { 816 return "AmbientLightSensorData(" + sensorName + ", " + sensorType + ")"; 817 } 818 } 819 820 /** 821 * Associate a internal display to a {@link DisplayOffloader}. 822 * 823 * @param displayId the id of the internal display. 824 * @param displayOffloader the {@link DisplayOffloader} that controls offloading ops of internal 825 * display whose id is displayId. 826 * @return a {@link DisplayOffloadSession} associated with given displayId and displayOffloader. 827 */ registerDisplayOffloader( int displayId, DisplayOffloader displayOffloader)828 public abstract DisplayOffloadSession registerDisplayOffloader( 829 int displayId, DisplayOffloader displayOffloader); 830 831 /** The callbacks that controls the entry & exit of display offloading. */ 832 public interface DisplayOffloader { startOffload()833 boolean startOffload(); 834 stopOffload()835 void stopOffload(); 836 837 /** 838 * Called when {@link DisplayOffloadSession} tries to block screen turning on. 839 * 840 * @param unblocker a {@link Runnable} executed upon all work required before screen turning 841 * on is done. 842 */ onBlockingScreenOn(Runnable unblocker)843 void onBlockingScreenOn(Runnable unblocker); 844 845 /** 846 * Called while display is turning to screen state other than state ON to notify that any 847 * pending work from the previous blockScreenOn call should have been cancelled. 848 */ cancelBlockScreenOn()849 void cancelBlockScreenOn(); 850 851 /** Whether auto brightness update in doze is allowed */ allowAutoBrightnessInDoze()852 boolean allowAutoBrightnessInDoze(); 853 } 854 855 /** A session token that associates a internal display with a {@link DisplayOffloader}. */ 856 public interface DisplayOffloadSession { 857 /** Provide the display state to use in place of state DOZE. */ setDozeStateOverride(int displayState)858 void setDozeStateOverride(int displayState); 859 860 /** Whether the session is active. */ isActive()861 boolean isActive(); 862 863 /** Whether auto brightness update in doze is allowed */ allowAutoBrightnessInDoze()864 boolean allowAutoBrightnessInDoze(); 865 866 /** 867 * Update the brightness from the offload chip. 868 * @param brightness The brightness value between {@link PowerManager.BRIGHTNESS_MIN} and 869 * {@link PowerManager.BRIGHTNESS_MAX}, or 870 * {@link PowerManager.BRIGHTNESS_INVALID_FLOAT} which removes 871 * the brightness from offload. Other values will be ignored. 872 */ updateBrightness(float brightness)873 void updateBrightness(float brightness); 874 875 /** 876 * Called while display is turning to state ON to leave a small period for displayoffload 877 * session to finish some work. 878 * 879 * @param unblocker a {@link Runnable} used by displayoffload session to notify 880 * {@link DisplayManager} that it can continue turning screen on. 881 */ blockScreenOn(Runnable unblocker)882 boolean blockScreenOn(Runnable unblocker); 883 884 /** 885 * Called while display is turning to screen state other than state ON to notify that any 886 * pending work from the previous blockScreenOn call should have been cancelled. 887 */ cancelBlockScreenOn()888 void cancelBlockScreenOn(); 889 890 /** 891 * Get the brightness levels used to determine automatic brightness based on lux levels. 892 * @param mode The auto-brightness mode 893 * (AutomaticBrightnessController.AutomaticBrightnessMode) 894 * @return The brightness levels for the specified mode. The values are between 895 * {@link PowerManager.BRIGHTNESS_MIN} and {@link PowerManager.BRIGHTNESS_MAX}. 896 */ getAutoBrightnessLevels(int mode)897 float[] getAutoBrightnessLevels(int mode); 898 899 /** 900 * Get the lux levels used to determine automatic brightness. 901 * @param mode The auto-brightness mode 902 * (AutomaticBrightnessController.AutomaticBrightnessMode) 903 * @return The lux levels for the specified mode 904 */ getAutoBrightnessLuxLevels(int mode)905 float[] getAutoBrightnessLuxLevels(int mode); 906 907 /** 908 * @return The current brightness setting 909 */ getBrightness()910 float getBrightness(); 911 912 /** 913 * @return The brightness value that is used when the device is in doze 914 */ getDozeBrightness()915 float getDozeBrightness(); 916 917 /** Returns whether displayoffload supports the given display state. */ isSupportedOffloadState(int displayState)918 static boolean isSupportedOffloadState(int displayState) { 919 return Display.isSuspendedState(displayState); 920 } 921 } 922 } 923