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

Commit 9dd8eacd authored by Schneider Victor-tulias's avatar Schneider Victor-tulias Committed by Automerger Merge Worker
Browse files

Merge "Fix launcher activity leak in TouchInteractionService" into udc-dev am: 8f953070

parents 258f5d5a 8f953070
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -878,7 +878,9 @@ public class QuickstepLauncher extends Launcher {


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


+3 −1
Original line number Original line Diff line number Diff line
@@ -144,8 +144,10 @@ public final class RecentsActivity extends StatefulActivity<RecentsState> {


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


    @Override
    @Override
    public void runOnBindToTouchInteractionService(Runnable r) {
    public void runOnBindToTouchInteractionService(Runnable r) {
+112 −66
Original line number Original line Diff line number Diff line
@@ -139,8 +139,10 @@ import com.android.wm.shell.transition.IShellTransitions;


import java.io.FileDescriptor;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.LinkedList;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Function;


/**
/**
@@ -157,15 +159,21 @@ public class TouchInteractionService extends Service


    private static final String HAS_ENABLED_QUICKSTEP_ONCE = "launcher.has_enabled_quickstep_once";
    private static final String HAS_ENABLED_QUICKSTEP_ONCE = "launcher.has_enabled_quickstep_once";


    private final TISBinder mTISBinder = new TISBinder();
    private final TISBinder mTISBinder = new TISBinder(this);


    /**
    /**
     * Local IOverviewProxy implementation with some methods for local components
     * Local IOverviewProxy implementation with some methods for local components
     */
     */
    public class TISBinder extends IOverviewProxy.Stub {
    public static class TISBinder extends IOverviewProxy.Stub {

        private final WeakReference<TouchInteractionService> mTis;


        @Nullable private Runnable mOnOverviewTargetChangeListener = null;
        @Nullable private Runnable mOnOverviewTargetChangeListener = null;


        private TISBinder(TouchInteractionService tis) {
            mTis = new WeakReference<>(tis);
        }

        @BinderThread
        @BinderThread
        public void onInitialize(Bundle bundle) {
        public void onInitialize(Bundle bundle) {
            ISystemUiProxy proxy = ISystemUiProxy.Stub.asInterface(
            ISystemUiProxy proxy = ISystemUiProxy.Stub.asInterface(
@@ -193,14 +201,14 @@ public class TouchInteractionService extends Service
                    bundle.getBinder(KEY_EXTRA_UNFOLD_ANIMATION_FORWARDER));
                    bundle.getBinder(KEY_EXTRA_UNFOLD_ANIMATION_FORWARDER));
            IDragAndDrop dragAndDrop = IDragAndDrop.Stub.asInterface(
            IDragAndDrop dragAndDrop = IDragAndDrop.Stub.asInterface(
                    bundle.getBinder(KEY_EXTRA_SHELL_DRAG_AND_DROP));
                    bundle.getBinder(KEY_EXTRA_SHELL_DRAG_AND_DROP));
            MAIN_EXECUTOR.execute(() -> {
            MAIN_EXECUTOR.execute(() -> executeForTouchInteractionService(tis -> {
                SystemUiProxy.INSTANCE.get(TouchInteractionService.this).setProxy(proxy, pip,
                SystemUiProxy.INSTANCE.get(tis).setProxy(proxy, pip,
                        bubbles, splitscreen, onehanded, shellTransitions, startingWindow,
                        bubbles, splitscreen, onehanded, shellTransitions, startingWindow,
                        recentTasks, launcherUnlockAnimationController, backAnimation, desktopMode,
                        recentTasks, launcherUnlockAnimationController, backAnimation, desktopMode,
                        unfoldTransition, dragAndDrop);
                        unfoldTransition, dragAndDrop);
                TouchInteractionService.this.initInputMonitor("TISBinder#onInitialize()");
                tis.initInputMonitor("TISBinder#onInitialize()");
                preloadOverview(true /* fromInit */);
                tis.preloadOverview(true /* fromInit */);
            });
            }));
            sIsInitialized = true;
            sIsInitialized = true;
        }
        }


@@ -208,65 +216,72 @@ public class TouchInteractionService extends Service
        @Override
        @Override
        public void onTaskbarToggled() {
        public void onTaskbarToggled() {
            if (!FeatureFlags.ENABLE_KEYBOARD_TASKBAR_TOGGLE.get()) return;
            if (!FeatureFlags.ENABLE_KEYBOARD_TASKBAR_TOGGLE.get()) return;
            MAIN_EXECUTOR.execute(() -> {
            MAIN_EXECUTOR.execute(() -> executeForTouchInteractionService(tis -> {
                TaskbarActivityContext activityContext =
                TaskbarActivityContext activityContext =
                        mTaskbarManager.getCurrentActivityContext();
                        tis.mTaskbarManager.getCurrentActivityContext();


                if (activityContext != null) {
                if (activityContext != null) {
                    activityContext.toggleTaskbarStash();
                    activityContext.toggleTaskbarStash();
                }
                }
            });
            }));
        }
        }


        @BinderThread
        @BinderThread
        public void onOverviewToggle() {
        public void onOverviewToggle() {
            TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onOverviewToggle");
            TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onOverviewToggle");
            executeForTouchInteractionService(tis -> {
                // If currently screen pinning, do not enter overview
                // If currently screen pinning, do not enter overview
            if (mDeviceState.isScreenPinningActive()) {
                if (tis.mDeviceState.isScreenPinningActive()) {
                    return;
                    return;
                }
                }
                TaskUtils.closeSystemWindowsAsync(CLOSE_SYSTEM_WINDOWS_REASON_RECENTS);
                TaskUtils.closeSystemWindowsAsync(CLOSE_SYSTEM_WINDOWS_REASON_RECENTS);
            mOverviewCommandHelper.addCommand(OverviewCommandHelper.TYPE_TOGGLE);
                tis.mOverviewCommandHelper.addCommand(OverviewCommandHelper.TYPE_TOGGLE);
            });
        }
        }


        @BinderThread
        @BinderThread
        @Override
        @Override
        public void onOverviewShown(boolean triggeredFromAltTab) {
        public void onOverviewShown(boolean triggeredFromAltTab) {
            executeForTouchInteractionService(tis -> {
                if (triggeredFromAltTab) {
                if (triggeredFromAltTab) {
                    TaskUtils.closeSystemWindowsAsync(CLOSE_SYSTEM_WINDOWS_REASON_RECENTS);
                    TaskUtils.closeSystemWindowsAsync(CLOSE_SYSTEM_WINDOWS_REASON_RECENTS);
                mOverviewCommandHelper.addCommand(OverviewCommandHelper.TYPE_KEYBOARD_INPUT);
                    tis.mOverviewCommandHelper.addCommand(
                            OverviewCommandHelper.TYPE_KEYBOARD_INPUT);
                } else {
                } else {
                mOverviewCommandHelper.addCommand(OverviewCommandHelper.TYPE_SHOW);
                    tis.mOverviewCommandHelper.addCommand(OverviewCommandHelper.TYPE_SHOW);
                }
                }
            });
        }
        }


        @BinderThread
        @BinderThread
        @Override
        @Override
        public void onOverviewHidden(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {
        public void onOverviewHidden(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {
            executeForTouchInteractionService(tis -> {
                if (triggeredFromAltTab && !triggeredFromHomeKey) {
                if (triggeredFromAltTab && !triggeredFromHomeKey) {
                    // onOverviewShownFromAltTab hides the overview and ends at the target app
                    // onOverviewShownFromAltTab hides the overview and ends at the target app
                mOverviewCommandHelper.addCommand(OverviewCommandHelper.TYPE_HIDE);
                    tis.mOverviewCommandHelper.addCommand(OverviewCommandHelper.TYPE_HIDE);
                }
                }
            });
        }
        }


        @BinderThread
        @BinderThread
        @Override
        @Override
        public void onAssistantAvailable(boolean available, boolean longPressHomeEnabled) {
        public void onAssistantAvailable(boolean available, boolean longPressHomeEnabled) {
            MAIN_EXECUTOR.execute(() -> {
            MAIN_EXECUTOR.execute(() -> executeForTouchInteractionService(tis -> {
                mDeviceState.setAssistantAvailable(available);
                tis.mDeviceState.setAssistantAvailable(available);
                TouchInteractionService.this.onAssistantVisibilityChanged();
                tis.onAssistantVisibilityChanged();
                executeForTaskbarManager(() -> mTaskbarManager
                executeForTaskbarManager(taskbarManager -> taskbarManager
                        .onLongPressHomeEnabled(longPressHomeEnabled));
                        .onLongPressHomeEnabled(longPressHomeEnabled));
            });
            }));
        }
        }


        @BinderThread
        @BinderThread
        @Override
        @Override
        public void onAssistantVisibilityChanged(float visibility) {
        public void onAssistantVisibilityChanged(float visibility) {
            MAIN_EXECUTOR.execute(() -> {
            MAIN_EXECUTOR.execute(() -> executeForTouchInteractionService(tis -> {
                mDeviceState.setAssistantVisibility(visibility);
                tis.mDeviceState.setAssistantVisibility(visibility);
                TouchInteractionService.this.onAssistantVisibilityChanged();
                tis.onAssistantVisibilityChanged();
            });
            }));
        }
        }


        @Override
        @Override
@@ -276,16 +291,17 @@ public class TouchInteractionService extends Service


        @BinderThread
        @BinderThread
        public void onSystemUiStateChanged(int stateFlags) {
        public void onSystemUiStateChanged(int stateFlags) {
            MAIN_EXECUTOR.execute(() -> {
            MAIN_EXECUTOR.execute(() -> executeForTouchInteractionService(tis -> {
                int lastFlags = mDeviceState.getSystemUiStateFlags();
                int lastFlags = tis.mDeviceState.getSystemUiStateFlags();
                mDeviceState.setSystemUiFlags(stateFlags);
                tis.mDeviceState.setSystemUiFlags(stateFlags);
                TouchInteractionService.this.onSystemUiFlagsChanged(lastFlags);
                tis.onSystemUiFlagsChanged(lastFlags);
            });
            }));
        }
        }


        @BinderThread
        @BinderThread
        public void onActiveNavBarRegionChanges(Region region) {
        public void onActiveNavBarRegionChanges(Region region) {
            MAIN_EXECUTOR.execute(() -> mDeviceState.setDeferredGestureRegion(region));
            MAIN_EXECUTOR.execute(() -> executeForTouchInteractionService(
                    tis -> tis.mDeviceState.setDeferredGestureRegion(region)));
        }
        }


        @BinderThread
        @BinderThread
@@ -309,75 +325,105 @@ public class TouchInteractionService extends Service
        @BinderThread
        @BinderThread
        @Override
        @Override
        public void enterStageSplitFromRunningApp(boolean leftOrTop) {
        public void enterStageSplitFromRunningApp(boolean leftOrTop) {
            executeForTouchInteractionService(tis -> {
                StatefulActivity activity =
                StatefulActivity activity =
                    mOverviewComponentObserver.getActivityInterface().getCreatedActivity();
                        tis.mOverviewComponentObserver.getActivityInterface().getCreatedActivity();
                if (activity != null) {
                if (activity != null) {
                    activity.enterStageSplitFromRunningApp(leftOrTop);
                    activity.enterStageSplitFromRunningApp(leftOrTop);
                }
                }
            });
        }
        }


        /**
        /**
         * Preloads the Overview activity.
         * Preloads the Overview activity.
         *
         * <p>
         * This method should only be used when the All Set page of the SUW is reached to safely
         * This method should only be used when the All Set page of the SUW is reached to safely
         * preload the Launcher for the SUW first reveal.
         * preload the Launcher for the SUW first reveal.
         */
         */
        public void preloadOverviewForSUWAllSet() {
        public void preloadOverviewForSUWAllSet() {
            preloadOverview(false, true);
            executeForTouchInteractionService(tis -> tis.preloadOverview(false, true));
        }
        }


        @Override
        @Override
        public void onRotationProposal(int rotation, boolean isValid) {
        public void onRotationProposal(int rotation, boolean isValid) {
            executeForTaskbarManager(() -> mTaskbarManager.onRotationProposal(rotation, isValid));
            executeForTaskbarManager(taskbarManager ->
                    taskbarManager.onRotationProposal(rotation, isValid));
        }
        }


        @Override
        @Override
        public void disable(int displayId, int state1, int state2, boolean animate) {
        public void disable(int displayId, int state1, int state2, boolean animate) {
            executeForTaskbarManager(() -> mTaskbarManager
            executeForTaskbarManager(taskbarManager ->
                    .disableNavBarElements(displayId, state1, state2, animate));
                    taskbarManager.disableNavBarElements(displayId, state1, state2, animate));
        }
        }


        @Override
        @Override
        public void onSystemBarAttributesChanged(int displayId, int behavior) {
        public void onSystemBarAttributesChanged(int displayId, int behavior) {
            executeForTaskbarManager(() -> mTaskbarManager
            executeForTaskbarManager(taskbarManager ->
                    .onSystemBarAttributesChanged(displayId, behavior));
                    taskbarManager.onSystemBarAttributesChanged(displayId, behavior));
        }
        }


        @Override
        @Override
        public void onNavButtonsDarkIntensityChanged(float darkIntensity) {
        public void onNavButtonsDarkIntensityChanged(float darkIntensity) {
            executeForTaskbarManager(() -> mTaskbarManager
            executeForTaskbarManager(taskbarManager ->
                    .onNavButtonsDarkIntensityChanged(darkIntensity));
                    taskbarManager.onNavButtonsDarkIntensityChanged(darkIntensity));
        }
        }


        private void executeForTaskbarManager(final Runnable r) {
        private void executeForTouchInteractionService(
            MAIN_EXECUTOR.execute(() -> {
                @NonNull Consumer<TouchInteractionService> tisConsumer) {
                if (mTaskbarManager == null) {
            TouchInteractionService tis = mTis.get();
                    return;
            if (tis == null) return;
            tisConsumer.accept(tis);
        }
        }
                r.run();

            });
        private void executeForTaskbarManager(
                @NonNull Consumer<TaskbarManager> taskbarManagerConsumer) {
            MAIN_EXECUTOR.execute(() -> executeForTouchInteractionService(tis -> {
                TaskbarManager taskbarManager = tis.mTaskbarManager;
                if (taskbarManager == null) return;
                taskbarManagerConsumer.accept(taskbarManager);
            }));
        }
        }


        /**
         * Returns the {@link TaskbarManager}.
         * <p>
         * Returns {@code null} if TouchInteractionService is not connected
         */
        @Nullable
        public TaskbarManager getTaskbarManager() {
        public TaskbarManager getTaskbarManager() {
            return mTaskbarManager;
            TouchInteractionService tis = mTis.get();
            if (tis == null) return null;
            return tis.mTaskbarManager;
        }
        }


        /**
         * Returns the {@link OverviewCommandHelper}.
         * <p>
         * Returns {@code null} if TouchInteractionService is not connected
         */
        @Nullable
        public OverviewCommandHelper getOverviewCommandHelper() {
        public OverviewCommandHelper getOverviewCommandHelper() {
            return mOverviewCommandHelper;
            TouchInteractionService tis = mTis.get();
            if (tis == null) return null;
            return tis.mOverviewCommandHelper;
        }
        }


        /**
        /**
         * Sets a proxy to bypass swipe up behavior
         * Sets a proxy to bypass swipe up behavior
         */
         */
        public void setSwipeUpProxy(Function<GestureState, AnimatedFloat> proxy) {
        public void setSwipeUpProxy(Function<GestureState, AnimatedFloat> proxy) {
            mSwipeUpProxyProvider = proxy != null ? proxy : (i -> null);
            TouchInteractionService tis = mTis.get();
            if (tis == null) return;
            tis.mSwipeUpProxyProvider = proxy != null ? proxy : (i -> null);
        }
        }


        /**
        /**
         * Sets the task id where gestures should be blocked
         * Sets the task id where gestures should be blocked
         */
         */
        public void setGestureBlockedTaskId(int taskId) {
        public void setGestureBlockedTaskId(int taskId) {
            mDeviceState.setGestureBlockingTaskId(taskId);
            TouchInteractionService tis = mTis.get();
            if (tis == null) return;
            tis.mDeviceState.setGestureBlockingTaskId(taskId);
        }
        }


        /** Sets a listener to be run on Overview Target updates. */
        /** Sets a listener to be run on Overview Target updates. */
+13 −6
Original line number Original line Diff line number Diff line
@@ -61,6 +61,7 @@ import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimatedFloat;
import com.android.launcher3.anim.AnimatedFloat;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.taskbar.TaskbarManager;
import com.android.launcher3.util.Executors;
import com.android.launcher3.util.Executors;
import com.android.quickstep.GestureState;
import com.android.quickstep.GestureState;
import com.android.quickstep.TouchInteractionService.TISBinder;
import com.android.quickstep.TouchInteractionService.TISBinder;
@@ -100,6 +101,7 @@ public class AllSetActivity extends Activity {


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


    private final AnimatedFloat mSwipeProgress = new AnimatedFloat(this::onSwipeProgressUpdate);
    private final AnimatedFloat mSwipeProgress = new AnimatedFloat(this::onSwipeProgressUpdate);
    private BgDrawable mBackground;
    private BgDrawable mBackground;
@@ -262,19 +264,25 @@ public class AllSetActivity extends Activity {
        mAnimatedBackground.playAnimation();
        mAnimatedBackground.playAnimation();
    }
    }


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

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


    private void onTISConnected(TISBinder binder) {
    private void onTISConnected(TISBinder binder) {
        mBinder = binder;
        mBinder = binder;
        mBinder.getTaskbarManager().setSetupUIVisible(isResumed());
        mTaskbarManager = mBinder.getTaskbarManager();
        setSetupUIVisible(isResumed());
        mBinder.setSwipeUpProxy(isResumed() ? this::createSwipeUpProxy : null);
        mBinder.setSwipeUpProxy(isResumed() ? this::createSwipeUpProxy : null);
        mBinder.setOverviewTargetChangeListener(mBinder::preloadOverviewForSUWAllSet);
        mBinder.setOverviewTargetChangeListener(mBinder::preloadOverviewForSUWAllSet);
        mBinder.preloadOverviewForSUWAllSet();
        mBinder.preloadOverviewForSUWAllSet();
@@ -293,7 +301,7 @@ public class AllSetActivity extends Activity {


    private void clearBinderOverride() {
    private void clearBinderOverride() {
        if (mBinder != null) {
        if (mBinder != null) {
            mBinder.getTaskbarManager().setSetupUIVisible(false);
            setSetupUIVisible(false);
            mBinder.setSwipeUpProxy(null);
            mBinder.setSwipeUpProxy(null);
            mBinder.setOverviewTargetChangeListener(null);
            mBinder.setOverviewTargetChangeListener(null);
        }
        }
@@ -352,9 +360,8 @@ public class AllSetActivity extends Activity {
        mContentView.setAlpha(alpha);
        mContentView.setAlpha(alpha);
        mContentView.setTranslationY((alpha - 1) * mSwipeUpShift);
        mContentView.setTranslationY((alpha - 1) * mSwipeUpShift);


        if (mLauncherStartAnim == null) {
        if (mLauncherStartAnim == null && mTaskbarManager != null) {
            mLauncherStartAnim = mBinder.getTaskbarManager().createLauncherStartFromSuwAnim(
            mLauncherStartAnim = mTaskbarManager.createLauncherStartFromSuwAnim(MAX_SWIPE_DURATION);
                    MAX_SWIPE_DURATION);
        }
        }
        if (mLauncherStartAnim != null) {
        if (mLauncherStartAnim != null) {
            mLauncherStartAnim.setPlayFraction(Utilities.mapBoundToRange(
            mLauncherStartAnim.setPlayFraction(Utilities.mapBoundToRange(