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

Commit 89c25ce1 authored by Arthur Hung's avatar Arthur Hung Committed by Automerger Merge Worker
Browse files

Merge "Cancel back invoke when window focus has lost" into tm-qpr-dev am: f52b4988

parents 7e2c9cb3 f52b4988
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ import android.os.WorkSource;
import android.service.voice.IVoiceInteractionSession;
import android.view.IRecentsAnimationRunner;
import android.view.IRemoteAnimationRunner;
import android.view.IWindowFocusObserver;
import android.view.RemoteAnimationDefinition;
import android.view.RemoteAnimationAdapter;
import android.window.IWindowOrganizerController;
@@ -352,6 +353,8 @@ interface IActivityTaskManager {
     * Prepare the back navigation in the server. This setups the leashed for sysui to animate
     * the back gesture and returns the data needed for the animation.
     * @param requestAnimation true if the caller wishes to animate the back navigation
     * @param focusObserver a remote callback to nofify shell when the focused window lost focus.
     */
    android.window.BackNavigationInfo startBackNavigation(in boolean requestAnimation);
    android.window.BackNavigationInfo startBackNavigation(in boolean requestAnimation,
            in IWindowFocusObserver focusObserver);
}
+0 −1
Original line number Diff line number Diff line
@@ -3761,7 +3761,6 @@ public final class ViewRootImpl implements ViewParent,
            }
        }
        mFirstInputStage.onWindowFocusChanged(hasWindowFocus);
        mOnBackInvokedDispatcher.onWindowFocusChanged(hasWindowFocus);

        // NOTE: there's no view visibility (appeared / disapparead) events when the windows focus
        // is lost, so we don't need to to force a flush - there might be other events such as
+1 −1
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ public final class BackNavigationInfo implements Parcelable {
     *                                back preview.
     * @param onBackInvokedCallback   The back callback registered by the current top level window.
     */
    public BackNavigationInfo(@BackTargetType int type,
    private BackNavigationInfo(@BackTargetType int type,
            @Nullable RemoteAnimationTarget departingAnimationTarget,
            @Nullable SurfaceControl screenshotSurface,
            @Nullable HardwareBuffer screenshotBuffer,
+1 −2
Original line number Diff line number Diff line
@@ -83,8 +83,7 @@ public class ImeOnBackInvokedDispatcher implements OnBackInvokedDispatcher, Parc
        final Bundle bundle = new Bundle();
        // Always invoke back for ime without checking the window focus.
        final IOnBackInvokedCallback iCallback =
                new WindowOnBackInvokedDispatcher.OnBackInvokedCallbackWrapper(callback,
                        () -> true);
                new WindowOnBackInvokedDispatcher.OnBackInvokedCallbackWrapper(callback);
        bundle.putBinder(RESULT_KEY_CALLBACK, iCallback.asBinder());
        bundle.putInt(RESULT_KEY_PRIORITY, priority);
        bundle.putInt(RESULT_KEY_ID, callback.hashCode());
+2 −22
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;
import java.util.TreeMap;
import java.util.function.Supplier;

/**
 * Provides window based implementation of {@link OnBackInvokedDispatcher}.
@@ -65,7 +64,6 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
    private final TreeMap<Integer, ArrayList<OnBackInvokedCallback>>
            mOnBackInvokedCallbacks = new TreeMap<>();
    private final Checker mChecker;
    private boolean mHasFocus;

    public WindowOnBackInvokedDispatcher(boolean applicationCallBackEnabled) {
        mChecker = new Checker(applicationCallBackEnabled);
@@ -191,7 +189,7 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
                                    .ImeOnBackInvokedCallback
                                ? ((ImeOnBackInvokedDispatcher.ImeOnBackInvokedCallback)
                                        callback).getIOnBackInvokedCallback()
                                : new OnBackInvokedCallbackWrapper(callback, this::hasFocus);
                                : new OnBackInvokedCallbackWrapper(callback);
                callbackInfo = new OnBackInvokedCallbackInfo(iCallback, priority);
            }
            mWindowSession.setOnBackInvokedCallbackInfo(mWindow, callbackInfo);
@@ -200,17 +198,6 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
        }
    }

    /**
     * Called when window focus changed.
     */
    public void onWindowFocusChanged(boolean hasFocus) {
        mHasFocus = hasFocus;
    }

    private boolean hasFocus() {
        return mHasFocus;
    }

    public OnBackInvokedCallback getTopCallback() {
        if (mAllCallbacks.isEmpty()) {
            return null;
@@ -234,11 +221,8 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {

    static class OnBackInvokedCallbackWrapper extends IOnBackInvokedCallback.Stub {
        private final WeakReference<OnBackInvokedCallback> mCallback;
        private final Supplier<Boolean> mHasFocus;
        OnBackInvokedCallbackWrapper(@NonNull OnBackInvokedCallback callback,
                @NonNull Supplier<Boolean> hasFocus) {
        OnBackInvokedCallbackWrapper(@NonNull OnBackInvokedCallback callback) {
            mCallback = new WeakReference<>(callback);
            mHasFocus = hasFocus;
        }

        @Override
@@ -278,10 +262,6 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
                if (callback == null) {
                    return;
                }
                if (!mHasFocus.get()) {
                    Log.w(TAG, "Skip back invoke due to current focus has lost.");
                    return;
                }
                callback.onBackInvoked();
            });
        }
Loading