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

Commit 24e738e8 authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Removing some dependencies on Activity" into main

parents 1819868d e82a20a4
Loading
Loading
Loading
Loading
+22 −25
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;

import static com.android.launcher3.BaseActivity.EVENT_DESTROYED;
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.config.FeatureFlags.enableTaskbarNoRecreate;
import static com.android.launcher3.util.DisplayController.TASKBAR_NOT_DESTROYED_TAG;
@@ -30,7 +31,6 @@ import static com.android.quickstep.util.SystemActionConstants.ACTION_SHOW_TASKB
import static com.android.quickstep.util.SystemActionConstants.SYSTEM_ACTION_ID_TASKBAR;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.ComponentCallbacks;
import android.content.Context;
@@ -61,7 +61,6 @@ import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.statemanager.StatefulActivity;
import com.android.launcher3.taskbar.unfold.NonDestroyableScopedUnfoldTransitionProgressProvider;
import com.android.launcher3.uioverrides.QuickstepLauncher;
import com.android.launcher3.util.ActivityLifecycleCallbacksAdapter;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.SettingsCache;
import com.android.launcher3.util.SimpleBroadcastReceiver;
@@ -145,18 +144,16 @@ public class TaskbarManager {
    private final SimpleBroadcastReceiver mTaskbarBroadcastReceiver =
            new SimpleBroadcastReceiver(this::showTaskbarFromBroadcast);

    private final ActivityLifecycleCallbacksAdapter mLifecycleCallbacks =
            new ActivityLifecycleCallbacksAdapter() {
    private final Runnable mActivityOnDestroyCallback = new Runnable() {
        @Override
                public void onActivityDestroyed(Activity activity) {
                    if (mActivity != activity) return;
        public void run() {
            if (mActivity != null) {
                mActivity.removeOnDeviceProfileChangeListener(
                        mDebugActivityDeviceProfileChanged);
                Log.d(TASKBAR_NOT_DESTROYED_TAG,
                        "unregistering activity lifecycle callbacks from "
                                + "onActivityDestroyed.");
                        mActivity.unregisterActivityLifecycleCallbacks(this);
                mActivity.removeEventCallback(EVENT_DESTROYED, this);
            }
            mActivity = null;
            debugWhyTaskbarNotDestroyed("clearActivity");
@@ -371,7 +368,7 @@ public class TaskbarManager {
        mActivity.addOnDeviceProfileChangeListener(mDebugActivityDeviceProfileChanged);
        Log.d(TASKBAR_NOT_DESTROYED_TAG,
                "registering activity lifecycle callbacks from setActivity().");
        mActivity.registerActivityLifecycleCallbacks(mLifecycleCallbacks);
        mActivity.addEventCallback(EVENT_DESTROYED, mActivityOnDestroyCallback);
        UnfoldTransitionProgressProvider unfoldTransitionProgressProvider =
                getUnfoldTransitionProgressProviderForActivity(activity);
        if (unfoldTransitionProgressProvider != null) {
@@ -547,7 +544,7 @@ public class TaskbarManager {
            Log.d(TASKBAR_NOT_DESTROYED_TAG,
                    "unregistering activity lifecycle callbacks from "
                            + "removeActivityCallbackAndListeners().");
            mActivity.unregisterActivityLifecycleCallbacks(mLifecycleCallbacks);
            mActivity.removeEventCallback(EVENT_DESTROYED, mActivityOnDestroyCallback);
            UnfoldTransitionProgressProvider unfoldTransitionProgressProvider =
                    getUnfoldTransitionProgressProviderForActivity(mActivity);
            if (unfoldTransitionProgressProvider != null) {
+0 −5
Original line number Diff line number Diff line
@@ -1183,11 +1183,6 @@ public class QuickstepLauncher extends Launcher {
        }
    }

    @Override
    public void tryClearAccessibilityFocus(View view) {
        view.clearAccessibilityFocus();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
+18 −21
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import static android.widget.Toast.LENGTH_SHORT;
import static com.android.app.animation.Interpolators.ACCELERATE_DECELERATE;
import static com.android.app.animation.Interpolators.DECELERATE;
import static com.android.app.animation.Interpolators.OVERSHOOT_1_2;
import static com.android.launcher3.BaseActivity.EVENT_DESTROYED;
import static com.android.launcher3.BaseActivity.EVENT_STARTED;
import static com.android.launcher3.BaseActivity.INVISIBLE_BY_STATE_HANDLER;
import static com.android.launcher3.BaseActivity.STATE_HANDLER_INVISIBILITY_FLAGS;
import static com.android.launcher3.LauncherPrefs.ALL_APPS_OVERVIEW_THRESHOLD;
@@ -62,7 +64,6 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.TaskInfo;
import android.app.WindowConfiguration;
@@ -110,7 +111,6 @@ import com.android.launcher3.statemanager.StatefulActivity;
import com.android.launcher3.taskbar.TaskbarThresholdUtils;
import com.android.launcher3.taskbar.TaskbarUIController;
import com.android.launcher3.uioverrides.QuickstepLauncher;
import com.android.launcher3.util.ActivityLifecycleCallbacksAdapter;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.SafeCloseable;
import com.android.launcher3.util.TraceHelper;
@@ -185,18 +185,12 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
    protected MultiStateCallback mStateCallback;
    protected boolean mCanceled;
    private boolean mRecentsViewScrollLinked = false;
    private final ActivityLifecycleCallbacksAdapter mLifecycleCallbacks =
            new ActivityLifecycleCallbacksAdapter() {
                @Override
                public void onActivityDestroyed(Activity activity) {
                    if (mActivity != activity) {
                        return;
                    }

    private final Runnable mLauncherOnDestroyCallback = () -> {
        ActiveGestureLog.INSTANCE.addLog("Launcher destroyed", LAUNCHER_DESTROYED);
        mRecentsView = null;
        mActivity = null;
        mStateCallback.clearState(STATE_LAUNCHER_PRESENT);
                }
    };

    private static int FLAG_COUNT = 0;
@@ -318,6 +312,7 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
    private final int mSplashMainWindowShiftLength;

    private final Runnable mOnDeferredActivityLaunch = this::onDeferredActivityLaunch;
    private final Runnable mLauncherOnStartCallback = this::onLauncherStart;

    @Nullable private SwipePipToHomeAnimator mSwipePipToHomeAnimator;
    protected boolean mIsSwipingPipToHome;
@@ -491,6 +486,7 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
                mGestureState.setState(STATE_RECENTS_SCROLLING_FINISHED);
                return true;
            }
            resetLauncherListeners();

            // The launcher may have been recreated as a result of device rotation.
            int oldState = mStateCallback.getState() & ~LAUNCHER_UI_STATES;
@@ -514,7 +510,7 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
        if (alreadyOnHome) {
            onLauncherStart();
        } else {
            activity.runOnceOnStart(this::onLauncherStart);
            activity.addEventCallback(EVENT_STARTED, mLauncherOnStartCallback);
        }

        // Set up a entire animation lifecycle callback to notify the current recents view when
@@ -539,9 +535,8 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,

        setupRecentsViewUi();
        mRecentsView.runOnPageScrollsInitialized(this::linkRecentsViewScroll);
        activity.runOnBindToTouchInteractionService(this::onLauncherBindToService);

        mActivity.registerActivityLifecycleCallbacks(mLifecycleCallbacks);
        mActivity.runOnBindToTouchInteractionService(this::onLauncherBindToService);
        mActivity.addEventCallback(EVENT_DESTROYED, mLauncherOnDestroyCallback);
        return true;
    }

@@ -1868,7 +1863,6 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
        if (mActivity != null) {
            // In the off chance that the gesture ends before Launcher is started, we should clear
            // the callback here so that it doesn't update with the wrong state
            mActivity.clearRunOnceOnStartCallback();
            resetLauncherListeners();
        }
        if (mGestureState.isRecentsAnimationRunning() && mGestureState.getEndTarget() != null
@@ -1934,7 +1928,7 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
    private void reset() {
        mStateCallback.setStateOnUiThread(STATE_HANDLER_INVALIDATED);
        if (mActivity != null) {
            mActivity.unregisterActivityLifecycleCallbacks(mLifecycleCallbacks);
            mActivity.removeEventCallback(EVENT_DESTROYED, mLauncherOnDestroyCallback);
        }
    }

@@ -2005,6 +1999,9 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
     * continued quick switch gesture, which cancels the previous handler but doesn't invalidate it.
     */
    private void resetLauncherListeners() {
        mActivity.removeEventCallback(EVENT_STARTED, mLauncherOnStartCallback);
        mActivity.removeEventCallback(EVENT_DESTROYED, mLauncherOnDestroyCallback);

        mActivity.getRootView().setOnApplyWindowInsetsListener(null);

        if (mRecentsView != null) {
+21 −25
Original line number Diff line number Diff line
@@ -18,11 +18,13 @@ package com.android.quickstep.util;

import static android.app.ActivityTaskManager.INVALID_TASK_ID;

import android.app.Activity;
import static com.android.launcher3.BaseActivity.EVENT_DESTROYED;
import static com.android.launcher3.BaseActivity.EVENT_RESUMED;
import static com.android.launcher3.BaseActivity.EVENT_STOPPED;

import androidx.annotation.NonNull;

import com.android.launcher3.util.ActivityLifecycleCallbacksAdapter;
import com.android.launcher3.BaseActivity;
import com.android.quickstep.RecentsModel;

/**
@@ -34,19 +36,28 @@ import com.android.quickstep.RecentsModel;
 * If we hit either of those signals and the task is no longer valid, then the registered failure
 * callback will be notified.
 */
public class TaskRemovedDuringLaunchListener implements ActivityLifecycleCallbacksAdapter {
public class TaskRemovedDuringLaunchListener {

    private Activity mActivity;
    private BaseActivity mActivity;
    private int mLaunchedTaskId = INVALID_TASK_ID;
    private Runnable mTaskLaunchFailedCallback = null;

    private final Runnable mUnregisterCallback = this::unregister;
    private final Runnable mResumeCallback = this::checkTaskLaunchFailed;

    /**
     * Registers a failure listener callback if it detects a scenario in which an app launch
     * failed before the transition finished.
     */
    public void register(Activity activity, int launchedTaskId,
    public void register(BaseActivity activity, int launchedTaskId,
            @NonNull Runnable taskLaunchFailedCallback) {
        activity.registerActivityLifecycleCallbacks(this);
        // The normal task launch case, Launcher stops and updates its state correctly
        activity.addEventCallback(EVENT_STOPPED, mUnregisterCallback);
        // The transition hasn't finished but Launcher was resumed, check if the launch failed
        activity.addEventCallback(EVENT_RESUMED, mResumeCallback);
        // If we somehow don't get any of the above signals, then just unregister this listener
        activity.addEventCallback(EVENT_DESTROYED, mUnregisterCallback);

        mActivity = activity;
        mLaunchedTaskId = launchedTaskId;
        mTaskLaunchFailedCallback = taskLaunchFailedCallback;
@@ -56,7 +67,10 @@ public class TaskRemovedDuringLaunchListener implements ActivityLifecycleCallbac
     * Unregisters the failure listener.
     */
    private void unregister() {
        mActivity.unregisterActivityLifecycleCallbacks(this);
        mActivity.removeEventCallback(EVENT_STOPPED, mUnregisterCallback);
        mActivity.removeEventCallback(EVENT_RESUMED, mResumeCallback);
        mActivity.removeEventCallback(EVENT_DESTROYED, mUnregisterCallback);

        mActivity = null;
        mLaunchedTaskId = INVALID_TASK_ID;
        mTaskLaunchFailedCallback = null;
@@ -70,24 +84,6 @@ public class TaskRemovedDuringLaunchListener implements ActivityLifecycleCallbac
        checkTaskLaunchFailed();
    }

    @Override
    public void onActivityStopped(Activity activity) {
        // The normal task launch case, Launcher stops and updates its state correctly
        unregister();
    }

    @Override
    public void onActivityResumed(Activity activity) {
        // The transition hasn't finished but Launcher was resumed, check if the launch failed
        checkTaskLaunchFailed();
    }

    @Override
    public void onActivityDestroyed(Activity activity) {
        // If we somehow don't get any of the above signals, then just unregister this listener
        unregister();
    }

    private void checkTaskLaunchFailed() {
        if (mLaunchedTaskId != INVALID_TASK_ID) {
            final int launchedTaskId = mLaunchedTaskId;
+31 −4
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.window.OnBackInvokedDispatcher;

import androidx.annotation.IntDef;
@@ -38,6 +37,7 @@ import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.util.RunnableList;
import com.android.launcher3.util.SystemUiController;
import com.android.launcher3.util.ViewCache;
import com.android.launcher3.views.ActivityContext;
@@ -153,6 +153,18 @@ public abstract class BaseActivity extends Activity implements ActivityContext {

    private final ViewCache mViewCache = new ViewCache();

    @Retention(SOURCE)
    @IntDef({EVENT_STARTED, EVENT_RESUMED, EVENT_STOPPED, EVENT_DESTROYED})
    public @interface ActivityEvent { }
    public static final int EVENT_STARTED = 0;
    public static final int EVENT_RESUMED = 1;
    public static final int EVENT_STOPPED = 2;
    public static final int EVENT_DESTROYED = 3;

    // Callback array that corresponds to events defined in @ActivityEvent
    private final RunnableList[] mEventCallbacks =
            {new RunnableList(), new RunnableList(), new RunnableList(), new RunnableList()};

    @Override
    public ViewCache getViewCache() {
        return mViewCache;
@@ -205,12 +217,14 @@ public abstract class BaseActivity extends Activity implements ActivityContext {
    protected void onStart() {
        addActivityFlags(ACTIVITY_STATE_STARTED);
        super.onStart();
        mEventCallbacks[EVENT_STARTED].executeAllAndClear();
    }

    @Override
    protected void onResume() {
        setResumed();
        super.onResume();
        mEventCallbacks[EVENT_RESUMED].executeAllAndClear();
    }

    @Override
@@ -232,12 +246,20 @@ public abstract class BaseActivity extends Activity implements ActivityContext {
        removeActivityFlags(ACTIVITY_STATE_STARTED | ACTIVITY_STATE_USER_ACTIVE);
        mForceInvisible = 0;
        super.onStop();
        mEventCallbacks[EVENT_STOPPED].executeAllAndClear();


        // Reset the overridden sysui flags used for the task-swipe launch animation, this is a
        // catch all for if we do not get resumed (and therefore not paused below)
        getSystemUiController().updateUiState(UI_STATE_FULLSCREEN_TASK, 0);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mEventCallbacks[EVENT_DESTROYED].executeAllAndClear();
    }

    @Override
    protected void onPause() {
        setPaused();
@@ -258,7 +280,6 @@ public abstract class BaseActivity extends Activity implements ActivityContext {
        } else {
            removeActivityFlags(ACTIVITY_STATE_WINDOW_FOCUSED);
        }

    }

    protected void registerBackDispatcher() {
@@ -364,9 +385,15 @@ public abstract class BaseActivity extends Activity implements ActivityContext {
    }

    /**
     * Attempts to clear accessibility focus on {@param view}.
     * Adds a callback for the provided activity event
     */
    public void tryClearAccessibilityFocus(View view) {
    public void addEventCallback(@ActivityEvent int event, Runnable callback) {
        mEventCallbacks[event].add(callback);
    }

    /** Removes a previously added callback */
    public void removeEventCallback(@ActivityEvent int event, Runnable callback) {
        mEventCallbacks[event].remove(callback);
    }

    public interface MultiWindowModeChangedListener {
Loading