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

Commit ee804af7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fixing bindAllApplications scheduled with null list." into ub-launcher3-dorval-polish2

parents 1d2eaa76 49fc3f7a
Loading
Loading
Loading
Loading
+23 −35
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
import com.android.launcher3.util.ActivityResultInfo;
import com.android.launcher3.util.RunnableWithId;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.MultiHashMap;
@@ -146,6 +147,9 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.Executor;

import static com.android.launcher3.util.RunnableWithId.RUNNABLE_ID_BIND_APPS;
import static com.android.launcher3.util.RunnableWithId.RUNNABLE_ID_BIND_WIDGETS;

/**
 * Default launcher application.
 */
@@ -246,7 +250,6 @@ public class Launcher extends BaseActivity

    // Main container view and the model for the widget tray screen.
    @Thunk WidgetsContainerView mWidgetsView;
    @Thunk MultiHashMap<PackageItemInfo, WidgetItem> mAllWidgets;

    // We set the state in both onCreate and then onNewIntent in some cases, which causes both
    // scroll issues (because the workspace may not have been measured yet) and extra work.
@@ -3113,12 +3116,12 @@ public class Launcher extends BaseActivity
     *
     * @return {@code true} if we are currently paused. The caller might be able to skip some work
     */
    @Thunk boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
    @Thunk boolean waitUntilResume(Runnable run) {
        if (mPaused) {
            if (LOGD) Log.d(TAG, "Deferring update until onResume");
            if (deletePreviousRunnables) {
                while (mBindOnResumeCallbacks.remove(run)) {
                }
            if (run instanceof RunnableWithId) {
                // Remove any runnables which have the same id
                while (mBindOnResumeCallbacks.remove(run)) { }
            }
            mBindOnResumeCallbacks.add(run);
            return true;
@@ -3127,10 +3130,6 @@ public class Launcher extends BaseActivity
        }
    }

    private boolean waitUntilResume(Runnable run) {
        return waitUntilResume(run, false);
    }

    public void addOnResumeCallback(Runnable run) {
        mOnResumeCallbacks.add(run);
    }
@@ -3663,26 +3662,18 @@ public class Launcher extends BaseActivity
        return LauncherCallbacks.SEARCH_BAR_HEIGHT_NORMAL;
    }

    /**
     * A runnable that we can dequeue and re-enqueue when all applications are bound (to prevent
     * multiple calls to bind the same list.)
     */
    @Thunk ArrayList<AppInfo> mTmpAppsList;
    private final Runnable mBindAllApplicationsRunnable = new Runnable() {
        public void run() {
            bindAllApplications(mTmpAppsList);
            mTmpAppsList = null;
        }
    };

    /**
     * Add the icons for all apps.
     *
     * Implementation of the method from LauncherModel.Callbacks.
     */
    public void bindAllApplications(final ArrayList<AppInfo> apps) {
        if (waitUntilResume(mBindAllApplicationsRunnable, true)) {
            mTmpAppsList = apps;
        Runnable r = new RunnableWithId(RUNNABLE_ID_BIND_APPS) {
            public void run() {
                bindAllApplications(apps);
            }
        };
        if (waitUntilResume(r)) {
            return;
        }

@@ -3690,10 +3681,10 @@ public class Launcher extends BaseActivity
            Executor pendingExecutor = getPendingExecutor();
            if (pendingExecutor != null && mState != State.APPS) {
                // Wait until the fade in animation has finished before setting all apps list.
                mTmpAppsList = apps;
                pendingExecutor.execute(mBindAllApplicationsRunnable);
                pendingExecutor.execute(r);
                return;
            }

            mAppsView.setApps(apps);
        }
        if (mLauncherCallbacks != null) {
@@ -3887,28 +3878,25 @@ public class Launcher extends BaseActivity
        }
    }

    private final Runnable mBindAllWidgetsRunnable = new Runnable() {
    @Override
    public void bindAllWidgets(final MultiHashMap<PackageItemInfo, WidgetItem> allWidgets) {
        Runnable r = new RunnableWithId(RUNNABLE_ID_BIND_WIDGETS) {
            @Override
            public void run() {
                bindAllWidgets(mAllWidgets);
                bindAllWidgets(allWidgets);
            }
        };

    @Override
    public void bindAllWidgets(MultiHashMap<PackageItemInfo, WidgetItem> allWidgets) {
        if (waitUntilResume(mBindAllWidgetsRunnable, true)) {
            mAllWidgets = allWidgets;
        if (waitUntilResume(r)) {
            return;
        }

        if (mWidgetsView != null && allWidgets != null) {
            Executor pendingExecutor = getPendingExecutor();
            if (pendingExecutor != null && mState != State.WIDGETS) {
                mAllWidgets = allWidgets;
                pendingExecutor.execute(mBindAllWidgetsRunnable);
                pendingExecutor.execute(r);
                return;
            }
            mWidgetsView.setWidgets(allWidgets);
            mAllWidgets = null;
        }

        AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this);
+36 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.launcher3.util;

/**
 * A runnable with an id associated which is used for equality check.
 */
public abstract class RunnableWithId implements Runnable {

    public static final int RUNNABLE_ID_BIND_APPS = 1;
    public static final int RUNNABLE_ID_BIND_WIDGETS = 2;

    public final int id;

    public RunnableWithId(int id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object obj) {
        return obj instanceof RunnableWithId && ((RunnableWithId) obj).id == id;
    }
}