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

Commit 8bda5002 authored by Ionut Hulub's avatar Ionut Hulub Committed by Chris Li
Browse files

Reparent ImeContainer under parent when organized.

If, for whatever reason, the SystemUI process crashed and restarted,
the IME wasn't functional anymore (it would not become visible).

That happened because, after the SystemUI crash, the IME was
unorganized for a while and the framework reparented its surface
under an activity.

With this commit we fix this issue by reparenting the IME under its
parent when it becomes organized again.

Manual Test: Checked that the IME becomes visible after a systemui
             crash.
Test: atest DisplayContentTests
      #testImeContainerIsReparentedUnderParentWhenOrganized
Bug: 224800157
Change-Id: I303baf96c905a9c4b444189b731f63c7d51a11f2

Change-Id: I4d2934516e528bf353395e1759f59612542bdb56
parent 2907ec82
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -1927,6 +1927,12 @@
      "group": "WM_SHOW_TRANSACTIONS",
      "at": "com\/android\/server\/wm\/Session.java"
    },
    "-81121442": {
      "message": "ImeContainer just became organized but it doesn't have a parent or the parent doesn't have a surface control. mSurfaceControl=%s imeParentSurfaceControl=%s",
      "level": "ERROR",
      "group": "WM_DEBUG_IME",
      "at": "com\/android\/server\/wm\/DisplayContent.java"
    },
    "-80004683": {
      "message": "Resume failed; resetting state to %s: %s",
      "level": "VERBOSE",
@@ -2767,12 +2773,6 @@
      "group": "WM_DEBUG_WALLPAPER",
      "at": "com\/android\/server\/wm\/WallpaperWindowToken.java"
    },
    "736003885": {
      "message": "Unable to retrieve the task token to start recording for display %d",
      "level": "VERBOSE",
      "group": "WM_DEBUG_CONTENT_RECORDING",
      "at": "com\/android\/server\/wm\/ContentRecorder.java"
    },
    "736692676": {
      "message": "Config is relaunching %s",
      "level": "VERBOSE",
@@ -3139,6 +3139,12 @@
      "group": "WM_DEBUG_BACK_PREVIEW",
      "at": "com\/android\/server\/wm\/BackNavigationController.java"
    },
    "1175495463": {
      "message": "ImeContainer just became organized. Reparenting under parent. imeParentSurfaceControl=%s",
      "level": "INFO",
      "group": "WM_DEBUG_IME",
      "at": "com\/android\/server\/wm\/DisplayContent.java"
    },
    "1178653181": {
      "message": "Old wallpaper still the target.",
      "level": "VERBOSE",
+17 −0
Original line number Diff line number Diff line
@@ -4877,6 +4877,23 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        void setOrganizer(IDisplayAreaOrganizer organizer, boolean skipDisplayAreaAppeared) {
            super.setOrganizer(organizer, skipDisplayAreaAppeared);
            mDisplayContent.updateImeParent();

            // If the ImeContainer was previously unorganized then the framework might have
            // reparented its surface control under an activity so we need to reparent it back
            // under its parent.
            if (organizer != null) {
                final SurfaceControl imeParentSurfaceControl = getParentSurfaceControl();
                if (mSurfaceControl != null && imeParentSurfaceControl != null) {
                    ProtoLog.i(WM_DEBUG_IME, "ImeContainer just became organized. Reparenting "
                            + "under parent. imeParentSurfaceControl=%s", imeParentSurfaceControl);
                    getPendingTransaction().reparent(mSurfaceControl, imeParentSurfaceControl);
                } else {
                    ProtoLog.e(WM_DEBUG_IME, "ImeContainer just became organized but it doesn't "
                            + "have a parent or the parent doesn't have a surface control."
                            + " mSurfaceControl=%s imeParentSurfaceControl=%s",
                            mSurfaceControl, imeParentSurfaceControl);
                }
            }
        }
    }

+27 −0
Original line number Diff line number Diff line
@@ -414,6 +414,33 @@ public class DisplayContentTests extends WindowTestsBase {
        imeContainer.setOrganizer(null);
    }

    @Test
    public void testImeContainerIsReparentedUnderParentWhenOrganized() {
        final DisplayArea.Tokens imeContainer = mDisplayContent.getImeContainer();
        final ActivityRecord activity = createActivityRecord(mDisplayContent);

        final WindowState startingWin = createWindow(null, TYPE_APPLICATION_STARTING, activity,
                "startingWin");
        startingWin.setHasSurface(true);
        assertTrue(startingWin.canBeImeTarget());

        final Transaction transaction = mDisplayContent.getPendingTransaction();
        spyOn(transaction);

        // Organized the ime container.
        final IDisplayAreaOrganizer mockImeOrganizer = mock(IDisplayAreaOrganizer.class);
        when(mockImeOrganizer.asBinder()).thenReturn(new Binder());
        imeContainer.setOrganizer(mockImeOrganizer);

        // Verify that the ime container surface is reparented under
        // its parent surface as a consequence of the setOrganizer call.
        SurfaceControl imeParentSurfaceControl = imeContainer.getParentSurfaceControl();
        verify(transaction).reparent(imeContainer.getSurfaceControl(), imeParentSurfaceControl);

        // Clean up organizer.
        imeContainer.setOrganizer(null);
    }

    /**
     * This tests root task movement between displays and proper root task's, task's and app token's
     * display container references updates.