Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c3afd69e authored by Matthew Sedam's avatar Matthew Sedam
Browse files

ContextHubService: Start message sequence number randomly

This CL reduces the probability of the following
scenario:

1. A host endpoint sends a reliable message.
2. The service restarts.
3. A host endpoint sends a new reliable message with the
same message sequence number (always start with 0).
4. CHRE sends a response to the
message from (1).
5. The service completes the message in (3) incorrectly.

Bug: 333567700
Change-Id: Iecdb9e7492cb8ead71b8b3580c05018a4df4e463
Test: Presubmits
parent 0bd59c0d
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -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