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

Commit fc3d011a authored by Adrian Roos's avatar Adrian Roos Committed by Automerger Merge Worker
Browse files

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

Merge "IMMS: Fix NPE in SoftInputShowHideHistory.dump" into udc-dev am: 0cd56136 am: d9e017b6 am: f9deda09

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22848436



Change-Id: Ic5bae87b2e789fa81f764bd624f165344a0395a3
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents a32374f2 f9deda09
Loading
Loading
Loading
Loading
+12 −6
Original line number Original line Diff line number Diff line
@@ -856,13 +856,15 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
    @GuardedBy("ImfLock.class")
    @GuardedBy("ImfLock.class")
    private final WeakHashMap<IBinder, IBinder> mImeTargetWindowMap = new WeakHashMap<>();
    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 final Entry[] mEntries = new Entry[16];
        private int mNextIndex = 0;
        private int mNextIndex = 0;
        private static final AtomicInteger sSequenceNumber = new AtomicInteger(0);
        private static final AtomicInteger sSequenceNumber = new AtomicInteger(0);


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


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


                pw.print(prefix);
                pw.print(prefix);
                pw.println(" focusedWindowSoftInputMode=" + InputMethodDebug.softInputModeToString(
                pw.println(" focusedWindowSoftInputMode=" + InputMethodDebug.softInputModeToString(
+30 −0
Original line number Original line 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.Display.INVALID_DISPLAY;
import static android.view.WindowManager.DISPLAY_IME_POLICY_FALLBACK_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.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.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assert.fail;


import android.platform.test.annotations.Presubmit;

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


import com.android.internal.inputmethod.SoftInputShowHideReason;

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


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

@Presubmit
@SmallTest
@SmallTest
@RunWith(AndroidJUnit4.class)
@RunWith(AndroidJUnit4.class)
public class InputMethodManagerServiceTests {
public class InputMethodManagerServiceTests {
@@ -87,4 +96,25 @@ public class InputMethodManagerServiceTests {
                InputMethodManagerService.computeImeDisplayIdForTarget(
                InputMethodManagerService.computeImeDisplayIdForTarget(
                        SYSTEM_DECORATION_SUPPORT_DISPLAY_ID, sChecker));
                        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.
    }
}
}