-
Notifications
You must be signed in to change notification settings - Fork 46
Managed profile Android util method #2561
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
Changes from all commits
baeb138
1be2853
3935e5c
f64ea0e
ca21a79
7c0568b
5d9292b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
|
|
||
| import android.app.Activity; | ||
| import android.app.ActivityManager; | ||
| import android.app.admin.DevicePolicyManager; | ||
| import android.content.ComponentName; | ||
| import android.content.Context; | ||
| import android.content.pm.ActivityInfo; | ||
|
|
@@ -37,6 +38,7 @@ | |
| import android.os.Handler; | ||
| import android.os.Looper; | ||
| import android.os.SystemClock; | ||
| import android.os.UserManager; | ||
|
|
||
| import com.microsoft.identity.common.BuildConfig; | ||
| import com.microsoft.identity.common.adal.internal.AuthenticationConstants; | ||
|
|
@@ -261,6 +263,33 @@ public static ArrayList<Map.Entry<String, String>> updateWithOrDeleteWebAuthnPar | |
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * Check if the host app is running within a managed profile. | ||
| * @param appContext current application context. | ||
| * @return true if app is in a managed profile, false if in personal profile or OS is below LOLLIPOP. | ||
| */ | ||
| public static boolean isInManagedProfile(@NonNull final Context appContext) { | ||
| // If the device is running on Android R or above, we can use the UserManager method isManagedProfile. | ||
| // Otherwise, if the device is running on Lollipop or above, we'll use DPM's isProfileOwnerApp. We return false for lower versions. | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | ||
| final UserManager um = (UserManager) appContext.getSystemService(Context.USER_SERVICE); | ||
| return um.isManagedProfile(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
| final DevicePolicyManager dpm = (DevicePolicyManager) appContext.getSystemService(Context.DEVICE_POLICY_SERVICE); | ||
| final List<ComponentName> activeAdmins = dpm.getActiveAdmins(); | ||
| if (activeAdmins != null) { | ||
| // If any active admin apps are the profile owner, then the current calling app is in a managed profile. | ||
| for (final ComponentName admin : activeAdmins) { | ||
| final String packageName = admin.getPackageName(); | ||
| if (dpm.isProfileOwnerApp(packageName)) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * This method optionally re-orders tasks to bring the task that launched | ||
| * the interactive activity to the foreground. This is useful when the activity provided | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.