summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxshu <xshu@google.com>2019-12-02 14:39:55 -0800
committerOscar Shu <xshu@google.com>2019-12-04 18:25:58 +0000
commitb113e7f7d5b3e3d64f6bcb98de29c1a331008118 (patch)
tree730119fc2d039cc6fe719d389949d508c4fb8fc0
parent2674f15734493eebb98528982908e398255d9e4e (diff)
downloadandroid_frameworks_opt_net_wifi-b113e7f7d5b3e3d64f6bcb98de29c1a331008118.tar.gz
android_frameworks_opt_net_wifi-b113e7f7d5b3e3d64f6bcb98de29c1a331008118.tar.bz2
android_frameworks_opt_net_wifi-b113e7f7d5b3e3d64f6bcb98de29c1a331008118.zip
Fix race in StaEvents metrics collection
A race is happening because one part of StaEventList modification is current unprotected, and we have 2 different threads that trigger StaEventList modifications: - Thread 1: Binder thread -> dump() -> clearing StaEventList - Thread 2: WifiLooper -> addStaEvent() -> may result in removing first element if StaEventList if 'full' Bug: 145673220 Test: atest FrameworksWifiTests Change-Id: Id390bae9a9a661900073195fd1224106a03273ee Merged-In: Id390bae9a9a661900073195fd1224106a03273ee (cherry picked from commit df3b786149d9a86fdc247ec9cc7910e6b98de1cf)
-rw-r--r--service/java/com/android/server/wifi/WifiMetrics.java8
1 files changed, 5 insertions, 3 deletions
diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java
index 2e9e34c07..7578d3723 100644
--- a/service/java/com/android/server/wifi/WifiMetrics.java
+++ b/service/java/com/android/server/wifi/WifiMetrics.java
@@ -3791,9 +3791,11 @@ public class WifiMetrics {
mLastScore = -1;
mLastWifiUsabilityScore = -1;
mLastPredictionHorizonSec = -1;
- mStaEventList.add(new StaEventWithTime(staEvent, mClock.getWallClockMillis()));
- // Prune StaEventList if it gets too long
- if (mStaEventList.size() > MAX_STA_EVENTS) mStaEventList.remove();
+ synchronized (mLock) {
+ mStaEventList.add(new StaEventWithTime(staEvent, mClock.getWallClockMillis()));
+ // Prune StaEventList if it gets too long
+ if (mStaEventList.size() > MAX_STA_EVENTS) mStaEventList.remove();
+ }
}
private ConfigInfo createConfigInfo(WifiConfiguration config) {