EMM(企业移动管理)中Android设备管控,DeviceAdmin(弱管控)、DeviceOwner(强管控)。
企业移动管理EMM(Enterprise Mobile Management)功能对移动终端设备进行全生命周期的管理。包括资产管理、设备管理(MDM)、应用管理(MAM)、内容管理(MCM)和日志管理等多方面提供完善的移动管理方案。
资产管理功能可以将移动终端作为企业资产纳入管理体系,包括终端注册、状态、注销等管理,具体功能如下:
移动设备管理主要提供终端设备能力的管理和系统环境策略的配置,具体功能如下:
移动应用管理主要提供企业应用管理及第三方应用的策略控制,具体功能如下:
移动内容管理主要指对企业数据在终端本地保存使用和传输过程中的安全保护,具体功能如下:
移动设备管理中主要使用Android的DeviceAdmin和DeviceOwner两大模块功能。
移动设备管理中使用Google提供的DeviceAdmin设备管理功能,在Android在2.2版本中引进的。通过用户授权自己的应用设备管理权限后,可以在代码中修改很多系统设置,比如设置锁屏方式、恢复出厂设置、设置密码、强制清除密码,修改密码等操作。
通过DeviceAdmin所做的功能很有限,所以你需要用到DeviceOwner。“设备所有者”是一类特殊的设备管理员,具有在设备上创建和移除辅助用户以及配置全局设置的额外能力。之前申请的DeviceAdmin可以对你的设备进行一些修改,而当你的应用成为DeviceOwner后,你就可以拥有更多的能力,可以对其他应用进行限制。
<?xml version="1.0" encoding="utf-8"?>
<device-admin>
<uses-policies>
<!--停用相机-->
<disable-camera/>
<!--锁屏时禁用某些功能-->
<disable-keyguard-features/>
<!--设置存储设备加密-->
<encrypted-storage/>
<!--设置锁定屏幕密码的有效期-->
<expire-password/>
<!--锁定屏幕-->
<force-lock/>
<!--设置密码规则-->
<limit-password/>
<!--更改屏幕解锁密码-->
<reset-password/>
<!--设置设备全局代理-->
<set-global-proxy/>
<!--监控屏幕解锁尝试次数-->
<watch-login/>
<!--恢复出厂设置-->
<wipe-data/>
</uses-policies>
</device-admin>
package cn.com.codeteenager.devicemanager.receiver;
import android.annotation.TargetApi;
import android.app.admin.DeviceAdminReceiver;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.util.Log;
import cn.com.codeteenager.devicemanager.MainActivity;
import cn.com.codeteenager.devicemanager.R;
public class CTDeviceAdminReceiver extends DeviceAdminReceiver {
@Override
public void onEnabled(Context context, Intent intent) {
Log.i("onEnabled", "设备管理:可用");
}
@Override
public CharSequence onDisableRequested(Context context, Intent intent) {
Log.e("onDisableRequested", "设备管理:不可用");
return super.onDisableRequested(context, intent);
}
@Override
public void onDisabled(Context context, Intent intent) {
super.onDisabled(context, intent);
Log.e("onDisableRequested", "设备管理:不可用");
}
/**
* Called on the new profile when device owner provisioning has completed. Device owner
* provisioning is the process of setting up the device so that its main profile is managed by
* the mobile device management (MDM) application set up as the device owner.
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onProfileProvisioningComplete(Context context, Intent intent) {
// Enable the profile
DevicePolicyManager manager =
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName componentName = getComponentName(context);
manager.setProfileName(componentName, context.getString(R.string.app_name));
// Open the main screen
Intent launch = new Intent(context, MainActivity.class);
launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(launch);
}
/**
* Generates a {@link ComponentName} that is used throughout the app.
*
* @return a {@link ComponentName}
*/
public static ComponentName getComponentName(Context context) {
return new ComponentName(context.getApplicationContext(), CTDeviceAdminReceiver.class);
}
}
<!--定义设备管理策略-->
<receiver
android:name=".receiver.CTDeviceAdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/device_admin_receiver" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
<action android:name="android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED" />
<action android:name="android.app.action.DEVICE_ADMIN_DISABLED" />
</intent-filter>
</receiver>
if (!mDevicePolicyManager.isAdminActive(mDeviceAdminReceiver)) {
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminReceiver);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "用于设备和应用安全管理");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
mContext.startActivity(intent);
} else {
Toast.makeText(this, "此App已激活设备管理器", Toast.LENGTH_SHORT).show()
}
使用利用ADB命令。
$adb shell dpm set-device-owner cn.com.codeteenager.devicemanager/cn.com.codeteenager.devicemanager.receiver.CTDeviceAdminReceiver
若出现如下类似错误:
java.lang.IllegalStateException: Not allowed to set the device owner because
there are already some accounts on the device
则可尝试到设置-账号中退出所有账户,然后重新尝试ADB设置。
当一个app成为DeviceOwner后,这个app是不能被卸载,也无法在设置->安全中关闭其权限。要想DeviceOwner后还能卸载这个app,也就是退出DeviceOwner,有如下方法: