Loading core/api/test-current.txt +2 −0 Original line number Diff line number Diff line Loading @@ -914,6 +914,8 @@ package android.hardware.devicestate { method @NonNull public int[] getSupportedStates(); method public void removeDeviceStateListener(@NonNull android.hardware.devicestate.DeviceStateManager.DeviceStateListener); method @RequiresPermission(android.Manifest.permission.CONTROL_DEVICE_STATE) public void requestState(@NonNull android.hardware.devicestate.DeviceStateRequest, @Nullable java.util.concurrent.Executor, @Nullable android.hardware.devicestate.DeviceStateRequest.Callback); field public static final int MAXIMUM_DEVICE_STATE = 255; // 0xff field public static final int MINIMUM_DEVICE_STATE = 0; // 0x0 } public static interface DeviceStateManager.DeviceStateListener { Loading core/java/android/hardware/devicestate/DeviceStateManager.java +6 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,12 @@ public final class DeviceStateManager { */ public static final int INVALID_DEVICE_STATE = -1; /** The minimum allowed device state identifier. */ public static final int MINIMUM_DEVICE_STATE = 0; /** The maximum allowed device state identifier. */ public static final int MAXIMUM_DEVICE_STATE = 255; private final DeviceStateManagerGlobal mGlobal; /** @hide */ Loading services/core/java/com/android/server/devicestate/DeviceState.java +12 −6 Original line number Diff line number Diff line Loading @@ -16,9 +16,14 @@ package com.android.server.devicestate; import static android.hardware.devicestate.DeviceStateManager.MAXIMUM_DEVICE_STATE; import static android.hardware.devicestate.DeviceStateManager.MINIMUM_DEVICE_STATE; import android.annotation.IntRange; import android.annotation.NonNull; import com.android.internal.util.Preconditions; import java.util.Objects; /** Loading @@ -35,24 +40,25 @@ import java.util.Objects; */ public final class DeviceState { /** Unique identifier for the device state. */ @IntRange(from = 0) @IntRange(from = MINIMUM_DEVICE_STATE, to = MAXIMUM_DEVICE_STATE) private final int mIdentifier; /** String description of the device state. */ @NonNull private final String mName; public DeviceState(@IntRange(from = 0) int identifier, public DeviceState( @IntRange(from = MINIMUM_DEVICE_STATE, to = MAXIMUM_DEVICE_STATE) int identifier, @NonNull String name) { if (identifier < 0) { throw new IllegalArgumentException("Identifier must be greater than or equal to zero."); } Preconditions.checkArgumentInRange(identifier, MINIMUM_DEVICE_STATE, MAXIMUM_DEVICE_STATE, "identifier"); mIdentifier = identifier; mName = name; } /** Returns the unique identifier for the device state. */ @IntRange(from = 0) @IntRange(from = MINIMUM_DEVICE_STATE, to = MAXIMUM_DEVICE_STATE) public int getIdentifier() { return mIdentifier; } Loading services/core/java/com/android/server/devicestate/DeviceStateManagerService.java +6 −3 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ package com.android.server.devicestate; import static android.Manifest.permission.CONTROL_DEVICE_STATE; import static android.hardware.devicestate.DeviceStateManager.MAXIMUM_DEVICE_STATE; import static android.hardware.devicestate.DeviceStateManager.MINIMUM_DEVICE_STATE; import static android.hardware.devicestate.DeviceStateRequest.FLAG_CANCEL_WHEN_BASE_CHANGES; import android.annotation.IntRange; Loading Loading @@ -89,7 +91,7 @@ public final class DeviceStateManagerService extends SystemService { // the current state after the initial callback from the DeviceStateProvider. @GuardedBy("mLock") @NonNull private DeviceState mCommittedState = new DeviceState(0, "UNSET"); private DeviceState mCommittedState = new DeviceState(MINIMUM_DEVICE_STATE, "UNSET"); // The device state that is currently awaiting callback from the policy to be committed. @GuardedBy("mLock") @NonNull Loading Loading @@ -598,8 +600,9 @@ public final class DeviceStateManagerService extends SystemService { } @Override public void onStateChanged(@IntRange(from = 0) int identifier) { if (identifier < 0) { public void onStateChanged( @IntRange(from = MINIMUM_DEVICE_STATE, to = MAXIMUM_DEVICE_STATE) int identifier) { if (identifier < MINIMUM_DEVICE_STATE || identifier > MAXIMUM_DEVICE_STATE) { throw new IllegalArgumentException("Invalid identifier: " + identifier); } Loading services/core/java/com/android/server/devicestate/DeviceStateProvider.java +7 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ package com.android.server.devicestate; import static android.hardware.devicestate.DeviceStateManager.MAXIMUM_DEVICE_STATE; import static android.hardware.devicestate.DeviceStateManager.MINIMUM_DEVICE_STATE; import android.annotation.IntRange; /** Loading Loading @@ -65,8 +68,10 @@ public interface DeviceStateProvider { * * @param identifier the identifier of the new device state. * * @throws IllegalArgumentException if the state is less than 0. * @throws IllegalArgumentException if the state is less than {@link MINIMUM_DEVICE_STATE} * or greater than {@link MAXIMUM_DEVICE_STATE}. */ void onStateChanged(@IntRange(from = 0) int identifier); void onStateChanged( @IntRange(from = MINIMUM_DEVICE_STATE, to = MAXIMUM_DEVICE_STATE) int identifier); } } Loading
core/api/test-current.txt +2 −0 Original line number Diff line number Diff line Loading @@ -914,6 +914,8 @@ package android.hardware.devicestate { method @NonNull public int[] getSupportedStates(); method public void removeDeviceStateListener(@NonNull android.hardware.devicestate.DeviceStateManager.DeviceStateListener); method @RequiresPermission(android.Manifest.permission.CONTROL_DEVICE_STATE) public void requestState(@NonNull android.hardware.devicestate.DeviceStateRequest, @Nullable java.util.concurrent.Executor, @Nullable android.hardware.devicestate.DeviceStateRequest.Callback); field public static final int MAXIMUM_DEVICE_STATE = 255; // 0xff field public static final int MINIMUM_DEVICE_STATE = 0; // 0x0 } public static interface DeviceStateManager.DeviceStateListener { Loading
core/java/android/hardware/devicestate/DeviceStateManager.java +6 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,12 @@ public final class DeviceStateManager { */ public static final int INVALID_DEVICE_STATE = -1; /** The minimum allowed device state identifier. */ public static final int MINIMUM_DEVICE_STATE = 0; /** The maximum allowed device state identifier. */ public static final int MAXIMUM_DEVICE_STATE = 255; private final DeviceStateManagerGlobal mGlobal; /** @hide */ Loading
services/core/java/com/android/server/devicestate/DeviceState.java +12 −6 Original line number Diff line number Diff line Loading @@ -16,9 +16,14 @@ package com.android.server.devicestate; import static android.hardware.devicestate.DeviceStateManager.MAXIMUM_DEVICE_STATE; import static android.hardware.devicestate.DeviceStateManager.MINIMUM_DEVICE_STATE; import android.annotation.IntRange; import android.annotation.NonNull; import com.android.internal.util.Preconditions; import java.util.Objects; /** Loading @@ -35,24 +40,25 @@ import java.util.Objects; */ public final class DeviceState { /** Unique identifier for the device state. */ @IntRange(from = 0) @IntRange(from = MINIMUM_DEVICE_STATE, to = MAXIMUM_DEVICE_STATE) private final int mIdentifier; /** String description of the device state. */ @NonNull private final String mName; public DeviceState(@IntRange(from = 0) int identifier, public DeviceState( @IntRange(from = MINIMUM_DEVICE_STATE, to = MAXIMUM_DEVICE_STATE) int identifier, @NonNull String name) { if (identifier < 0) { throw new IllegalArgumentException("Identifier must be greater than or equal to zero."); } Preconditions.checkArgumentInRange(identifier, MINIMUM_DEVICE_STATE, MAXIMUM_DEVICE_STATE, "identifier"); mIdentifier = identifier; mName = name; } /** Returns the unique identifier for the device state. */ @IntRange(from = 0) @IntRange(from = MINIMUM_DEVICE_STATE, to = MAXIMUM_DEVICE_STATE) public int getIdentifier() { return mIdentifier; } Loading
services/core/java/com/android/server/devicestate/DeviceStateManagerService.java +6 −3 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ package com.android.server.devicestate; import static android.Manifest.permission.CONTROL_DEVICE_STATE; import static android.hardware.devicestate.DeviceStateManager.MAXIMUM_DEVICE_STATE; import static android.hardware.devicestate.DeviceStateManager.MINIMUM_DEVICE_STATE; import static android.hardware.devicestate.DeviceStateRequest.FLAG_CANCEL_WHEN_BASE_CHANGES; import android.annotation.IntRange; Loading Loading @@ -89,7 +91,7 @@ public final class DeviceStateManagerService extends SystemService { // the current state after the initial callback from the DeviceStateProvider. @GuardedBy("mLock") @NonNull private DeviceState mCommittedState = new DeviceState(0, "UNSET"); private DeviceState mCommittedState = new DeviceState(MINIMUM_DEVICE_STATE, "UNSET"); // The device state that is currently awaiting callback from the policy to be committed. @GuardedBy("mLock") @NonNull Loading Loading @@ -598,8 +600,9 @@ public final class DeviceStateManagerService extends SystemService { } @Override public void onStateChanged(@IntRange(from = 0) int identifier) { if (identifier < 0) { public void onStateChanged( @IntRange(from = MINIMUM_DEVICE_STATE, to = MAXIMUM_DEVICE_STATE) int identifier) { if (identifier < MINIMUM_DEVICE_STATE || identifier > MAXIMUM_DEVICE_STATE) { throw new IllegalArgumentException("Invalid identifier: " + identifier); } Loading
services/core/java/com/android/server/devicestate/DeviceStateProvider.java +7 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ package com.android.server.devicestate; import static android.hardware.devicestate.DeviceStateManager.MAXIMUM_DEVICE_STATE; import static android.hardware.devicestate.DeviceStateManager.MINIMUM_DEVICE_STATE; import android.annotation.IntRange; /** Loading Loading @@ -65,8 +68,10 @@ public interface DeviceStateProvider { * * @param identifier the identifier of the new device state. * * @throws IllegalArgumentException if the state is less than 0. * @throws IllegalArgumentException if the state is less than {@link MINIMUM_DEVICE_STATE} * or greater than {@link MAXIMUM_DEVICE_STATE}. */ void onStateChanged(@IntRange(from = 0) int identifier); void onStateChanged( @IntRange(from = MINIMUM_DEVICE_STATE, to = MAXIMUM_DEVICE_STATE) int identifier); } }