本文整理汇总了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();
}
}
}
示例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());
}