Introduce KeyboardStateManager to maintain keyboardstate as show or hide.

- Add a feature flag for IME Latency logging.

- Removed mShowImeAfterFirstLayout from ExtendedEditText.

   http://ag/1414509 added `mShowImeAfterFirstLayout`and cl description
   says "Show IME when search query != null after rotation".

   I verified the behavior by turning on "Allow home screen rotation".
   Keyboard is not getting dismissed on rotation in AA+ screen in a-z list
   or even in the search screen.
   Video : https://drive.google.com/file/d/1BWUTrW9OSEo6ojErj8INMwjFCPArVD4B/view?usp=sharing&resourcekey=0-SXTcKyUw1wCSi8Bm37ktow

Bug: 240192346
Test: Manual.

Verified by setting `ENABLE_KEYBOARD_TRANSITION_SYNC` to false and for
following usecases.

- All apps entry with ime enabled, scrolling a-z list to hide keyboard
- Folder name change - showing and dismissing keyboard
- Toast entry from Allapps and QSB - showing and dismissing keyboard

Change-Id: I1a6b5759b8e71e77744f58677b6d1b73e2f633e8
diff --git a/src/com/android/launcher3/ExtendedEditText.java b/src/com/android/launcher3/ExtendedEditText.java
index 4629ca7..98c71c5 100644
--- a/src/com/android/launcher3/ExtendedEditText.java
+++ b/src/com/android/launcher3/ExtendedEditText.java
@@ -15,6 +15,7 @@
  */
 package com.android.launcher3;
 
+import static com.android.launcher3.logging.KeyboardStateManager.KeyboardState.SHOW;
 import static com.android.launcher3.util.UiThreadHelper.hideKeyboardAsync;
 
 import android.content.Context;
@@ -33,8 +34,6 @@
  * Note: AppCompatEditText doesn't fully support #displayCompletions and #onCommitCompletion
  */
 public class ExtendedEditText extends EditText {
-
-    private boolean mShowImeAfterFirstLayout;
     private boolean mForceDisableSuggestions = false;
 
     /**
@@ -85,21 +84,9 @@
         return false;
     }
 
-    @Override
-    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
-        super.onLayout(changed, left, top, right, bottom);
-        if (mShowImeAfterFirstLayout) {
-            // soft input only shows one frame after the layout of the EditText happens,
-            post(() -> {
-                showSoftInput();
-                mShowImeAfterFirstLayout = false;
-            });
-        }
-    }
-
-
     public void showKeyboard() {
-        mShowImeAfterFirstLayout = !showSoftInput();
+        onKeyboardShown();
+        showSoftInput();
     }
 
     public void hideKeyboard() {
@@ -107,6 +94,11 @@
         clearFocus();
     }
 
+    protected void onKeyboardShown() {
+        ActivityContext.lookupContext(getContext()).getStatsLogManager()
+                .keyboardStateManager().setKeyboardState(SHOW);
+    }
+
     private boolean showSoftInput() {
         return requestFocus() &&
                 getContext().getSystemService(InputMethodManager.class)