用于设置密码验证的Android DevicePolicyManager策略

时间:2016-09-14 11:55:02

标签: android security device-admin device-policy-manager

我正在使用DevicePolicyManager来设置密码策略,我使用了以下内容 他们工作正常

DevicePolicyManager devicePolicyManager;
    ComponentName demoDeviceAdmin;

// Initialize Device Policy Manager service and our receiver class
                devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
                demoDeviceAdmin = new ComponentName(this, AdminReceiver.class);

devicePolicyManager.lockNow();
devicePolicyManager.wipeData(0);

但是当我使用DevicePolicyManager的以下方法创建如下所示的密码验证时,无法正常工作

devicePolicyManager.setPasswordMinimumLetters(demoDeviceAdmin, 2);
            devicePolicyManager.setPasswordMinimumLowerCase(demoDeviceAdmin, 2);
            devicePolicyManager.setPasswordMinimumNumeric(demoDeviceAdmin, 2);
            devicePolicyManager.setPasswordMinimumUpperCase(demoDeviceAdmin, 2);
devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, 10);

只有以下方法正常工作

devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, 10);

请有人指导我做错了吗?

public class AdminReceiver extends DeviceAdminReceiver {

    @Override
    public void onEnabled(Context context, Intent intent) {
        super.onEnabled(context, intent);
         showToast(context, "---onEnabled----");
         Log.e("------onEnabled--------", "------onEnabled--------");
    }

    @Override
    public CharSequence onDisableRequested(Context context, Intent intent) {
        // TODO Auto-generated method stub
         showToast(context, "---onDisableRequested----");
         Log.e("------onDisableRequested--------", "------onDisableRequested--------");
        return super.onDisableRequested(context, intent);
    }



    @Override
    public void onPasswordExpiring(Context context, Intent intent) {
        // TODO Auto-generated method stub
        super.onPasswordExpiring(context, intent);
        showToast(context, "----onPasswordExpiring---");
    }

    @Override
    public void onPasswordFailed(Context context, Intent intent) {
        // TODO Auto-generated method stub
        super.onPasswordFailed(context, intent);
        showToast(context, "----onPasswordFailed---");
    }

    @Override
    public void onPasswordSucceeded(Context context, Intent intent) {
        // TODO Auto-generated method stub
        super.onPasswordSucceeded(context, intent);
        showToast(context, "----onPasswordSucceeded---");
    }


    void showToast(Context context, String msg) {
        Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
    }

    @Override
    public void onDisabled(Context context, Intent intent) {
        showToast(context, "onDisabled");
        Log.e("------onDisabled--------", "------onDisabled--------");
    }

    @Override
    public void onPasswordChanged(Context context, Intent intent) {
        showToast(context, "----onPasswordChanged---");
    }

}

0 个答案:

没有答案