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.graphics.Point; 22 import android.hardware.SensorManager; 23 import android.os.Handler; 24 import android.os.IBinder; 25 import android.os.PowerManager; 26 import android.util.IntArray; 27 import android.util.Slog; 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.Transaction; 33 34 import java.lang.annotation.Retention; 35 import java.lang.annotation.RetentionPolicy; 36 import java.util.List; 37 import java.util.Objects; 38 39 /** 40 * Display manager local system service interface. 41 * 42 * @hide Only for use within the system server. 43 */ 44 public abstract class DisplayManagerInternal { 45 46 @IntDef(prefix = {"REFRESH_RATE_LIMIT_"}, value = { 47 REFRESH_RATE_LIMIT_HIGH_BRIGHTNESS_MODE 48 }) 49 @Retention(RetentionPolicy.SOURCE) 50 public @interface RefreshRateLimitType {} 51 52 /** Refresh rate should be limited when High Brightness Mode is active. */ 53 public static final int REFRESH_RATE_LIMIT_HIGH_BRIGHTNESS_MODE = 1; 54 55 /** 56 * Called by the power manager to initialize power management facilities. 57 */ initPowerManagement(DisplayPowerCallbacks callbacks, Handler handler, SensorManager sensorManager)58 public abstract void initPowerManagement(DisplayPowerCallbacks callbacks, 59 Handler handler, SensorManager sensorManager); 60 61 /** 62 * Called by the power manager to request a new power state. 63 * <p> 64 * The display power controller makes a copy of the provided object and then 65 * begins adjusting the power state to match what was requested. 66 * </p> 67 * 68 * @param groupId The identifier for the display group being requested to change power state 69 * @param request The requested power state. 70 * @param waitForNegativeProximity If {@code true}, issues a request to wait for 71 * negative proximity before turning the screen back on, assuming the screen 72 * was turned off by the proximity sensor. 73 * @return {@code true} if display group is ready, {@code false} if there are important 74 * changes that must be made asynchronously (such as turning the screen on), in which case 75 * the caller should grab a wake lock, watch for {@link DisplayPowerCallbacks#onStateChanged} 76 * then try the request again later until the state converges. If the provided {@code groupId} 77 * cannot be found then {@code true} will be returned. 78 */ requestPowerState(int groupId, DisplayPowerRequest request, boolean waitForNegativeProximity)79 public abstract boolean requestPowerState(int groupId, DisplayPowerRequest request, 80 boolean waitForNegativeProximity); 81 82 /** 83 * Returns {@code true} if the proximity sensor screen-off function is available. 84 */ isProximitySensorAvailable()85 public abstract boolean isProximitySensorAvailable(); 86 87 /** 88 * Registers a display group listener which will be informed of the addition, removal, or change 89 * of display groups. 90 * 91 * @param listener The listener to register. 92 */ registerDisplayGroupListener(DisplayGroupListener listener)93 public abstract void registerDisplayGroupListener(DisplayGroupListener listener); 94 95 /** 96 * Unregisters a display group listener which will be informed of the addition, removal, or 97 * change of display groups. 98 * 99 * @param listener The listener to unregister. 100 */ unregisterDisplayGroupListener(DisplayGroupListener listener)101 public abstract void unregisterDisplayGroupListener(DisplayGroupListener listener); 102 103 /** 104 * Screenshot for internal system-only use such as rotation, etc. This method includes 105 * secure layers and the result should never be exposed to non-system applications. 106 * This method does not apply any rotation and provides the output in natural orientation. 107 * 108 * @param displayId The display id to take the screenshot of. 109 * @return The buffer or null if we have failed. 110 */ systemScreenshot(int displayId)111 public abstract SurfaceControl.ScreenshotHardwareBuffer systemScreenshot(int displayId); 112 113 /** 114 * General screenshot functionality that excludes secure layers and applies appropriate 115 * rotation that the device is currently in. 116 * 117 * @param displayId The display id to take the screenshot of. 118 * @return The buffer or null if we have failed. 119 */ userScreenshot(int displayId)120 public abstract SurfaceControl.ScreenshotHardwareBuffer userScreenshot(int displayId); 121 122 /** 123 * Returns information about the specified logical display. 124 * 125 * @param displayId The logical display id. 126 * @return The logical display info, or null if the display does not exist. The 127 * returned object must be treated as immutable. 128 */ getDisplayInfo(int displayId)129 public abstract DisplayInfo getDisplayInfo(int displayId); 130 131 /** 132 * Returns the position of the display's projection. 133 * 134 * @param displayId The logical display id. 135 * @return The x, y coordinates of the display, or null if the display does not exist. The 136 * return object must be treated as immutable. 137 */ 138 @Nullable getDisplayPosition(int displayId)139 public abstract Point getDisplayPosition(int displayId); 140 141 /** 142 * Registers a display transaction listener to provide the client a chance to 143 * update its surfaces within the same transaction as any display layout updates. 144 * 145 * @param listener The listener to register. 146 */ registerDisplayTransactionListener(DisplayTransactionListener listener)147 public abstract void registerDisplayTransactionListener(DisplayTransactionListener listener); 148 149 /** 150 * Unregisters a display transaction listener to provide the client a chance to 151 * update its surfaces within the same transaction as any display layout updates. 152 * 153 * @param listener The listener to unregister. 154 */ unregisterDisplayTransactionListener(DisplayTransactionListener listener)155 public abstract void unregisterDisplayTransactionListener(DisplayTransactionListener listener); 156 157 /** 158 * Overrides the display information of a particular logical display. 159 * This is used by the window manager to control the size and characteristics 160 * of the default display. It is expected to apply the requested change 161 * to the display information synchronously so that applications will immediately 162 * observe the new state. 163 * 164 * NOTE: This method must be the only entry point by which the window manager 165 * influences the logical configuration of displays. 166 * 167 * @param displayId The logical display id. 168 * @param info The new data to be stored. 169 */ setDisplayInfoOverrideFromWindowManager( int displayId, DisplayInfo info)170 public abstract void setDisplayInfoOverrideFromWindowManager( 171 int displayId, DisplayInfo info); 172 173 /** 174 * Get current display info without override from WindowManager. 175 * Current implementation of LogicalDisplay#getDisplayInfoLocked() always returns display info 176 * with overrides from WM if set. This method can be used for getting real display size without 177 * overrides to determine if real changes to display metrics happened. 178 * @param displayId Id of the target display. 179 * @param outInfo {@link DisplayInfo} to fill. 180 */ getNonOverrideDisplayInfo(int displayId, DisplayInfo outInfo)181 public abstract void getNonOverrideDisplayInfo(int displayId, DisplayInfo outInfo); 182 183 /** 184 * Called by the window manager to perform traversals while holding a 185 * surface flinger transaction. 186 */ performTraversal(Transaction t)187 public abstract void performTraversal(Transaction t); 188 189 /** 190 * Tells the display manager about properties of the display that depend on the windows on it. 191 * This includes whether there is interesting unique content on the specified logical display, 192 * and whether the one of the windows has a preferred refresh rate. 193 * <p> 194 * If the display has unique content, then the display manager arranges for it 195 * to be presented on a physical display if appropriate. Otherwise, the display manager 196 * may choose to make the physical display mirror some other logical display. 197 * </p> 198 * 199 * <p> 200 * If one of the windows on the display has a preferred refresh rate that's supported by the 201 * display, then the display manager will request its use. 202 * </p> 203 * 204 * @param displayId The logical display id to update. 205 * @param hasContent True if the logical display has content. This is used to control automatic 206 * mirroring. 207 * @param requestedRefreshRate The preferred refresh rate for the top-most visible window that 208 * has a preference. 209 * @param requestedModeId The preferred mode id for the top-most visible window that has a 210 * preference. 211 * @param requestedMinRefreshRate The preferred lowest refresh rate for the top-most visible 212 * window that has a preference. 213 * @param requestedMaxRefreshRate The preferred highest refresh rate for the top-most visible 214 * window that has a preference. 215 * @param requestedMinimalPostProcessing The preferred minimal post processing setting for the 216 * display. This is true when there is at least one visible window that wants minimal post 217 * processng on. 218 * @param inTraversal True if called from WindowManagerService during a window traversal 219 * prior to call to performTraversalInTransactionFromWindowManager. 220 */ setDisplayProperties(int displayId, boolean hasContent, float requestedRefreshRate, int requestedModeId, float requestedMinRefreshRate, float requestedMaxRefreshRate, boolean requestedMinimalPostProcessing, boolean inTraversal)221 public abstract void setDisplayProperties(int displayId, boolean hasContent, 222 float requestedRefreshRate, int requestedModeId, float requestedMinRefreshRate, 223 float requestedMaxRefreshRate, boolean requestedMinimalPostProcessing, 224 boolean inTraversal); 225 226 /** 227 * Applies an offset to the contents of a display, for example to avoid burn-in. 228 * <p> 229 * TODO: Technically this should be associated with a physical rather than logical 230 * display but this is good enough for now. 231 * </p> 232 * 233 * @param displayId The logical display id to update. 234 * @param x The X offset by which to shift the contents of the display. 235 * @param y The Y offset by which to shift the contents of the display. 236 */ setDisplayOffsets(int displayId, int x, int y)237 public abstract void setDisplayOffsets(int displayId, int x, int y); 238 239 /** 240 * Disables scaling for a display. 241 * 242 * @param displayId The logical display id to disable scaling for. 243 * @param disableScaling {@code true} to disable scaling, 244 * {@code false} to use the default scaling behavior of the logical display. 245 */ setDisplayScalingDisabled(int displayId, boolean disableScaling)246 public abstract void setDisplayScalingDisabled(int displayId, boolean disableScaling); 247 248 /** 249 * Provide a list of UIDs that are present on the display and are allowed to access it. 250 * 251 * @param displayAccessUIDs Mapping displayId -> int array of UIDs. 252 */ setDisplayAccessUIDs(SparseArray<IntArray> displayAccessUIDs)253 public abstract void setDisplayAccessUIDs(SparseArray<IntArray> displayAccessUIDs); 254 255 /** 256 * Persist brightness slider events and ambient brightness stats. 257 */ persistBrightnessTrackerState()258 public abstract void persistBrightnessTrackerState(); 259 260 /** 261 * Notifies the display manager that resource overlays have changed. 262 */ onOverlayChanged()263 public abstract void onOverlayChanged(); 264 265 /** 266 * Get the attributes available for display color sampling. 267 * @param displayId id of the display to collect the sample from. 268 * 269 * @return The attributes the display supports, or null if sampling is not supported. 270 */ 271 @Nullable getDisplayedContentSamplingAttributes( int displayId)272 public abstract DisplayedContentSamplingAttributes getDisplayedContentSamplingAttributes( 273 int displayId); 274 275 /** 276 * Enable or disable the collection of color samples. 277 * 278 * @param displayId id of the display to collect the sample from. 279 * @param componentMask a bitmask of the color channels to collect samples for, or zero for all 280 * available. 281 * @param maxFrames maintain a ringbuffer of the last maxFrames. 282 * @param enable True to enable, False to disable. 283 * 284 * @return True if sampling was enabled, false if failure. 285 */ setDisplayedContentSamplingEnabled( int displayId, boolean enable, int componentMask, int maxFrames)286 public abstract boolean setDisplayedContentSamplingEnabled( 287 int displayId, boolean enable, int componentMask, int maxFrames); 288 289 /** 290 * Accesses the color histogram statistics of displayed frames on devices that support sampling. 291 * 292 * @param displayId id of the display to collect the sample from 293 * @param maxFrames limit the statistics to the last maxFrames number of frames. 294 * @param timestamp discard statistics that were collected prior to timestamp, where timestamp 295 * is given as CLOCK_MONOTONIC. 296 * @return The statistics representing a histogram of the color distribution of the frames 297 * displayed on-screen, or null if sampling is not supported. 298 */ 299 @Nullable getDisplayedContentSample( int displayId, long maxFrames, long timestamp)300 public abstract DisplayedContentSample getDisplayedContentSample( 301 int displayId, long maxFrames, long timestamp); 302 303 /** 304 * Temporarily ignore proximity-sensor-based display behavior until there is a change 305 * to the proximity sensor state. This allows the display to turn back on even if something 306 * is obstructing the proximity sensor. 307 */ ignoreProximitySensorUntilChanged()308 public abstract void ignoreProximitySensorUntilChanged(); 309 310 /** 311 * Returns the refresh rate switching type. 312 */ 313 @DisplayManager.SwitchingType getRefreshRateSwitchingType()314 public abstract int getRefreshRateSwitchingType(); 315 316 /** 317 * TODO: b/191384041 - Replace this with getRefreshRateLimitations() 318 * Return the refresh rate restriction for the specified display and sensor pairing. If the 319 * specified sensor is identified as an associated sensor in the specified display's 320 * display-device-config file, then return any refresh rate restrictions that it might define. 321 * If no restriction is specified, or the sensor is not associated with the display, then null 322 * will be returned. 323 * 324 * @param displayId The display to check against. 325 * @param name The name of the sensor. 326 * @param type The type of sensor. 327 * 328 * @return The min/max refresh-rate restriction as a {@link Pair} of floats, or null if not 329 * restricted. 330 */ getRefreshRateForDisplayAndSensor( int displayId, String name, String type)331 public abstract RefreshRateRange getRefreshRateForDisplayAndSensor( 332 int displayId, String name, String type); 333 334 /** 335 * Returns a list of various refresh rate limitations for the specified display. 336 * 337 * @param displayId The display to get limitations for. 338 * 339 * @return a list of {@link RefreshRateLimitation}s describing the various limits. 340 */ getRefreshRateLimitations(int displayId)341 public abstract List<RefreshRateLimitation> getRefreshRateLimitations(int displayId); 342 343 /** 344 * Returns the window token of the level of the WindowManager hierarchy to mirror. Returns null 345 * if layer mirroring by SurfaceFlinger should not be performed for the given displayId. 346 * For now, only used for mirroring started from MediaProjection. 347 */ getWindowTokenClientToMirror(int displayId)348 public abstract IBinder getWindowTokenClientToMirror(int displayId); 349 350 /** 351 * For the given displayId, updates the window token of the level of the WindowManager hierarchy 352 * to mirror. If windowToken is null, then SurfaceFlinger performs no layer mirroring to the 353 * given display. 354 * For now, only used for mirroring started from MediaProjection. 355 */ setWindowTokenClientToMirror(int displayId, IBinder windowToken)356 public abstract void setWindowTokenClientToMirror(int displayId, IBinder windowToken); 357 358 /** 359 * Returns the default size of the surface associated with the display, or null if the surface 360 * is not provided for layer mirroring by SurfaceFlinger. 361 * For now, only used for mirroring started from MediaProjection. 362 */ getDisplaySurfaceDefaultSize(int displayId)363 public abstract Point getDisplaySurfaceDefaultSize(int displayId); 364 365 /** 366 * Describes the requested power state of the display. 367 * 368 * This object is intended to describe the general characteristics of the 369 * power state, such as whether the screen should be on or off and the current 370 * brightness controls leaving the DisplayPowerController to manage the 371 * details of how the transitions between states should occur. The goal is for 372 * the PowerManagerService to focus on the global power state and not 373 * have to micro-manage screen off animations, auto-brightness and other effects. 374 */ 375 public static final class DisplayPowerRequest { 376 // Policy: Turn screen off as if the user pressed the power button 377 // including playing a screen off animation if applicable. 378 public static final int POLICY_OFF = 0; 379 // Policy: Enable dozing and always-on display functionality. 380 public static final int POLICY_DOZE = 1; 381 // Policy: Make the screen dim when the user activity timeout is 382 // about to expire. 383 public static final int POLICY_DIM = 2; 384 // Policy: Make the screen bright as usual. 385 public static final int POLICY_BRIGHT = 3; 386 // Policy: Keep the screen and display optimized for VR mode. 387 public static final int POLICY_VR = 4; 388 389 // The basic overall policy to apply: off, doze, dim or bright. 390 public int policy; 391 392 // If true, the proximity sensor overrides the screen state when an object is 393 // nearby, turning it off temporarily until the object is moved away. 394 public boolean useProximitySensor; 395 396 // An override of the screen brightness. 397 // Set to PowerManager.BRIGHTNESS_INVALID if there's no override. 398 public float screenBrightnessOverride; 399 400 // An override of the screen auto-brightness adjustment factor in the range -1 (dimmer) to 401 // 1 (brighter). Set to Float.NaN if there's no override. 402 public float screenAutoBrightnessAdjustmentOverride; 403 404 // If true, enables automatic brightness control. 405 public boolean useAutoBrightness; 406 407 // If true, scales the brightness to a fraction of desired (as defined by 408 // screenLowPowerBrightnessFactor). 409 public boolean lowPowerMode; 410 411 // The factor to adjust the screen brightness in low power mode in the range 412 // 0 (screen off) to 1 (no change) 413 public float screenLowPowerBrightnessFactor; 414 415 // If true, applies a brightness boost. 416 public boolean boostScreenBrightness; 417 418 // If true, prevents the screen from completely turning on if it is currently off. 419 // The display does not enter a "ready" state if this flag is true and screen on is 420 // blocked. The window manager policy blocks screen on while it prepares the keyguard to 421 // prevent the user from seeing intermediate updates. 422 // 423 // Technically, we may not block the screen itself from turning on (because that introduces 424 // extra unnecessary latency) but we do prevent content on screen from becoming 425 // visible to the user. 426 public boolean blockScreenOn; 427 428 // Overrides the policy for adjusting screen brightness and state while dozing. 429 public int dozeScreenState; 430 public float dozeScreenBrightness; 431 DisplayPowerRequest()432 public DisplayPowerRequest() { 433 policy = POLICY_BRIGHT; 434 useProximitySensor = false; 435 screenBrightnessOverride = PowerManager.BRIGHTNESS_INVALID_FLOAT; 436 useAutoBrightness = false; 437 screenAutoBrightnessAdjustmentOverride = Float.NaN; 438 screenLowPowerBrightnessFactor = 0.5f; 439 blockScreenOn = false; 440 dozeScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT; 441 dozeScreenState = Display.STATE_UNKNOWN; 442 } 443 DisplayPowerRequest(DisplayPowerRequest other)444 public DisplayPowerRequest(DisplayPowerRequest other) { 445 copyFrom(other); 446 } 447 isBrightOrDim()448 public boolean isBrightOrDim() { 449 return policy == POLICY_BRIGHT || policy == POLICY_DIM; 450 } 451 isVr()452 public boolean isVr() { 453 return policy == POLICY_VR; 454 } 455 copyFrom(DisplayPowerRequest other)456 public void copyFrom(DisplayPowerRequest other) { 457 policy = other.policy; 458 useProximitySensor = other.useProximitySensor; 459 screenBrightnessOverride = other.screenBrightnessOverride; 460 useAutoBrightness = other.useAutoBrightness; 461 screenAutoBrightnessAdjustmentOverride = other.screenAutoBrightnessAdjustmentOverride; 462 screenLowPowerBrightnessFactor = other.screenLowPowerBrightnessFactor; 463 blockScreenOn = other.blockScreenOn; 464 lowPowerMode = other.lowPowerMode; 465 boostScreenBrightness = other.boostScreenBrightness; 466 dozeScreenBrightness = other.dozeScreenBrightness; 467 dozeScreenState = other.dozeScreenState; 468 } 469 470 @Override equals(@ullable Object o)471 public boolean equals(@Nullable Object o) { 472 return o instanceof DisplayPowerRequest 473 && equals((DisplayPowerRequest)o); 474 } 475 equals(DisplayPowerRequest other)476 public boolean equals(DisplayPowerRequest other) { 477 return other != null 478 && policy == other.policy 479 && useProximitySensor == other.useProximitySensor 480 && floatEquals(screenBrightnessOverride, 481 other.screenBrightnessOverride) 482 && useAutoBrightness == other.useAutoBrightness 483 && floatEquals(screenAutoBrightnessAdjustmentOverride, 484 other.screenAutoBrightnessAdjustmentOverride) 485 && screenLowPowerBrightnessFactor 486 == other.screenLowPowerBrightnessFactor 487 && blockScreenOn == other.blockScreenOn 488 && lowPowerMode == other.lowPowerMode 489 && boostScreenBrightness == other.boostScreenBrightness 490 && floatEquals(dozeScreenBrightness, other.dozeScreenBrightness) 491 && dozeScreenState == other.dozeScreenState; 492 } 493 floatEquals(float f1, float f2)494 private boolean floatEquals(float f1, float f2) { 495 return f1 == f2 || Float.isNaN(f1) && Float.isNaN(f2); 496 } 497 498 @Override hashCode()499 public int hashCode() { 500 return 0; // don't care 501 } 502 503 @Override toString()504 public String toString() { 505 return "policy=" + policyToString(policy) 506 + ", useProximitySensor=" + useProximitySensor 507 + ", screenBrightnessOverride=" + screenBrightnessOverride 508 + ", useAutoBrightness=" + useAutoBrightness 509 + ", screenAutoBrightnessAdjustmentOverride=" 510 + screenAutoBrightnessAdjustmentOverride 511 + ", screenLowPowerBrightnessFactor=" + screenLowPowerBrightnessFactor 512 + ", blockScreenOn=" + blockScreenOn 513 + ", lowPowerMode=" + lowPowerMode 514 + ", boostScreenBrightness=" + boostScreenBrightness 515 + ", dozeScreenBrightness=" + dozeScreenBrightness 516 + ", dozeScreenState=" + Display.stateToString(dozeScreenState); 517 } 518 policyToString(int policy)519 public static String policyToString(int policy) { 520 switch (policy) { 521 case POLICY_OFF: 522 return "OFF"; 523 case POLICY_DOZE: 524 return "DOZE"; 525 case POLICY_DIM: 526 return "DIM"; 527 case POLICY_BRIGHT: 528 return "BRIGHT"; 529 case POLICY_VR: 530 return "VR"; 531 default: 532 return Integer.toString(policy); 533 } 534 } 535 } 536 537 /** 538 * Asynchronous callbacks from the power controller to the power manager service. 539 */ 540 public interface DisplayPowerCallbacks { onStateChanged()541 void onStateChanged(); onProximityPositive()542 void onProximityPositive(); onProximityNegative()543 void onProximityNegative(); onDisplayStateChange(boolean allInactive, boolean allOff)544 void onDisplayStateChange(boolean allInactive, boolean allOff); 545 acquireSuspendBlocker()546 void acquireSuspendBlocker(); releaseSuspendBlocker()547 void releaseSuspendBlocker(); 548 } 549 550 /** 551 * Called within a Surface transaction whenever the size or orientation of a 552 * display may have changed. Provides an opportunity for the client to 553 * update the position of its surfaces as part of the same transaction. 554 */ 555 public interface DisplayTransactionListener { onDisplayTransaction(Transaction t)556 void onDisplayTransaction(Transaction t); 557 } 558 559 /** 560 * Called when there are changes to {@link com.android.server.display.DisplayGroup 561 * DisplayGroups}. 562 */ 563 public interface DisplayGroupListener { 564 /** 565 * A new display group with the provided {@code groupId} was added. 566 * 567 * <ol> 568 * <li>The {@code groupId} is applied to all appropriate {@link Display displays}. 569 * <li>This method is called. 570 * <li>{@link android.hardware.display.DisplayManager.DisplayListener DisplayListeners} 571 * are informed of any corresponding changes. 572 * </ol> 573 */ onDisplayGroupAdded(int groupId)574 void onDisplayGroupAdded(int groupId); 575 576 /** 577 * The display group with the provided {@code groupId} was removed. 578 * 579 * <ol> 580 * <li>All affected {@link Display displays} have their group IDs updated appropriately. 581 * <li>{@link android.hardware.display.DisplayManager.DisplayListener DisplayListeners} 582 * are informed of any corresponding changes. 583 * <li>This method is called. 584 * </ol> 585 */ onDisplayGroupRemoved(int groupId)586 void onDisplayGroupRemoved(int groupId); 587 588 /** 589 * The display group with the provided {@code groupId} has changed. 590 * 591 * <ol> 592 * <li>All affected {@link Display displays} have their group IDs updated appropriately. 593 * <li>{@link android.hardware.display.DisplayManager.DisplayListener DisplayListeners} 594 * are informed of any corresponding changes. 595 * <li>This method is called. 596 * </ol> 597 */ onDisplayGroupChanged(int groupId)598 void onDisplayGroupChanged(int groupId); 599 } 600 601 /** 602 * Information about the min and max refresh rate DM would like to set the display to. 603 */ 604 public static final class RefreshRateRange { 605 public static final String TAG = "RefreshRateRange"; 606 607 // The tolerance within which we consider something approximately equals. 608 public static final float FLOAT_TOLERANCE = 0.01f; 609 610 /** 611 * The lowest desired refresh rate. 612 */ 613 public float min; 614 615 /** 616 * The highest desired refresh rate. 617 */ 618 public float max; 619 RefreshRateRange()620 public RefreshRateRange() {} 621 RefreshRateRange(float min, float max)622 public RefreshRateRange(float min, float max) { 623 if (min < 0 || max < 0 || min > max + FLOAT_TOLERANCE) { 624 Slog.e(TAG, "Wrong values for min and max when initializing RefreshRateRange : " 625 + min + " " + max); 626 this.min = this.max = 0; 627 return; 628 } 629 if (min > max) { 630 // Min and max are within epsilon of each other, but in the wrong order. 631 float t = min; 632 min = max; 633 max = t; 634 } 635 this.min = min; 636 this.max = max; 637 } 638 639 /** 640 * Checks whether the two objects have the same values. 641 */ 642 @Override equals(Object other)643 public boolean equals(Object other) { 644 if (other == this) { 645 return true; 646 } 647 648 if (!(other instanceof RefreshRateRange)) { 649 return false; 650 } 651 652 RefreshRateRange refreshRateRange = (RefreshRateRange) other; 653 return (min == refreshRateRange.min && max == refreshRateRange.max); 654 } 655 656 @Override hashCode()657 public int hashCode() { 658 return Objects.hash(min, max); 659 } 660 661 @Override toString()662 public String toString() { 663 return "(" + min + " " + max + ")"; 664 } 665 } 666 667 /** 668 * Describes a limitation on a display's refresh rate. Includes the allowed refresh rate 669 * range as well as information about when it applies, such as high-brightness-mode. 670 */ 671 public static final class RefreshRateLimitation { 672 @RefreshRateLimitType public int type; 673 674 /** The range the that refresh rate should be limited to. */ 675 public RefreshRateRange range; 676 RefreshRateLimitation(@efreshRateLimitType int type, float min, float max)677 public RefreshRateLimitation(@RefreshRateLimitType int type, float min, float max) { 678 this.type = type; 679 range = new RefreshRateRange(min, max); 680 } 681 682 @Override toString()683 public String toString() { 684 return "RefreshRateLimitation(" + type + ": " + range + ")"; 685 } 686 } 687 } 688