OSDN Git Service

Fix issue with deferred start of the background loader.
authorWinson Chung <winsonc@google.com>
Tue, 16 May 2017 23:57:18 +0000 (16:57 -0700)
committerWinson Chung <winsonc@google.com>
Tue, 16 May 2017 23:58:30 +0000 (16:58 -0700)
- Previously we were (incorrectly) assuming that the creation of the
  BackgroundTaskLoader would be followed synchronously by a call to start()
  the background loader itself.  However, now that we post the start of
  the loader, the run() call can be made before the start() call.

Bug: 38310660
Test: This is an intermittent bug, hard to repro.
Change-Id: I4dfd18b8c3c127429c790177e98ca41ec70f493d

packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoader.java

index 97a9659..e2ee263 100644 (file)
@@ -102,6 +102,7 @@ class BackgroundTaskLoader implements Runnable {
     Bitmap mDefaultThumbnail;
     BitmapDrawable mDefaultIcon;
 
+    boolean mStarted;
     boolean mCancelled;
     boolean mWaitingOnLoadQueue;
 
@@ -121,16 +122,21 @@ class BackgroundTaskLoader implements Runnable {
                 android.os.Process.THREAD_PRIORITY_BACKGROUND);
         mLoadThread.start();
         mLoadThreadHandler = new Handler(mLoadThread.getLooper());
-        mLoadThreadHandler.post(this);
     }
 
     /** Restarts the loader thread */
     void start(Context context) {
         mContext = context;
         mCancelled = false;
-        // Notify the load thread to start loading
-        synchronized(mLoadThread) {
-            mLoadThread.notifyAll();
+        if (!mStarted) {
+            // Start loading on the load thread
+            mStarted = true;
+            mLoadThreadHandler.post(this);
+        } else {
+            // Notify the load thread to start loading again
+            synchronized (mLoadThread) {
+                mLoadThread.notifyAll();
+            }
         }
     }