Skip to content

Commit 0e03a7e

Browse files
committed
Fix isManagedProfileOwner() before profile is enabled.
Previously, we check the app is the profile owner and that there is more than one profile to make sure it is a managed profile. However, before the managed profile is enabled it does not count as a profile so the test was giving incorrect results. Now, we assume it is a managed profile if the app is a profile owner as TestDPC only supports being a profile owner in a managed profile. This only affects pre-M devices as N introduces DPM.isManagedProfile(). Bug: 62134588 Change-Id: I10bb0d7e6398e0da4e734609fa88fe28c3d8daed
1 parent f92d745 commit 0e03a7e

File tree

1 file changed

+6
-3
lines changed
  • app/src/main/java/com/afwsamples/testdpc/common

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,11 @@ public static boolean isManagedProfileOwner(Context context) {
116116
return false;
117117
}
118118
}
119-
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
120-
return isProfileOwner(context) && userManager.getUserProfiles().size() > 1;
119+
120+
// Pre-N, TestDPC only supports being the profile owner for a managed profile. Other apps
121+
// may support being a profile owner in other contexts (e.g. a secondary user) which will
122+
// require further checks.
123+
return isProfileOwner(context);
121124
}
122125

123126
@TargetApi(VERSION_CODES.M)
@@ -194,4 +197,4 @@ public static boolean installCaCertificate(InputStream certificateInputStream,
194197
private static DevicePolicyManager getDevicePolicyManager(Context context) {
195198
return (DevicePolicyManager)context.getSystemService(Service.DEVICE_POLICY_SERVICE);
196199
}
197-
}
200+
}

0 commit comments

Comments
 (0)