summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Michel Trivi <jmtrivi@google.com>2015-10-05 15:26:21 -0700
committerJean-Michel Trivi <jmtrivi@google.com>2015-10-05 15:26:21 -0700
commit0155856a1d1cb272d83b6175953dd7151fe65daa (patch)
treefb3c2df194e92c0489aa0386b5689024bd06115b
parentfaebbe82fa72036db75d679d366681822d2d551c (diff)
downloadbase-0155856a1d1cb272d83b6175953dd7151fe65daa.tar.gz
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
-rw-r--r--services/core/java/com/android/server/audio/RotationHelper.java10
1 files changed, 6 insertions, 4 deletions
diff --git a/services/core/java/com/android/server/audio/RotationHelper.java b/services/core/java/com/android/server/audio/RotationHelper.java
index f03e6c7c545a..359cc360bbc7 100644
--- a/services/core/java/com/android/server/audio/RotationHelper.java
+++ b/services/core/java/com/android/server/audio/RotationHelper.java
@@ -192,16 +192,18 @@ class RotationHelper {
}
public void run() {
- int newRotation;
while (mWaitCounter < WAIT_TIMES_MS.length) {
- updateOrientation();
int waitTimeMs;
synchronized(mCounterLock) {
- waitTimeMs = WAIT_TIMES_MS[mWaitCounter];
+ waitTimeMs = mWaitCounter < WAIT_TIMES_MS.length ?
+ WAIT_TIMES_MS[mWaitCounter] : 0;
mWaitCounter++;
}
try {
- sleep(waitTimeMs);
+ if (waitTimeMs > 0) {
+ sleep(waitTimeMs);
+ updateOrientation();
+ }
} catch (InterruptedException e) { }
}
}