Don't set the view if it stays the same

Fixes: 158019885
Test: manual
Change-Id: I41554db9d906f8c7eaff0d28233cf54d5e373521
diff --git a/car-apps-common/src/com/android/car/apps/common/ControlBar.java b/car-apps-common/src/com/android/car/apps/common/ControlBar.java
index d663d94..5d6d76c 100644
--- a/car-apps-common/src/com/android/car/apps/common/ControlBar.java
+++ b/car-apps-common/src/com/android/car/apps/common/ControlBar.java
@@ -291,8 +291,12 @@
     }
 
     private void setView(@Nullable View view, FrameLayout container) {
-        container.removeAllViews();
         if (view != null) {
+            // Don't set the view if it stays the same.
+            if (container.getChildCount() == 1 && container.getChildAt(0) == view) {
+                return;
+            }
+
             ViewGroup parent = (ViewGroup) view.getParent();
             // As we are removing views (on BT disconnect, for example), some items will be
             // shifting from expanded to collapsed (like Queue item) - remove those from the
@@ -300,9 +304,13 @@
             if (view.getParent() != null) {
                 parent.removeView(view);
             }
+            container.removeAllViews();
             container.addView(view);
             container.setVisibility(VISIBLE);
         } else {
+            if (container.getChildCount() != 0) {
+                container.removeAllViews();
+            }
             container.setVisibility(INVISIBLE);
         }
     }