Fix PlatformScenarioTests test AddGuest for HSUM
Bug: 288234861
Test: atest PlatformScenarioTests:android.platform.test.scenario.sysui.multiuser.AddGuest#testAddGuest
Change-Id: I1e0519f11afdab35fd31675fc9b32b021d88c4bb
diff --git a/libraries/systemui-helper/src/android/platform/helpers/CommonUtils.java b/libraries/systemui-helper/src/android/platform/helpers/CommonUtils.java
index ecacf80..c8a1e6a 100644
--- a/libraries/systemui-helper/src/android/platform/helpers/CommonUtils.java
+++ b/libraries/systemui-helper/src/android/platform/helpers/CommonUtils.java
@@ -65,6 +65,7 @@
private static final int SWIPE_STEPS = 100;
private static final int DEFAULT_MARGIN = 5;
private static final String LIST_ALL_USERS_COMMAND = "cmd user list -v --all";
+ private static final String GET_MAIN_USER_COMMAND = "cmd user get-main-user";
private CommonUtils() {
}
@@ -332,7 +333,7 @@
}
/**
- * Returns the current user user ID. NOTE: UserID = 0 is for Owner
+ * Returns the current user user ID. NOTE: UserID = 0 is for System
*
* @return a current user ID
*/
@@ -367,6 +368,23 @@
throw new RuntimeException("Failed to find current user ID.");
}
+ /**
+ * Returns the main user ID. Main user is the main human user on the device.
+ * Returns 0 by default, if there is no main user. Android Auto is example of HSUM without
+ * main user.
+ *
+ * NOTE: For headless system main user it is NOT 0. Therefore Main user should be used in
+ * test cases rather than owner or deprecated primary user.
+ */
+ public static int getMainUserId() {
+ ArrayList<String> output = executeShellCommandWithDetailedOutput(GET_MAIN_USER_COMMAND);
+ try {
+ return Integer.parseInt(output.get(0).trim());
+ } catch (NumberFormatException e) {
+ return 0;
+ }
+ }
+
public static boolean isSplitShade() {
int orientation = getContext().getResources().getConfiguration().orientation;
return isLargeScreen() && orientation == Configuration.ORIENTATION_LANDSCAPE;