From 97d507d95f9885ceb12f2ce2483361b5ed265f9f Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Mon, 25 Mar 2013 17:45:19 -0700 Subject: Avoid sending messages after HandlerThread.quit(). Bug: 8470658 Change-Id: I4cfd6a01c2c2d845a72d3f58c29eec8b44176537 --- .../android/providers/downloads/DownloadService.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/com/android') diff --git a/src/com/android/providers/downloads/DownloadService.java b/src/com/android/providers/downloads/DownloadService.java index 6c61193c..c519faaf 100644 --- a/src/com/android/providers/downloads/DownloadService.java +++ b/src/com/android/providers/downloads/DownloadService.java @@ -189,6 +189,7 @@ public class DownloadService extends Service { getContentResolver().unregisterContentObserver(mObserver); mScanner.shutdown(); mUpdateThread.quit(); + mUpdateThread = null; if (Constants.LOGVV) { Log.v(Constants.TAG, "Service onDestroy"); } @@ -199,8 +200,10 @@ public class DownloadService extends Service { * Enqueue an {@link #updateLocked()} pass to occur in future. */ private void enqueueUpdate() { - mUpdateHandler.removeMessages(MSG_UPDATE); - mUpdateHandler.obtainMessage(MSG_UPDATE, mLastStartId, -1).sendToTarget(); + if (mUpdateThread != null) { + mUpdateHandler.removeMessages(MSG_UPDATE); + mUpdateHandler.obtainMessage(MSG_UPDATE, mLastStartId, -1).sendToTarget(); + } } /** @@ -208,10 +211,12 @@ public class DownloadService extends Service { * catch any finished operations that didn't trigger an update pass. */ private void enqueueFinalUpdate() { - mUpdateHandler.removeMessages(MSG_FINAL_UPDATE); - mUpdateHandler.sendMessageDelayed( - mUpdateHandler.obtainMessage(MSG_FINAL_UPDATE, mLastStartId, -1), - 5 * MINUTE_IN_MILLIS); + if (mUpdateThread != null) { + mUpdateHandler.removeMessages(MSG_FINAL_UPDATE); + mUpdateHandler.sendMessageDelayed( + mUpdateHandler.obtainMessage(MSG_FINAL_UPDATE, mLastStartId, -1), + 5 * MINUTE_IN_MILLIS); + } } private static final int MSG_UPDATE = 1; @@ -269,6 +274,7 @@ public class DownloadService extends Service { if (stopSelfResult(startId)) { if (DEBUG_LIFECYCLE) Log.v(TAG, "Nothing left; stopped"); mUpdateThread.quit(); + mUpdateThread = null; } } -- cgit v1.2.3