Skip to content

Commit 090a276

Browse files
AndrewScullandroid-build-team Robot
authored andcommitted
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 (cherry picked from commit 384879e45dbdf719ae07fb18e74c336954c99a7c)
1 parent c50afdb commit 090a276

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
@@ -129,8 +129,11 @@ public static boolean isManagedProfileOwner(Context context) {
129129
return false;
130130
}
131131
}
132-
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
133-
return isProfileOwner(context) && userManager.getUserProfiles().size() > 1;
132+
133+
// Pre-N, TestDPC only supports being the profile owner for a managed profile. Other apps
134+
// may support being a profile owner in other contexts (e.g. a secondary user) which will
135+
// require further checks.
136+
return isProfileOwner(context);
134137
}
135138

136139
@TargetApi(VERSION_CODES.M)
@@ -207,4 +210,4 @@ public static boolean installCaCertificate(InputStream certificateInputStream,
207210
private static DevicePolicyManager getDevicePolicyManager(Context context) {
208211
return (DevicePolicyManager)context.getSystemService(Service.DEVICE_POLICY_SERVICE);
209212
}
210-
}
213+
}

0 commit comments

Comments
 (0)