diff options
| author | 2024-03-27 16:42:19 +0000 | |
|---|---|---|
| committer | 2024-03-27 16:42:19 +0000 | |
| commit | 0f65a72e04603440d5f7c30495df94e0d0e15679 (patch) | |
| tree | 986e5606deb11668f9e20a76f6b58c768f492118 | |
| parent | c3bab3203a0918dc2dc6b6fb4fc76c0d6d757e2c (diff) | |
| parent | c9f0cbbf53cd195726081e0d8a9805280e7a9180 (diff) | |
Merge "Passes in more specific types to DeviceState and DeviceStateInfo" into main
5 files changed, 36 insertions, 36 deletions
diff --git a/core/java/android/hardware/devicestate/DeviceState.java b/core/java/android/hardware/devicestate/DeviceState.java index 689e343bcbc6..64fc4c29db90 100644 --- a/core/java/android/hardware/devicestate/DeviceState.java +++ b/core/java/android/hardware/devicestate/DeviceState.java @@ -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. */ @@ -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)); } } } diff --git a/core/java/android/hardware/devicestate/DeviceStateInfo.java b/core/java/android/hardware/devicestate/DeviceStateInfo.java index c319c893aaab..28561ec37ee6 100644 --- a/core/java/android/hardware/devicestate/DeviceStateInfo.java +++ b/core/java/android/hardware/devicestate/DeviceStateInfo.java @@ -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; @@ -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; } @@ -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) diff --git a/core/tests/devicestatetests/src/android/hardware/devicestate/DeviceStateInfoTest.java b/core/tests/devicestatetests/src/android/hardware/devicestate/DeviceStateInfoTest.java index 08977265667c..cf7c5491f787 100644 --- a/core/tests/devicestatetests/src/android/hardware/devicestate/DeviceStateInfoTest.java +++ b/core/tests/devicestatetests/src/android/hardware/devicestate/DeviceStateInfoTest.java @@ -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; @@ -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; @@ -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; @@ -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; @@ -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); @@ -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); @@ -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); @@ -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 = diff --git a/core/tests/devicestatetests/src/android/hardware/devicestate/DeviceStateManagerGlobalTest.java b/core/tests/devicestatetests/src/android/hardware/devicestate/DeviceStateManagerGlobalTest.java index ee238c0a5533..f4d363167a75 100644 --- a/core/tests/devicestatetests/src/android/hardware/devicestate/DeviceStateManagerGlobalTest.java +++ b/core/tests/devicestatetests/src/android/hardware/devicestate/DeviceStateManagerGlobalTest.java @@ -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; @@ -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() { diff --git a/services/core/java/com/android/server/devicestate/DeviceStateManagerService.java b/services/core/java/com/android/server/devicestate/DeviceStateManagerService.java index e2ae3def0b1b..e8394d43f266 100644 --- a/services/core/java/com/android/server/devicestate/DeviceStateManagerService.java +++ b/services/core/java/com/android/server/devicestate/DeviceStateManagerService.java @@ -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)); } |