Skip to content
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

Merged
merged 7 commits into from
Jan 2, 2025
Merged

Conversation

melissaahn
Copy link
Contributor

Summary

This PR creates an AndroidPlatformUtil method named isInWorkProfile, 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 of UserManager. For Android level 21 (Android 5/Lollipop) and above, we get the DevicePolicyManager 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 in InstallCertActivity 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.

Copy link

❌ Work item link check failed. Description does not contain AB#{ID}.

Click here to Learn more.

@melissaahn melissaahn marked this pull request as ready for review December 30, 2024 19:17
@melissaahn melissaahn requested a review from a team as a code owner December 30, 2024 19:17
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return um.isManagedProfile();

if the device is fully managed, would this return false?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@mohitc1 mohitc1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@melissaahn melissaahn changed the title Work profile Android util method Managed profile Android util method Jan 2, 2025
@melissaahn melissaahn merged commit 08c1ca1 into dev Jan 2, 2025
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants