Clear junk when closing and reopening the kb

Update widescreen kb contentview as soon as action is received. There is no guarantee that onAppPrivateCommand and onStartupInputView will be called in any order. The views should be updated when the value is received from app.

Fix: 174812208
Bug: 170343703
Test: Manual
Change-Id: I628a87d6394059fc613c8d40960ceddcca5667de
diff --git a/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/imewidescreen/CarUiImeWideScreenController.java b/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/imewidescreen/CarUiImeWideScreenController.java
index bf7d2bf..bdead1a 100644
--- a/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/imewidescreen/CarUiImeWideScreenController.java
+++ b/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/imewidescreen/CarUiImeWideScreenController.java
@@ -328,6 +328,11 @@
         if (mAllowAppToHideContentArea || (mInputEditorInfo != null && isPackageAuthorized(
                 mInputEditorInfo.packageName))) {
             mImeRendersAllContent = data.getBoolean(REQUEST_RENDER_CONTENT_AREA, true);
+            if (!mImeRendersAllContent) {
+                mContentAreaAutomotive.setVisibility(View.GONE);
+            } else {
+                mContentAreaAutomotive.setVisibility(View.VISIBLE);
+            }
         }
 
         if (data.getParcelable(CONTENT_AREA_SURFACE_PACKAGE) != null
@@ -499,11 +504,6 @@
         } else {
             mFullscreenArea.setVisibility(View.VISIBLE);
         }
-        if (!mImeRendersAllContent) {
-            mContentAreaAutomotive.setVisibility(View.GONE);
-        } else {
-            mContentAreaAutomotive.setVisibility(View.VISIBLE);
-        }
 
         // This view is rendered by the framework when IME is in full screen mode. For more info
         // see {@link #onEvaluateFullscreenMode}
@@ -565,8 +565,8 @@
      * it draw its own content.
      */
     private void sendSurfaceInfo() {
-        if (!mAllowAppToHideContentArea && !(mInputEditorInfo != null
-                && isPackageAuthorized(mInputEditorInfo.packageName))) {
+        if (!mAllowAppToHideContentArea && mContentAreaSurfaceView.getDisplay() == null && !(
+                mInputEditorInfo != null && isPackageAuthorized(mInputEditorInfo.packageName))) {
             return;
         }
         int displayId = mContentAreaSurfaceView.getDisplay().getDisplayId();
@@ -779,7 +779,7 @@
         mImeRendersAllContent = true;
         mIsExtractIconProvidedByApp = false;
         mExtractViewHidden = false;
-        mAutomotiveSearchItems = new ArrayList<>();
+        mAutomotiveSearchItems = null;
     }
 
     /**