New Profile icon Test File to to verify the Guest user Profile in the Action Bar

Test: https://android-build.corp.google.com/test_investigate/?invocationId=I98600010177497721&testResultId=TR38628785276844862&redirect=http://fusion2/9992bf6f-3358-4368-b58f-283d31a6bb49

Bug: 282683856

Change-Id: I515d39aeda9c368c1db242aad7d0b7e7fba3345c
diff --git a/libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoHomeHelper.java b/libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoHomeHelper.java
index c44607c..12fc50c 100644
--- a/libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoHomeHelper.java
+++ b/libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoHomeHelper.java
@@ -55,6 +55,13 @@
      */
     boolean hasDisplayBrightness();
 
+    /**
+     * Setup expectations: Verifying the Guest label displayed in profile icon in status bar
+     *
+     * <p>Get the text of the Guest profile
+     */
+    String getUserProfileName();
+
     /** Opens Media Widget from home screen. */
     void openMediaWidget();
 
diff --git a/libraries/automotive-helpers/auto-default-config/resources/assets/defaultSpectatioConfig.json b/libraries/automotive-helpers/auto-default-config/resources/assets/defaultSpectatioConfig.json
index ee30f5a..f5bf3d6 100644
--- a/libraries/automotive-helpers/auto-default-config/resources/assets/defaultSpectatioConfig.json
+++ b/libraries/automotive-helpers/auto-default-config/resources/assets/defaultSpectatioConfig.json
@@ -381,6 +381,11 @@
       "VALUE": "qc_signal_status_icon",
       "PACKAGE": "com.android.systemui"
     },
+    "HOME_PROFILE_GUEST_ICON": {
+      "TYPE": "RESOURCE_ID",
+      "VALUE": "user_name_text",
+      "PACKAGE": "com.android.systemui"
+    },
     "HOME_FACET_BUTTON": {
       "TYPE": "RESOURCE_ID",
       "VALUE": "home",
diff --git a/libraries/automotive-helpers/auto-default-config/src/android/platform/helpers/AutomotiveConfigConstants.java b/libraries/automotive-helpers/auto-default-config/src/android/platform/helpers/AutomotiveConfigConstants.java
index db99668..2770421 100644
--- a/libraries/automotive-helpers/auto-default-config/src/android/platform/helpers/AutomotiveConfigConstants.java
+++ b/libraries/automotive-helpers/auto-default-config/src/android/platform/helpers/AutomotiveConfigConstants.java
@@ -497,4 +497,7 @@
     public static final String LOCATION_SWITCH = "LOCATION_SWITCH";
     public static final String LOCATION_WIDGET = "LOCATION_WIDGET";
     public static final String RECENTLY_CLOSED_TEXT = "RECENTLY_CLOSED_TEXT";
+
+    // Guest Profile
+    public static final String HOME_PROFILE_GUEST_ICON = "HOME_PROFILE_GUEST_ICON";
 }
diff --git a/libraries/automotive-helpers/home-helper/src/android/platform/helpers/HomeHelperImpl.java b/libraries/automotive-helpers/home-helper/src/android/platform/helpers/HomeHelperImpl.java
index 8b7d51c..3ba8175 100644
--- a/libraries/automotive-helpers/home-helper/src/android/platform/helpers/HomeHelperImpl.java
+++ b/libraries/automotive-helpers/home-helper/src/android/platform/helpers/HomeHelperImpl.java
@@ -25,6 +25,7 @@
 import java.util.List;
 
 public class HomeHelperImpl extends AbstractStandardAppHelper implements IAutoHomeHelper {
+    private static final int WAIT_TIME_MS = 30000;
 
     public HomeHelperImpl(Instrumentation instr) {
         super(instr);
@@ -124,6 +125,20 @@
 
     /** {@inheritDoc} */
     @Override
+    public String getUserProfileName() {
+        getSpectatioUiUtil().waitForIdle();
+        getSpectatioUiUtil().waitNSeconds(WAIT_TIME_MS);
+        BySelector profileGuestIconWidgetSelector =
+                getUiElementFromConfig(AutomotiveConfigConstants.HOME_PROFILE_GUEST_ICON);
+        UiObject2 guestIconButtonLink =
+                getSpectatioUiUtil().findUiObject(profileGuestIconWidgetSelector);
+        validateUiObject(guestIconButtonLink, AutomotiveConfigConstants.HOME_PROFILE_GUEST_ICON);
+        String profileText = guestIconButtonLink.getText();
+        return profileText;
+    }
+
+    /** {@inheritDoc} */
+    @Override
     public void open() {
         getSpectatioUiUtil().pressHome();
         getSpectatioUiUtil().waitForIdle();
diff --git a/tests/automotive/functional/profileicon/Android.bp b/tests/automotive/functional/profileicon/Android.bp
new file mode 100644
index 0000000..006376c
--- /dev/null
+++ b/tests/automotive/functional/profileicon/Android.bp
@@ -0,0 +1,44 @@
+// Copyright (C) 2023 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 {
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_test {
+    name: "AndroidAutomotiveProfileIconTests",
+    min_sdk_version: "24",
+    static_libs: [
+               "androidx.test.rules",
+               "automotive-config-lib",
+               "automotive-multiuser-scenarios",
+               "automotive-health-test-rules",
+               "automotive-settings-app-helper",
+               "automotive-home-helper",
+               "app-helpers-common-interfaces",
+               "collector-device-lib-platform",
+               "common-platform-scenarios",
+               "common-platform-scenario-tests",
+               "microbenchmark-device-lib",
+               "platform-test-rules",
+               "platform-test-options",
+               "multi-user-helper",
+               "microbenchmark-device-lib",
+               "longevity-device-lib",
+    ],
+     srcs: ["src/**/*.java"],
+        certificate: "platform",
+        test_suites: ["catbox"],
+        privileged: true,
+}
diff --git a/tests/automotive/functional/profileicon/AndroidManifest.xml b/tests/automotive/functional/profileicon/AndroidManifest.xml
new file mode 100644
index 0000000..2ff960c
--- /dev/null
+++ b/tests/automotive/functional/profileicon/AndroidManifest.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2023 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+          package="android.platform.tests">
+    <uses-sdk android:minSdkVersion="24"
+              android:targetSdkVersion="24" />
+    <uses-permission android:name="android.permission.GET_RUNTIME_PERMISSIONS" />
+    <uses-permission android:name="android.permission.GRANT_RUNTIME_PERMISSIONS" />
+    <uses-permission android:name="android.permission.DUMP" />
+    <uses-permission android:name="android.permission.MANAGE_ACTIVITY_TASKS"/>
+    <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
+    <uses-permission android:name="android.Manifest.permission.MANAGE_USERS" />
+    <uses-permission android:name="android.permission.MANAGE_USERS" />
+    <uses-permission android:name="android.permission.CREATE_USERS" />
+    <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
+    <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
+    <instrumentation
+        android:name="androidx.test.runner.AndroidJUnitRunner"
+        android:targetPackage="android.platform.tests"
+        android:label="Android Automotive Profile Icon Test" />
+</manifest>
\ No newline at end of file
diff --git a/tests/automotive/functional/profileicon/src/android/platform/tests/ProfileIconTest.java b/tests/automotive/functional/profileicon/src/android/platform/tests/ProfileIconTest.java
new file mode 100644
index 0000000..b4be964
--- /dev/null
+++ b/tests/automotive/functional/profileicon/src/android/platform/tests/ProfileIconTest.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2023 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 android.platform.tests;
+
+import static junit.framework.Assert.assertTrue;
+
+import android.content.pm.UserInfo;
+import android.platform.helpers.HelperAccessor;
+import android.platform.helpers.IAutoHomeHelper;
+import android.platform.helpers.IAutoUserHelper;
+import android.platform.helpers.MultiUserHelper;
+import android.platform.scenario.multiuser.MultiUserConstants;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class ProfileIconTest {
+
+    private static final String USER_NAME = MultiUserConstants.GUEST_NAME;
+
+    private final MultiUserHelper mMultiUserHelper = MultiUserHelper.getInstance();
+
+    private HelperAccessor<IAutoUserHelper> mUsersHelper;
+
+    private HelperAccessor<IAutoHomeHelper> mHomeHelper;
+
+    public ProfileIconTest() {
+        mHomeHelper = new HelperAccessor<>(IAutoHomeHelper.class);
+        mUsersHelper = new HelperAccessor<>(IAutoUserHelper.class);
+    }
+
+    @Test
+    public void testToVerifyGuestProfile() throws Exception {
+        mUsersHelper.get().switchUser("Driver", USER_NAME);
+        UserInfo guest = mMultiUserHelper.getCurrentForegroundUserInfo();
+        mMultiUserHelper.switchAndWaitForStable(guest.id, MultiUserConstants.WAIT_FOR_IDLE_TIME_MS);
+        assertTrue(
+                "Failed to switch from current user to Guest Profile.",
+                USER_NAME.equals(mHomeHelper.get().getUserProfileName()));
+    }
+}