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

Commit 0cd56136 authored by Adrian Roos's avatar Adrian Roos Committed by Android (Google) Code Review
Browse files

Merge "IMMS: Fix NPE in SoftInputShowHideHistory.dump" into udc-dev

parents 73942fb4 d0ea5c38
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -856,13 +856,15 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
    @GuardedBy("ImfLock.class")
    private final WeakHashMap<IBinder, IBinder> mImeTargetWindowMap = new WeakHashMap<>();

    private static final class SoftInputShowHideHistory {
    @VisibleForTesting
    static final class SoftInputShowHideHistory {
        private final Entry[] mEntries = new Entry[16];
        private int mNextIndex = 0;
        private static final AtomicInteger sSequenceNumber = new AtomicInteger(0);

        private static final class Entry {
        static final class Entry {
            final int mSequenceNumber = sSequenceNumber.getAndIncrement();
            @Nullable
            final ClientState mClientState;
            @SoftInputModeFlags
            final int mFocusedWindowSoftInputMode;
@@ -874,7 +876,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            final boolean mInFullscreenMode;
            @NonNull
            final String mFocusedWindowName;
            @NonNull
            @Nullable
            final EditorInfo mEditorInfo;
            @NonNull
            final String mRequestWindowName;
@@ -953,9 +955,13 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub

                pw.print(prefix);
                pw.print(" editorInfo: ");
                if (entry.mEditorInfo != null) {
                    pw.print(" inputType=" + entry.mEditorInfo.inputType);
                    pw.print(" privateImeOptions=" + entry.mEditorInfo.privateImeOptions);
                    pw.println(" fieldId (viewId)=" + entry.mEditorInfo.fieldId);
                } else {
                    pw.println("null");
                }

                pw.print(prefix);
                pw.println(" focusedWindowSoftInputMode=" + InputMethodDebug.softInputModeToString(
+30 −0
Original line number Diff line number Diff line
@@ -20,16 +20,25 @@ import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.WindowManager.DISPLAY_IME_POLICY_FALLBACK_DISPLAY;
import static android.view.WindowManager.DISPLAY_IME_POLICY_LOCAL;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import android.platform.test.annotations.Presubmit;

import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.internal.inputmethod.SoftInputShowHideReason;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.PrintWriter;
import java.io.StringWriter;

@Presubmit
@SmallTest
@RunWith(AndroidJUnit4.class)
public class InputMethodManagerServiceTests {
@@ -87,4 +96,25 @@ public class InputMethodManagerServiceTests {
                InputMethodManagerService.computeImeDisplayIdForTarget(
                        SYSTEM_DECORATION_SUPPORT_DISPLAY_ID, sChecker));
    }

    @Test
    public void testSoftInputShowHideHistoryDump_withNulls_doesntThrow() {
        var writer = new StringWriter();
        var history = new InputMethodManagerService.SoftInputShowHideHistory();
        history.addEntry(new InputMethodManagerService.SoftInputShowHideHistory.Entry(
                null,
                null,
                null,
                SOFT_INPUT_STATE_UNSPECIFIED,
                SoftInputShowHideReason.SHOW_SOFT_INPUT,
                false,
                null,
                null,
                null,
                null));

        history.dump(new PrintWriter(writer), "" /* prefix */);

        // Asserts that dump doesn't throw an NPE.
    }
}