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

Commit e9c6f4cc authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Fixing interactive state for background states and

notifying LauncherCallback accordingly

During quick switch Launcher can get resumed only to be paused again
when launching a new app. Updating the logic for deferred resume to
account for that and moving some additional calls to deferredResume

Bug: 134062513
Change-Id: Ia607f178bc17d45d53fb032a06cd70f9abc6b513
parent f07cf179
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -32,7 +32,8 @@ import com.android.quickstep.views.TaskView;
public class BackgroundAppState extends OverviewState {

    private static final int STATE_FLAGS =
            FLAG_DISABLE_RESTORE | FLAG_OVERVIEW_UI | FLAG_DISABLE_ACCESSIBILITY;
            FLAG_DISABLE_RESTORE | FLAG_OVERVIEW_UI | FLAG_DISABLE_ACCESSIBILITY
                    | FLAG_DISABLE_INTERACTION;

    public BackgroundAppState(int id) {
        this(id, LauncherLogProto.ContainerType.TASKSWITCHER);
+23 −15
Original line number Diff line number Diff line
@@ -277,6 +277,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,

    final Handler mHandler = new Handler();
    private final Runnable mHandleDeferredResume = this::handleDeferredResume;
    private boolean mDeferredResumePending;

    private float mCurrentAssistantVisibility = 0f;

@@ -890,26 +891,40 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
    }

    private void handleDeferredResume() {
        if (hasBeenResumed()) {
        if (hasBeenResumed() && !mStateManager.getState().disableInteraction) {
            getUserEventDispatcher().logActionCommand(Action.Command.RESUME,
                    mStateManager.getState().containerType, -1);
            getUserEventDispatcher().startSession();

            UiFactory.onLauncherStateOrResumeChanged(this);
            AppLaunchTracker.INSTANCE.get(this).onReturnedToHome();
            resetPendingActivityResultIfNeeded();
        }
    }

    private void resetPendingActivityResultIfNeeded() {
        if (hasBeenResumed() && mPendingActivityRequestCode != -1 && isInState(NORMAL)) {
            // Process any items that were added while Launcher was away.
            InstallShortcutReceiver.disableAndFlushInstallQueue(
                    InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED, this);

            // Refresh shortcuts if the permission changed.
            mModel.refreshShortcutsIfRequired();

            DiscoveryBounce.showForHomeIfNeeded(this);

            if (mPendingActivityRequestCode != -1 && isInState(NORMAL)) {
                UiFactory.resetPendingActivityResults(this, mPendingActivityRequestCode);
            }
            mDeferredResumePending = false;
        } else {
            mDeferredResumePending = true;
        }
    }

    protected void onStateSet(LauncherState state) {
        getAppWidgetHost().setResumed(state == LauncherState.NORMAL);
        resetPendingActivityResultIfNeeded();
        if (mDeferredResumePending) {
            handleDeferredResume();
        }
        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.onStateChanged();
        }
    }

    @Override
@@ -923,14 +938,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
        Utilities.postAsyncCallback(mHandler, mHandleDeferredResume);

        setOnResumeCallback(null);
        // Process any items that were added while Launcher was away.
        InstallShortcutReceiver.disableAndFlushInstallQueue(
                InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED, this);

        // Refresh shortcuts if the permission changed.
        mModel.refreshShortcutsIfRequired();

        DiscoveryBounce.showForHomeIfNeeded(this);
        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.onResume();
        }
+5 −1
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.os.Bundle;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;

/**
 * LauncherCallbacks is an interface used to extend the Launcher activity. It includes many hooks
@@ -53,6 +52,11 @@ public interface LauncherCallbacks {
    boolean handleBackPressed();
    void onTrimMemory(int level);

    /**
     * Called when the launcher state changed
     */
    default void onStateChanged() { }

    /*
     * Extension points for providing custom behavior on certain user interactions.
     */