Loading core/java/android/hardware/devicestate/DeviceState.java +6 −8 Original line number Diff line number Diff line Loading @@ -333,14 +333,12 @@ public final class DeviceState { private final ArraySet<@PhysicalDeviceStateProperties Integer> mPhysicalProperties; private Configuration(int identifier, @NonNull String name, @NonNull Set<@SystemDeviceStateProperties Integer> systemProperties, @NonNull Set<@PhysicalDeviceStateProperties Integer> physicalProperties) { @NonNull ArraySet<@SystemDeviceStateProperties Integer> systemProperties, @NonNull ArraySet<@PhysicalDeviceStateProperties Integer> physicalProperties) { mIdentifier = identifier; mName = name; mSystemProperties = new ArraySet<@SystemDeviceStateProperties Integer>( systemProperties); mPhysicalProperties = new ArraySet<@PhysicalDeviceStateProperties Integer>( physicalProperties); mSystemProperties = systemProperties; mPhysicalProperties = physicalProperties; } /** Returns the unique identifier for the device state. */ Loading Loading @@ -479,8 +477,8 @@ public final class DeviceState { */ @NonNull public DeviceState.Configuration build() { return new DeviceState.Configuration(mIdentifier, mName, mSystemProperties, mPhysicalProperties); return new DeviceState.Configuration(mIdentifier, mName, new ArraySet<>(mSystemProperties), new ArraySet<>(mPhysicalProperties)); } } } Loading core/java/android/hardware/devicestate/DeviceStateInfo.java +6 −5 Original line number Diff line number Diff line Loading @@ -25,7 +25,6 @@ import android.os.Parcelable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.concurrent.Executor; Loading Loading @@ -77,9 +76,11 @@ public final class DeviceStateInfo implements Parcelable { * NOTE: Unlike {@link #DeviceStateInfo(DeviceStateInfo)}, this constructor does not copy the * supplied parameters. */ public DeviceStateInfo(@NonNull List<DeviceState> supportedStates, DeviceState baseState, // Using the specific types to avoid virtual method calls in binder transactions @SuppressWarnings("NonApiType") public DeviceStateInfo(@NonNull ArrayList<DeviceState> supportedStates, DeviceState baseState, DeviceState state) { this.supportedStates = new ArrayList<>(supportedStates); this.supportedStates = supportedStates; this.baseState = baseState; this.currentState = state; } Loading @@ -89,13 +90,13 @@ public final class DeviceStateInfo implements Parcelable { * the fields of the returned instance. */ public DeviceStateInfo(@NonNull DeviceStateInfo info) { this(List.copyOf(info.supportedStates), info.baseState, info.currentState); this(new ArrayList<>(info.supportedStates), info.baseState, info.currentState); } @Override public boolean equals(@Nullable Object other) { if (this == other) return true; if (other == null || getClass() != other.getClass()) return false; if (other == null || (getClass() != other.getClass())) return false; DeviceStateInfo that = (DeviceStateInfo) other; return baseState.equals(that.baseState) && currentState.equals(that.currentState) Loading core/tests/devicestatetests/src/android/hardware/devicestate/DeviceStateInfoTest.java +21 −21 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import java.util.ArrayList; import java.util.List; import java.util.Set; Loading Loading @@ -73,8 +74,8 @@ public final class DeviceStateInfoTest { @Test public void create() { final List<DeviceState> supportedStates = List.of(DEVICE_STATE_0, DEVICE_STATE_1, DEVICE_STATE_2); final ArrayList<DeviceState> supportedStates = new ArrayList<>( List.of(DEVICE_STATE_0, DEVICE_STATE_1, DEVICE_STATE_2)); final DeviceState baseState = DEVICE_STATE_0; final DeviceState currentState = DEVICE_STATE_2; Loading @@ -87,8 +88,8 @@ public final class DeviceStateInfoTest { @Test public void equals() { final List<DeviceState> supportedStates = List.of(DEVICE_STATE_0, DEVICE_STATE_1, DEVICE_STATE_2); final ArrayList<DeviceState> supportedStates = new ArrayList<>( List.of(DEVICE_STATE_0, DEVICE_STATE_1, DEVICE_STATE_2)); final DeviceState baseState = DEVICE_STATE_0; final DeviceState currentState = DEVICE_STATE_2; Loading @@ -100,15 +101,14 @@ public final class DeviceStateInfoTest { Assert.assertEquals(info, sameInfo); final DeviceStateInfo differentInfo = new DeviceStateInfo( List.of(DEVICE_STATE_0, DEVICE_STATE_2), baseState, currentState); new ArrayList<>(List.of(DEVICE_STATE_0, DEVICE_STATE_2)), baseState, currentState); assertNotEquals(info, differentInfo); } @Test public void diff_sameObject() { final List<DeviceState> supportedStates = List.of(DEVICE_STATE_0, DEVICE_STATE_1, DEVICE_STATE_2); final ArrayList<DeviceState> supportedStates = new ArrayList<>( List.of(DEVICE_STATE_0, DEVICE_STATE_1, DEVICE_STATE_2)); final DeviceState baseState = DEVICE_STATE_0; final DeviceState currentState = DEVICE_STATE_2; Loading @@ -118,10 +118,10 @@ public final class DeviceStateInfoTest { @Test public void diff_differentSupportedStates() { final DeviceStateInfo info = new DeviceStateInfo(List.of(DEVICE_STATE_1), DEVICE_STATE_0, DEVICE_STATE_0); final DeviceStateInfo otherInfo = new DeviceStateInfo(List.of(DEVICE_STATE_2), final DeviceStateInfo info = new DeviceStateInfo(new ArrayList<>(List.of(DEVICE_STATE_1)), DEVICE_STATE_0, DEVICE_STATE_0); final DeviceStateInfo otherInfo = new DeviceStateInfo( new ArrayList<>(List.of(DEVICE_STATE_2)), DEVICE_STATE_0, DEVICE_STATE_0); final int diff = info.diff(otherInfo); assertTrue((diff & DeviceStateInfo.CHANGED_SUPPORTED_STATES) > 0); assertFalse((diff & DeviceStateInfo.CHANGED_BASE_STATE) > 0); Loading @@ -130,10 +130,10 @@ public final class DeviceStateInfoTest { @Test public void diff_differentNonOverrideState() { final DeviceStateInfo info = new DeviceStateInfo(List.of(DEVICE_STATE_1), DEVICE_STATE_1, DEVICE_STATE_0); final DeviceStateInfo otherInfo = new DeviceStateInfo(List.of(DEVICE_STATE_1), DEVICE_STATE_2, DEVICE_STATE_0); final DeviceStateInfo info = new DeviceStateInfo(new ArrayList<>(List.of(DEVICE_STATE_1)), DEVICE_STATE_1, DEVICE_STATE_0); final DeviceStateInfo otherInfo = new DeviceStateInfo( new ArrayList<>(List.of(DEVICE_STATE_1)), DEVICE_STATE_2, DEVICE_STATE_0); final int diff = info.diff(otherInfo); assertFalse((diff & DeviceStateInfo.CHANGED_SUPPORTED_STATES) > 0); assertTrue((diff & DeviceStateInfo.CHANGED_BASE_STATE) > 0); Loading @@ -142,10 +142,10 @@ public final class DeviceStateInfoTest { @Test public void diff_differentState() { final DeviceStateInfo info = new DeviceStateInfo(List.of(DEVICE_STATE_1), DEVICE_STATE_0, DEVICE_STATE_1); final DeviceStateInfo otherInfo = new DeviceStateInfo(List.of(DEVICE_STATE_1), DEVICE_STATE_0, DEVICE_STATE_2); final DeviceStateInfo info = new DeviceStateInfo(new ArrayList<>(List.of(DEVICE_STATE_1)), DEVICE_STATE_0, DEVICE_STATE_1); final DeviceStateInfo otherInfo = new DeviceStateInfo( new ArrayList<>(List.of(DEVICE_STATE_1)), DEVICE_STATE_0, DEVICE_STATE_2); final int diff = info.diff(otherInfo); assertFalse((diff & DeviceStateInfo.CHANGED_SUPPORTED_STATES) > 0); assertFalse((diff & DeviceStateInfo.CHANGED_BASE_STATE) > 0); Loading @@ -154,8 +154,8 @@ public final class DeviceStateInfoTest { @Test public void writeToParcel() { final List<DeviceState> supportedStates = List.of(DEVICE_STATE_0, DEVICE_STATE_1, DEVICE_STATE_2); final ArrayList<DeviceState> supportedStates = new ArrayList<>( List.of(DEVICE_STATE_0, DEVICE_STATE_1, DEVICE_STATE_2)); final DeviceState nonOverrideState = DEVICE_STATE_0; final DeviceState state = DEVICE_STATE_2; final DeviceStateInfo originalInfo = Loading core/tests/devicestatetests/src/android/hardware/devicestate/DeviceStateManagerGlobalTest.java +2 −1 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; Loading Loading @@ -276,7 +277,7 @@ public final class DeviceStateManagerGlobalTest { new DeviceState.Configuration.Builder(mergedBaseState, "" /* name */).build()); final DeviceState state = new DeviceState( new DeviceState.Configuration.Builder(mergedState, "" /* name */).build()); return new DeviceStateInfo(mSupportedDeviceStates, baseState, state); return new DeviceStateInfo(new ArrayList<>(mSupportedDeviceStates), baseState, state); } private void notifyDeviceStateInfoChanged() { Loading services/core/java/com/android/server/devicestate/DeviceStateManagerService.java +1 −1 Original line number Diff line number Diff line Loading @@ -399,7 +399,7 @@ public final class DeviceStateManagerService extends SystemService { final DeviceState baseState = mBaseState.orElse(INVALID_DEVICE_STATE); final DeviceState currentState = mCommittedState.orElse(INVALID_DEVICE_STATE); return new DeviceStateInfo(supportedStates, baseState, return new DeviceStateInfo(new ArrayList<>(supportedStates), baseState, createMergedDeviceState(currentState, baseState)); } Loading Loading
core/java/android/hardware/devicestate/DeviceState.java +6 −8 Original line number Diff line number Diff line Loading @@ -333,14 +333,12 @@ public final class DeviceState { private final ArraySet<@PhysicalDeviceStateProperties Integer> mPhysicalProperties; private Configuration(int identifier, @NonNull String name, @NonNull Set<@SystemDeviceStateProperties Integer> systemProperties, @NonNull Set<@PhysicalDeviceStateProperties Integer> physicalProperties) { @NonNull ArraySet<@SystemDeviceStateProperties Integer> systemProperties, @NonNull ArraySet<@PhysicalDeviceStateProperties Integer> physicalProperties) { mIdentifier = identifier; mName = name; mSystemProperties = new ArraySet<@SystemDeviceStateProperties Integer>( systemProperties); mPhysicalProperties = new ArraySet<@PhysicalDeviceStateProperties Integer>( physicalProperties); mSystemProperties = systemProperties; mPhysicalProperties = physicalProperties; } /** Returns the unique identifier for the device state. */ Loading Loading @@ -479,8 +477,8 @@ public final class DeviceState { */ @NonNull public DeviceState.Configuration build() { return new DeviceState.Configuration(mIdentifier, mName, mSystemProperties, mPhysicalProperties); return new DeviceState.Configuration(mIdentifier, mName, new ArraySet<>(mSystemProperties), new ArraySet<>(mPhysicalProperties)); } } } Loading
core/java/android/hardware/devicestate/DeviceStateInfo.java +6 −5 Original line number Diff line number Diff line Loading @@ -25,7 +25,6 @@ import android.os.Parcelable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.concurrent.Executor; Loading Loading @@ -77,9 +76,11 @@ public final class DeviceStateInfo implements Parcelable { * NOTE: Unlike {@link #DeviceStateInfo(DeviceStateInfo)}, this constructor does not copy the * supplied parameters. */ public DeviceStateInfo(@NonNull List<DeviceState> supportedStates, DeviceState baseState, // Using the specific types to avoid virtual method calls in binder transactions @SuppressWarnings("NonApiType") public DeviceStateInfo(@NonNull ArrayList<DeviceState> supportedStates, DeviceState baseState, DeviceState state) { this.supportedStates = new ArrayList<>(supportedStates); this.supportedStates = supportedStates; this.baseState = baseState; this.currentState = state; } Loading @@ -89,13 +90,13 @@ public final class DeviceStateInfo implements Parcelable { * the fields of the returned instance. */ public DeviceStateInfo(@NonNull DeviceStateInfo info) { this(List.copyOf(info.supportedStates), info.baseState, info.currentState); this(new ArrayList<>(info.supportedStates), info.baseState, info.currentState); } @Override public boolean equals(@Nullable Object other) { if (this == other) return true; if (other == null || getClass() != other.getClass()) return false; if (other == null || (getClass() != other.getClass())) return false; DeviceStateInfo that = (DeviceStateInfo) other; return baseState.equals(that.baseState) && currentState.equals(that.currentState) Loading
core/tests/devicestatetests/src/android/hardware/devicestate/DeviceStateInfoTest.java +21 −21 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import java.util.ArrayList; import java.util.List; import java.util.Set; Loading Loading @@ -73,8 +74,8 @@ public final class DeviceStateInfoTest { @Test public void create() { final List<DeviceState> supportedStates = List.of(DEVICE_STATE_0, DEVICE_STATE_1, DEVICE_STATE_2); final ArrayList<DeviceState> supportedStates = new ArrayList<>( List.of(DEVICE_STATE_0, DEVICE_STATE_1, DEVICE_STATE_2)); final DeviceState baseState = DEVICE_STATE_0; final DeviceState currentState = DEVICE_STATE_2; Loading @@ -87,8 +88,8 @@ public final class DeviceStateInfoTest { @Test public void equals() { final List<DeviceState> supportedStates = List.of(DEVICE_STATE_0, DEVICE_STATE_1, DEVICE_STATE_2); final ArrayList<DeviceState> supportedStates = new ArrayList<>( List.of(DEVICE_STATE_0, DEVICE_STATE_1, DEVICE_STATE_2)); final DeviceState baseState = DEVICE_STATE_0; final DeviceState currentState = DEVICE_STATE_2; Loading @@ -100,15 +101,14 @@ public final class DeviceStateInfoTest { Assert.assertEquals(info, sameInfo); final DeviceStateInfo differentInfo = new DeviceStateInfo( List.of(DEVICE_STATE_0, DEVICE_STATE_2), baseState, currentState); new ArrayList<>(List.of(DEVICE_STATE_0, DEVICE_STATE_2)), baseState, currentState); assertNotEquals(info, differentInfo); } @Test public void diff_sameObject() { final List<DeviceState> supportedStates = List.of(DEVICE_STATE_0, DEVICE_STATE_1, DEVICE_STATE_2); final ArrayList<DeviceState> supportedStates = new ArrayList<>( List.of(DEVICE_STATE_0, DEVICE_STATE_1, DEVICE_STATE_2)); final DeviceState baseState = DEVICE_STATE_0; final DeviceState currentState = DEVICE_STATE_2; Loading @@ -118,10 +118,10 @@ public final class DeviceStateInfoTest { @Test public void diff_differentSupportedStates() { final DeviceStateInfo info = new DeviceStateInfo(List.of(DEVICE_STATE_1), DEVICE_STATE_0, DEVICE_STATE_0); final DeviceStateInfo otherInfo = new DeviceStateInfo(List.of(DEVICE_STATE_2), final DeviceStateInfo info = new DeviceStateInfo(new ArrayList<>(List.of(DEVICE_STATE_1)), DEVICE_STATE_0, DEVICE_STATE_0); final DeviceStateInfo otherInfo = new DeviceStateInfo( new ArrayList<>(List.of(DEVICE_STATE_2)), DEVICE_STATE_0, DEVICE_STATE_0); final int diff = info.diff(otherInfo); assertTrue((diff & DeviceStateInfo.CHANGED_SUPPORTED_STATES) > 0); assertFalse((diff & DeviceStateInfo.CHANGED_BASE_STATE) > 0); Loading @@ -130,10 +130,10 @@ public final class DeviceStateInfoTest { @Test public void diff_differentNonOverrideState() { final DeviceStateInfo info = new DeviceStateInfo(List.of(DEVICE_STATE_1), DEVICE_STATE_1, DEVICE_STATE_0); final DeviceStateInfo otherInfo = new DeviceStateInfo(List.of(DEVICE_STATE_1), DEVICE_STATE_2, DEVICE_STATE_0); final DeviceStateInfo info = new DeviceStateInfo(new ArrayList<>(List.of(DEVICE_STATE_1)), DEVICE_STATE_1, DEVICE_STATE_0); final DeviceStateInfo otherInfo = new DeviceStateInfo( new ArrayList<>(List.of(DEVICE_STATE_1)), DEVICE_STATE_2, DEVICE_STATE_0); final int diff = info.diff(otherInfo); assertFalse((diff & DeviceStateInfo.CHANGED_SUPPORTED_STATES) > 0); assertTrue((diff & DeviceStateInfo.CHANGED_BASE_STATE) > 0); Loading @@ -142,10 +142,10 @@ public final class DeviceStateInfoTest { @Test public void diff_differentState() { final DeviceStateInfo info = new DeviceStateInfo(List.of(DEVICE_STATE_1), DEVICE_STATE_0, DEVICE_STATE_1); final DeviceStateInfo otherInfo = new DeviceStateInfo(List.of(DEVICE_STATE_1), DEVICE_STATE_0, DEVICE_STATE_2); final DeviceStateInfo info = new DeviceStateInfo(new ArrayList<>(List.of(DEVICE_STATE_1)), DEVICE_STATE_0, DEVICE_STATE_1); final DeviceStateInfo otherInfo = new DeviceStateInfo( new ArrayList<>(List.of(DEVICE_STATE_1)), DEVICE_STATE_0, DEVICE_STATE_2); final int diff = info.diff(otherInfo); assertFalse((diff & DeviceStateInfo.CHANGED_SUPPORTED_STATES) > 0); assertFalse((diff & DeviceStateInfo.CHANGED_BASE_STATE) > 0); Loading @@ -154,8 +154,8 @@ public final class DeviceStateInfoTest { @Test public void writeToParcel() { final List<DeviceState> supportedStates = List.of(DEVICE_STATE_0, DEVICE_STATE_1, DEVICE_STATE_2); final ArrayList<DeviceState> supportedStates = new ArrayList<>( List.of(DEVICE_STATE_0, DEVICE_STATE_1, DEVICE_STATE_2)); final DeviceState nonOverrideState = DEVICE_STATE_0; final DeviceState state = DEVICE_STATE_2; final DeviceStateInfo originalInfo = Loading
core/tests/devicestatetests/src/android/hardware/devicestate/DeviceStateManagerGlobalTest.java +2 −1 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; Loading Loading @@ -276,7 +277,7 @@ public final class DeviceStateManagerGlobalTest { new DeviceState.Configuration.Builder(mergedBaseState, "" /* name */).build()); final DeviceState state = new DeviceState( new DeviceState.Configuration.Builder(mergedState, "" /* name */).build()); return new DeviceStateInfo(mSupportedDeviceStates, baseState, state); return new DeviceStateInfo(new ArrayList<>(mSupportedDeviceStates), baseState, state); } private void notifyDeviceStateInfoChanged() { Loading
services/core/java/com/android/server/devicestate/DeviceStateManagerService.java +1 −1 Original line number Diff line number Diff line Loading @@ -399,7 +399,7 @@ public final class DeviceStateManagerService extends SystemService { final DeviceState baseState = mBaseState.orElse(INVALID_DEVICE_STATE); final DeviceState currentState = mCommittedState.orElse(INVALID_DEVICE_STATE); return new DeviceStateInfo(supportedStates, baseState, return new DeviceStateInfo(new ArrayList<>(supportedStates), baseState, createMergedDeviceState(currentState, baseState)); } Loading