MultiUserUtils { public static int getUserIdFromAmParameters(@NotNull String amFlags) { String userFlag = "--user"; int i = amFlags.indexOf(userFlag); if ((i < 0)) { return PRIMARY_USERID; } i += userFlag.length() + 1; if (i > amFlags.length()) { return PRIMARY_USERID; } amFlags = amFlags.substring(i).trim(); try { return Integer.parseInt(amFlags); } catch (NumberFormatException e) { return PRIMARY_USERID; } }  static boolean isCurrentUserThePrimaryUser(@NotNull IDevice device, long timeout, TimeUnit units, boolean defaultValue); static boolean hasMultipleUsers(@Nullable IDevice device, long timeout, TimeUnit units, boolean defaultValue); static int getUserIdFromAmParameters(@NotNull String amFlags); static final int PRIMARY_USERID; }
@Test public void userIdExtractionFromAmFlags() { assertEquals(MultiUserUtils.PRIMARY_USERID, MultiUserUtils.getUserIdFromAmParameters("")); assertEquals(MultiUserUtils.PRIMARY_USERID, MultiUserUtils.getUserIdFromAmParameters(" --user")); assertEquals(MultiUserUtils.PRIMARY_USERID, MultiUserUtils.getUserIdFromAmParameters(" --user 0")); assertEquals(20, MultiUserUtils.getUserIdFromAmParameters(" --user 20")); }