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

Commit 0155856a authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

Fix AudioService rotation helper thread

Fix a race condition where the wait index can be incremented inbetween
  the while() loop and the lock
Fix when updateOrientation() is called: after the sleep, otherwise
  the last sleep is useless.

Bug 24677424

Change-Id: I03770a0fc8af57f4696ebee7e9c9110e17c55a24
parent faebbe82
Loading
Loading
Loading
Loading
+6 −4
Original line number Original line Diff line number Diff line
@@ -192,16 +192,18 @@ class RotationHelper {
        }
        }


        public void run() {
        public void run() {
            int newRotation;
            while (mWaitCounter < WAIT_TIMES_MS.length) {
            while (mWaitCounter < WAIT_TIMES_MS.length) {
                updateOrientation();
                int waitTimeMs;
                int waitTimeMs;
                synchronized(mCounterLock) {
                synchronized(mCounterLock) {
                    waitTimeMs = WAIT_TIMES_MS[mWaitCounter];
                    waitTimeMs = mWaitCounter < WAIT_TIMES_MS.length ?
                            WAIT_TIMES_MS[mWaitCounter] : 0;
                    mWaitCounter++;
                    mWaitCounter++;
                }
                }
                try {
                try {
                    if (waitTimeMs > 0) {
                        sleep(waitTimeMs);
                        sleep(waitTimeMs);
                        updateOrientation();
                    }
                } catch (InterruptedException e) { }
                } catch (InterruptedException e) { }
            }
            }
        }
        }