Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 62674a2f authored by Winson Chung's avatar Winson Chung
Browse files

Fix issue with deferred start of the background loader.

- 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
parent 4bc839e2
Loading
Loading
Loading
Loading
+10 −4
Original line number Original line Diff line number Diff line
@@ -102,6 +102,7 @@ class BackgroundTaskLoader implements Runnable {
    Bitmap mDefaultThumbnail;
    Bitmap mDefaultThumbnail;
    BitmapDrawable mDefaultIcon;
    BitmapDrawable mDefaultIcon;


    boolean mStarted;
    boolean mCancelled;
    boolean mCancelled;
    boolean mWaitingOnLoadQueue;
    boolean mWaitingOnLoadQueue;


@@ -121,18 +122,23 @@ class BackgroundTaskLoader implements Runnable {
                android.os.Process.THREAD_PRIORITY_BACKGROUND);
                android.os.Process.THREAD_PRIORITY_BACKGROUND);
        mLoadThread.start();
        mLoadThread.start();
        mLoadThreadHandler = new Handler(mLoadThread.getLooper());
        mLoadThreadHandler = new Handler(mLoadThread.getLooper());
        mLoadThreadHandler.post(this);
    }
    }


    /** Restarts the loader thread */
    /** Restarts the loader thread */
    void start(Context context) {
    void start(Context context) {
        mContext = context;
        mContext = context;
        mCancelled = false;
        mCancelled = false;
        // Notify the load thread to start loading
        if (!mStarted) {
            // Start loading on the load thread
            mStarted = true;
            mLoadThreadHandler.post(this);
        } else {
            // Notify the load thread to start loading again
            synchronized (mLoadThread) {
            synchronized (mLoadThread) {
                mLoadThread.notifyAll();
                mLoadThread.notifyAll();
            }
            }
        }
        }
    }


    /** Requests the loader thread to stop after the current iteration */
    /** Requests the loader thread to stop after the current iteration */
    void stop() {
    void stop() {