diff options
| -rw-r--r-- | services/core/java/com/android/server/location/contexthub/ContextHubTransactionManager.java | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubTransactionManager.java b/services/core/java/com/android/server/location/contexthub/ContextHubTransactionManager.java index b18871cbf809..a0dbfa082978 100644 --- a/services/core/java/com/android/server/location/contexthub/ContextHubTransactionManager.java +++ b/services/core/java/com/android/server/location/contexthub/ContextHubTransactionManager.java @@ -28,6 +28,7 @@ import java.util.ArrayDeque; import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Random; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -77,9 +78,12 @@ import java.util.concurrent.atomic.AtomicInteger; private final AtomicInteger mNextAvailableId = new AtomicInteger(); /** - * The next available message sequence number + * The next available message sequence number. We choose a random + * number to start with to avoid collisions and limit the bound to + * half of the max value to avoid overflow. */ - private final AtomicInteger mNextAvailableMessageSequenceNumber = new AtomicInteger(); + private final AtomicInteger mNextAvailableMessageSequenceNumber = + new AtomicInteger(new Random().nextInt(Integer.MAX_VALUE / 2)); /* * An executor and the future object for scheduling timeout timers |