@@ -59,6 +59,7 @@ public class DeviceAdminReceiver extends android.app.admin.DeviceAdminReceiver {
59
59
"com.afwsamples.testdpc.policy.PASSWORD_REQUIREMENTS_CHANGED" ;
60
60
61
61
private static final int CHANGE_PASSWORD_NOTIFICATION_ID = 101 ;
62
+ private static final int PASSWORD_FAILED_NOTIFICATION_ID = 102 ;
62
63
63
64
@ Override
64
65
public void onReceive (Context context , Intent intent ) {
@@ -235,6 +236,45 @@ public static ComponentName getComponentName(Context context) {
235
236
return new ComponentName (context .getApplicationContext (), DeviceAdminReceiver .class );
236
237
}
237
238
239
+ @ Override
240
+ public void onPasswordFailed (Context context , Intent intent ) {
241
+ DevicePolicyManager devicePolicyManager = (DevicePolicyManager ) context .getSystemService (
242
+ Context .DEVICE_POLICY_SERVICE );
243
+ /*
244
+ * Post a notification to show:
245
+ * - how many wrong passwords have been entered;
246
+ * - how many wrong passwords need to be entered for the device to be wiped.
247
+ */
248
+ int attempts = devicePolicyManager .getCurrentFailedPasswordAttempts ();
249
+ int maxAttempts = devicePolicyManager .getMaximumFailedPasswordsForWipe (null );
250
+
251
+ String title = context .getQuantityString (
252
+ R .plurals .password_failed_attempts_title , attempts , attempts );
253
+ String content = maxAttempts == 0
254
+ ? context .getString (R .string .password_failed_no_limit_set )
255
+ : context .getQuantityString (
256
+ R .plurals .password_failed_attempts_content , maxAttempts , maxAttempts );
257
+
258
+ Notification .Builder warn = new Notification .Builder (context )
259
+ .setSmallIcon (R .drawable .ic_launcher )
260
+ .setTicker (title )
261
+ .setContentTitle (title )
262
+ .setContentText (content )
263
+ .setContentIntent (PendingIntent .getActivity (context , /* requestCode */ -1 ,
264
+ new Intent (DevicePolicyManager .ACTION_SET_NEW_PASSWORD ), /* flags */ 0 ));
265
+
266
+ NotificationManager nm = (NotificationManager )
267
+ context .getSystemService (Context .NOTIFICATION_SERVICE );
268
+ nm .notify (PASSWORD_FAILED_NOTIFICATION_ID , warn .getNotification ());
269
+ }
270
+
271
+ @ Override
272
+ public void onPasswordSucceeded (Context context , Intent intent ) {
273
+ NotificationManager nm = (NotificationManager )
274
+ context .getSystemService (Context .NOTIFICATION_SERVICE );
275
+ nm .cancel (PASSWORD_FAILED_NOTIFICATION_ID );
276
+ }
277
+
238
278
@ Override
239
279
public void onPasswordChanged (Context context , Intent intent ) {
240
280
updatePasswordQualityNotification (context );
0 commit comments