File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
src/main/java/com/afwsamples/testdpc/common Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments