From dd1179c09fb6ac2420292e52ea3ced395f76a7be Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Wed, 20 Feb 2013 16:10:39 -0800 Subject: Ack, we actually need to UpdateThread.quit(). Otherwise they end up leaking. There is a race around UpdateThread continuing to process messages before onDestroy() has been invoked, so explicitly UpdateThread.quit() in both places. Bug: 8233041 Change-Id: I73f1b70aedace19e23a61a3dddf4986d82f2c7d6 --- src/com/android/providers/downloads/DownloadService.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/com/android/providers/downloads') diff --git a/src/com/android/providers/downloads/DownloadService.java b/src/com/android/providers/downloads/DownloadService.java index 20cf6294..c8e55d7d 100644 --- a/src/com/android/providers/downloads/DownloadService.java +++ b/src/com/android/providers/downloads/DownloadService.java @@ -158,11 +158,9 @@ public class DownloadService extends Service { mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mStorageManager = new StorageManager(this); - if (mUpdateThread == null) { - mUpdateThread = new HandlerThread(TAG + "-UpdateThread"); - mUpdateThread.start(); - mUpdateHandler = new Handler(mUpdateThread.getLooper(), mUpdateCallback); - } + mUpdateThread = new HandlerThread(TAG + "-UpdateThread"); + mUpdateThread.start(); + mUpdateHandler = new Handler(mUpdateThread.getLooper(), mUpdateCallback); mScanner = new DownloadScanner(this); @@ -187,8 +185,9 @@ public class DownloadService extends Service { @Override public void onDestroy() { - mScanner.shutdown(); getContentResolver().unregisterContentObserver(mObserver); + mScanner.shutdown(); + mUpdateThread.quit(); if (Constants.LOGVV) { Log.v(Constants.TAG, "Service onDestroy"); } @@ -257,8 +256,7 @@ public class DownloadService extends Service { if (stopSelfResult(startId)) { if (DEBUG_LIFECYCLE) Log.v(TAG, "Nothing left; stopped"); - mUpdateHandler.removeMessages(MSG_UPDATE); - mUpdateHandler.removeMessages(MSG_FINAL_UPDATE); + mUpdateThread.quit(); } } -- cgit v1.2.3