16
16
17
17
package com .afwsamples .testdpc ;
18
18
19
- import static com .afwsamples .testdpc .policy .PolicyManagementFragment .OVERRIDE_KEY_SELECTION_KEY ;
20
-
21
19
import android .annotation .TargetApi ;
22
20
import android .app .Notification ;
23
21
import android .app .NotificationManager ;
35
33
import android .os .UserHandle ;
36
34
import android .os .UserManager ;
37
35
import android .preference .PreferenceManager ;
36
+ import android .support .v7 .app .NotificationCompat ;
38
37
import android .text .TextUtils ;
39
38
import android .util .Log ;
40
39
import android .widget .Toast ;
41
40
41
+ import com .afwsamples .testdpc .common .NotificationUtil ;
42
42
import com .afwsamples .testdpc .common .Util ;
43
43
import com .afwsamples .testdpc .provision .PostProvisioningTask ;
44
44
59
59
import java .util .Date ;
60
60
import java .util .List ;
61
61
62
+ import static com .afwsamples .testdpc .policy .PolicyManagementFragment .OVERRIDE_KEY_SELECTION_KEY ;
63
+
62
64
/**
63
65
* Handles events related to the managed profile.
64
66
*/
@@ -189,9 +191,9 @@ public void onProfileProvisioningComplete(Context context, Intent intent) {
189
191
@ Override
190
192
public void onBugreportSharingDeclined (Context context , Intent intent ) {
191
193
Log .i (TAG , "Bugreport sharing declined" );
192
- Util .showNotification (context , R .string .bugreport_title ,
194
+ NotificationUtil .showNotification (context , R .string .bugreport_title ,
193
195
context .getString (R .string .bugreport_sharing_declined ),
194
- Util .BUGREPORT_NOTIFICATION_ID );
196
+ NotificationUtil .BUGREPORT_NOTIFICATION_ID );
195
197
}
196
198
197
199
@ TargetApi (Build .VERSION_CODES .N )
@@ -234,8 +236,8 @@ protected String doInBackground(Void... params) {
234
236
235
237
@ Override
236
238
protected void onPostExecute (String message ) {
237
- Util .showNotification (context , R .string .bugreport_title ,
238
- message , Util .BUGREPORT_NOTIFICATION_ID );
239
+ NotificationUtil .showNotification (context , R .string .bugreport_title ,
240
+ message , NotificationUtil .BUGREPORT_NOTIFICATION_ID );
239
241
result .finish ();
240
242
}
241
243
@@ -258,9 +260,9 @@ public void onBugreportFailed(Context context, Intent intent, int failureCode) {
258
260
R .string .bugreport_failure_failed_completing );
259
261
}
260
262
Log .i (TAG , "Bugreport failed: " + failureReason );
261
- Util .showNotification (context , R .string .bugreport_title ,
263
+ NotificationUtil .showNotification (context , R .string .bugreport_title ,
262
264
context .getString (R .string .bugreport_failure_message , failureReason ),
263
- Util .BUGREPORT_NOTIFICATION_ID );
265
+ NotificationUtil .BUGREPORT_NOTIFICATION_ID );
264
266
}
265
267
266
268
@@ -271,9 +273,9 @@ public void onUserAdded(Context context, Intent intent, UserHandle newUser) {
271
273
String message = context .getString (R .string .on_user_added_message ,
272
274
userManager .getSerialNumberForUser (newUser ));
273
275
Log .i (TAG , message );
274
- Util .showNotification (context , R .string .on_user_added_title ,
276
+ NotificationUtil .showNotification (context , R .string .on_user_added_title ,
275
277
message ,
276
- Util .USER_ADDED_NOTIFICATION_ID );
278
+ NotificationUtil .USER_ADDED_NOTIFICATION_ID );
277
279
}
278
280
279
281
@ TargetApi (Build .VERSION_CODES .O )
@@ -283,8 +285,8 @@ public void onUserRemoved(Context context, Intent intent, UserHandle removedUser
283
285
String message = context .getString (R .string .on_user_removed_message ,
284
286
userManager .getSerialNumberForUser (removedUser ));
285
287
Log .i (TAG , message );
286
- Util .showNotification (context , R .string .on_user_removed_title , message ,
287
- Util .USER_REMOVED_NOTIFICATION_ID );
288
+ NotificationUtil .showNotification (context , R .string .on_user_removed_title , message ,
289
+ NotificationUtil .USER_REMOVED_NOTIFICATION_ID );
288
290
}
289
291
290
292
@ TargetApi (Build .VERSION_CODES .M )
@@ -349,11 +351,11 @@ public void onPasswordExpiring(Context context, Intent intent, UserHandle user)
349
351
devicePolicyManager .getPasswordExpiration (getComponentName (context ));
350
352
final boolean expiredBySelf = (timeNow >= timeAdminExpires && timeAdminExpires != 0 );
351
353
352
- Util .showNotification (context , R .string .password_expired_title ,
354
+ NotificationUtil .showNotification (context , R .string .password_expired_title ,
353
355
context .getString (expiredBySelf
354
356
? R .string .password_expired_by_self
355
357
: R .string .password_expired_by_others ),
356
- Util .PASSWORD_EXPIRATION_NOTIFICATION_ID );
358
+ NotificationUtil .PASSWORD_EXPIRATION_NOTIFICATION_ID );
357
359
}
358
360
359
361
@ Deprecated
@@ -397,15 +399,15 @@ public void onPasswordFailed(Context context, Intent intent, UserHandle user) {
397
399
: context .getResources ().getQuantityString (
398
400
R .plurals .password_failed_attempts_content , maxAttempts , maxAttempts );
399
401
400
- Notification .Builder warn = new Notification . Builder (context )
401
- .setSmallIcon (R .drawable .ic_launcher )
402
+ NotificationCompat .Builder warn = NotificationUtil . getNotificationBuilder (context );
403
+ warn .setSmallIcon (R .drawable .ic_launcher )
402
404
.setTicker (title )
403
405
.setContentTitle (title )
404
406
.setContentText (content )
405
407
.setContentIntent (PendingIntent .getActivity (context , /* requestCode */ -1 ,
406
408
new Intent (DevicePolicyManager .ACTION_SET_NEW_PASSWORD ), /* flags */ 0 ));
407
409
408
- Notification .InboxStyle inboxStyle = new Notification .InboxStyle ();
410
+ NotificationCompat .InboxStyle inboxStyle = new NotificationCompat .InboxStyle ();
409
411
inboxStyle .setBigContentTitle (title );
410
412
411
413
final DateFormat dateFormat = SimpleDateFormat .getDateTimeInstance ();
@@ -416,7 +418,7 @@ public void onPasswordFailed(Context context, Intent intent, UserHandle user) {
416
418
417
419
NotificationManager nm = (NotificationManager )
418
420
context .getSystemService (Context .NOTIFICATION_SERVICE );
419
- nm .notify (PASSWORD_FAILED_NOTIFICATION_ID , warn .getNotification ());
421
+ nm .notify (PASSWORD_FAILED_NOTIFICATION_ID , warn .build ());
420
422
}
421
423
422
424
@ Deprecated
@@ -520,8 +522,8 @@ private static void updatePasswordQualityNotification(Context context) {
520
522
context .getSystemService (Context .NOTIFICATION_SERVICE );
521
523
522
524
if (!devicePolicyManager .isActivePasswordSufficient ()) {
523
- Notification .Builder warn = new Notification . Builder (context )
524
- .setOngoing (true )
525
+ NotificationCompat .Builder warn = NotificationUtil . getNotificationBuilder (context );
526
+ warn .setOngoing (true )
525
527
.setSmallIcon (R .drawable .ic_launcher )
526
528
.setTicker (context .getText (R .string .password_not_compliant_title ))
527
529
.setContentTitle (context .getText (R .string .password_not_compliant_title ))
0 commit comments