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

Commit 871d7fc3 authored by Schneider Victor-tulias's avatar Schneider Victor-tulias
Browse files

Moved TISBinder lifecycle handling to TISBinderHelper

- All instances where we used TISBinder will now use TISBinderHelper#getBinder. This will allow TISBinderHelper to handle its lifecycle
- Moved all instance of TaskbarManager and OverviewCommandHelper as well since TIS and TISBinder handle their lifecycles
- Cleaning up launcher instance from TaskbarManager when TISBinder is being destroyed

Flag: not needed
Bug: 283490010
Test: ran launcher and performed gestures
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:248794e698417b1156bf911adb31682186fe2e34)
Change-Id: I8415a6b2c1dba0776e7c0e1ee32ad3c683100bde
parent 8d90ac04
Loading
Loading
Loading
Loading
+23 −15
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import static com.android.launcher3.util.FlagDebugUtils.formatFlagChange;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.ComponentCallbacks;
import android.content.Context;
@@ -56,6 +57,7 @@ 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.NavigationMode;
import com.android.launcher3.util.SettingsCache;
@@ -144,6 +146,25 @@ public class TaskbarManager {
                }
            };

    private final ActivityLifecycleCallbacksAdapter mLifecycleCallbacks =
            new ActivityLifecycleCallbacksAdapter() {
                @Override
                public void onActivityDestroyed(Activity activity) {
                    if (mActivity != activity) return;
                    if (mActivity != null) {
                        mActivity.removeOnDeviceProfileChangeListener(
                                mDebugActivityDeviceProfileChanged);
                        mActivity.unregisterActivityLifecycleCallbacks(this);
                    }
                    mActivity = null;
                    debugWhyTaskbarNotDestroyed("clearActivity");
                    if (mTaskbarActivityContext != null) {
                        mTaskbarActivityContext.setUIController(TaskbarUIController.DEFAULT);
                    }
                    mUnfoldProgressProvider.setSourceProvider(null);
                }
            };

    @SuppressLint("WrongConstant")
    public TaskbarManager(TouchInteractionService service) {
        mDisplayController = DisplayController.INSTANCE.get(service);
@@ -306,10 +327,12 @@ public class TaskbarManager {
        }
        if (mActivity != null) {
            mActivity.removeOnDeviceProfileChangeListener(mDebugActivityDeviceProfileChanged);
            mActivity.unregisterActivityLifecycleCallbacks(mLifecycleCallbacks);
        }
        mActivity = activity;
        debugWhyTaskbarNotDestroyed("Set mActivity=" + mActivity);
        mActivity.addOnDeviceProfileChangeListener(mDebugActivityDeviceProfileChanged);
        mActivity.registerActivityLifecycleCallbacks(mLifecycleCallbacks);
        UnfoldTransitionProgressProvider unfoldTransitionProgressProvider =
                getUnfoldTransitionProgressProviderForActivity(activity);
        mUnfoldProgressProvider.setSourceProvider(unfoldTransitionProgressProvider);
@@ -348,21 +371,6 @@ public class TaskbarManager {
        return TaskbarUIController.DEFAULT;
    }

    /**
     * Clears a previously set {@link StatefulActivity}
     */
    public void clearActivity(@NonNull StatefulActivity activity) {
        if (mActivity == activity) {
            mActivity.removeOnDeviceProfileChangeListener(mDebugActivityDeviceProfileChanged);
            mActivity = null;
            debugWhyTaskbarNotDestroyed("clearActivity");
            if (mTaskbarActivityContext != null) {
                mTaskbarActivityContext.setUIController(TaskbarUIController.DEFAULT);
            }
            mUnfoldProgressProvider.setSourceProvider(null);
        }
    }

    /**
     * This method is called multiple times (ex. initial init, then when user unlocks) in which case
     * we fully want to destroy an existing taskbar and create a new one.
+12 −16
Original line number Diff line number Diff line
@@ -211,8 +211,6 @@ public class QuickstepLauncher extends Launcher {
    private QuickstepTransitionManager mAppTransitionManager;
    private OverviewActionsView mActionsView;
    private TISBindHelper mTISBindHelper;
    private @Nullable TaskbarManager mTaskbarManager;
    private @Nullable OverviewCommandHelper mOverviewCommandHelper;
    private @Nullable LauncherTaskbarUIController mTaskbarUIController;
    // Will be updated when dragging from taskbar.
    private @Nullable DragOptions mNextWorkspaceDragOptions = null;
@@ -480,9 +478,6 @@ public class QuickstepLauncher extends Launcher {
        }

        mTISBindHelper.onDestroy();
        if (mTaskbarManager != null) {
            mTaskbarManager.clearActivity(this);
        }

        if (mLauncherUnfoldAnimationController != null) {
            mLauncherUnfoldAnimationController.onDestroy();
@@ -694,9 +689,9 @@ public class QuickstepLauncher extends Launcher {
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);

        if (mOverviewCommandHelper != null) {
            mOverviewCommandHelper.clearPendingCommands();
        OverviewCommandHelper overviewCommandHelper = mTISBindHelper.getOverviewCommandHelper();
        if (overviewCommandHelper != null) {
            overviewCommandHelper.clearPendingCommands();
        }
    }

@@ -819,8 +814,9 @@ public class QuickstepLauncher extends Launcher {
    }

    private void onTaskbarInAppDisplayProgressUpdate(float progress, int flag) {
        if (mTaskbarManager == null
                || mTaskbarManager.getCurrentActivityContext() == null
        TaskbarManager taskbarManager = mTISBindHelper.getTaskbarManager();
        if (taskbarManager == null
                || taskbarManager.getCurrentActivityContext() == null
                || mTaskbarUIController == null) {
            return;
        }
@@ -892,11 +888,10 @@ public class QuickstepLauncher extends Launcher {
    }

    private void onTISConnected(TISBinder binder) {
        mTaskbarManager = binder.getTaskbarManager();
        if (mTaskbarManager != null) {
            mTaskbarManager.setActivity(this);
        TaskbarManager taskbarManager = mTISBindHelper.getTaskbarManager();
        if (taskbarManager != null) {
            taskbarManager.setActivity(this);
        }
        mOverviewCommandHelper = binder.getOverviewCommandHelper();
    }

    @Override
@@ -1280,8 +1275,9 @@ public class QuickstepLauncher extends Launcher {
        Trace.instantForTrack(TRACE_TAG_APP, "QuickstepLauncher#DeviceProfileChanged",
                getDeviceProfile().toSmallString());
        SystemUiProxy.INSTANCE.get(this).setLauncherAppIconSize(mDeviceProfile.iconSizePx);
        if (mTaskbarManager != null) {
            mTaskbarManager.debugWhyTaskbarNotDestroyed("QuickstepLauncher#onDeviceProfileChanged");
        TaskbarManager taskbarManager = mTISBindHelper.getTaskbarManager();
        if (taskbarManager != null) {
            taskbarManager.debugWhyTaskbarNotDestroyed("QuickstepLauncher#onDeviceProfileChanged");
        }
    }

+3 −7
Original line number Diff line number Diff line
@@ -106,7 +106,6 @@ public final class RecentsActivity extends StatefulActivity<RecentsState> {
    private FallbackRecentsView mFallbackRecentsView;
    private OverviewActionsView mActionsView;
    private TISBindHelper mTISBindHelper;
    private @Nullable TaskbarManager mTaskbarManager;
    private @Nullable FallbackTaskbarUIController mTaskbarUIController;

    private StateManager<RecentsState> mStateManager;
@@ -142,9 +141,9 @@ public final class RecentsActivity extends StatefulActivity<RecentsState> {
    }

    private void onTISConnected(TouchInteractionService.TISBinder binder) {
        mTaskbarManager = binder.getTaskbarManager();
        if (mTaskbarManager != null) {
            mTaskbarManager.setActivity(this);
        TaskbarManager taskbarManager = binder.getTaskbarManager();
        if (taskbarManager != null) {
            taskbarManager.setActivity(this);
        }
    }

@@ -385,9 +384,6 @@ public final class RecentsActivity extends StatefulActivity<RecentsState> {
        mActivityLaunchAnimationRunner = null;

        mTISBindHelper.onDestroy();
        if (mTaskbarManager != null) {
            mTaskbarManager.clearActivity(this);
        }
    }

    @Override
+16 −16
Original line number Diff line number Diff line
@@ -100,8 +100,6 @@ public class AllSetActivity extends Activity {
    private final Rect mTempExclusionBounds = new Rect();

    private TISBindHelper mTISBindHelper;
    private TISBinder mBinder;
    @Nullable private TaskbarManager mTaskbarManager = null;

    private final AnimatedFloat mSwipeProgress = new AnimatedFloat(this::onSwipeProgressUpdate);
    private BgDrawable mBackground;
@@ -265,27 +263,27 @@ public class AllSetActivity extends Activity {
    }

    private void setSetupUIVisible(boolean visible) {
        if (mBinder == null || mTaskbarManager == null) return;
        mTaskbarManager.setSetupUIVisible(visible);
        TaskbarManager taskbarManager = mTISBindHelper.getTaskbarManager();
        if (taskbarManager == null) return;
        taskbarManager.setSetupUIVisible(visible);
    }

    @Override
    protected void onResume() {
        super.onResume();
        maybeResumeOrPauseBackgroundAnimation();
        if (mBinder != null) {
        TISBinder binder = mTISBindHelper.getBinder();
        if (binder != null) {
            setSetupUIVisible(true);
            mBinder.setSwipeUpProxy(this::createSwipeUpProxy);
            binder.setSwipeUpProxy(this::createSwipeUpProxy);
        }
    }

    private void onTISConnected(TISBinder binder) {
        mBinder = binder;
        mTaskbarManager = mBinder.getTaskbarManager();
        setSetupUIVisible(isResumed());
        mBinder.setSwipeUpProxy(isResumed() ? this::createSwipeUpProxy : null);
        mBinder.setOverviewTargetChangeListener(mBinder::preloadOverviewForSUWAllSet);
        mBinder.preloadOverviewForSUWAllSet();
        binder.setSwipeUpProxy(isResumed() ? this::createSwipeUpProxy : null);
        binder.setOverviewTargetChangeListener(binder::preloadOverviewForSUWAllSet);
        binder.preloadOverviewForSUWAllSet();
    }

    @Override
@@ -300,10 +298,11 @@ public class AllSetActivity extends Activity {
    }

    private void clearBinderOverride() {
        if (mBinder != null) {
        TISBinder binder = mTISBindHelper.getBinder();
        if (binder != null) {
            setSetupUIVisible(false);
            mBinder.setSwipeUpProxy(null);
            mBinder.setOverviewTargetChangeListener(null);
            binder.setSwipeUpProxy(null);
            binder.setOverviewTargetChangeListener(null);
        }
    }

@@ -360,8 +359,9 @@ public class AllSetActivity extends Activity {
        mContentView.setAlpha(alpha);
        mContentView.setTranslationY((alpha - 1) * mSwipeUpShift);

        if (mLauncherStartAnim == null && mTaskbarManager != null) {
            mLauncherStartAnim = mTaskbarManager.createLauncherStartFromSuwAnim(MAX_SWIPE_DURATION);
        TaskbarManager taskbarManager = mTISBindHelper.getTaskbarManager();
        if (mLauncherStartAnim == null && taskbarManager != null) {
            mLauncherStartAnim = taskbarManager.createLauncherStartFromSuwAnim(MAX_SWIPE_DURATION);
        }
        if (mLauncherStartAnim != null) {
            mLauncherStartAnim.setPlayFraction(Utilities.mapBoundToRange(
+3 −4
Original line number Diff line number Diff line
@@ -58,7 +58,6 @@ public class GestureSandboxActivity extends FragmentActivity {
    private StatsLogManager mStatsLogManager;

    private TISBindHelper mTISBindHelper;
    private TISBinder mBinder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
@@ -271,7 +270,6 @@ public class GestureSandboxActivity extends FragmentActivity {
    }

    private void onTISConnected(TISBinder binder) {
        mBinder = binder;
        updateServiceState(isResumed());
    }

@@ -282,8 +280,9 @@ public class GestureSandboxActivity extends FragmentActivity {
    }

    private void updateServiceState(boolean isEnabled) {
        if (mBinder != null) {
            mBinder.setGestureBlockedTaskId(isEnabled ? getTaskId() : -1);
        TISBinder binder = mTISBindHelper.getBinder();
        if (binder != null) {
            binder.setGestureBlockedTaskId(isEnabled ? getTaskId() : -1);
        }
    }

Loading