简体   繁体   English

检测运行MDM的设备(移动设备管理)

[英]Detect devices running MDM (mobile device management)

I have a feature to pop up an app update prompt dialog in old app versions (the version is controlled via Firebase Remote Config). 我有一个功能,可以在旧的应用程序版本中弹出应用程序更新提示对话框(该版本通过Firebase远程配置进行控制)。

However, turns out a lot (but not most) of my customers use MDM to lock down their phone, in which case the end users cannot directly update the app. 然而,结果很多(但不是大多数)我的客户使用MDM来锁定他们的手机,在这种情况下,最终用户无法直接更新应用程序。

I'm using the normal detection of intent.resolveActivity(packageManager) to check if the play store activity can be started before showing the dialog. 我正在使用intent.resolveActivity(packageManager)的正常检测来检查是否可以在显示对话框之前启动Play商店活动。 But that check passes - the Play Store is there, but updates are blocked. 但该检查通过 - Play商店就在那里,但更新被阻止。

I want to disable the update prompt for these end users. 我想为这些最终用户禁用更新提示。

Is there a way to detect MDMs? 有没有办法检测MDM? Or at least a way to detect that app updates have been blocked? 或者至少是一种检测应用更新被阻止的方法?

You can use UserManager: 您可以使用UserManager:

UserManager user_manager = (UserManager) getSystemService(Context.USER_SERVICE);
    if (user_manager.hasUserRestriction("WORK_PROFILE_RESTRICTION")) {
        System.out.print("app under MDM");
     } else {
         System.out.print("app not under MDM");
     }

Although if the admin did not set-up the value you will receive false. 虽然如果管理员没有设置该值,您将收到错误。 If you get true it means that you are definitely under a managed profile, but if you get false it can be a false negative. 如果你成功了,那就意味着你肯定属于托管档案,但如果你弄错了,那就可能是假阴性。

The Test DPC google sample contains a ProvisioningStateUtil with a few utility methods : Test DPC google示例包含一个ProvisioningStateUtil ,其中包含一些实用程序方法:

/**
 * @return true if the device or profile is already owned
 */
public static boolean isManaged(Context context) {
    DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(
            Context.DEVICE_POLICY_SERVICE);

    List<ComponentName> admins = devicePolicyManager.getActiveAdmins();
    if (admins == null) return false;
    for (ComponentName admin : admins) {
        String adminPackageName = admin.getPackageName();
        if (devicePolicyManager.isDeviceOwnerApp(adminPackageName)
                || devicePolicyManager.isProfileOwnerApp(adminPackageName)) {
            return true;
        }
    }

    return false;
}

This require at least Android 5.0 (API 21) 这需要至少Android 5.0(API 21)

You can also directly check if the current user is allowed to install or update applications : 您还可以直接检查是否允许当前用户安装或更新应用程序:

UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
boolean blocked = userManager.hasUserRestriction(UserManager.DISALLOW_INSTALL_APPS);

It also require API 21 它还需要API 21

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM