-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Managed profile Android util method #2561
Conversation
❌ Work item link check failed. Description does not contain AB#{ID}. Click here to Learn more. |
public static boolean isInWorkProfile(@NonNull final Context appContext) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | ||
final UserManager um = (UserManager) appContext.getSystemService(Context.USER_SERVICE); | ||
return um.isManagedProfile(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talked to Mohit about this offline; the thinking is that for COBO devices, since they would constitute as a managed device (and not a managed profile), this method would return false. One Intune engineer also believes this is the case, but I will also check in with a different Intune team.
This question also prompted a renaming from isInWorkProfile to isInManagedProfile, to avoid any confusion as to what constitutes as a work profile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary
This PR creates an
AndroidPlatformUtil
method namedisInWorkProfile
, which returns a boolean based on if the host app is in a work profile.For Android level 30 (Android 11/R) and above, we are able to use the simple
isManagedProfile
method ofUserManager
. For Android level 21 (Android 5/Lollipop) and above, we get theDevicePolicyManager
instance and get a list of the active admins. If any of these active admins are found to be the profile owner app, then we know that the calling app is in a work profile. (We do something similar inInstallCertActivity
of the WPJ feature). If the device is below Android level 21 (should be very rare), we always return false.I tested this method out using testDPC and made sure both paths of the logic return the correct values.