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

Commit 3d4a7d1b authored by Louis Chang's avatar Louis Chang
Browse files

Unregister ImeInsetsSourceConsumer when focus lost

ImeInsetsSourceConsumer was not unregistered when focus lost, it
was still references by InputMethodManager. So, the last activity
in the process won’t be GCed even though it has been destroyed.

Bug: 130216346
Test: atest ImeInsetsSourceConsumerTest
Change-Id: Ida19411d8361180692e7de7e012d2cd3b431fa9f
parent c53df3a9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {
    @Override
    public void onWindowFocusLost() {
        mHasWindowFocus = false;
        getImm().unregisterImeConsumer(this);
    }

    /**
+17 −0
Original line number Diff line number Diff line
@@ -1950,6 +1950,23 @@ public final class InputMethodManager {
        }
    }

    /**
     * Unregister for IME state callbacks and applying visibility in
     * {@link android.view.ImeInsetsSourceConsumer}.
     * @hide
     */
    public void unregisterImeConsumer(@NonNull ImeInsetsSourceConsumer imeInsetsConsumer) {
        if (imeInsetsConsumer == null) {
            throw new IllegalStateException("ImeInsetsSourceConsumer cannot be null.");
        }

        synchronized (mH) {
            if (mImeInsetsConsumer == imeInsetsConsumer) {
                mImeInsetsConsumer = null;
            }
        }
    }

    /**
     * Call showSoftInput with currently focused view.
     * @return {@code true} if IME can be shown.