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

Commit fc44d950 authored by Louis Chang's avatar Louis Chang Committed by Android (Google) Code Review
Browse files

Merge "Makes raw back event sends to the secondary container" into main

parents 6807ec6f 4346e583
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -4708,6 +4708,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            case KeyEvent.KEYCODE_BACK: {
                logKeyboardSystemsEventOnActionUp(event, KeyboardLogEvent.BACK);
                if (down) {
                    // There may have other embedded activities on the same Task. Try to move the
                    // focus before processing the back event.
                    mWindowManagerInternal.moveFocusToTopEmbeddedWindowIfNeeded();
                    mBackKeyHandled = false;
                } else {
                    if (!hasLongPressOnBackBehavior()) {
+6 −17
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.server.wm;
import static android.app.ActivityTaskManager.INVALID_TASK_ID;
import static android.view.RemoteAnimationTarget.MODE_CLOSING;
import static android.view.RemoteAnimationTarget.MODE_OPENING;
import static android.view.View.FOCUS_FORWARD;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static android.view.WindowManager.TRANSIT_CLOSE;
import static android.view.WindowManager.TRANSIT_OLD_NONE;
@@ -61,7 +60,6 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.policy.TransitionAnimation;
import com.android.internal.protolog.common.ProtoLog;
import com.android.server.wm.utils.InsetUtils;
import com.android.window.flags.Flags;

import java.io.PrintWriter;
import java.util.ArrayList;
@@ -165,23 +163,14 @@ class BackNavigationController {
                return null;
            }

            // Move focus to the adjacent embedded window if it is higher than this window
            final TaskFragment taskFragment = window.getTaskFragment();
            final TaskFragment adjacentTaskFragment =
                    taskFragment != null ? taskFragment.getAdjacentTaskFragment() : null;
            if (adjacentTaskFragment != null && taskFragment.isEmbedded()
                    && Flags.embeddedActivityBackNavFlag()) {
                final WindowContainer parent = taskFragment.getParent();
                if (parent.mChildren.indexOf(taskFragment) < parent.mChildren.indexOf(
                        adjacentTaskFragment)) {
                    mWindowManagerService.moveFocusToAdjacentWindow(window, FOCUS_FORWARD);
            // Move focus to the top embedded window if possible
            if (mWindowManagerService.moveFocusToTopEmbeddedWindow(window)) {
                window = wmService.getFocusedWindowLocked();
                if (window == null) {
                        Slog.e(TAG, "Adjacent window is null, returning null.");
                    Slog.e(TAG, "New focused window is null, returning null.");
                    return null;
                }
            }
            }

            // This is needed to bridge the old and new back behavior with recents.  While in
            // Overview with live tile enabled, the previous app is technically focused but we
+8 −1
Original line number Diff line number Diff line
@@ -1005,7 +1005,14 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
    public boolean moveFocusToAdjacentWindow(IWindow fromWindow, @FocusDirection int direction) {
        final long identity = Binder.clearCallingIdentity();
        try {
            return mService.moveFocusToAdjacentWindow(this, fromWindow, direction);
            synchronized (mService.mGlobalLock) {
                final WindowState win =
                        mService.windowForClientLocked(this, fromWindow, false /* throwOnError */);
                if (win == null) {
                    return false;
                }
                return mService.moveFocusToAdjacentWindow(win, direction);
            }
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
+5 −0
Original line number Diff line number Diff line
@@ -1047,4 +1047,9 @@ public abstract class WindowManagerInternal {
     * * {@link #addBlockScreenCaptureForApps(ArraySet)}
     */
    public abstract void clearBlockedApps();

    /**
     * Moves the current focus to the top activity window if the top activity is embedded.
     */
    public abstract boolean moveFocusToTopEmbeddedWindowIfNeeded();
}
+65 −15
Original line number Diff line number Diff line
@@ -346,6 +346,7 @@ import com.android.server.policy.WindowManagerPolicy.ScreenOffListener;
import com.android.server.power.ShutdownThread;
import com.android.server.utils.PriorityDump;
import com.android.server.wallpaper.WallpaperCropper.WallpaperCropUtils;
import com.android.window.flags.Flags;

import dalvik.annotation.optimization.NeverCompile;

@@ -8629,6 +8630,24 @@ public class WindowManagerService extends IWindowManager.Stub
                }
            }
        }

        @Override
        public boolean moveFocusToTopEmbeddedWindowIfNeeded() {
            synchronized (mGlobalLock) {
                final WindowState focusedWindow = getFocusedWindow();
                if (focusedWindow == null) {
                    return false;
                }

                if (moveFocusToTopEmbeddedWindow(focusedWindow)) {
                    // Sync the input transactions to ensure the input focus updates as well.
                    syncInputTransactions(false);
                    return true;
                }

                return false;
            }
        }
    }

    private final class ImeTargetVisibilityPolicyImpl extends ImeTargetVisibilityPolicy {
@@ -9162,18 +9181,48 @@ public class WindowManagerService extends IWindowManager.Stub
                win.mClient);
    }

    boolean moveFocusToAdjacentWindow(Session session, IWindow fromWindow,
            @FocusDirection int direction) {
        synchronized (mGlobalLock) {
            final WindowState fromWin = windowForClientLocked(session, fromWindow, false);
            if (fromWin == null || !fromWin.isFocused()) {
    /**
     * Move focus to the top embedded window if possible.
     */
    boolean moveFocusToTopEmbeddedWindow(@NonNull WindowState focusedWindow) {
        final TaskFragment taskFragment = focusedWindow.getTaskFragment();
        if (taskFragment == null) {
            // Skip if not an Activity window.
            return false;
        }

        if (!Flags.embeddedActivityBackNavFlag()) {
            // Skip if flag is not enabled.
            return false;
        }

        final ActivityRecord topActivity =
                taskFragment.getTask().topRunningActivity(true /* focusableOnly */);
        if (topActivity == null || topActivity == focusedWindow.mActivityRecord) {
            // Skip if the focused activity is already the top-most activity on the Task.
            return false;
        }

        if (!topActivity.isEmbedded()) {
            // Skip if the top activity is not embedded
            return false;
        }
            return moveFocusToAdjacentWindow(fromWin, direction);

        final TaskFragment topTaskFragment = topActivity.getTaskFragment();
        if (topTaskFragment.isIsolatedNav()
                && taskFragment.getAdjacentTaskFragment() == topTaskFragment) {
            // Skip if the top TaskFragment is adjacent to current focus and is set to isolated nav.
            return false;
        }

        moveFocusToActivity(topActivity);
        return !focusedWindow.isFocused();
    }

    boolean moveFocusToAdjacentWindow(WindowState fromWin, @FocusDirection int direction) {
    boolean moveFocusToAdjacentWindow(@NonNull WindowState fromWin, @FocusDirection int direction) {
        if (!fromWin.isFocused()) {
            return false;
        }
        final TaskFragment fromFragment = fromWin.getTaskFragment();
        if (fromFragment == null) {
            return false;
@@ -9222,12 +9271,13 @@ public class WindowManagerService extends IWindowManager.Stub
        if (topRunningActivity == null) {
            return false;
        }
        moveDisplayToTopInternal(topRunningActivity.getDisplayId());
        handleTaskFocusChange(topRunningActivity.getTask(), topRunningActivity);
        if (fromWin.isFocused()) {
            return false;
        moveFocusToActivity(topRunningActivity);
        return !fromWin.isFocused();
    }
        return true;

    private void moveFocusToActivity(@NonNull ActivityRecord activity) {
        moveDisplayToTopInternal(activity.getDisplayId());
        handleTaskFocusChange(activity.getTask(), activity);
    }

    /** Return whether layer tracing is enabled */
Loading