Provide more accurate nav button states

Override the logic to find the top activity to highlight the nav button states. Each HOME screen could be implemented in different ways. For example, using Task Views or display area or combination of both. In such scenarios the finding the topActivity should be use case specific.

Bug: 228639659
Fix: 241463042
Test: Manual
Change-Id: I6bb6f63d0d1fdaca1d9f9cd3acdcf2765ebaeef6
diff --git a/car_product/car_ui_portrait/apps/CarUiPortraitSystemUI/src/com/android/systemui/car/systembar/CarUiPortraitButtonSelectionStateController.java b/car_product/car_ui_portrait/apps/CarUiPortraitSystemUI/src/com/android/systemui/car/systembar/CarUiPortraitButtonSelectionStateController.java
new file mode 100644
index 0000000..0bbd51c
--- /dev/null
+++ b/car_product/car_ui_portrait/apps/CarUiPortraitSystemUI/src/com/android/systemui/car/systembar/CarUiPortraitButtonSelectionStateController.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.car.systembar;
+
+import android.app.ActivityTaskManager;
+import android.content.ComponentName;
+import android.content.Context;
+
+import com.android.systemui.dagger.SysUISingleton;
+
+/**
+ * CarSystemBarButtons can optionally have selection state that toggles certain visual indications
+ * based on whether the active application on screen is associated with it. This is basically a
+ * similar concept to a radio button group.
+ *
+ * This class controls the selection state of CarSystemBarButtons that have opted in to have such
+ * selection state-dependent visual indications.
+ */
+@SysUISingleton
+public class CarUiPortraitButtonSelectionStateController extends ButtonSelectionStateController {
+
+    public CarUiPortraitButtonSelectionStateController(Context context) {
+        super(context);
+    }
+
+    @Override
+    protected ComponentName getTopActivity(
+            ActivityTaskManager.RootTaskInfo validTaskInfo) {
+        return validTaskInfo.topActivity;
+    }
+}
diff --git a/car_product/car_ui_portrait/apps/CarUiPortraitSystemUI/src/com/android/systemui/car/systembar/CarUiPortraitSystemBarModule.java b/car_product/car_ui_portrait/apps/CarUiPortraitSystemUI/src/com/android/systemui/car/systembar/CarUiPortraitSystemBarModule.java
index e26046d..5363e13 100644
--- a/car_product/car_ui_portrait/apps/CarUiPortraitSystemUI/src/com/android/systemui/car/systembar/CarUiPortraitSystemBarModule.java
+++ b/car_product/car_ui_portrait/apps/CarUiPortraitSystemUI/src/com/android/systemui/car/systembar/CarUiPortraitSystemBarModule.java
@@ -39,4 +39,11 @@
         return new CarUiPortraitButtonSelectionStateListener(context,
                 buttonSelectionStateController, displayAreaController);
     }
+
+    @SysUISingleton
+    @Provides
+    @CarSysUIDynamicOverride
+    static ButtonSelectionStateController provideButtonSelectionStateController(Context context) {
+        return new CarUiPortraitButtonSelectionStateController(context);
+    }
 }