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

Commit 110c8d09 authored by Tiger Huang's avatar Tiger Huang
Browse files

Notify when a fake control target changes the requested visibility

When a system bar is forcibly shown transiently, the original
controlling target will become the fake control target. And the real
control target will be InsetsPolicy#mTransientControlTarget which will
control the leash of the system bar. At this moment, the fake control
target should still be able to control the visibility of the insets
source dispatched to the client windows.

This CL calls notifyInsetsChanged when a fake control target changes the
requested visibility of its controlling type.

Bug: 393646206
Flag: EXEMPT bugfix
Test: Hide status bar in an app when a heads up notification is showing,
      and see if the app changes its layout accordingly while the
      notification it still there.
Test: ActivityRecordTests InsetsPolicyTest InsetsStateControllerTest
Change-Id: I083ac979486f1fdfa1fb50b4da0c53264624adbb
parent a513c260
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -7112,14 +7112,19 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        }

        /**
         * @return an integer as the changed requested visible insets types.
         * @see #getRequestedVisibleTypes()
         */
        void updateRequestedVisibleTypes(@InsetsType int visibleTypes, @InsetsType int mask) {
            int newRequestedVisibleTypes =
        @InsetsType int updateRequestedVisibleTypes(
                @InsetsType int visibleTypes, @InsetsType int mask) {
            final int newRequestedVisibleTypes =
                    (mRequestedVisibleTypes & ~mask) | (visibleTypes & mask);
            if (mRequestedVisibleTypes != newRequestedVisibleTypes) {
                final int changedTypes = mRequestedVisibleTypes ^ newRequestedVisibleTypes;
                mRequestedVisibleTypes = newRequestedVisibleTypes;
                return changedTypes;
            }
            return 0;
        }
    }

+10 −5
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.util.proto.ProtoOutputStream;
import android.view.InputApplicationHandle;
import android.view.InputChannel;
import android.view.WindowInsets;
import android.view.WindowInsets.Type.InsetsType;
import android.window.InputTransferToken;

import com.android.internal.protolog.ProtoLog;
@@ -260,7 +261,7 @@ class EmbeddedWindowController {

        // The EmbeddedWindow can only request the IME. All other insets types are requested by
        // the host window.
        private @WindowInsets.Type.InsetsType int mRequestedVisibleTypes = 0;
        private @InsetsType int mRequestedVisibleTypes = 0;

        /** Whether the gesture is transferred to embedded window. */
        boolean mGestureToEmbedded = false;
@@ -354,24 +355,28 @@ class EmbeddedWindowController {
        }

        @Override
        public boolean isRequestedVisible(@WindowInsets.Type.InsetsType int types) {
        public boolean isRequestedVisible(@InsetsType int types) {
            return (mRequestedVisibleTypes & types) != 0;
        }

        @Override
        public @WindowInsets.Type.InsetsType int getRequestedVisibleTypes() {
        public @InsetsType int getRequestedVisibleTypes() {
            return mRequestedVisibleTypes;
        }

        /**
         * Only the IME can be requested from the EmbeddedWindow.
         * @param requestedVisibleTypes other types than {@link WindowInsets.Type.IME} are
         * @param requestedVisibleTypes other types than {@link WindowInsets.Type#ime()} are
         *                              not sent to system server via WindowlessWindowManager.
         * @return an integer as the changed requested visible insets types.
         */
        void setRequestedVisibleTypes(@WindowInsets.Type.InsetsType int requestedVisibleTypes) {
        @InsetsType int setRequestedVisibleTypes(@InsetsType int requestedVisibleTypes) {
            if (mRequestedVisibleTypes != requestedVisibleTypes) {
                final int changedTypes = mRequestedVisibleTypes ^ requestedVisibleTypes;
                mRequestedVisibleTypes = requestedVisibleTypes;
                return changedTypes;
            }
            return 0;
        }

        @Override
+2 −2
Original line number Diff line number Diff line
@@ -437,9 +437,9 @@ class InsetsPolicy {
        return originalState;
    }

    void onRequestedVisibleTypesChanged(InsetsTarget caller,
    void onRequestedVisibleTypesChanged(InsetsTarget caller, @InsetsType int changedTypes,
            @Nullable ImeTracker.Token statsToken) {
        mStateController.onRequestedVisibleTypesChanged(caller, statsToken);
        mStateController.onRequestedVisibleTypesChanged(caller, changedTypes, statsToken);
        checkAbortTransient(caller);
        updateBarControlTarget(mFocusedWin);
    }
+12 −5
Original line number Diff line number Diff line
@@ -219,14 +219,20 @@ class InsetsStateController {
        }
    }

    void onRequestedVisibleTypesChanged(InsetsTarget caller,
    void onRequestedVisibleTypesChanged(InsetsTarget caller, @InsetsType int changedTypes,
            @Nullable ImeTracker.Token statsToken) {
        boolean changed = false;
        for (int i = mProviders.size() - 1; i >= 0; i--) {
            final InsetsSourceProvider provider = mProviders.valueAt(i);
            final boolean isImeProvider = provider.getSource().getType() == WindowInsets.Type.ime();
            changed |= provider.updateClientVisibility(caller,
                    isImeProvider ? statsToken : null);
            final @InsetsType int type = provider.getSource().getType();
            if ((type & changedTypes) != 0) {
                final boolean isImeProvider = type == WindowInsets.Type.ime();
                changed |= provider.updateClientVisibility(
                                caller, isImeProvider ? statsToken : null)
                        // Fake control target cannot change the client visibility, but it should
                        // change the insets with its newly requested visibility.
                        || (caller == provider.getFakeControlTarget());
            }
        }
        if (changed) {
            notifyInsetsChanged();
@@ -435,7 +441,8 @@ class InsetsStateController {
            for (int i = newControlTargets.size() - 1; i >= 0; i--) {
                // TODO(b/353463205) the statsToken shouldn't be null as it is used later in the
                //  IME provider. Check if we have to create a new request here
                onRequestedVisibleTypesChanged(newControlTargets.valueAt(i), null /* statsToken */);
                onRequestedVisibleTypesChanged(newControlTargets.valueAt(i),
                        WindowInsets.Type.all(), null /* statsToken */);
            }
            newControlTargets.clear();
            if (!android.view.inputmethod.Flags.refactorInsetsController()) {
+6 −4
Original line number Diff line number Diff line
@@ -704,9 +704,10 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
                    ImeTracker.forLogging().onProgress(imeStatsToken,
                            ImeTracker.PHASE_WM_UPDATE_REQUESTED_VISIBLE_TYPES);
                }
                final @InsetsType int changedTypes =
                        win.setRequestedVisibleTypes(requestedVisibleTypes);
                win.getDisplayContent().getInsetsPolicy().onRequestedVisibleTypesChanged(win,
                        imeStatsToken);
                        changedTypes, imeStatsToken);
                final Task task = win.getTask();
                if (task != null) {
                    task.dispatchTaskInfoChangedIfNeeded(/* forced= */ true);
@@ -723,10 +724,11 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
                    // TODO(b/353463205) Use different phase here
                    ImeTracker.forLogging().onProgress(imeStatsToken,
                            ImeTracker.PHASE_WM_UPDATE_REQUESTED_VISIBLE_TYPES);
                    embeddedWindow.setRequestedVisibleTypes(
                    final @InsetsType int changedTypes = embeddedWindow.setRequestedVisibleTypes(
                            requestedVisibleTypes & WindowInsets.Type.ime());
                    embeddedWindow.getDisplayContent().getInsetsPolicy()
                            .onRequestedVisibleTypesChanged(embeddedWindow, imeStatsToken);
                            .onRequestedVisibleTypesChanged(
                                    embeddedWindow, changedTypes, imeStatsToken);
                } else {
                    ImeTracker.forLogging().onFailed(imeStatsToken,
                            ImeTracker.PHASE_WM_UPDATE_REQUESTED_VISIBLE_TYPES);
Loading