From a1e79948ecf1057fe91733baac2759ea91cc1894 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Wed, 2 Aug 2017 14:24:35 -0600 Subject: [PATCH] Give DeviceStorageMonitorService it's own thread. When devices are low on space, it calls down into installd to clear cached files, which can block for a long time. Instead of risking the wrath of the Watchdog on IoThread, give ourselves a separate thread. Test: builds, boots Bug: 64080821 Change-Id: Iaca00966bb836d58e8d2400d6c9d544023ef1af8 --- .../storage/DeviceStorageMonitorService.java | 31 ++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java b/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java index 88b6d870afd7..a35383f385f2 100644 --- a/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java +++ b/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java @@ -29,6 +29,7 @@ import android.os.Binder; import android.os.Environment; import android.os.FileObserver; import android.os.Handler; +import android.os.HandlerThread; import android.os.Message; import android.os.ResultReceiver; import android.os.ServiceManager; @@ -154,20 +155,8 @@ public class DeviceStorageMonitorService extends SystemService { private static final String TV_NOTIFICATION_CHANNEL_ID = "devicestoragemonitor.tv"; - /** - * Handler that checks the amount of disk space on the device and sends a - * notification if the device runs low on disk space - */ - private final Handler mHandler = new Handler(IoThread.get().getLooper()) { - @Override - public void handleMessage(Message msg) { - switch (msg.what) { - case MSG_CHECK: - check(); - return; - } - } - }; + private final HandlerThread mHandlerThread; + private final Handler mHandler; private State findOrCreateState(UUID uuid) { State state = mStates.get(uuid); @@ -256,6 +245,20 @@ public class DeviceStorageMonitorService extends SystemService { public DeviceStorageMonitorService(Context context) { super(context); + + mHandlerThread = new HandlerThread(TAG, android.os.Process.THREAD_PRIORITY_BACKGROUND); + mHandlerThread.start(); + + mHandler = new Handler(mHandlerThread.getLooper()) { + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case MSG_CHECK: + check(); + return; + } + } + }; } private static boolean isBootImageOnDisk() { -- 2.11.0