-
Notifications
You must be signed in to change notification settings - Fork 327
/
DeviceAdminReceiver.java
651 lines (580 loc) · 22.9 KB
/
DeviceAdminReceiver.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.afwsamples.testdpc;
import android.annotation.TargetApi;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Binder;
import android.os.Build.VERSION_CODES;
import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;
import android.widget.Toast;
import androidx.core.app.NotificationCompat;
import com.afwsamples.testdpc.common.NotificationUtil;
import com.afwsamples.testdpc.common.Util;
import com.afwsamples.testdpc.provision.PostProvisioningTask;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
/** Handles events related to the managed profile. */
public class DeviceAdminReceiver extends android.app.admin.DeviceAdminReceiver {
private static final String TAG = "DeviceAdminReceiver";
public static final String ACTION_PASSWORD_REQUIREMENTS_CHANGED =
"com.afwsamples.testdpc.policy.PASSWORD_REQUIREMENTS_CHANGED";
private static final String LOGS_DIR = "logs";
private static final String FAILED_PASSWORD_LOG_FILE = "failed_pw_attempts_timestamps.log";
private static final int CHANGE_PASSWORD_NOTIFICATION_ID = 101;
private static final int PASSWORD_FAILED_NOTIFICATION_ID = 102;
@Override
public void onReceive(Context context, Intent intent) {
switch (intent.getAction()) {
case ACTION_PASSWORD_REQUIREMENTS_CHANGED:
case Intent.ACTION_BOOT_COMPLETED:
updatePasswordConstraintNotification(context);
break;
case DevicePolicyManager.ACTION_PROFILE_OWNER_CHANGED:
onProfileOwnerChanged(context);
break;
case DevicePolicyManager.ACTION_DEVICE_OWNER_CHANGED:
onDeviceOwnerChanged(context);
break;
default:
super.onReceive(context, intent);
break;
}
}
/* TODO(b/210723613): fix build version and re-add it
@Override
@TargetApi(VERSION_CODES.S)
public void onOperationSafetyStateChanged(Context context, int reasonType, boolean safe) {
Log.d(TAG, "onOperationSafetyStateChanged(): " + reasonType + " = " + safe);
String status = safe ? context.getString(R.string.safe) : context.getString(R.string.unsafe);
String reason;
switch (reasonType) {
case DevicePolicyManager.OPERATION_SAFETY_REASON_DRIVING_DISTRACTION:
reason = context.getString(R.string.unsafe_operation_reason_driving_distraction);
break;
default:
reason = context.getString(R.string.unsafe_operation_reason_driving_undefined);
}
String message = context.getString(R.string.safety_operations_change_message, reason, status);
showToast(context, message);
}
*/
@TargetApi(VERSION_CODES.N)
@Override
public void onSecurityLogsAvailable(Context context, Intent intent) {
Log.i(TAG, "onSecurityLogsAvailable() called");
showToast(context, R.string.on_security_logs_available);
}
/*
* TODO: reconsider how to store and present the logs in the future, e.g. save the file into
* internal memory and show the content in a ListView
*/
@TargetApi(VERSION_CODES.O)
@Override
public void onNetworkLogsAvailable(
Context context, Intent intent, long batchToken, int networkLogsCount) {
Log.i(TAG, "onNetworkLogsAvailable() called");
CommonReceiverOperations.onNetworkLogsAvailable(
context, getComponentName(context), batchToken, networkLogsCount);
}
@Override
public void onProfileProvisioningComplete(Context context, Intent intent) {
if (Util.SDK_INT >= VERSION_CODES.O) {
// See http://b/177617306.
return;
}
PostProvisioningTask task = new PostProvisioningTask(context);
if (!task.performPostProvisioningOperations(intent)) {
return;
}
final Intent launchIntent = task.getPostProvisioningLaunchIntent(intent);
if (launchIntent != null) {
context.startActivity(launchIntent);
} else {
Log.e(
TAG,
"DeviceAdminReceiver.onProvisioningComplete() invoked, but ownership " + "not assigned");
showToast(context, R.string.device_admin_receiver_failure);
}
}
@TargetApi(VERSION_CODES.N)
@Override
public void onBugreportSharingDeclined(Context context, Intent intent) {
Log.i(TAG, "Bugreport sharing declined");
NotificationUtil.showNotification(
context,
R.string.bugreport_title,
context.getString(R.string.bugreport_sharing_declined),
NotificationUtil.BUGREPORT_NOTIFICATION_ID);
}
@TargetApi(VERSION_CODES.N)
@Override
public void onBugreportShared(
final Context context, Intent intent, final String bugreportFileHash) {
Log.i(TAG, "Bugreport shared, hash: " + bugreportFileHash);
final Uri bugreportUri = intent.getData();
Log.i(TAG, "Bugreport URI: " + bugreportUri);
final PendingResult result = goAsync();
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
File outputBugreportFile;
String message;
InputStream in;
OutputStream out;
try {
ParcelFileDescriptor mInputPfd =
context.getContentResolver().openFileDescriptor(bugreportUri, "r");
in = new FileInputStream(mInputPfd.getFileDescriptor());
outputBugreportFile =
new File(context.getExternalFilesDir(null), bugreportUri.getLastPathSegment());
Log.i(TAG, "Writing bugreport to " + outputBugreportFile);
out = new FileOutputStream(outputBugreportFile);
byte[] buffer = new byte[1024];
int read;
long totalRead = 0;
while ((read = in.read(buffer)) != -1) {
totalRead += read;
out.write(buffer, 0, read);
}
in.close();
out.close();
message =
context.getString(
R.string.received_bugreport,
outputBugreportFile.getPath(),
bugreportFileHash,
totalRead);
Log.i(TAG, message);
} catch (IOException e) {
Log.e(TAG, e.getMessage());
message = context.getString(R.string.received_bugreport_failed_retrieval);
}
return message;
}
@Override
protected void onPostExecute(String message) {
NotificationUtil.showNotification(
context, R.string.bugreport_title, message, NotificationUtil.BUGREPORT_NOTIFICATION_ID);
result.finish();
}
}.execute();
}
@TargetApi(VERSION_CODES.N)
@Override
public void onBugreportFailed(Context context, Intent intent, int failureCode) {
String failureReason;
switch (failureCode) {
case BUGREPORT_FAILURE_FILE_NO_LONGER_AVAILABLE:
failureReason = context.getString(R.string.bugreport_failure_file_no_longer_available);
break;
case BUGREPORT_FAILURE_FAILED_COMPLETING:
// fall through
default:
failureReason = context.getString(R.string.bugreport_failure_failed_completing);
}
Log.i(TAG, "Bugreport failed: " + failureReason);
NotificationUtil.showNotification(
context,
R.string.bugreport_title,
context.getString(R.string.bugreport_failure_message, failureReason),
NotificationUtil.BUGREPORT_NOTIFICATION_ID);
}
@TargetApi(VERSION_CODES.O)
@Override
public void onUserAdded(Context context, Intent intent, UserHandle newUser) {
handleUserAction(
context,
newUser,
R.string.on_user_added_title,
R.string.on_user_added_message,
NotificationUtil.USER_ADDED_NOTIFICATION_ID);
}
@TargetApi(VERSION_CODES.O)
@Override
public void onUserRemoved(Context context, Intent intent, UserHandle removedUser) {
handleUserAction(
context,
removedUser,
R.string.on_user_removed_title,
R.string.on_user_removed_message,
NotificationUtil.USER_REMOVED_NOTIFICATION_ID);
}
@TargetApi(VERSION_CODES.P)
@Override
public void onUserStarted(Context context, Intent intent, UserHandle startedUser) {
handleUserAction(
context,
startedUser,
R.string.on_user_started_title,
R.string.on_user_started_message,
NotificationUtil.USER_STARTED_NOTIFICATION_ID);
}
@TargetApi(VERSION_CODES.P)
@Override
public void onUserStopped(Context context, Intent intent, UserHandle stoppedUser) {
handleUserAction(
context,
stoppedUser,
R.string.on_user_stopped_title,
R.string.on_user_stopped_message,
NotificationUtil.USER_STOPPED_NOTIFICATION_ID);
}
@TargetApi(VERSION_CODES.P)
@Override
public void onUserSwitched(Context context, Intent intent, UserHandle switchedUser) {
handleUserAction(
context,
switchedUser,
R.string.on_user_switched_title,
R.string.on_user_switched_message,
NotificationUtil.USER_SWITCHED_NOTIFICATION_ID);
}
@TargetApi(VERSION_CODES.M)
@Override
@SuppressWarnings("SimpleDateFormat")
public void onSystemUpdatePending(Context context, Intent intent, long receivedTime) {
if (receivedTime != -1) {
DateFormat sdf = new SimpleDateFormat("hh:mm:ss dd/MM/yyyy");
String timeString = sdf.format(new Date(receivedTime));
showToast(context, "System update received at: " + timeString);
} else {
// No system update is currently available on this device.
}
}
@TargetApi(VERSION_CODES.M)
@Override
public String onChoosePrivateKeyAlias(
Context context, Intent intent, int uid, Uri uri, String alias) {
return CommonReceiverOperations.onChoosePrivateKeyAlias(context, uid);
}
/**
* @param context The context of the application.
* @return The component name of this component in the given context.
*/
public static ComponentName getComponentName(Context context) {
return new ComponentName(context.getApplicationContext(), DeviceAdminReceiver.class);
}
@Deprecated
@Override
public void onPasswordExpiring(Context context, Intent intent) {
onPasswordExpiring(context, intent, Process.myUserHandle());
}
@TargetApi(VERSION_CODES.O)
@Override
public void onPasswordExpiring(Context context, Intent intent, UserHandle user) {
if (!Process.myUserHandle().equals(user)) {
// This password expiration was on another user, for example a parent profile. Skip it.
return;
}
DevicePolicyManager devicePolicyManager =
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
final long timeNow = System.currentTimeMillis();
final long timeAdminExpires =
devicePolicyManager.getPasswordExpiration(getComponentName(context));
final boolean expiredBySelf = (timeNow >= timeAdminExpires && timeAdminExpires != 0);
NotificationUtil.showNotification(
context,
R.string.password_expired_title,
context.getString(
expiredBySelf
? R.string.password_expired_by_self
: R.string.password_expired_by_others),
NotificationUtil.PASSWORD_EXPIRATION_NOTIFICATION_ID);
}
@Deprecated
@Override
public void onPasswordFailed(Context context, Intent intent) {
onPasswordFailed(context, intent, Process.myUserHandle());
}
@TargetApi(VERSION_CODES.O)
@Override
@SuppressWarnings("UnspecifiedImmutableFlag") // TODO(b/210723613): proper fix
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 */
PendingIntent.FLAG_IMMUTABLE));
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());
}
@Deprecated
@Override
public void onPasswordSucceeded(Context context, Intent intent) {
onPasswordSucceeded(context, intent, Process.myUserHandle());
}
@TargetApi(VERSION_CODES.O)
@Override
public void onPasswordSucceeded(Context context, Intent intent, UserHandle user) {
if (Process.myUserHandle().equals(user)) {
logFile(context).delete();
}
}
@Deprecated
@Override
public void onPasswordChanged(Context context, Intent intent) {
onPasswordChanged(context, intent, Process.myUserHandle());
}
@TargetApi(VERSION_CODES.O)
@Override
public void onPasswordChanged(Context context, Intent intent, UserHandle user) {
if (Process.myUserHandle().equals(user)) {
updatePasswordConstraintNotification(context);
}
}
@Override
public void onEnabled(Context context, Intent intent) {
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
long serialNumber = userManager.getSerialNumberForUser(Binder.getCallingUserHandle());
Log.i(TAG, "Device admin enabled in user with serial number: " + serialNumber);
}
private static File logFile(Context context) {
File parent = context.getDir(LOGS_DIR, Context.MODE_PRIVATE);
return new File(parent, FAILED_PASSWORD_LOG_FILE);
}
private static ArrayList<Date> getFailedPasswordAttempts(Context context) {
File logFile = logFile(context);
ArrayList<Date> result = new ArrayList<Date>();
if (!logFile.exists()) {
return result;
}
FileInputStream fis = null;
try {
fis = new FileInputStream(logFile);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String line = null;
while ((line = br.readLine()) != null && line.length() > 0) {
result.add(new Date(Long.parseLong(line)));
}
br.close();
} catch (IOException e) {
Log.e(TAG, "Unable to read failed password attempts", e);
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
Log.e(TAG, "Unable to close failed password attempts log file", e);
}
}
}
return result;
}
private static void saveFailedPasswordAttempts(Context context, ArrayList<Date> attempts)
throws IOException {
File logFile = logFile(context);
if (!logFile.exists()) {
logFile.createNewFile();
}
FileOutputStream fos = new FileOutputStream(logFile);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
for (Date date : attempts) {
bw.write(Long.toString(date.getTime()));
bw.newLine();
}
bw.close();
}
@SuppressWarnings("UnspecifiedImmutableFlag") // TODO(b/210723613): proper fix
private static void updatePasswordConstraintNotification(Context context) {
final DevicePolicyManager dpm =
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
if (!dpm.isProfileOwnerApp(context.getPackageName())
&& !dpm.isDeviceOwnerApp(context.getPackageName())) {
// Only try to update the notification if we are a profile or device owner.
return;
}
final NotificationManager nm =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
final ArrayList<CharSequence> problems = new ArrayList<>();
if (!dpm.isActivePasswordSufficient()) {
problems.add(context.getText(R.string.password_not_compliant_title));
}
if (um.hasUserRestriction(UserManager.DISALLOW_UNIFIED_PASSWORD)
&& Util.isManagedProfileOwner(context)
&& isUsingUnifiedPassword(context)) {
problems.add(context.getText(R.string.separate_challenge_required_title));
}
if (!problems.isEmpty()) {
final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
style.setBigContentTitle(context.getText(R.string.set_new_password_notification_content));
for (final CharSequence problem : problems) {
style.addLine(problem);
}
final NotificationCompat.Builder warn = NotificationUtil.getNotificationBuilder(context);
warn.setOngoing(true)
.setSmallIcon(R.drawable.ic_launcher)
.setStyle(style)
.setContentIntent(
PendingIntent.getActivity(
context, /*requestCode*/
-1,
new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD), /*flags*/
PendingIntent.FLAG_IMMUTABLE));
nm.notify(CHANGE_PASSWORD_NOTIFICATION_ID, warn.getNotification());
} else {
nm.cancel(CHANGE_PASSWORD_NOTIFICATION_ID);
}
}
@TargetApi(VERSION_CODES.P)
private static Boolean isUsingUnifiedPassword(Context context) {
if (Util.SDK_INT < VERSION_CODES.P) {
return false;
}
final DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
return dpm.isUsingUnifiedPassword(getComponentName(context));
}
/**
* Notify the admin receiver that something about the password has changed, e.g. quality
* constraints or separate challenge requirements.
*
* <p>This has to be sent manually because the system server only sends broadcasts for changes to
* the actual password, not any of the constraints related it it.
*
* <p>May trigger a show/hide of the notification warning to change the password through Settings.
*/
public static void sendPasswordRequirementsChanged(Context context) {
final Intent changedIntent =
new Intent(DeviceAdminReceiver.ACTION_PASSWORD_REQUIREMENTS_CHANGED);
changedIntent.setComponent(getComponentName(context));
context.sendBroadcast(changedIntent);
}
private void onProfileOwnerChanged(Context context) {
Log.i(TAG, "onProfileOwnerChanged");
NotificationUtil.showNotification(
context,
R.string.transfer_ownership_profile_owner_changed_title,
context.getString(R.string.transfer_ownership_profile_owner_changed_title),
NotificationUtil.PROFILE_OWNER_CHANGED_ID);
}
private void onDeviceOwnerChanged(Context context) {
Log.i(TAG, "onDeviceOwnerChanged");
NotificationUtil.showNotification(
context,
R.string.transfer_ownership_device_owner_changed_title,
context.getString(R.string.transfer_ownership_device_owner_changed_title),
NotificationUtil.DEVICE_OWNER_CHANGED_ID);
}
@TargetApi(VERSION_CODES.P)
public void onTransferOwnershipComplete(Context context, PersistableBundle bundle) {
Log.i(TAG, "onTransferOwnershipComplete");
NotificationUtil.showNotification(
context,
R.string.transfer_ownership_complete_title,
context.getString(R.string.transfer_ownership_complete_message, getComponentName(context)),
NotificationUtil.TRANSFER_OWNERSHIP_COMPLETE_ID);
}
@TargetApi(VERSION_CODES.P)
public void onTransferAffiliatedProfileOwnershipComplete(Context context, UserHandle user) {
Log.i(TAG, "onTransferAffiliatedProfileOwnershipComplete");
NotificationUtil.showNotification(
context,
R.string.transfer_ownership_affiliated_complete_title,
context.getString(R.string.transfer_ownership_affiliated_complete_message, user),
NotificationUtil.TRANSFER_AFFILIATED_PROFILE_OWNERSHIP_COMPLETE_ID);
}
private void handleUserAction(
Context context,
UserHandle userHandle,
int titleResId,
int messageResId,
int notificationId) {
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
String message =
context.getString(messageResId, userManager.getSerialNumberForUser(userHandle));
Log.i(TAG, message);
NotificationUtil.showNotification(context, titleResId, message, notificationId);
}
private void showToast(Context context, int resId) {
showToast(context, context.getString(resId));
}
private void showToast(Context context, String message) {
Log.v(TAG, "showToast():" + message);
Toast.makeText(context, message, Toast.LENGTH_LONG).show();
}
}