From ef0904eac06a3ad43125d5f259c2d2f619bb846c Mon Sep 17 00:00:00 2001 From: Ruchir Rastogi Date: Wed, 3 Jun 2020 17:29:46 -0700 Subject: Move GnssStats puller to binder thread Pass direct executor to setPullAtomCallback. This causes the puller to run directly on the binder thread, as opposed to the Background thread, which could be busy with other work. This change means that the puller can be executed concurrently. To properly handle that, the Statistics class is made thread-safe. Test: adb shell cmd stats pull-source 10074 Bug: 157186182 Change-Id: I6c0940fd4ed231f9d962981cc1f9e8c983c48f7f --- .../internal/location/gnssmetrics/GnssMetrics.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'location') diff --git a/location/java/com/android/internal/location/gnssmetrics/GnssMetrics.java b/location/java/com/android/internal/location/gnssmetrics/GnssMetrics.java index 450ddc10deda..6c401161062f 100644 --- a/location/java/com/android/internal/location/gnssmetrics/GnssMetrics.java +++ b/location/java/com/android/internal/location/gnssmetrics/GnssMetrics.java @@ -32,7 +32,7 @@ import android.util.TimeUtils; import com.android.internal.app.IBatteryStats; import com.android.internal.location.nano.GnssLogsProto.GnssLog; import com.android.internal.location.nano.GnssLogsProto.PowerMetrics; -import com.android.internal.os.BackgroundThread; +import com.android.internal.util.ConcurrentUtils; import com.android.internal.util.FrameworkStatsLog; import java.util.ArrayList; @@ -465,7 +465,7 @@ public class GnssMetrics { mConstellationTypes = new boolean[GnssStatus.CONSTELLATION_COUNT]; } - /** Class for storing statistics */ + /** Thread-safe class for storing statistics */ private static class Statistics { private int mCount; @@ -474,7 +474,7 @@ public class GnssMetrics { private long mLongSum; /** Resets statistics */ - public void reset() { + public synchronized void reset() { mCount = 0; mSum = 0.0; mSumSquare = 0.0; @@ -482,7 +482,7 @@ public class GnssMetrics { } /** Adds an item */ - public void addItem(double item) { + public synchronized void addItem(double item) { mCount++; mSum += item; mSumSquare += item * item; @@ -490,17 +490,17 @@ public class GnssMetrics { } /** Returns number of items added */ - public int getCount() { + public synchronized int getCount() { return mCount; } /** Returns mean */ - public double getMean() { + public synchronized double getMean() { return mSum / mCount; } /** Returns standard deviation */ - public double getStandardDeviation() { + public synchronized double getStandardDeviation() { double m = mSum / mCount; m = m * m; double v = mSumSquare / mCount; @@ -511,7 +511,7 @@ public class GnssMetrics { } /** Returns long sum */ - public long getLongSum() { + public synchronized long getLongSum() { return mLongSum; } } @@ -625,7 +625,7 @@ public class GnssMetrics { mStatsManager.setPullAtomCallback( FrameworkStatsLog.GNSS_STATS, null, // use default PullAtomMetadata values - BackgroundThread.getExecutor(), pullAtomCallback); + ConcurrentUtils.DIRECT_EXECUTOR, pullAtomCallback); } /** -- cgit v1.2.3