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

Commit 29947f0b authored by Sunny Goyal's avatar Sunny Goyal
Browse files

No more waiting around for resume

Apply model updates as son as they arrive instead of waiting for onResume.
Various workspace items do not use any configuration dependent resources.
For Widgets, we wait until the host starts lietening before inflating the actual view.

Change-Id: Icb2f5e5940c1ce6c27062ccd34eff87e80af5ab1
parent e15e2a82
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2015, 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.
*/
-->

<inset
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:inset="8dp">
    <color android:color="#77000000" />
</inset>
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import android.view.ViewGroup;
import com.android.launcher3.accessibility.DragViewStateAnnouncer;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.util.FocusLogic;
import com.android.launcher3.widget.LauncherAppWidgetHostView;

public class AppWidgetResizeFrame extends AbstractFloatingView implements View.OnKeyListener {
    private static final int SNAP_DURATION = 150;
+1 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import com.android.launcher3.util.GridOccupancy;
import com.android.launcher3.util.ParcelableSparseArray;
import com.android.launcher3.util.Themes;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.widget.LauncherAppWidgetHostView;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+22 −218
Original line number Diff line number Diff line
@@ -29,8 +29,6 @@ import static com.android.launcher3.LauncherState.ALL_APPS;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
import static com.android.launcher3.util.RunnableWithId.RUNNABLE_ID_BIND_APPS;
import static com.android.launcher3.util.RunnableWithId.RUNNABLE_ID_BIND_WIDGETS;

import android.Manifest;
import android.animation.Animator;
@@ -127,15 +125,16 @@ import com.android.launcher3.util.MultiHashMap;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.PendingRequestArgs;
import com.android.launcher3.util.RunnableWithId;
import com.android.launcher3.util.SystemUiController;
import com.android.launcher3.util.Themes;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.util.TraceHelper;
import com.android.launcher3.util.UiThreadHelper;
import com.android.launcher3.util.ViewOnDrawExecutor;
import com.android.launcher3.widget.LauncherAppWidgetHostView;
import com.android.launcher3.widget.PendingAddShortcutInfo;
import com.android.launcher3.widget.PendingAddWidgetInfo;
import com.android.launcher3.widget.PendingAppWidgetHostView;
import com.android.launcher3.widget.WidgetAddFlowHandler;
import com.android.launcher3.widget.WidgetHostViewLoader;
import com.android.launcher3.widget.WidgetListRowEntry;
@@ -237,9 +236,7 @@ public class Launcher extends BaseActivity
    @Thunk boolean mWorkspaceLoading = true;

    private boolean mPaused = true;
    private boolean mOnResumeNeedsLoad;

    private final ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<>();
    private OnResumeCallback mOnResumeCallback;

    private ViewOnDrawExecutor mPendingExecutor;
@@ -811,20 +808,6 @@ public class Launcher extends BaseActivity
        mAppLaunchSuccess = false;
        getUserEventDispatcher().resetElapsedSessionMillis();
        mPaused = false;
        if (mOnResumeNeedsLoad) {
            setWorkspaceLoading(true);
            mModel.startLoader(getCurrentWorkspaceScreen());
            mOnResumeNeedsLoad = false;
        }
        if (mBindOnResumeCallbacks.size() > 0) {
            // We might have postponed some bind calls until onResume (see waitUntilResume) --
            // execute them here
            for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
                mBindOnResumeCallbacks.get(i).run();
            }
            mBindOnResumeCallbacks.clear();
        }

        setOnResumeCallback(null);
        // Process any items that were added while Launcher was away.
        InstallShortcutReceiver.disableAndFlushInstallQueue(
@@ -1161,9 +1144,6 @@ public class Launcher extends BaseActivity
    };

    public void updateIconBadges(final Set<PackageUserKey> updatedBadges) {
        Runnable r = new Runnable() {
            @Override
            public void run() {
        mWorkspace.updateIconBadges(updatedBadges);
        mAppsView.updateIconBadges(updatedBadges);

@@ -1172,11 +1152,6 @@ public class Launcher extends BaseActivity
            popup.updateNotificationHeader(updatedBadges);
        }
    }
        };
        if (!waitUntilResume(r)) {
            r.run();
        }
    }

    @Override
    public void onAttachedToWindow() {
@@ -2156,33 +2131,6 @@ public class Launcher extends BaseActivity
        return result;
    }

    /**
     * If the activity is currently paused, signal that we need to run the passed Runnable
     * in onResume.
     *
     * This needs to be called from incoming places where resources might have been loaded
     * while the activity is paused. That is because the Configuration (e.g., rotation)  might be
     * wrong when we're not running, and if the activity comes back to what the configuration was
     * when we were paused, activity is not restarted.
     *
     * Implementation of the method from LauncherModel.Callbacks.
     *
     * @return {@code true} if we are currently paused. The caller might be able to skip some work
     */
    @Thunk boolean waitUntilResume(Runnable run) {
        if (mPaused) {
            if (LOGD) Log.d(TAG, "Deferring update until onResume");
            if (run instanceof RunnableWithId) {
                // Remove any runnables which have the same id
                while (mBindOnResumeCallbacks.remove(run)) { }
            }
            mBindOnResumeCallbacks.add(run);
            return true;
        } else {
            return false;
        }
    }

    public void setOnResumeCallback(OnResumeCallback callback) {
        if (mOnResumeCallback != null) {
            mOnResumeCallback.onLauncherResume();
@@ -2190,31 +2138,6 @@ public class Launcher extends BaseActivity
        mOnResumeCallback = callback;
    }

    /**
     * If the activity is currently paused, signal that we need to re-run the loader
     * in onResume.
     *
     * This needs to be called from incoming places where resources might have been loaded
     * while we are paused.  That is becaues the Configuration might be wrong
     * when we're not running, and if it comes back to what it was when we
     * were paused, we are not restarted.
     *
     * Implementation of the method from LauncherModel.Callbacks.
     *
     * @return true if we are currently paused.  The caller might be able to
     * skip some work in that case since we will come back again.
     */
    @Override
    public boolean setLoadOnResume() {
        if (mPaused) {
            if (LOGD) Log.d(TAG, "setLoadOnResume");
            mOnResumeNeedsLoad = true;
            return true;
        } else {
            return false;
        }
    }

    /**
     * Implementation of the method from LauncherModel.Callbacks.
     */
@@ -2233,7 +2156,6 @@ public class Launcher extends BaseActivity
     */
    @Override
    public void clearPendingBinds() {
        mBindOnResumeCallbacks.clear();
        if (mPendingExecutor != null) {
            mPendingExecutor.markCompleted();
            mPendingExecutor = null;
@@ -2297,18 +2219,8 @@ public class Launcher extends BaseActivity
    }

    @Override
    public void bindAppsAdded(final ArrayList<Long> newScreens,
                              final ArrayList<ItemInfo> addNotAnimated,
                              final ArrayList<ItemInfo> addAnimated) {
        Runnable r = new Runnable() {
            public void run() {
                bindAppsAdded(newScreens, addNotAnimated, addAnimated);
            }
        };
        if (waitUntilResume(r)) {
            return;
        }

    public void bindAppsAdded(ArrayList<Long> newScreens, ArrayList<ItemInfo> addNotAnimated,
            ArrayList<ItemInfo> addAnimated) {
        // Add the new screens
        if (newScreens != null) {
            bindAddScreens(newScreens);
@@ -2334,15 +2246,6 @@ public class Launcher extends BaseActivity
     */
    @Override
    public void bindItems(final List<ItemInfo> items, final boolean forceAnimateIcons) {
        Runnable r = new Runnable() {
            public void run() {
                bindItems(items, forceAnimateIcons);
            }
        };
        if (waitUntilResume(r)) {
            return;
        }

        // Get the list of added items and intersect them with the set of items here
        final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
        final Collection<Animator> bounceAnims = new ArrayList<>();
@@ -2585,7 +2488,7 @@ public class Launcher extends BaseActivity
        }

        if (((PendingAppWidgetHostView) view).isReinflateIfNeeded()) {
            view.reinflate();
            view.reInflate();
        }

        getModelWriter().updateItemInDatabase(info);
@@ -2613,27 +2516,11 @@ public class Launcher extends BaseActivity

    @Override
    public void finishFirstPageBind(final ViewOnDrawExecutor executor) {
        Runnable r = new Runnable() {
            public void run() {
                finishFirstPageBind(executor);
            }
        };
        if (waitUntilResume(r)) {
            return;
        }

        Runnable onComplete = new Runnable() {
            @Override
            public void run() {
                if (executor != null) {
                    executor.onLoadAnimationCompleted();
                }
            }
        };
        if (mDragLayer.getAlpha() < 1) {
            mDragLayer.animate().alpha(1).withEndAction(onComplete).start();
        } else {
            onComplete.run();
            mDragLayer.animate().alpha(1).withEndAction(
                    executor == null ? null : executor::onLoadAnimationCompleted).start();
        } else if (executor != null) {
            executor.onLoadAnimationCompleted();
        }
    }

@@ -2643,10 +2530,6 @@ public class Launcher extends BaseActivity
     * Implementation of the method from LauncherModel.Callbacks.
     */
    public void finishBindingItems() {
        Runnable r = this::finishBindingItems;
        if (waitUntilResume(r)) {
            return;
        }
        TraceHelper.beginSection("finishBindingItems");
        mWorkspace.restoreInstanceStateForRemainingPages();

@@ -2687,21 +2570,12 @@ public class Launcher extends BaseActivity
     *
     * Implementation of the method from LauncherModel.Callbacks.
     */
    public void bindAllApplications(final ArrayList<AppInfo> apps) {
        Runnable r = new RunnableWithId(RUNNABLE_ID_BIND_APPS) {
            public void run() {
                bindAllApplications(apps);
            }
        };
        if (waitUntilResume(r)) {
            return;
        }

    public void bindAllApplications(ArrayList<AppInfo> apps) {
        if (mAppsView != null) {
            Executor pendingExecutor = getPendingExecutor();
            if (pendingExecutor != null && !isInState(ALL_APPS)) {
                // Wait until the fade in animation has finished before setting all apps list.
                pendingExecutor.execute(r);
                pendingExecutor.execute(() -> bindAllApplications(apps));
                return;
            }

@@ -2734,47 +2608,22 @@ public class Launcher extends BaseActivity
     *
     * Implementation of the method from LauncherModel.Callbacks.
     */
    public void bindAppsAddedOrUpdated(final ArrayList<AppInfo> apps) {
        Runnable r = new Runnable() {
            public void run() {
                bindAppsAddedOrUpdated(apps);
            }
        };
        if (waitUntilResume(r)) {
            return;
        }

    @Override
    public void bindAppsAddedOrUpdated(ArrayList<AppInfo> apps) {
        if (mAppsView != null) {
            mAppsView.addOrUpdateApps(apps);
        }
    }

    @Override
    public void bindPromiseAppProgressUpdated(final PromiseAppInfo app) {
        Runnable r = new Runnable() {
            public void run() {
                bindPromiseAppProgressUpdated(app);
            }
        };
        if (waitUntilResume(r)) {
            return;
        }

    public void bindPromiseAppProgressUpdated(PromiseAppInfo app) {
        if (mAppsView != null) {
            mAppsView.updatePromiseAppProgress(app);
        }
    }

    @Override
    public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) {
        Runnable r = new Runnable() {
            public void run() {
                bindWidgetsRestored(widgets);
            }
        };
        if (waitUntilResume(r)) {
            return;
        }
    public void bindWidgetsRestored(ArrayList<LauncherAppWidgetInfo> widgets) {
        mWorkspace.widgetsRestored(widgets);
    }

@@ -2785,16 +2634,7 @@ public class Launcher extends BaseActivity
     * @param updated list of shortcuts which have changed.
     */
    @Override
    public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated, final UserHandle user) {
        Runnable r = new Runnable() {
            public void run() {
                bindShortcutsChanged(updated, user);
            }
        };
        if (waitUntilResume(r)) {
            return;
        }

    public void bindShortcutsChanged(ArrayList<ShortcutInfo> updated, final UserHandle user) {
        if (!updated.isEmpty()) {
            mWorkspace.updateShortcuts(updated);
        }
@@ -2806,16 +2646,7 @@ public class Launcher extends BaseActivity
     * Implementation of the method from LauncherModel.Callbacks.
     */
    @Override
    public void bindRestoreItemsChange(final HashSet<ItemInfo> updates) {
        Runnable r = new Runnable() {
            public void run() {
                bindRestoreItemsChange(updates);
            }
        };
        if (waitUntilResume(r)) {
            return;
        }

    public void bindRestoreItemsChange(HashSet<ItemInfo> updates) {
        mWorkspace.updateRestoreItems(updates);
    }

@@ -2828,29 +2659,12 @@ public class Launcher extends BaseActivity
     */
    @Override
    public void bindWorkspaceComponentsRemoved(final ItemInfoMatcher matcher) {
        Runnable r = new Runnable() {
            public void run() {
                bindWorkspaceComponentsRemoved(matcher);
            }
        };
        if (waitUntilResume(r)) {
            return;
        }
        mWorkspace.removeItemsByMatcher(matcher);
        mDragController.onAppsRemoved(matcher);
    }

    @Override
    public void bindAppInfosRemoved(final ArrayList<AppInfo> appInfos) {
        Runnable r = new Runnable() {
            public void run() {
                bindAppInfosRemoved(appInfos);
            }
        };
        if (waitUntilResume(r)) {
            return;
        }

        // Update AllApps
        if (mAppsView != null) {
            mAppsView.removeApps(appInfos);
@@ -2860,16 +2674,6 @@ public class Launcher extends BaseActivity
    @Override
    public void bindAllWidgets(final ArrayList<WidgetListRowEntry> allWidgets) {
        mPopupDataProvider.setAllWidgets(allWidgets);
        Runnable r = new RunnableWithId(RUNNABLE_ID_BIND_WIDGETS) {
            @Override
            public void run() {
                bindAllWidgets(allWidgets);
            }
        };
        if (waitUntilResume(r)) {
            return;
        }

        AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this);
        if (topView != null) {
            topView.onWidgetsBound();
+7 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.util.Log;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.PackageInstallerCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.notification.NotificationListener;
import com.android.launcher3.util.ConfigMonitor;
import com.android.launcher3.util.Preconditions;
@@ -39,6 +40,8 @@ import static com.android.launcher3.SettingsActivity.NOTIFICATION_BADGING;

public class LauncherAppState {

    public static final String ACTION_FORCE_ROLOAD = "force-reload-launcher";

    // We do not need any synchronization for this variable as its only written on UI thread.
    private static LauncherAppState INSTANCE;

@@ -103,6 +106,10 @@ public class LauncherAppState {
        filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
        filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNLOCKED);

        if (FeatureFlags.IS_DOGFOOD_BUILD) {
            filter.addAction(ACTION_FORCE_ROLOAD);
        }

        mContext.registerReceiver(mModel, filter);
        UserManagerCompat.getInstance(mContext).enableAndResetCache();
        new ConfigMonitor(mContext).register();
Loading