[automerge] Don't send old media ids to the newly selected app 2p: 65c41fe0fe

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Car/Media/+/16793029

Change-Id: Idb27b3aeb58efc2e6ef0a99d4a6481494989d6cd
diff --git a/src/com/android/car/media/MediaActivity.java b/src/com/android/car/media/MediaActivity.java
index b437a1a..591285a 100644
--- a/src/com/android/car/media/MediaActivity.java
+++ b/src/com/android/car/media/MediaActivity.java
@@ -426,10 +426,6 @@
                 break;
             case BROWSING:
                 if (oldMode == Mode.PLAYBACK) {
-                    // When switching from PLAYBACK mode to BROWSING mode, if a CarUiRecyclerView
-                    // shows up and it's in rotary mode, restore focus in the CarUiRecyclerView.
-                    mMediaActivityController.restoreFocusInCurrentNode();
-
                     ViewUtils.hideViewAnimated(mErrorContainer, 0);
                     ViewUtils.showViewAnimated(mBrowseContainer, 0);
                     animateOutPlaybackContainer(fadeOutDuration);
diff --git a/src/com/android/car/media/MediaActivityController.java b/src/com/android/car/media/MediaActivityController.java
index a29b40d..9882e70 100644
--- a/src/com/android/car/media/MediaActivityController.java
+++ b/src/com/android/car/media/MediaActivityController.java
@@ -406,6 +406,7 @@
         updateAppBar();
     }
 
+    @NonNull
     private BrowseViewController getControllerForItem(@NonNull MediaItemMetadata item) {
         BrowseViewController controller = mBrowseViewControllersByNode.get(item);
         if (controller == null) {
@@ -438,15 +439,15 @@
     }
 
     // If the current node has a CarUiRecyclerView and it's in rotary mode, restore focus in it.
-    void restoreFocusInCurrentNode() {
+    // Should remain private and definitely NOT be called from MediaActivity#changeModeInternal
+    // as the controller isn't ready to show the browse data of the new media source (it hasn't
+    // connected to it (b/217159531).
+    private void restoreFocusInCurrentNode() {
         MediaItemMetadata currentNode = getCurrentMediaItem();
         if (currentNode == null) {
             return;
         }
         BrowseViewController controller = getControllerForItem(currentNode);
-        if (controller == null) {
-            return;
-        }
         CarUiRecyclerView carUiRecyclerView =
                 controller.getContent().findViewById(R.id.browse_list);
         if (carUiRecyclerView != null && carUiRecyclerView instanceof LazyLayoutView