Loading core/java/android/app/IUiModeManager.aidl +3 −0 Original line number Diff line number Diff line Loading @@ -73,6 +73,7 @@ interface IUiModeManager { * @param nightModeCustomType * @hide */ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.MODIFY_DAY_NIGHT_MODE)") void setNightModeCustomType(int nightModeCustomType); /** Loading @@ -82,6 +83,7 @@ interface IUiModeManager { * {@link #MODE_NIGHT_CUSTOM_TYPE_UNKNOWN}. * @hide */ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.MODIFY_DAY_NIGHT_MODE)") int getNightModeCustomType(); /** Loading Loading @@ -113,6 +115,7 @@ interface IUiModeManager { * {@code nightModeCustomType}. * @hide */ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.MODIFY_DAY_NIGHT_MODE)") boolean setNightModeActivatedForCustomMode(int nightModeCustom, boolean active); /** Loading core/java/android/app/UiModeManager.java +16 −3 Original line number Diff line number Diff line Loading @@ -244,17 +244,28 @@ public class UiModeManager { public static final int MODE_NIGHT_YES = 2; /** * Granular types for {@link MODE_NIGHT_CUSTOM_TYPE_BEDTIME} * Granular types for {@link #setNightModeCustomType(int)} * @hide */ @IntDef(prefix = { "MODE_NIGHT_CUSTOM_TYPE_" }, value = { MODE_NIGHT_CUSTOM_TYPE_UNKNOWN, MODE_NIGHT_CUSTOM_TYPE_SCHEDULE, MODE_NIGHT_CUSTOM_TYPE_BEDTIME, }) @Retention(RetentionPolicy.SOURCE) public @interface NightModeCustomType {} /** * Granular types for {@link #getNightModeCustomType()} * @hide */ @IntDef(prefix = { "MODE_NIGHT_CUSTOM_TYPE_" }, value = { MODE_NIGHT_CUSTOM_TYPE_UNKNOWN, MODE_NIGHT_CUSTOM_TYPE_SCHEDULE, MODE_NIGHT_CUSTOM_TYPE_BEDTIME, }) @Retention(RetentionPolicy.SOURCE) public @interface NightModeCustomReturnType {} /** * A granular type for {@link #MODE_NIGHT_CUSTOM} which is unknown. * <p> Loading Loading @@ -539,6 +550,8 @@ public class UiModeManager { * {@code nightModeCustomType}. * * @param nightModeCustomType * @throws IllegalArgumentException if passed an unsupported type to * {@code nightModeCustomType}. * @hide */ @SystemApi Loading @@ -562,7 +575,7 @@ public class UiModeManager { */ @SystemApi @RequiresPermission(android.Manifest.permission.MODIFY_DAY_NIGHT_MODE) public int getNightModeCustomType() { public @NightModeCustomReturnType int getNightModeCustomType() { if (mService != null) { try { return mService.getNightModeCustomType(); Loading services/core/java/com/android/server/UiModeManagerService.java +11 −2 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ import android.app.NotificationManager; import android.app.PendingIntent; import android.app.StatusBarManager; import android.app.UiModeManager; import android.app.UiModeManager.NightModeCustomReturnType; import android.app.UiModeManager.NightModeCustomType; import android.content.BroadcastReceiver; import android.content.Context; Loading Loading @@ -111,6 +112,9 @@ final class UiModeManagerService extends SystemService { // Enable launching of applications when entering the dock. private static final boolean ENABLE_LAUNCH_DESK_DOCK_APP = true; private static final String SYSTEM_PROPERTY_DEVICE_THEME = "persist.sys.theme"; @VisibleForTesting public static final Set<Integer> SUPPORTED_NIGHT_MODE_CUSTOM_TYPES = new ArraySet( new Integer[]{MODE_NIGHT_CUSTOM_TYPE_SCHEDULE, MODE_NIGHT_CUSTOM_TYPE_BEDTIME}); private final Injector mInjector; private final Object mLock = new Object(); Loading Loading @@ -728,8 +732,13 @@ final class UiModeManagerService extends SystemService { case UiModeManager.MODE_NIGHT_NO: case UiModeManager.MODE_NIGHT_YES: case MODE_NIGHT_AUTO: break; case MODE_NIGHT_CUSTOM: if (SUPPORTED_NIGHT_MODE_CUSTOM_TYPES.contains(customModeType)) { break; } throw new IllegalArgumentException( "Can't set the custom type to " + customModeType); default: throw new IllegalArgumentException("Unknown mode: " + mode); } Loading Loading @@ -783,7 +792,7 @@ final class UiModeManagerService extends SystemService { } @Override public int getNightModeCustomType() { public @NightModeCustomReturnType int getNightModeCustomType() { if (getContext().checkCallingOrSelfPermission( android.Manifest.permission.MODIFY_DAY_NIGHT_MODE) != PackageManager.PERMISSION_GRANTED) { Loading services/tests/uiservicestests/src/com/android/server/UiModeManagerServiceTest.java +20 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,8 @@ import static android.app.UiModeManager.PROJECTION_TYPE_ALL; import static android.app.UiModeManager.PROJECTION_TYPE_AUTOMOTIVE; import static android.app.UiModeManager.PROJECTION_TYPE_NONE; import static com.android.server.UiModeManagerService.SUPPORTED_NIGHT_MODE_CUSTOM_TYPES; import static com.google.common.truth.Truth.assertThat; import static junit.framework.TestCase.assertFalse; Loading Loading @@ -294,6 +296,24 @@ public class UiModeManagerServiceTest extends UiServiceTestCase { () -> mService.setNightModeCustomType(MODE_NIGHT_CUSTOM_TYPE_BEDTIME)); } @Test public void setNightModeCustomType_customTypeUnknown_shouldThrow() throws RemoteException { assertThrows(IllegalArgumentException.class, () -> mService.setNightModeCustomType(MODE_NIGHT_CUSTOM_TYPE_UNKNOWN)); } @Test public void setNightModeCustomType_customTypeUnsupported_shouldThrow() throws RemoteException { assertThrows(IllegalArgumentException.class, () -> { int maxSupportedCustomType = 0; for (Integer supportedType : SUPPORTED_NIGHT_MODE_CUSTOM_TYPES) { maxSupportedCustomType = Math.max(maxSupportedCustomType, supportedType); } mService.setNightModeCustomType(maxSupportedCustomType + 1); }); } @Test public void setNightModeCustomType_bedtime_shouldHaveNoScreenOffRegistered() throws RemoteException { Loading Loading @@ -777,7 +797,6 @@ public class UiModeManagerServiceTest extends UiServiceTestCase { } @Test public void customTime_darkThemeOn_beforeStartEnd() throws RemoteException { LocalTime now = LocalTime.now(); Loading Loading
core/java/android/app/IUiModeManager.aidl +3 −0 Original line number Diff line number Diff line Loading @@ -73,6 +73,7 @@ interface IUiModeManager { * @param nightModeCustomType * @hide */ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.MODIFY_DAY_NIGHT_MODE)") void setNightModeCustomType(int nightModeCustomType); /** Loading @@ -82,6 +83,7 @@ interface IUiModeManager { * {@link #MODE_NIGHT_CUSTOM_TYPE_UNKNOWN}. * @hide */ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.MODIFY_DAY_NIGHT_MODE)") int getNightModeCustomType(); /** Loading Loading @@ -113,6 +115,7 @@ interface IUiModeManager { * {@code nightModeCustomType}. * @hide */ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.MODIFY_DAY_NIGHT_MODE)") boolean setNightModeActivatedForCustomMode(int nightModeCustom, boolean active); /** Loading
core/java/android/app/UiModeManager.java +16 −3 Original line number Diff line number Diff line Loading @@ -244,17 +244,28 @@ public class UiModeManager { public static final int MODE_NIGHT_YES = 2; /** * Granular types for {@link MODE_NIGHT_CUSTOM_TYPE_BEDTIME} * Granular types for {@link #setNightModeCustomType(int)} * @hide */ @IntDef(prefix = { "MODE_NIGHT_CUSTOM_TYPE_" }, value = { MODE_NIGHT_CUSTOM_TYPE_UNKNOWN, MODE_NIGHT_CUSTOM_TYPE_SCHEDULE, MODE_NIGHT_CUSTOM_TYPE_BEDTIME, }) @Retention(RetentionPolicy.SOURCE) public @interface NightModeCustomType {} /** * Granular types for {@link #getNightModeCustomType()} * @hide */ @IntDef(prefix = { "MODE_NIGHT_CUSTOM_TYPE_" }, value = { MODE_NIGHT_CUSTOM_TYPE_UNKNOWN, MODE_NIGHT_CUSTOM_TYPE_SCHEDULE, MODE_NIGHT_CUSTOM_TYPE_BEDTIME, }) @Retention(RetentionPolicy.SOURCE) public @interface NightModeCustomReturnType {} /** * A granular type for {@link #MODE_NIGHT_CUSTOM} which is unknown. * <p> Loading Loading @@ -539,6 +550,8 @@ public class UiModeManager { * {@code nightModeCustomType}. * * @param nightModeCustomType * @throws IllegalArgumentException if passed an unsupported type to * {@code nightModeCustomType}. * @hide */ @SystemApi Loading @@ -562,7 +575,7 @@ public class UiModeManager { */ @SystemApi @RequiresPermission(android.Manifest.permission.MODIFY_DAY_NIGHT_MODE) public int getNightModeCustomType() { public @NightModeCustomReturnType int getNightModeCustomType() { if (mService != null) { try { return mService.getNightModeCustomType(); Loading
services/core/java/com/android/server/UiModeManagerService.java +11 −2 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ import android.app.NotificationManager; import android.app.PendingIntent; import android.app.StatusBarManager; import android.app.UiModeManager; import android.app.UiModeManager.NightModeCustomReturnType; import android.app.UiModeManager.NightModeCustomType; import android.content.BroadcastReceiver; import android.content.Context; Loading Loading @@ -111,6 +112,9 @@ final class UiModeManagerService extends SystemService { // Enable launching of applications when entering the dock. private static final boolean ENABLE_LAUNCH_DESK_DOCK_APP = true; private static final String SYSTEM_PROPERTY_DEVICE_THEME = "persist.sys.theme"; @VisibleForTesting public static final Set<Integer> SUPPORTED_NIGHT_MODE_CUSTOM_TYPES = new ArraySet( new Integer[]{MODE_NIGHT_CUSTOM_TYPE_SCHEDULE, MODE_NIGHT_CUSTOM_TYPE_BEDTIME}); private final Injector mInjector; private final Object mLock = new Object(); Loading Loading @@ -728,8 +732,13 @@ final class UiModeManagerService extends SystemService { case UiModeManager.MODE_NIGHT_NO: case UiModeManager.MODE_NIGHT_YES: case MODE_NIGHT_AUTO: break; case MODE_NIGHT_CUSTOM: if (SUPPORTED_NIGHT_MODE_CUSTOM_TYPES.contains(customModeType)) { break; } throw new IllegalArgumentException( "Can't set the custom type to " + customModeType); default: throw new IllegalArgumentException("Unknown mode: " + mode); } Loading Loading @@ -783,7 +792,7 @@ final class UiModeManagerService extends SystemService { } @Override public int getNightModeCustomType() { public @NightModeCustomReturnType int getNightModeCustomType() { if (getContext().checkCallingOrSelfPermission( android.Manifest.permission.MODIFY_DAY_NIGHT_MODE) != PackageManager.PERMISSION_GRANTED) { Loading
services/tests/uiservicestests/src/com/android/server/UiModeManagerServiceTest.java +20 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,8 @@ import static android.app.UiModeManager.PROJECTION_TYPE_ALL; import static android.app.UiModeManager.PROJECTION_TYPE_AUTOMOTIVE; import static android.app.UiModeManager.PROJECTION_TYPE_NONE; import static com.android.server.UiModeManagerService.SUPPORTED_NIGHT_MODE_CUSTOM_TYPES; import static com.google.common.truth.Truth.assertThat; import static junit.framework.TestCase.assertFalse; Loading Loading @@ -294,6 +296,24 @@ public class UiModeManagerServiceTest extends UiServiceTestCase { () -> mService.setNightModeCustomType(MODE_NIGHT_CUSTOM_TYPE_BEDTIME)); } @Test public void setNightModeCustomType_customTypeUnknown_shouldThrow() throws RemoteException { assertThrows(IllegalArgumentException.class, () -> mService.setNightModeCustomType(MODE_NIGHT_CUSTOM_TYPE_UNKNOWN)); } @Test public void setNightModeCustomType_customTypeUnsupported_shouldThrow() throws RemoteException { assertThrows(IllegalArgumentException.class, () -> { int maxSupportedCustomType = 0; for (Integer supportedType : SUPPORTED_NIGHT_MODE_CUSTOM_TYPES) { maxSupportedCustomType = Math.max(maxSupportedCustomType, supportedType); } mService.setNightModeCustomType(maxSupportedCustomType + 1); }); } @Test public void setNightModeCustomType_bedtime_shouldHaveNoScreenOffRegistered() throws RemoteException { Loading Loading @@ -777,7 +797,6 @@ public class UiModeManagerServiceTest extends UiServiceTestCase { } @Test public void customTime_darkThemeOn_beforeStartEnd() throws RemoteException { LocalTime now = LocalTime.now(); Loading