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

Commit 51f220da authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Fixing ANR when loader task could run while helding the lock object

During AppWidgetRestoredReceiver, we call forceReload from worker thread
which in turn starts the loader while holding mLock. This causes other
loader calls on UI thread to cause ANR

Bug: 133651528
Change-Id: Iabf983c4319bd6e6ef88e74fe6076289294454f9
parent 5860288f
Loading
Loading
Loading
Loading
+11 −13
Original line number Diff line number Diff line
@@ -165,17 +165,6 @@ public class LauncherModel extends BroadcastReceiver
        mBgAllAppsList = new AllAppsList(iconCache, appFilter);
    }

    /** Runs the specified runnable immediately if called from the worker thread, otherwise it is
     * posted on the worker thread handler. */
    private static void runOnWorkerThread(Runnable r) {
        if (sWorkerThread.getThreadId() == Process.myTid()) {
            r.run();
        } else {
            // If we are not on the worker thread, then post to the worker handler
            sWorker.post(r);
        }
    }

    public void setPackageState(PackageInstallInfo installInfo) {
        enqueueModelUpdateTask(new PackageInstallStateChangedTask(installInfo));
    }
@@ -400,7 +389,10 @@ public class LauncherModel extends BroadcastReceiver
        synchronized (mLock) {
            stopLoader();
            mLoaderTask = new LoaderTask(mApp, mBgAllAppsList, sBgDataModel, results);
            runOnWorkerThread(mLoaderTask);

            // Always post the loader task, instead of running directly (even on same thread) so
            // that we exit any nested synchronized blocks
            sWorker.post(mLoaderTask);
        }
    }

@@ -505,7 +497,13 @@ public class LauncherModel extends BroadcastReceiver

    public void enqueueModelUpdateTask(ModelUpdateTask task) {
        task.init(mApp, this, sBgDataModel, mBgAllAppsList, mUiExecutor);
        runOnWorkerThread(task);

        if (sWorkerThread.getThreadId() == Process.myTid()) {
            task.run();
        } else {
            // If we are not on the worker thread, then post to the worker handler
            sWorker.post(task);
        }
    }

    /**