From 20b84dfa59190bfef04aac6dc8fb90c9bac5f21b Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Tue, 19 Apr 2016 17:33:33 -0700 Subject: Move batterystats stats collection to its own thread Too many other tasks run on common handlers, and the batterystats collection may block waiting for a timeout of up to 2 seconds. Bug:27857665 Change-Id: I5be1ddc374d69620f4f7d821eb29e8524294c9a4 --- .../core/java/com/android/server/am/BatteryStatsService.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java index 6cd6ff43b5ce..2516f5df4cbf 100644 --- a/services/core/java/com/android/server/am/BatteryStatsService.java +++ b/services/core/java/com/android/server/am/BatteryStatsService.java @@ -58,8 +58,8 @@ import com.android.internal.app.IBatteryStats; import com.android.internal.os.BatteryStatsHelper; import com.android.internal.os.BatteryStatsImpl; import com.android.internal.os.PowerProfile; -import com.android.server.FgThread; import com.android.server.LocalServices; +import com.android.server.ServiceThread; import java.io.File; import java.io.FileDescriptor; @@ -176,7 +176,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub BatteryStatsService(File systemDir, Handler handler) { // Our handler here will be accessing the disk, use a different thread than // what the ActivityManagerService gave us (no I/O on that one!). - mHandler = new BatteryStatsHandler(FgThread.getHandler().getLooper()); + final ServiceThread thread = new ServiceThread("batterystats-sync", + Process.THREAD_PRIORITY_DEFAULT, true); + thread.start(); + mHandler = new BatteryStatsHandler(thread.getLooper()); // BatteryStatsImpl expects the ActivityManagerService handler, so pass that one through. mStats = new BatteryStatsImpl(systemDir, handler, mHandler); @@ -209,6 +212,9 @@ public final class BatteryStatsService extends IBatteryStats.Stub synchronized (mStats) { mStats.shutdownLocked(); } + + // Shutdown the thread we made. + mHandler.getLooper().quit(); } public static IBatteryStats getService() { -- cgit v1.2.3-59-g8ed1b