Skip to content

Commit dc8b794

Browse files
jscott1989pfmaggi
authored andcommitted
No public description
PiperOrigin-RevId: 635769126
1 parent c636254 commit dc8b794

File tree

1 file changed

+11
-1
lines changed
  • src/main/java/com/afwsamples/testdpc/common

1 file changed

+11
-1
lines changed

src/main/java/com/afwsamples/testdpc/common/Util.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,17 @@ public static boolean isManagedProfile(Context context) {
154154
public static boolean isPrimaryUser(Context context) {
155155
if (Util.SDK_INT >= VERSION_CODES.M) {
156156
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
157-
return userManager.isSystemUser();
157+
158+
// Starting from Android V, on headless devices TestDPC is provisioned using the single_user
159+
// DO mode and is set as the DO on the main user. UserManager.isMainUser is not a public API,
160+
// so we'll have to depend on the fact that the DO is installed on the main user for the
161+
// check.
162+
if (Util.SDK_INT >= VERSION_CODES.VANILLA_ICE_CREAM
163+
&& userManager.isHeadlessSystemUserMode()) {
164+
return isDeviceOwner(context);
165+
} else {
166+
return userManager.isSystemUser();
167+
}
158168
} else {
159169
// Assume only DO can be primary user. This is not perfect but the cases in which it is
160170
// wrong are uncommon and require adb to set up.

0 commit comments

Comments
 (0)