Loading core/java/android/hardware/display/DisplayManagerGlobal.java +9 −4 Original line number Original line Diff line number Diff line Loading @@ -549,15 +549,20 @@ public final class DisplayManagerGlobal { } } /** /** * Request to power a display ON or OFF. * Request to power a display OFF or reset it to a power state it supposed to have. * @param displayId the id of the display * @param state one of {@link android.view.Display#STATE_UNKNOWN} (to reset the state to * the one the display should have had now), {@link android.view.Display#STATE_OFF}. * @return true if successful, false otherwise * @hide * @hide */ */ @RequiresPermission("android.permission.MANAGE_DISPLAYS") @RequiresPermission("android.permission.MANAGE_DISPLAYS") public boolean requestDisplayPower(int displayId, boolean on) { public boolean requestDisplayPower(int displayId, int state) { try { try { return mDm.requestDisplayPower(displayId, on); return mDm.requestDisplayPower(displayId, state); } catch (RemoteException ex) { } catch (RemoteException ex) { Log.e(TAG, "Error trying to request display power " + on, ex); Log.e(TAG, "Error trying to request display power:" + " state=" + state, ex); return false; return false; } } } } Loading core/java/android/hardware/display/IDisplayManager.aidl +2 −2 Original line number Original line Diff line number Diff line Loading @@ -236,9 +236,9 @@ interface IDisplayManager { @EnforcePermission("MANAGE_DISPLAYS") @EnforcePermission("MANAGE_DISPLAYS") void disableConnectedDisplay(int displayId); void disableConnectedDisplay(int displayId); // Request to power display ON or OFF. // Request to power display OFF or reset it to a power state it supposed to have. @EnforcePermission("MANAGE_DISPLAYS") @EnforcePermission("MANAGE_DISPLAYS") boolean requestDisplayPower(int displayId, boolean on); boolean requestDisplayPower(int displayId, int state); // Restricts display modes to specified modeIds. // Restricts display modes to specified modeIds. @EnforcePermission("RESTRICT_DISPLAY_MODES") @EnforcePermission("RESTRICT_DISPLAY_MODES") Loading services/core/java/com/android/server/display/DisplayManagerService.java +28 −9 Original line number Original line Diff line number Diff line Loading @@ -822,6 +822,13 @@ public final class DisplayManagerService extends SystemService { ? SmallAreaDetectionController.create(mContext) : null; ? SmallAreaDetectionController.create(mContext) : null; } } @VisibleForTesting void setDisplayState(int displayId, int state) { synchronized (mSyncRoot) { mDisplayStates.setValueAt(displayId, state); } } @VisibleForTesting @VisibleForTesting Handler getDisplayHandler() { Handler getDisplayHandler() { return mHandler; return mHandler; Loading Loading @@ -3411,27 +3418,39 @@ public final class DisplayManagerService extends SystemService { } } } } boolean requestDisplayPower(int displayId, boolean on) { boolean requestDisplayPower(int displayId, int requestedState) { synchronized (mSyncRoot) { synchronized (mSyncRoot) { final var display = mLogicalDisplayMapper.getDisplayLocked(displayId); final var display = mLogicalDisplayMapper.getDisplayLocked(displayId); if (display == null) { if (display == null) { Slog.w(TAG, "requestDisplayPower: Cannot find a display with displayId=" Slog.w(TAG, "requestDisplayPower: Cannot find the display with displayId=" + displayId); + displayId); return false; return false; } } var state = requestedState; if (state == Display.STATE_UNKNOWN) { state = mDisplayStates.get(displayId); } final BrightnessPair brightnessPair = mDisplayBrightnesses.get(displayId); final BrightnessPair brightnessPair = mDisplayBrightnesses.get(displayId); var brightnessState = brightnessPair.brightness; if (state == Display.STATE_OFF) { brightnessState = PowerManager.BRIGHTNESS_OFF_FLOAT; } var runnable = display.getPrimaryDisplayDeviceLocked().requestDisplayStateLocked( var runnable = display.getPrimaryDisplayDeviceLocked().requestDisplayStateLocked( on ? Display.STATE_ON : Display.STATE_OFF, state, on ? brightnessPair.brightness : PowerManager.BRIGHTNESS_OFF_FLOAT, brightnessState, brightnessPair.sdrBrightness, brightnessPair.sdrBrightness, display.getDisplayOffloadSessionLocked()); display.getDisplayOffloadSessionLocked()); if (runnable == null) { if (runnable == null) { Slog.w(TAG, "requestDisplayPower: Cannot update the power state to ON=" + on Slog.w(TAG, "requestDisplayPower: Cannot set power state = " + state + " for a display with displayId=" + displayId + ", runnable is null"); + " for the display with displayId=" + displayId + "," + " requestedState=" + requestedState + ": runnable is null"); return false; return false; } } runnable.run(); runnable.run(); Slog.i(TAG, "requestDisplayPower(displayId=" + displayId + ", on=" + on + ")"); Slog.i(TAG, "requestDisplayPower(displayId=" + displayId + ", requestedState=" + requestedState + "): state set to " + state); } } return true; return true; } } Loading Loading @@ -4660,9 +4679,9 @@ public final class DisplayManagerService extends SystemService { } } @EnforcePermission(MANAGE_DISPLAYS) @EnforcePermission(MANAGE_DISPLAYS) public boolean requestDisplayPower(int displayId, boolean on) { public boolean requestDisplayPower(int displayId, int state) { requestDisplayPower_enforcePermission(); requestDisplayPower_enforcePermission(); return DisplayManagerService.this.requestDisplayPower(displayId, on); return DisplayManagerService.this.requestDisplayPower(displayId, state); } } @EnforcePermission(RESTRICT_DISPLAY_MODES) @EnforcePermission(RESTRICT_DISPLAY_MODES) Loading services/core/java/com/android/server/display/DisplayManagerShellCommand.java +9 −5 Original line number Original line Diff line number Diff line Loading @@ -106,10 +106,10 @@ class DisplayManagerShellCommand extends ShellCommand { return setDisplayEnabled(true); return setDisplayEnabled(true); case "disable-display": case "disable-display": return setDisplayEnabled(false); return setDisplayEnabled(false); case "power-on": case "power-reset": return requestDisplayPower(true); return requestDisplayPower(Display.STATE_UNKNOWN); case "power-off": case "power-off": return requestDisplayPower(false); return requestDisplayPower(Display.STATE_OFF); default: default: return handleDefaultCommands(cmd); return handleDefaultCommands(cmd); } } Loading Loading @@ -183,6 +183,10 @@ class DisplayManagerShellCommand extends ShellCommand { pw.println(" disable-display DISPLAY_ID"); pw.println(" disable-display DISPLAY_ID"); pw.println(" Disable the DISPLAY_ID. Only possible if this is a connected display."); pw.println(" Disable the DISPLAY_ID. Only possible if this is a connected display."); } } pw.println(" power-reset DISPLAY_ID"); pw.println(" Turn the DISPLAY_ID power to a state the display supposed to have."); pw.println(" power-off DISPLAY_ID"); pw.println(" Turn the display DISPLAY_ID power off."); pw.println(); pw.println(); Intent.printIntentArgsHelp(pw , ""); Intent.printIntentArgsHelp(pw , ""); } } Loading Loading @@ -597,7 +601,7 @@ class DisplayManagerShellCommand extends ShellCommand { return 0; return 0; } } private int requestDisplayPower(boolean enable) { private int requestDisplayPower(int state) { final String displayIdText = getNextArg(); final String displayIdText = getNextArg(); if (displayIdText == null) { if (displayIdText == null) { getErrPrintWriter().println("Error: no displayId specified"); getErrPrintWriter().println("Error: no displayId specified"); Loading @@ -610,7 +614,7 @@ class DisplayManagerShellCommand extends ShellCommand { getErrPrintWriter().println("Error: invalid displayId: '" + displayIdText + "'"); getErrPrintWriter().println("Error: invalid displayId: '" + displayIdText + "'"); return 1; return 1; } } mService.requestDisplayPower(displayId, enable); mService.requestDisplayPower(displayId, state); return 0; return 0; } } } } services/tests/displayservicetests/src/com/android/server/display/DisplayManagerServiceTest.java +9 −6 Original line number Original line Diff line number Diff line Loading @@ -2584,18 +2584,19 @@ public class DisplayManagerServiceTest { LogicalDisplay display = LogicalDisplay display = logicalDisplayMapper.getDisplayLocked(displayDevice, /* includeDisabled= */ true); logicalDisplayMapper.getDisplayLocked(displayDevice, /* includeDisabled= */ true); displayManager.setDisplayState(display.getDisplayIdLocked(), Display.STATE_ON); assertThat(displayDevice.getDisplayDeviceInfoLocked().committedState) assertThat(displayDevice.getDisplayDeviceInfoLocked().committedState) .isEqualTo(Display.STATE_ON); .isEqualTo(Display.STATE_ON); assertThat(displayManager.requestDisplayPower(display.getDisplayIdLocked(), false)) assertThat(displayManager.requestDisplayPower(display.getDisplayIdLocked(), .isTrue(); Display.STATE_OFF)).isTrue(); assertThat(displayDevice.getDisplayDeviceInfoLocked().committedState) assertThat(displayDevice.getDisplayDeviceInfoLocked().committedState) .isEqualTo(Display.STATE_OFF); .isEqualTo(Display.STATE_OFF); assertThat(displayManager.requestDisplayPower(display.getDisplayIdLocked(), true)) assertThat(displayManager.requestDisplayPower(display.getDisplayIdLocked(), .isTrue(); Display.STATE_UNKNOWN)).isTrue(); assertThat(displayDevice.getDisplayDeviceInfoLocked().committedState) assertThat(displayDevice.getDisplayDeviceInfoLocked().committedState) .isEqualTo(Display.STATE_ON); .isEqualTo(Display.STATE_ON); Loading @@ -2621,8 +2622,10 @@ public class DisplayManagerServiceTest { assertThat(displayDevice.getDisplayDeviceInfoLocked().committedState) assertThat(displayDevice.getDisplayDeviceInfoLocked().committedState) .isEqualTo(Display.STATE_ON); .isEqualTo(Display.STATE_ON); assertThrows(SecurityException.class, () -> bs.requestDisplayPower(displayId, true)); assertThrows(SecurityException.class, assertThrows(SecurityException.class, () -> bs.requestDisplayPower(displayId, false)); () -> bs.requestDisplayPower(displayId, Display.STATE_UNKNOWN)); assertThrows(SecurityException.class, () -> bs.requestDisplayPower(displayId, Display.STATE_OFF)); } } @Test @Test Loading Loading
core/java/android/hardware/display/DisplayManagerGlobal.java +9 −4 Original line number Original line Diff line number Diff line Loading @@ -549,15 +549,20 @@ public final class DisplayManagerGlobal { } } /** /** * Request to power a display ON or OFF. * Request to power a display OFF or reset it to a power state it supposed to have. * @param displayId the id of the display * @param state one of {@link android.view.Display#STATE_UNKNOWN} (to reset the state to * the one the display should have had now), {@link android.view.Display#STATE_OFF}. * @return true if successful, false otherwise * @hide * @hide */ */ @RequiresPermission("android.permission.MANAGE_DISPLAYS") @RequiresPermission("android.permission.MANAGE_DISPLAYS") public boolean requestDisplayPower(int displayId, boolean on) { public boolean requestDisplayPower(int displayId, int state) { try { try { return mDm.requestDisplayPower(displayId, on); return mDm.requestDisplayPower(displayId, state); } catch (RemoteException ex) { } catch (RemoteException ex) { Log.e(TAG, "Error trying to request display power " + on, ex); Log.e(TAG, "Error trying to request display power:" + " state=" + state, ex); return false; return false; } } } } Loading
core/java/android/hardware/display/IDisplayManager.aidl +2 −2 Original line number Original line Diff line number Diff line Loading @@ -236,9 +236,9 @@ interface IDisplayManager { @EnforcePermission("MANAGE_DISPLAYS") @EnforcePermission("MANAGE_DISPLAYS") void disableConnectedDisplay(int displayId); void disableConnectedDisplay(int displayId); // Request to power display ON or OFF. // Request to power display OFF or reset it to a power state it supposed to have. @EnforcePermission("MANAGE_DISPLAYS") @EnforcePermission("MANAGE_DISPLAYS") boolean requestDisplayPower(int displayId, boolean on); boolean requestDisplayPower(int displayId, int state); // Restricts display modes to specified modeIds. // Restricts display modes to specified modeIds. @EnforcePermission("RESTRICT_DISPLAY_MODES") @EnforcePermission("RESTRICT_DISPLAY_MODES") Loading
services/core/java/com/android/server/display/DisplayManagerService.java +28 −9 Original line number Original line Diff line number Diff line Loading @@ -822,6 +822,13 @@ public final class DisplayManagerService extends SystemService { ? SmallAreaDetectionController.create(mContext) : null; ? SmallAreaDetectionController.create(mContext) : null; } } @VisibleForTesting void setDisplayState(int displayId, int state) { synchronized (mSyncRoot) { mDisplayStates.setValueAt(displayId, state); } } @VisibleForTesting @VisibleForTesting Handler getDisplayHandler() { Handler getDisplayHandler() { return mHandler; return mHandler; Loading Loading @@ -3411,27 +3418,39 @@ public final class DisplayManagerService extends SystemService { } } } } boolean requestDisplayPower(int displayId, boolean on) { boolean requestDisplayPower(int displayId, int requestedState) { synchronized (mSyncRoot) { synchronized (mSyncRoot) { final var display = mLogicalDisplayMapper.getDisplayLocked(displayId); final var display = mLogicalDisplayMapper.getDisplayLocked(displayId); if (display == null) { if (display == null) { Slog.w(TAG, "requestDisplayPower: Cannot find a display with displayId=" Slog.w(TAG, "requestDisplayPower: Cannot find the display with displayId=" + displayId); + displayId); return false; return false; } } var state = requestedState; if (state == Display.STATE_UNKNOWN) { state = mDisplayStates.get(displayId); } final BrightnessPair brightnessPair = mDisplayBrightnesses.get(displayId); final BrightnessPair brightnessPair = mDisplayBrightnesses.get(displayId); var brightnessState = brightnessPair.brightness; if (state == Display.STATE_OFF) { brightnessState = PowerManager.BRIGHTNESS_OFF_FLOAT; } var runnable = display.getPrimaryDisplayDeviceLocked().requestDisplayStateLocked( var runnable = display.getPrimaryDisplayDeviceLocked().requestDisplayStateLocked( on ? Display.STATE_ON : Display.STATE_OFF, state, on ? brightnessPair.brightness : PowerManager.BRIGHTNESS_OFF_FLOAT, brightnessState, brightnessPair.sdrBrightness, brightnessPair.sdrBrightness, display.getDisplayOffloadSessionLocked()); display.getDisplayOffloadSessionLocked()); if (runnable == null) { if (runnable == null) { Slog.w(TAG, "requestDisplayPower: Cannot update the power state to ON=" + on Slog.w(TAG, "requestDisplayPower: Cannot set power state = " + state + " for a display with displayId=" + displayId + ", runnable is null"); + " for the display with displayId=" + displayId + "," + " requestedState=" + requestedState + ": runnable is null"); return false; return false; } } runnable.run(); runnable.run(); Slog.i(TAG, "requestDisplayPower(displayId=" + displayId + ", on=" + on + ")"); Slog.i(TAG, "requestDisplayPower(displayId=" + displayId + ", requestedState=" + requestedState + "): state set to " + state); } } return true; return true; } } Loading Loading @@ -4660,9 +4679,9 @@ public final class DisplayManagerService extends SystemService { } } @EnforcePermission(MANAGE_DISPLAYS) @EnforcePermission(MANAGE_DISPLAYS) public boolean requestDisplayPower(int displayId, boolean on) { public boolean requestDisplayPower(int displayId, int state) { requestDisplayPower_enforcePermission(); requestDisplayPower_enforcePermission(); return DisplayManagerService.this.requestDisplayPower(displayId, on); return DisplayManagerService.this.requestDisplayPower(displayId, state); } } @EnforcePermission(RESTRICT_DISPLAY_MODES) @EnforcePermission(RESTRICT_DISPLAY_MODES) Loading
services/core/java/com/android/server/display/DisplayManagerShellCommand.java +9 −5 Original line number Original line Diff line number Diff line Loading @@ -106,10 +106,10 @@ class DisplayManagerShellCommand extends ShellCommand { return setDisplayEnabled(true); return setDisplayEnabled(true); case "disable-display": case "disable-display": return setDisplayEnabled(false); return setDisplayEnabled(false); case "power-on": case "power-reset": return requestDisplayPower(true); return requestDisplayPower(Display.STATE_UNKNOWN); case "power-off": case "power-off": return requestDisplayPower(false); return requestDisplayPower(Display.STATE_OFF); default: default: return handleDefaultCommands(cmd); return handleDefaultCommands(cmd); } } Loading Loading @@ -183,6 +183,10 @@ class DisplayManagerShellCommand extends ShellCommand { pw.println(" disable-display DISPLAY_ID"); pw.println(" disable-display DISPLAY_ID"); pw.println(" Disable the DISPLAY_ID. Only possible if this is a connected display."); pw.println(" Disable the DISPLAY_ID. Only possible if this is a connected display."); } } pw.println(" power-reset DISPLAY_ID"); pw.println(" Turn the DISPLAY_ID power to a state the display supposed to have."); pw.println(" power-off DISPLAY_ID"); pw.println(" Turn the display DISPLAY_ID power off."); pw.println(); pw.println(); Intent.printIntentArgsHelp(pw , ""); Intent.printIntentArgsHelp(pw , ""); } } Loading Loading @@ -597,7 +601,7 @@ class DisplayManagerShellCommand extends ShellCommand { return 0; return 0; } } private int requestDisplayPower(boolean enable) { private int requestDisplayPower(int state) { final String displayIdText = getNextArg(); final String displayIdText = getNextArg(); if (displayIdText == null) { if (displayIdText == null) { getErrPrintWriter().println("Error: no displayId specified"); getErrPrintWriter().println("Error: no displayId specified"); Loading @@ -610,7 +614,7 @@ class DisplayManagerShellCommand extends ShellCommand { getErrPrintWriter().println("Error: invalid displayId: '" + displayIdText + "'"); getErrPrintWriter().println("Error: invalid displayId: '" + displayIdText + "'"); return 1; return 1; } } mService.requestDisplayPower(displayId, enable); mService.requestDisplayPower(displayId, state); return 0; return 0; } } } }
services/tests/displayservicetests/src/com/android/server/display/DisplayManagerServiceTest.java +9 −6 Original line number Original line Diff line number Diff line Loading @@ -2584,18 +2584,19 @@ public class DisplayManagerServiceTest { LogicalDisplay display = LogicalDisplay display = logicalDisplayMapper.getDisplayLocked(displayDevice, /* includeDisabled= */ true); logicalDisplayMapper.getDisplayLocked(displayDevice, /* includeDisabled= */ true); displayManager.setDisplayState(display.getDisplayIdLocked(), Display.STATE_ON); assertThat(displayDevice.getDisplayDeviceInfoLocked().committedState) assertThat(displayDevice.getDisplayDeviceInfoLocked().committedState) .isEqualTo(Display.STATE_ON); .isEqualTo(Display.STATE_ON); assertThat(displayManager.requestDisplayPower(display.getDisplayIdLocked(), false)) assertThat(displayManager.requestDisplayPower(display.getDisplayIdLocked(), .isTrue(); Display.STATE_OFF)).isTrue(); assertThat(displayDevice.getDisplayDeviceInfoLocked().committedState) assertThat(displayDevice.getDisplayDeviceInfoLocked().committedState) .isEqualTo(Display.STATE_OFF); .isEqualTo(Display.STATE_OFF); assertThat(displayManager.requestDisplayPower(display.getDisplayIdLocked(), true)) assertThat(displayManager.requestDisplayPower(display.getDisplayIdLocked(), .isTrue(); Display.STATE_UNKNOWN)).isTrue(); assertThat(displayDevice.getDisplayDeviceInfoLocked().committedState) assertThat(displayDevice.getDisplayDeviceInfoLocked().committedState) .isEqualTo(Display.STATE_ON); .isEqualTo(Display.STATE_ON); Loading @@ -2621,8 +2622,10 @@ public class DisplayManagerServiceTest { assertThat(displayDevice.getDisplayDeviceInfoLocked().committedState) assertThat(displayDevice.getDisplayDeviceInfoLocked().committedState) .isEqualTo(Display.STATE_ON); .isEqualTo(Display.STATE_ON); assertThrows(SecurityException.class, () -> bs.requestDisplayPower(displayId, true)); assertThrows(SecurityException.class, assertThrows(SecurityException.class, () -> bs.requestDisplayPower(displayId, false)); () -> bs.requestDisplayPower(displayId, Display.STATE_UNKNOWN)); assertThrows(SecurityException.class, () -> bs.requestDisplayPower(displayId, Display.STATE_OFF)); } } @Test @Test Loading