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

Commit 1a189034 authored by Wei Sheng Shih's avatar Wei Sheng Shih Committed by Android (Google) Code Review
Browse files

Merge "Delegate back gesture request to Shell." into main

parents 857623fa f4e67a30
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -368,6 +368,11 @@ interface IActivityTaskManager {
    android.window.BackNavigationInfo startBackNavigation(
            in RemoteCallback navigationObserver, in BackAnimationAdapter adaptor);

    /**
     * Registers a callback to be invoked when the system server requests a back gesture.
     */
    void registerBackGestureDelegate(in RemoteCallback monitor);

    /**
     * registers a callback to be invoked when a background activity launch is aborted.
     *
+11 −0
Original line number Diff line number Diff line
@@ -525,3 +525,14 @@ flag {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "delegate_back_gesture_to_shell"
    namespace: "windowing_frontend"
    description: "Delegate back gesture event to back animation controller."
    bug: "394599430"
    is_fixed_read_only: true
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
 No newline at end of file
+27 −0
Original line number Diff line number Diff line
@@ -286,6 +286,7 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
                this::createExternalInterface, this);
        mShellCommandHandler.addDumpCallback(this::dump, this);
        mShellController.addConfigurationChangeListener(this);
        registerBackGestureDelegate();
    }

    public BackAnimation getBackAnimationImpl() {
@@ -1144,6 +1145,32 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
        mBackAnimationAdapter = new BackAnimationAdapter(runner);
    }

    private void registerBackGestureDelegate() {
        if (!Flags.delegateBackGestureToShell()) {
            return;
        }
        final RemoteCallback requestBackMonitor = new RemoteCallback(
                new RemoteCallback.OnResultListener() {
                    @Override
                    public void onResult(@Nullable Bundle result) {
                            mShellExecutor.execute(() -> {
                                if (mBackGestureStarted) {
                                    Log.w(TAG, "Back gesture is running, ignore request");
                                    return;
                                }
                                onMotionEvent(0, 0, KeyEvent.ACTION_DOWN, EDGE_NONE);
                                setTriggerBack(true);
                                onMotionEvent(0, 0, KeyEvent.ACTION_UP, EDGE_NONE);
                            });
                    }
                });
        try {
            mActivityTaskManager.registerBackGestureDelegate(requestBackMonitor);
        } catch (RemoteException remoteException) {
            Log.w(TAG, "Failed register back gesture request ", remoteException);
        }
    }

    /**
     * Description of current BackAnimationController state.
     */
+3 −0
Original line number Diff line number Diff line
@@ -4633,6 +4633,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {

    @SuppressLint("MissingPermission")
    private void injectBackGesture(long downtime) {
        if (mActivityTaskManagerInternal.requestBackGesture()) {
            return;
        }
        // Create and inject down event
        KeyEvent downEvent = new KeyEvent(downtime, downtime, KeyEvent.ACTION_DOWN,
                KeyEvent.KEYCODE_BACK, 0 /* repeat */, 0 /* metaState */,
+6 −0
Original line number Diff line number Diff line
@@ -803,4 +803,10 @@ public abstract class ActivityTaskManagerInternal {

    /** Returns whether assist data is allowed. */
    public abstract boolean isAssistDataAllowed();

    /**
     * Delegate back gesture request from shell.
     * Returns true if the back gesture request was successful, false otherwise.
     */
    public abstract boolean requestBackGesture();
}
Loading