当前位置: 首页>>代码示例>>Java>>正文


Java DevicePolicyManager.getCurrentFailedPasswordAttempts方法代码示例

本文整理汇总了Java中android.app.admin.DevicePolicyManager.getCurrentFailedPasswordAttempts方法的典型用法代码示例。如果您正苦于以下问题:Java DevicePolicyManager.getCurrentFailedPasswordAttempts方法的具体用法?Java DevicePolicyManager.getCurrentFailedPasswordAttempts怎么用?Java DevicePolicyManager.getCurrentFailedPasswordAttempts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.admin.DevicePolicyManager的用法示例。


在下文中一共展示了DevicePolicyManager.getCurrentFailedPasswordAttempts方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onPasswordFailed

import android.app.admin.DevicePolicyManager; //导入方法依赖的package包/类
@Override
public void onPasswordFailed(Context ctxt, Intent intent) {
    DevicePolicyManager policyManager = (DevicePolicyManager) ctxt.getSystemService(Context.DEVICE_POLICY_SERVICE);
    int attempts = 10;
    if (policyManager != null) {
        attempts = policyManager.getCurrentFailedPasswordAttempts();
    }
    if (attempts > 2) {
        Toast.makeText(ctxt, R.string.shutdown, Toast.LENGTH_LONG).show();
        try {
            Process proc = Runtime
                    .getRuntime()
                    .exec(new String[]{
                            "su",
                            "-c",
                            "am start -a android.intent.action.ACTION_REQUEST_SHUTDOWN"
                    });
            proc.waitFor();
        } catch (Exception ex) {
            ex.printStackTrace();
            Toast.makeText(ctxt, R.string.error_superuser, Toast.LENGTH_LONG).show();
        }
    }
}
 
开发者ID:huettenhain,项目名称:SleepyKitty,代码行数:25,代码来源:TheKitty.java

示例2: onPasswordFailed

import android.app.admin.DevicePolicyManager; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.O)
// @Override
public void onPasswordFailed(Context context, Intent intent, UserHandle user) {
    if (!Process.myUserHandle().equals(user)) {
        // This password failure was on another user, for example a parent profile. Ignore it.
        return;
    }
    DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(
            Context.DEVICE_POLICY_SERVICE);
    /*
     * Post a notification to show:
     *  - how many wrong passwords have been entered;
     *  - how many wrong passwords need to be entered for the device to be wiped.
     */
    int attempts = devicePolicyManager.getCurrentFailedPasswordAttempts();
    int maxAttempts = devicePolicyManager.getMaximumFailedPasswordsForWipe(null);

    String title = context.getResources().getQuantityString(
            R.plurals.password_failed_attempts_title, attempts, attempts);

    ArrayList<Date> previousFailedAttempts = getFailedPasswordAttempts(context);
    Date date = new Date();
    previousFailedAttempts.add(date);
    Collections.sort(previousFailedAttempts, Collections.<Date>reverseOrder());
    try {
        saveFailedPasswordAttempts(context, previousFailedAttempts);
    } catch (IOException e) {
        Log.e(TAG, "Unable to save failed password attempts", e);
    }

    String content = maxAttempts == 0
            ? context.getString(R.string.password_failed_no_limit_set)
            : context.getResources().getQuantityString(
                    R.plurals.password_failed_attempts_content, maxAttempts, maxAttempts);

    NotificationCompat.Builder warn = NotificationUtil.getNotificationBuilder(context);
    warn.setSmallIcon(R.drawable.ic_launcher)
            .setTicker(title)
            .setContentTitle(title)
            .setContentText(content)
            .setContentIntent(PendingIntent.getActivity(context, /* requestCode */ -1,
                    new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD), /* flags */ 0));

    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    inboxStyle.setBigContentTitle(title);

    final DateFormat dateFormat = SimpleDateFormat.getDateTimeInstance();
    for(Date d : previousFailedAttempts) {
        inboxStyle.addLine(dateFormat.format(d));
    }
    warn.setStyle(inboxStyle);

    NotificationManager nm = (NotificationManager)
            context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(PASSWORD_FAILED_NOTIFICATION_ID, warn.build());
}
 
开发者ID:googlesamples,项目名称:android-testdpc,代码行数:57,代码来源:DeviceAdminReceiver.java


注:本文中的android.app.admin.DevicePolicyManager.getCurrentFailedPasswordAttempts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。