| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app; |
| 18 |
|
| 19 |
import android.annotation.IntDef; |
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.annotation.Nullable; |
| 22 |
import android.annotation.RequiresPermission; |
| 23 |
import android.annotation.SdkConstant; |
| 24 |
import android.annotation.SuppressLint; |
| 25 |
import android.annotation.SystemApi; |
| 26 |
import android.annotation.SystemService; |
| 27 |
import android.annotation.TestApi; |
| 28 |
import android.annotation.WorkerThread; |
| 29 |
import android.app.Notification.Builder; |
| 30 |
import android.compat.annotation.UnsupportedAppUsage; |
| 31 |
import android.content.ComponentName; |
| 32 |
import android.content.Context; |
| 33 |
import android.content.Intent; |
| 34 |
import android.content.pm.ParceledListSlice; |
| 35 |
import android.content.pm.ShortcutInfo; |
| 36 |
import android.graphics.drawable.Icon; |
| 37 |
import android.net.Uri; |
| 38 |
import android.os.Binder; |
| 39 |
import android.os.Build; |
| 40 |
import android.os.Bundle; |
| 41 |
import android.os.Handler; |
| 42 |
import android.os.IBinder; |
| 43 |
import android.os.Parcel; |
| 44 |
import android.os.Parcelable; |
| 45 |
import android.os.RemoteException; |
| 46 |
import android.os.ServiceManager; |
| 47 |
import android.os.StrictMode; |
| 48 |
import android.os.UserHandle; |
| 49 |
import android.provider.Settings.Global; |
| 50 |
import android.service.notification.Adjustment; |
| 51 |
import android.service.notification.Condition; |
| 52 |
import android.service.notification.StatusBarNotification; |
| 53 |
import android.service.notification.ZenModeConfig; |
| 54 |
import android.service.notification.ZenPolicy; |
| 55 |
import android.util.Log; |
| 56 |
import android.util.proto.ProtoOutputStream; |
| 57 |
|
| 58 |
import java.lang.annotation.Retention; |
| 59 |
import java.lang.annotation.RetentionPolicy; |
| 60 |
import java.util.ArrayList; |
| 61 |
import java.util.Arrays; |
| 62 |
import java.util.HashMap; |
| 63 |
import java.util.List; |
| 64 |
import java.util.Map; |
| 65 |
import java.util.Objects; |
| 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 |
@SystemService(Context.NOTIFICATION_SERVICE) |
| 104 |
public class NotificationManager { |
| 105 |
private static String TAG = "NotificationManager"; |
| 106 |
private static boolean localLOGV = false; |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
@SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 117 |
public static final String ACTION_APP_BLOCK_STATE_CHANGED = |
| 118 |
"android.app.action.APP_BLOCK_STATE_CHANGED"; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
@SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 133 |
public static final String ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED = |
| 134 |
"android.app.action.NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED"; |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
@SystemApi |
| 153 |
@RequiresPermission(android.Manifest.permission.STATUS_BAR_SERVICE) |
| 154 |
@SdkConstant(SdkConstant.SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 155 |
public static final String ACTION_TOGGLE_NOTIFICATION_HANDLER_PANEL = |
| 156 |
"android.app.action.TOGGLE_NOTIFICATION_HANDLER_PANEL"; |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
@SystemApi |
| 175 |
@RequiresPermission(android.Manifest.permission.STATUS_BAR_SERVICE) |
| 176 |
@SdkConstant(SdkConstant.SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 177 |
public static final String ACTION_OPEN_NOTIFICATION_HANDLER_PANEL = |
| 178 |
"android.app.action.OPEN_NOTIFICATION_HANDLER_PANEL"; |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
@SystemApi |
| 198 |
@RequiresPermission(android.Manifest.permission.STATUS_BAR_SERVICE) |
| 199 |
@SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 200 |
public static final String ACTION_CLOSE_NOTIFICATION_HANDLER_PANEL = |
| 201 |
"android.app.action.CLOSE_NOTIFICATION_HANDLER_PANEL"; |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
public static final String EXTRA_NOTIFICATION_CHANNEL_ID = |
| 210 |
"android.app.extra.NOTIFICATION_CHANNEL_ID"; |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
public static final String EXTRA_NOTIFICATION_CHANNEL_GROUP_ID = |
| 219 |
"android.app.extra.NOTIFICATION_CHANNEL_GROUP_ID"; |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
public static final String EXTRA_BLOCKED_STATE = "android.app.extra.BLOCKED_STATE"; |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
@SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 243 |
public static final String ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED = |
| 244 |
"android.app.action.NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED"; |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
@SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 258 |
public static final String ACTION_AUTOMATIC_ZEN_RULE_STATUS_CHANGED = |
| 259 |
"android.app.action.AUTOMATIC_ZEN_RULE_STATUS_CHANGED"; |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
public static final String EXTRA_AUTOMATIC_ZEN_RULE_STATUS = |
| 272 |
"android.app.extra.AUTOMATIC_ZEN_RULE_STATUS"; |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
public static final String EXTRA_AUTOMATIC_ZEN_RULE_ID = |
| 280 |
"android.app.extra.AUTOMATIC_ZEN_RULE_ID"; |
| 281 |
|
| 282 |
|
| 283 |
@IntDef(prefix = { "AUTOMATIC_RULE_STATUS" }, value = { |
| 284 |
AUTOMATIC_RULE_STATUS_ENABLED, AUTOMATIC_RULE_STATUS_DISABLED, |
| 285 |
AUTOMATIC_RULE_STATUS_REMOVED, AUTOMATIC_RULE_STATUS_UNKNOWN |
| 286 |
}) |
| 287 |
@Retention(RetentionPolicy.SOURCE) |
| 288 |
public @interface AutomaticZenRuleStatus {} |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
public static final int AUTOMATIC_RULE_STATUS_UNKNOWN = -1; |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
public static final int AUTOMATIC_RULE_STATUS_ENABLED = 1; |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
public static final int AUTOMATIC_RULE_STATUS_DISABLED = 2; |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
public static final int AUTOMATIC_RULE_STATUS_REMOVED = 3; |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
@SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 325 |
public static final String ACTION_EFFECTS_SUPPRESSOR_CHANGED |
| 326 |
= "android.os.action.ACTION_EFFECTS_SUPPRESSOR_CHANGED"; |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
@SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 335 |
public static final String ACTION_NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED |
| 336 |
= "android.app.action.NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED"; |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
@SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 343 |
public static final String ACTION_NOTIFICATION_POLICY_CHANGED |
| 344 |
= "android.app.action.NOTIFICATION_POLICY_CHANGED"; |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
@SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 351 |
public static final String ACTION_INTERRUPTION_FILTER_CHANGED |
| 352 |
= "android.app.action.INTERRUPTION_FILTER_CHANGED"; |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
@SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 360 |
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) |
| 361 |
public static final String ACTION_NOTIFICATION_LISTENER_ENABLED_CHANGED = |
| 362 |
"android.app.action.NOTIFICATION_LISTENER_ENABLED_CHANGED"; |
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
@SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 369 |
public static final String ACTION_INTERRUPTION_FILTER_CHANGED_INTERNAL |
| 370 |
= "android.app.action.INTERRUPTION_FILTER_CHANGED_INTERNAL"; |
| 371 |
|
| 372 |
|
| 373 |
@IntDef(prefix = { "INTERRUPTION_FILTER_" }, value = { |
| 374 |
INTERRUPTION_FILTER_NONE, INTERRUPTION_FILTER_PRIORITY, INTERRUPTION_FILTER_ALARMS, |
| 375 |
INTERRUPTION_FILTER_ALL, INTERRUPTION_FILTER_UNKNOWN |
| 376 |
}) |
| 377 |
@Retention(RetentionPolicy.SOURCE) |
| 378 |
public @interface InterruptionFilter {} |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
public static final int INTERRUPTION_FILTER_ALL = 1; |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
public static final int INTERRUPTION_FILTER_PRIORITY = 2; |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
public static final int INTERRUPTION_FILTER_NONE = 3; |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
public static final int INTERRUPTION_FILTER_ALARMS = 4; |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
public static final int INTERRUPTION_FILTER_UNKNOWN = 0; |
| 414 |
|
| 415 |
|
| 416 |
@IntDef(prefix = { "IMPORTANCE_" }, value = { |
| 417 |
IMPORTANCE_UNSPECIFIED, IMPORTANCE_NONE, |
| 418 |
IMPORTANCE_MIN, IMPORTANCE_LOW, IMPORTANCE_DEFAULT, IMPORTANCE_HIGH |
| 419 |
}) |
| 420 |
@Retention(RetentionPolicy.SOURCE) |
| 421 |
public @interface Importance {} |
| 422 |
|
| 423 |
|
| 424 |
@IntDef(prefix = { "BUBBLE_PREFERENCE_" }, value = { |
| 425 |
BUBBLE_PREFERENCE_NONE, BUBBLE_PREFERENCE_SELECTED, |
| 426 |
BUBBLE_PREFERENCE_ALL |
| 427 |
}) |
| 428 |
@Retention(RetentionPolicy.SOURCE) |
| 429 |
public @interface BubblePreference {} |
| 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 |
@SdkConstant(SdkConstant.SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 463 |
public static final String ACTION_AUTOMATIC_ZEN_RULE = |
| 464 |
"android.app.action.AUTOMATIC_ZEN_RULE"; |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
public static final String EXTRA_AUTOMATIC_RULE_ID = "android.app.extra.AUTOMATIC_RULE_ID"; |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
public static final String META_DATA_AUTOMATIC_RULE_TYPE = |
| 482 |
"android.service.zen.automatic.ruleType"; |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
public static final String META_DATA_RULE_INSTANCE_LIMIT = |
| 492 |
"android.service.zen.automatic.ruleInstanceLimit"; |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
public static final int VISIBILITY_NO_OVERRIDE = -1000; |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
public static final int IMPORTANCE_UNSPECIFIED = -1000; |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
public static final int IMPORTANCE_NONE = 0; |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
public static final int IMPORTANCE_MIN = 1; |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
public static final int IMPORTANCE_LOW = 2; |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
public static final int IMPORTANCE_DEFAULT = 3; |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
public static final int IMPORTANCE_HIGH = 4; |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
public static final int IMPORTANCE_MAX = 5; |
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
public static final int BUBBLE_PREFERENCE_NONE = 0; |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
public static final int BUBBLE_PREFERENCE_ALL = 1; |
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
public static final int BUBBLE_PREFERENCE_SELECTED = 2; |
| 564 |
|
| 565 |
@UnsupportedAppUsage |
| 566 |
private static INotificationManager sService; |
| 567 |
|
| 568 |
|
| 569 |
@UnsupportedAppUsage |
| 570 |
static public INotificationManager getService() |
| 571 |
{ |
| 572 |
if (sService != null) { |
| 573 |
return sService; |
| 574 |
} |
| 575 |
IBinder b = ServiceManager.getService("notification"); |
| 576 |
sService = INotificationManager.Stub.asInterface(b); |
| 577 |
return sService; |
| 578 |
} |
| 579 |
|
| 580 |
@UnsupportedAppUsage |
| 581 |
NotificationManager(Context context, Handler handler) |
| 582 |
{ |
| 583 |
mContext = context; |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
@UnsupportedAppUsage |
| 588 |
public static NotificationManager from(Context context) { |
| 589 |
return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); |
| 590 |
} |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
public void notify(int id, Notification notification) |
| 603 |
{ |
| 604 |
notify(null, id, notification); |
| 605 |
} |
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
public void notify(String tag, int id, Notification notification) |
| 627 |
{ |
| 628 |
notifyAsUser(tag, id, notification, mContext.getUser()); |
| 629 |
} |
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
public void notifyAsPackage(@NonNull String targetPackage, @Nullable String tag, int id, |
| 654 |
@NonNull Notification notification) { |
| 655 |
INotificationManager service = getService(); |
| 656 |
String sender = mContext.getPackageName(); |
| 657 |
|
| 658 |
try { |
| 659 |
if (localLOGV) Log.v(TAG, sender + ": notify(" + id + ", " + notification + ")"); |
| 660 |
service.enqueueNotificationWithTag(targetPackage, sender, tag, id, |
| 661 |
fixNotification(notification), mContext.getUser().getIdentifier()); |
| 662 |
} catch (RemoteException e) { |
| 663 |
throw e.rethrowFromSystemServer(); |
| 664 |
} |
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
@UnsupportedAppUsage |
| 671 |
public void notifyAsUser(String tag, int id, Notification notification, UserHandle user) |
| 672 |
{ |
| 673 |
INotificationManager service = getService(); |
| 674 |
String pkg = mContext.getPackageName(); |
| 675 |
|
| 676 |
try { |
| 677 |
if (localLOGV) Log.v(TAG, pkg + ": notify(" + id + ", " + notification + ")"); |
| 678 |
service.enqueueNotificationWithTag(pkg, mContext.getOpPackageName(), tag, id, |
| 679 |
fixNotification(notification), user.getIdentifier()); |
| 680 |
} catch (RemoteException e) { |
| 681 |
throw e.rethrowFromSystemServer(); |
| 682 |
} |
| 683 |
} |
| 684 |
|
| 685 |
private Notification fixNotification(Notification notification) { |
| 686 |
String pkg = mContext.getPackageName(); |
| 687 |
|
| 688 |
Notification.addFieldsFromContext(mContext, notification); |
| 689 |
|
| 690 |
if (notification.sound != null) { |
| 691 |
notification.sound = notification.sound.getCanonicalUri(); |
| 692 |
if (StrictMode.vmFileUriExposureEnabled()) { |
| 693 |
notification.sound.checkFileUriExposed("Notification.sound"); |
| 694 |
} |
| 695 |
|
| 696 |
} |
| 697 |
fixLegacySmallIcon(notification, pkg); |
| 698 |
if (mContext.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1) { |
| 699 |
if (notification.getSmallIcon() == null) { |
| 700 |
throw new IllegalArgumentException("Invalid notification (no valid small icon): " |
| 701 |
+ notification); |
| 702 |
} |
| 703 |
} |
| 704 |
|
| 705 |
notification.reduceImageSizes(mContext); |
| 706 |
return Builder.maybeCloneStrippedForDelivery(notification); |
| 707 |
} |
| 708 |
|
| 709 |
private void fixLegacySmallIcon(Notification n, String pkg) { |
| 710 |
if (n.getSmallIcon() == null && n.icon != 0) { |
| 711 |
n.setSmallIcon(Icon.createWithResource(pkg, n.icon)); |
| 712 |
} |
| 713 |
} |
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
public void cancel(int id) |
| 725 |
{ |
| 726 |
cancel(null, id); |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
public void cancel(@Nullable String tag, int id) |
| 739 |
{ |
| 740 |
cancelAsUser(tag, id, mContext.getUser()); |
| 741 |
} |
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
public void cancelAsPackage(@NonNull String targetPackage, @Nullable String tag, int id) { |
| 763 |
INotificationManager service = getService(); |
| 764 |
try { |
| 765 |
service.cancelNotificationWithTag(targetPackage, mContext.getOpPackageName(), |
| 766 |
tag, id, mContext.getUser().getIdentifier()); |
| 767 |
} catch (RemoteException e) { |
| 768 |
throw e.rethrowFromSystemServer(); |
| 769 |
} |
| 770 |
} |
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
@UnsupportedAppUsage |
| 776 |
public void cancelAsUser(String tag, int id, UserHandle user) |
| 777 |
{ |
| 778 |
INotificationManager service = getService(); |
| 779 |
String pkg = mContext.getPackageName(); |
| 780 |
if (localLOGV) Log.v(TAG, pkg + ": cancel(" + id + ")"); |
| 781 |
try { |
| 782 |
service.cancelNotificationWithTag( |
| 783 |
pkg, mContext.getOpPackageName(), tag, id, user.getIdentifier()); |
| 784 |
} catch (RemoteException e) { |
| 785 |
throw e.rethrowFromSystemServer(); |
| 786 |
} |
| 787 |
} |
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
public void cancelAll() |
| 794 |
{ |
| 795 |
INotificationManager service = getService(); |
| 796 |
String pkg = mContext.getPackageName(); |
| 797 |
if (localLOGV) Log.v(TAG, pkg + ": cancelAll()"); |
| 798 |
try { |
| 799 |
service.cancelAllNotifications(pkg, mContext.getUserId()); |
| 800 |
} catch (RemoteException e) { |
| 801 |
throw e.rethrowFromSystemServer(); |
| 802 |
} |
| 803 |
} |
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
public void setNotificationDelegate(@Nullable String delegate) { |
| 818 |
INotificationManager service = getService(); |
| 819 |
String pkg = mContext.getPackageName(); |
| 820 |
if (localLOGV) Log.v(TAG, pkg + ": cancelAll()"); |
| 821 |
try { |
| 822 |
service.setNotificationDelegate(pkg, delegate); |
| 823 |
} catch (RemoteException e) { |
| 824 |
throw e.rethrowFromSystemServer(); |
| 825 |
} |
| 826 |
} |
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
public @Nullable String getNotificationDelegate() { |
| 833 |
INotificationManager service = getService(); |
| 834 |
String pkg = mContext.getPackageName(); |
| 835 |
try { |
| 836 |
return service.getNotificationDelegate(pkg); |
| 837 |
} catch (RemoteException e) { |
| 838 |
throw e.rethrowFromSystemServer(); |
| 839 |
} |
| 840 |
} |
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
public boolean canNotifyAsPackage(@NonNull String pkg) { |
| 849 |
INotificationManager service = getService(); |
| 850 |
try { |
| 851 |
return service.canNotifyAsPackage(mContext.getPackageName(), pkg, mContext.getUserId()); |
| 852 |
} catch (RemoteException e) { |
| 853 |
throw e.rethrowFromSystemServer(); |
| 854 |
} |
| 855 |
} |
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
public void createNotificationChannelGroup(@NonNull NotificationChannelGroup group) { |
| 875 |
createNotificationChannelGroups(Arrays.asList(group)); |
| 876 |
} |
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
public void createNotificationChannelGroups(@NonNull List<NotificationChannelGroup> groups) { |
| 884 |
INotificationManager service = getService(); |
| 885 |
try { |
| 886 |
service.createNotificationChannelGroups(mContext.getPackageName(), |
| 887 |
new ParceledListSlice(groups)); |
| 888 |
} catch (RemoteException e) { |
| 889 |
throw e.rethrowFromSystemServer(); |
| 890 |
} |
| 891 |
} |
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
public void createNotificationChannel(@NonNull NotificationChannel channel) { |
| 917 |
createNotificationChannels(Arrays.asList(channel)); |
| 918 |
} |
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
public void createNotificationChannels(@NonNull List<NotificationChannel> channels) { |
| 927 |
INotificationManager service = getService(); |
| 928 |
try { |
| 929 |
service.createNotificationChannels(mContext.getPackageName(), |
| 930 |
new ParceledListSlice(channels)); |
| 931 |
} catch (RemoteException e) { |
| 932 |
throw e.rethrowFromSystemServer(); |
| 933 |
} |
| 934 |
} |
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
public NotificationChannel getNotificationChannel(String channelId) { |
| 945 |
INotificationManager service = getService(); |
| 946 |
try { |
| 947 |
return service.getNotificationChannel(mContext.getOpPackageName(), |
| 948 |
mContext.getUserId(), mContext.getPackageName(), channelId); |
| 949 |
} catch (RemoteException e) { |
| 950 |
throw e.rethrowFromSystemServer(); |
| 951 |
} |
| 952 |
} |
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
public @Nullable NotificationChannel getNotificationChannel(@NonNull String channelId, |
| 964 |
@NonNull String conversationId) { |
| 965 |
INotificationManager service = getService(); |
| 966 |
try { |
| 967 |
return service.getConversationNotificationChannel(mContext.getOpPackageName(), |
| 968 |
mContext.getUserId(), mContext.getPackageName(), channelId, true, |
| 969 |
conversationId); |
| 970 |
} catch (RemoteException e) { |
| 971 |
throw e.rethrowFromSystemServer(); |
| 972 |
} |
| 973 |
} |
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
public List<NotificationChannel> getNotificationChannels() { |
| 984 |
INotificationManager service = getService(); |
| 985 |
try { |
| 986 |
return service.getNotificationChannels(mContext.getOpPackageName(), |
| 987 |
mContext.getPackageName(), mContext.getUserId()).getList(); |
| 988 |
} catch (RemoteException e) { |
| 989 |
throw e.rethrowFromSystemServer(); |
| 990 |
} |
| 991 |
} |
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
public void deleteNotificationChannel(String channelId) { |
| 1001 |
INotificationManager service = getService(); |
| 1002 |
try { |
| 1003 |
service.deleteNotificationChannel(mContext.getPackageName(), channelId); |
| 1004 |
} catch (RemoteException e) { |
| 1005 |
throw e.rethrowFromSystemServer(); |
| 1006 |
} |
| 1007 |
} |
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
public NotificationChannelGroup getNotificationChannelGroup(String channelGroupId) { |
| 1015 |
INotificationManager service = getService(); |
| 1016 |
try { |
| 1017 |
return service.getNotificationChannelGroup(mContext.getPackageName(), channelGroupId); |
| 1018 |
} catch (RemoteException e) { |
| 1019 |
throw e.rethrowFromSystemServer(); |
| 1020 |
} |
| 1021 |
} |
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
public List<NotificationChannelGroup> getNotificationChannelGroups() { |
| 1027 |
INotificationManager service = getService(); |
| 1028 |
try { |
| 1029 |
final ParceledListSlice<NotificationChannelGroup> parceledList = |
| 1030 |
service.getNotificationChannelGroups(mContext.getPackageName()); |
| 1031 |
if (parceledList != null) { |
| 1032 |
return parceledList.getList(); |
| 1033 |
} |
| 1034 |
} catch (RemoteException e) { |
| 1035 |
throw e.rethrowFromSystemServer(); |
| 1036 |
} |
| 1037 |
return new ArrayList<>(); |
| 1038 |
} |
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
public void deleteNotificationChannelGroup(String groupId) { |
| 1045 |
INotificationManager service = getService(); |
| 1046 |
try { |
| 1047 |
service.deleteNotificationChannelGroup(mContext.getPackageName(), groupId); |
| 1048 |
} catch (RemoteException e) { |
| 1049 |
throw e.rethrowFromSystemServer(); |
| 1050 |
} |
| 1051 |
} |
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
@TestApi |
| 1057 |
public void updateNotificationChannel(@NonNull String pkg, int uid, |
| 1058 |
@NonNull NotificationChannel channel) { |
| 1059 |
INotificationManager service = getService(); |
| 1060 |
try { |
| 1061 |
service.updateNotificationChannelForPackage(pkg, uid, channel); |
| 1062 |
} catch (RemoteException e) { |
| 1063 |
throw e.rethrowFromSystemServer(); |
| 1064 |
} |
| 1065 |
} |
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
@TestApi |
| 1071 |
public ComponentName getEffectsSuppressor() { |
| 1072 |
INotificationManager service = getService(); |
| 1073 |
try { |
| 1074 |
return service.getEffectsSuppressor(); |
| 1075 |
} catch (RemoteException e) { |
| 1076 |
throw e.rethrowFromSystemServer(); |
| 1077 |
} |
| 1078 |
} |
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
public boolean matchesCallFilter(Bundle extras) { |
| 1084 |
INotificationManager service = getService(); |
| 1085 |
try { |
| 1086 |
return service.matchesCallFilter(extras); |
| 1087 |
} catch (RemoteException e) { |
| 1088 |
throw e.rethrowFromSystemServer(); |
| 1089 |
} |
| 1090 |
} |
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
@TestApi |
| 1096 |
public void cleanUpCallersAfter(long timeThreshold) { |
| 1097 |
INotificationManager service = getService(); |
| 1098 |
try { |
| 1099 |
service.cleanUpCallersAfter(timeThreshold); |
| 1100 |
} catch (RemoteException e) { |
| 1101 |
throw e.rethrowFromSystemServer(); |
| 1102 |
} |
| 1103 |
} |
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
public boolean isSystemConditionProviderEnabled(String path) { |
| 1109 |
INotificationManager service = getService(); |
| 1110 |
try { |
| 1111 |
return service.isSystemConditionProviderEnabled(path); |
| 1112 |
} catch (RemoteException e) { |
| 1113 |
throw e.rethrowFromSystemServer(); |
| 1114 |
} |
| 1115 |
} |
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
@UnsupportedAppUsage |
| 1121 |
public void setZenMode(int mode, Uri conditionId, String reason) { |
| 1122 |
INotificationManager service = getService(); |
| 1123 |
try { |
| 1124 |
service.setZenMode(mode, conditionId, reason); |
| 1125 |
} catch (RemoteException e) { |
| 1126 |
throw e.rethrowFromSystemServer(); |
| 1127 |
} |
| 1128 |
} |
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
public int getZenMode() { |
| 1134 |
INotificationManager service = getService(); |
| 1135 |
try { |
| 1136 |
return service.getZenMode(); |
| 1137 |
} catch (RemoteException e) { |
| 1138 |
throw e.rethrowFromSystemServer(); |
| 1139 |
} |
| 1140 |
} |
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 1146 |
public ZenModeConfig getZenModeConfig() { |
| 1147 |
INotificationManager service = getService(); |
| 1148 |
try { |
| 1149 |
return service.getZenModeConfig(); |
| 1150 |
} catch (RemoteException e) { |
| 1151 |
throw e.rethrowFromSystemServer(); |
| 1152 |
} |
| 1153 |
} |
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
public @NonNull NotificationManager.Policy getConsolidatedNotificationPolicy() { |
| 1165 |
INotificationManager service = getService(); |
| 1166 |
try { |
| 1167 |
return service.getConsolidatedNotificationPolicy(); |
| 1168 |
} catch (RemoteException e) { |
| 1169 |
throw e.rethrowFromSystemServer(); |
| 1170 |
} |
| 1171 |
} |
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
public int getRuleInstanceCount(ComponentName owner) { |
| 1177 |
INotificationManager service = getService(); |
| 1178 |
try { |
| 1179 |
return service.getRuleInstanceCount(owner); |
| 1180 |
} catch (RemoteException e) { |
| 1181 |
throw e.rethrowFromSystemServer(); |
| 1182 |
} |
| 1183 |
} |
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
public Map<String, AutomaticZenRule> getAutomaticZenRules() { |
| 1193 |
INotificationManager service = getService(); |
| 1194 |
try { |
| 1195 |
List<ZenModeConfig.ZenRule> rules = service.getZenRules(); |
| 1196 |
Map<String, AutomaticZenRule> ruleMap = new HashMap<>(); |
| 1197 |
for (ZenModeConfig.ZenRule rule : rules) { |
| 1198 |
AutomaticZenRule azr = new AutomaticZenRule(rule.name, rule.component, |
| 1199 |
rule.configurationActivity, rule.conditionId, rule.zenPolicy, |
| 1200 |
zenModeToInterruptionFilter(rule.zenMode), rule.enabled, |
| 1201 |
rule.creationTime); |
| 1202 |
azr.setPackageName(rule.pkg); |
| 1203 |
ruleMap.put(rule.id, azr); |
| 1204 |
} |
| 1205 |
return ruleMap; |
| 1206 |
} catch (RemoteException e) { |
| 1207 |
throw e.rethrowFromSystemServer(); |
| 1208 |
} |
| 1209 |
} |
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
public AutomaticZenRule getAutomaticZenRule(String id) { |
| 1223 |
INotificationManager service = getService(); |
| 1224 |
try { |
| 1225 |
return service.getAutomaticZenRule(id); |
| 1226 |
} catch (RemoteException e) { |
| 1227 |
throw e.rethrowFromSystemServer(); |
| 1228 |
} |
| 1229 |
} |
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
public String addAutomaticZenRule(AutomaticZenRule automaticZenRule) { |
| 1242 |
INotificationManager service = getService(); |
| 1243 |
try { |
| 1244 |
return service.addAutomaticZenRule(automaticZenRule, mContext.getPackageName()); |
| 1245 |
} catch (RemoteException e) { |
| 1246 |
throw e.rethrowFromSystemServer(); |
| 1247 |
} |
| 1248 |
} |
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
public boolean updateAutomaticZenRule(String id, AutomaticZenRule automaticZenRule) { |
| 1264 |
INotificationManager service = getService(); |
| 1265 |
try { |
| 1266 |
return service.updateAutomaticZenRule(id, automaticZenRule); |
| 1267 |
} catch (RemoteException e) { |
| 1268 |
throw e.rethrowFromSystemServer(); |
| 1269 |
} |
| 1270 |
} |
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
public void setAutomaticZenRuleState(@NonNull String id, @NonNull Condition condition) { |
| 1284 |
INotificationManager service = getService(); |
| 1285 |
try { |
| 1286 |
service.setAutomaticZenRuleState(id, condition); |
| 1287 |
} catch (RemoteException e) { |
| 1288 |
throw e.rethrowFromSystemServer(); |
| 1289 |
} |
| 1290 |
} |
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
public boolean removeAutomaticZenRule(String id) { |
| 1305 |
INotificationManager service = getService(); |
| 1306 |
try { |
| 1307 |
return service.removeAutomaticZenRule(id); |
| 1308 |
} catch (RemoteException e) { |
| 1309 |
throw e.rethrowFromSystemServer(); |
| 1310 |
} |
| 1311 |
} |
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
public boolean removeAutomaticZenRules(String packageName) { |
| 1319 |
INotificationManager service = getService(); |
| 1320 |
try { |
| 1321 |
return service.removeAutomaticZenRules(packageName); |
| 1322 |
} catch (RemoteException e) { |
| 1323 |
throw e.rethrowFromSystemServer(); |
| 1324 |
} |
| 1325 |
} |
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
public @Importance int getImportance() { |
| 1332 |
INotificationManager service = getService(); |
| 1333 |
try { |
| 1334 |
return service.getPackageImportance(mContext.getPackageName()); |
| 1335 |
} catch (RemoteException e) { |
| 1336 |
throw e.rethrowFromSystemServer(); |
| 1337 |
} |
| 1338 |
} |
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
public boolean areNotificationsEnabled() { |
| 1344 |
INotificationManager service = getService(); |
| 1345 |
try { |
| 1346 |
return service.areNotificationsEnabled(mContext.getPackageName()); |
| 1347 |
} catch (RemoteException e) { |
| 1348 |
throw e.rethrowFromSystemServer(); |
| 1349 |
} |
| 1350 |
} |
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
@Deprecated |
| 1363 |
public boolean areBubblesAllowed() { |
| 1364 |
INotificationManager service = getService(); |
| 1365 |
try { |
| 1366 |
return service.areBubblesAllowed(mContext.getPackageName()); |
| 1367 |
} catch (RemoteException e) { |
| 1368 |
throw e.rethrowFromSystemServer(); |
| 1369 |
} |
| 1370 |
} |
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
public boolean areBubblesEnabled() { |
| 1379 |
INotificationManager service = getService(); |
| 1380 |
try { |
| 1381 |
return service.areBubblesEnabled(mContext.getUser()); |
| 1382 |
} catch (RemoteException e) { |
| 1383 |
throw e.rethrowFromSystemServer(); |
| 1384 |
} |
| 1385 |
} |
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
public @BubblePreference int getBubblePreference() { |
| 1406 |
INotificationManager service = getService(); |
| 1407 |
try { |
| 1408 |
return service.getBubblePreferenceForPackage(mContext.getPackageName(), |
| 1409 |
Binder.getCallingUid()); |
| 1410 |
} catch (RemoteException e) { |
| 1411 |
throw e.rethrowFromSystemServer(); |
| 1412 |
} |
| 1413 |
} |
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
public void silenceNotificationSound() { |
| 1426 |
INotificationManager service = getService(); |
| 1427 |
try { |
| 1428 |
service.silenceNotificationSound(); |
| 1429 |
} catch (RemoteException e) { |
| 1430 |
throw e.rethrowFromSystemServer(); |
| 1431 |
} |
| 1432 |
} |
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
public boolean areNotificationsPaused() { |
| 1442 |
INotificationManager service = getService(); |
| 1443 |
try { |
| 1444 |
return service.isPackagePaused(mContext.getPackageName()); |
| 1445 |
} catch (RemoteException e) { |
| 1446 |
throw e.rethrowFromSystemServer(); |
| 1447 |
} |
| 1448 |
} |
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
public boolean isNotificationPolicyAccessGranted() { |
| 1465 |
INotificationManager service = getService(); |
| 1466 |
try { |
| 1467 |
return service.isNotificationPolicyAccessGranted(mContext.getOpPackageName()); |
| 1468 |
} catch (RemoteException e) { |
| 1469 |
throw e.rethrowFromSystemServer(); |
| 1470 |
} |
| 1471 |
} |
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
public boolean isNotificationListenerAccessGranted(ComponentName listener) { |
| 1486 |
INotificationManager service = getService(); |
| 1487 |
try { |
| 1488 |
return service.isNotificationListenerAccessGranted(listener); |
| 1489 |
} catch (RemoteException e) { |
| 1490 |
throw e.rethrowFromSystemServer(); |
| 1491 |
} |
| 1492 |
} |
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
@SystemApi |
| 1509 |
public boolean isNotificationAssistantAccessGranted(@NonNull ComponentName assistant) { |
| 1510 |
INotificationManager service = getService(); |
| 1511 |
try { |
| 1512 |
return service.isNotificationAssistantAccessGranted(assistant); |
| 1513 |
} catch (RemoteException e) { |
| 1514 |
throw e.rethrowFromSystemServer(); |
| 1515 |
} |
| 1516 |
} |
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
public boolean shouldHideSilentStatusBarIcons() { |
| 1526 |
INotificationManager service = getService(); |
| 1527 |
try { |
| 1528 |
return service.shouldHideSilentStatusIcons(mContext.getOpPackageName()); |
| 1529 |
} catch (RemoteException e) { |
| 1530 |
throw e.rethrowFromSystemServer(); |
| 1531 |
} |
| 1532 |
} |
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
@SystemApi |
| 1544 |
public @NonNull @Adjustment.Keys List<String> getAllowedAssistantAdjustments() { |
| 1545 |
INotificationManager service = getService(); |
| 1546 |
try { |
| 1547 |
return service.getAllowedAssistantAdjustments(mContext.getOpPackageName()); |
| 1548 |
} catch (RemoteException e) { |
| 1549 |
throw e.rethrowFromSystemServer(); |
| 1550 |
} |
| 1551 |
} |
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
@TestApi |
| 1557 |
public void allowAssistantAdjustment(String capability) { |
| 1558 |
INotificationManager service = getService(); |
| 1559 |
try { |
| 1560 |
service.allowAssistantAdjustment(capability); |
| 1561 |
} catch (RemoteException e) { |
| 1562 |
throw e.rethrowFromSystemServer(); |
| 1563 |
} |
| 1564 |
} |
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
@TestApi |
| 1570 |
public void disallowAssistantAdjustment(String capability) { |
| 1571 |
INotificationManager service = getService(); |
| 1572 |
try { |
| 1573 |
service.disallowAssistantAdjustment(capability); |
| 1574 |
} catch (RemoteException e) { |
| 1575 |
throw e.rethrowFromSystemServer(); |
| 1576 |
} |
| 1577 |
} |
| 1578 |
|
| 1579 |
|
| 1580 |
@TestApi |
| 1581 |
public boolean isNotificationPolicyAccessGrantedForPackage(@NonNull String pkg) { |
| 1582 |
INotificationManager service = getService(); |
| 1583 |
try { |
| 1584 |
return service.isNotificationPolicyAccessGrantedForPackage(pkg); |
| 1585 |
} catch (RemoteException e) { |
| 1586 |
throw e.rethrowFromSystemServer(); |
| 1587 |
} |
| 1588 |
} |
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
public List<String> getEnabledNotificationListenerPackages() { |
| 1594 |
INotificationManager service = getService(); |
| 1595 |
try { |
| 1596 |
return service.getEnabledNotificationListenerPackages(); |
| 1597 |
} catch (RemoteException e) { |
| 1598 |
throw e.rethrowFromSystemServer(); |
| 1599 |
} |
| 1600 |
} |
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
public Policy getNotificationPolicy() { |
| 1608 |
INotificationManager service = getService(); |
| 1609 |
try { |
| 1610 |
return service.getNotificationPolicy(mContext.getOpPackageName()); |
| 1611 |
} catch (RemoteException e) { |
| 1612 |
throw e.rethrowFromSystemServer(); |
| 1613 |
} |
| 1614 |
} |
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
public void setNotificationPolicy(@NonNull Policy policy) { |
| 1626 |
checkRequired("policy", policy); |
| 1627 |
INotificationManager service = getService(); |
| 1628 |
try { |
| 1629 |
service.setNotificationPolicy(mContext.getOpPackageName(), policy); |
| 1630 |
} catch (RemoteException e) { |
| 1631 |
throw e.rethrowFromSystemServer(); |
| 1632 |
} |
| 1633 |
} |
| 1634 |
|
| 1635 |
|
| 1636 |
public void setNotificationPolicyAccessGranted(String pkg, boolean granted) { |
| 1637 |
INotificationManager service = getService(); |
| 1638 |
try { |
| 1639 |
service.setNotificationPolicyAccessGranted(pkg, granted); |
| 1640 |
} catch (RemoteException e) { |
| 1641 |
throw e.rethrowFromSystemServer(); |
| 1642 |
} |
| 1643 |
} |
| 1644 |
|
| 1645 |
|
| 1646 |
public void setNotificationListenerAccessGranted( |
| 1647 |
@NonNull ComponentName listener, boolean granted) { |
| 1648 |
setNotificationListenerAccessGranted(listener, granted, true); |
| 1649 |
} |
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
|
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
@SystemApi |
| 1662 |
@TestApi |
| 1663 |
@RequiresPermission(android.Manifest.permission.MANAGE_NOTIFICATION_LISTENERS) |
| 1664 |
public void setNotificationListenerAccessGranted( |
| 1665 |
@NonNull ComponentName listener, boolean granted, boolean userSet) { |
| 1666 |
INotificationManager service = getService(); |
| 1667 |
try { |
| 1668 |
service.setNotificationListenerAccessGranted(listener, granted, userSet); |
| 1669 |
} catch (RemoteException e) { |
| 1670 |
throw e.rethrowFromSystemServer(); |
| 1671 |
} |
| 1672 |
} |
| 1673 |
|
| 1674 |
|
| 1675 |
public void setNotificationListenerAccessGrantedForUser(ComponentName listener, int userId, |
| 1676 |
boolean granted) { |
| 1677 |
INotificationManager service = getService(); |
| 1678 |
try { |
| 1679 |
service.setNotificationListenerAccessGrantedForUser(listener, userId, granted, true); |
| 1680 |
} catch (RemoteException e) { |
| 1681 |
throw e.rethrowFromSystemServer(); |
| 1682 |
} |
| 1683 |
} |
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
@SystemApi |
| 1696 |
public void setNotificationAssistantAccessGranted(@Nullable ComponentName assistant, |
| 1697 |
boolean granted) { |
| 1698 |
INotificationManager service = getService(); |
| 1699 |
try { |
| 1700 |
service.setNotificationAssistantAccessGranted(assistant, granted); |
| 1701 |
} catch (RemoteException e) { |
| 1702 |
throw e.rethrowFromSystemServer(); |
| 1703 |
} |
| 1704 |
} |
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
@SystemApi |
| 1715 |
@RequiresPermission(android.Manifest.permission.MANAGE_NOTIFICATION_LISTENERS) |
| 1716 |
public @NonNull List<ComponentName> getEnabledNotificationListeners() { |
| 1717 |
return getEnabledNotificationListeners(mContext.getUserId()); |
| 1718 |
} |
| 1719 |
|
| 1720 |
|
| 1721 |
public List<ComponentName> getEnabledNotificationListeners(int userId) { |
| 1722 |
INotificationManager service = getService(); |
| 1723 |
try { |
| 1724 |
return service.getEnabledNotificationListeners(userId); |
| 1725 |
} catch (RemoteException e) { |
| 1726 |
throw e.rethrowFromSystemServer(); |
| 1727 |
} |
| 1728 |
} |
| 1729 |
|
| 1730 |
|
| 1731 |
@SystemApi |
| 1732 |
public @Nullable ComponentName getAllowedNotificationAssistant() { |
| 1733 |
INotificationManager service = getService(); |
| 1734 |
try { |
| 1735 |
return service.getAllowedNotificationAssistant(); |
| 1736 |
} catch (RemoteException e) { |
| 1737 |
throw e.rethrowFromSystemServer(); |
| 1738 |
} |
| 1739 |
} |
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) |
| 1750 |
@SuppressLint("UserHandle") |
| 1751 |
public boolean hasEnabledNotificationListener(@NonNull String packageName, |
| 1752 |
@NonNull UserHandle userHandle) { |
| 1753 |
INotificationManager service = getService(); |
| 1754 |
try { |
| 1755 |
return service.hasEnabledNotificationListener(packageName, userHandle.getIdentifier()); |
| 1756 |
} catch (RemoteException e) { |
| 1757 |
throw e.rethrowFromSystemServer(); |
| 1758 |
} |
| 1759 |
} |
| 1760 |
|
| 1761 |
private Context mContext; |
| 1762 |
|
| 1763 |
private static void checkRequired(String name, Object value) { |
| 1764 |
if (value == null) { |
| 1765 |
throw new IllegalArgumentException(name + " is required"); |
| 1766 |
} |
| 1767 |
} |
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
@TestApi |
| 1776 |
@RequiresPermission(android.Manifest.permission.MANAGE_TOAST_RATE_LIMITING) |
| 1777 |
public void setToastRateLimitingEnabled(boolean enable) { |
| 1778 |
INotificationManager service = getService(); |
| 1779 |
try { |
| 1780 |
service.setToastRateLimitingEnabled(enable); |
| 1781 |
} catch (RemoteException e) { |
| 1782 |
throw e.rethrowFromSystemServer(); |
| 1783 |
} |
| 1784 |
} |
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
public static class Policy implements android.os.Parcelable { |
| 1791 |
|
| 1792 |
public static final int PRIORITY_CATEGORY_REMINDERS = 1 << 0; |
| 1793 |
|
| 1794 |
public static final int PRIORITY_CATEGORY_EVENTS = 1 << 1; |
| 1795 |
|
| 1796 |
public static final int PRIORITY_CATEGORY_MESSAGES = 1 << 2; |
| 1797 |
|
| 1798 |
public static final int PRIORITY_CATEGORY_CALLS = 1 << 3; |
| 1799 |
|
| 1800 |
public static final int PRIORITY_CATEGORY_REPEAT_CALLERS = 1 << 4; |
| 1801 |
|
| 1802 |
public static final int PRIORITY_CATEGORY_ALARMS = 1 << 5; |
| 1803 |
|
| 1804 |
public static final int PRIORITY_CATEGORY_MEDIA = 1 << 6; |
| 1805 |
|
| 1806 |
public static final int PRIORITY_CATEGORY_SYSTEM = 1 << 7; |
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
public static final int PRIORITY_CATEGORY_CONVERSATIONS = 1 << 8; |
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
public static final int[] ALL_PRIORITY_CATEGORIES = { |
| 1816 |
PRIORITY_CATEGORY_ALARMS, |
| 1817 |
PRIORITY_CATEGORY_MEDIA, |
| 1818 |
PRIORITY_CATEGORY_SYSTEM, |
| 1819 |
PRIORITY_CATEGORY_REMINDERS, |
| 1820 |
PRIORITY_CATEGORY_EVENTS, |
| 1821 |
PRIORITY_CATEGORY_MESSAGES, |
| 1822 |
PRIORITY_CATEGORY_CALLS, |
| 1823 |
PRIORITY_CATEGORY_REPEAT_CALLERS, |
| 1824 |
PRIORITY_CATEGORY_CONVERSATIONS, |
| 1825 |
}; |
| 1826 |
|
| 1827 |
|
| 1828 |
@IntDef(prefix = { "PRIORITY_SENDERS_" }, value = { |
| 1829 |
PRIORITY_SENDERS_ANY, |
| 1830 |
PRIORITY_SENDERS_CONTACTS, |
| 1831 |
PRIORITY_SENDERS_STARRED, |
| 1832 |
}) |
| 1833 |
@Retention(RetentionPolicy.SOURCE) |
| 1834 |
public @interface PrioritySenders {} |
| 1835 |
|
| 1836 |
|
| 1837 |
public static final int PRIORITY_SENDERS_ANY = 0; |
| 1838 |
|
| 1839 |
public static final int PRIORITY_SENDERS_CONTACTS = 1; |
| 1840 |
|
| 1841 |
public static final int PRIORITY_SENDERS_STARRED = 2; |
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
@IntDef(prefix = { "CONVERSATION_SENDERS_" }, value = { |
| 1846 |
CONVERSATION_SENDERS_ANYONE, |
| 1847 |
CONVERSATION_SENDERS_IMPORTANT, |
| 1848 |
CONVERSATION_SENDERS_NONE, |
| 1849 |
}) |
| 1850 |
@Retention(RetentionPolicy.SOURCE) |
| 1851 |
public @interface ConversationSenders {} |
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
public static final int CONVERSATION_SENDERS_ANYONE = ZenPolicy.CONVERSATION_SENDERS_ANYONE; |
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
public static final int CONVERSATION_SENDERS_IMPORTANT = |
| 1861 |
ZenPolicy.CONVERSATION_SENDERS_IMPORTANT; |
| 1862 |
|
| 1863 |
|
| 1864 |
|
| 1865 |
|
| 1866 |
public static final int CONVERSATION_SENDERS_NONE = ZenPolicy.CONVERSATION_SENDERS_NONE; |
| 1867 |
|
| 1868 |
|
| 1869 |
public final int priorityCategories; |
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
public final int priorityCallSenders; |
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
public final int priorityMessageSenders; |
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
public final int priorityConversationSenders; |
| 1885 |
|
| 1886 |
|
| 1887 |
|
| 1888 |
|
| 1889 |
public static final int CONVERSATION_SENDERS_UNSET = -1; |
| 1890 |
|
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
public static final int SUPPRESSED_EFFECTS_UNSET = -1; |
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
@Deprecated |
| 1904 |
public static final int SUPPRESSED_EFFECT_SCREEN_OFF = 1 << 0; |
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
@Deprecated |
| 1912 |
public static final int SUPPRESSED_EFFECT_SCREEN_ON = 1 << 1; |
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
public static final int SUPPRESSED_EFFECT_FULL_SCREEN_INTENT = 1 << 2; |
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
public static final int SUPPRESSED_EFFECT_LIGHTS = 1 << 3; |
| 1925 |
|
| 1926 |
|
| 1927 |
|
| 1928 |
|
| 1929 |
public static final int SUPPRESSED_EFFECT_PEEK = 1 << 4; |
| 1930 |
|
| 1931 |
|
| 1932 |
|
| 1933 |
|
| 1934 |
|
| 1935 |
public static final int SUPPRESSED_EFFECT_STATUS_BAR = 1 << 5; |
| 1936 |
|
| 1937 |
|
| 1938 |
|
| 1939 |
|
| 1940 |
|
| 1941 |
public static final int SUPPRESSED_EFFECT_BADGE = 1 << 6; |
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
public static final int SUPPRESSED_EFFECT_AMBIENT = 1 << 7; |
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
public static final int SUPPRESSED_EFFECT_NOTIFICATION_LIST = 1 << 8; |
| 1955 |
|
| 1956 |
private static final int[] ALL_SUPPRESSED_EFFECTS = { |
| 1957 |
SUPPRESSED_EFFECT_SCREEN_OFF, |
| 1958 |
SUPPRESSED_EFFECT_SCREEN_ON, |
| 1959 |
SUPPRESSED_EFFECT_FULL_SCREEN_INTENT, |
| 1960 |
SUPPRESSED_EFFECT_LIGHTS, |
| 1961 |
SUPPRESSED_EFFECT_PEEK, |
| 1962 |
SUPPRESSED_EFFECT_STATUS_BAR, |
| 1963 |
SUPPRESSED_EFFECT_BADGE, |
| 1964 |
SUPPRESSED_EFFECT_AMBIENT, |
| 1965 |
SUPPRESSED_EFFECT_NOTIFICATION_LIST |
| 1966 |
}; |
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
public final int suppressedVisualEffects; |
| 1973 |
|
| 1974 |
|
| 1975 |
|
| 1976 |
|
| 1977 |
public static final int STATE_CHANNELS_BYPASSING_DND = 1 << 0; |
| 1978 |
|
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
public static final int STATE_UNSET = -1; |
| 1983 |
|
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
public final int state; |
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
public Policy(int priorityCategories, int priorityCallSenders, int priorityMessageSenders) { |
| 2005 |
this(priorityCategories, priorityCallSenders, priorityMessageSenders, |
| 2006 |
SUPPRESSED_EFFECTS_UNSET, STATE_UNSET, CONVERSATION_SENDERS_UNSET); |
| 2007 |
} |
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
|
| 2015 |
|
| 2016 |
|
| 2017 |
|
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
|
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
|
| 2034 |
|
| 2035 |
|
| 2036 |
|
| 2037 |
public Policy(int priorityCategories, int priorityCallSenders, int priorityMessageSenders, |
| 2038 |
int suppressedVisualEffects) { |
| 2039 |
this(priorityCategories, priorityCallSenders, priorityMessageSenders, |
| 2040 |
suppressedVisualEffects, STATE_UNSET, CONVERSATION_SENDERS_UNSET); |
| 2041 |
} |
| 2042 |
|
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
|
| 2051 |
|
| 2052 |
|
| 2053 |
|
| 2054 |
|
| 2055 |
|
| 2056 |
|
| 2057 |
|
| 2058 |
|
| 2059 |
|
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
|
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
public Policy(int priorityCategories, @PrioritySenders int priorityCallSenders, |
| 2080 |
@PrioritySenders int priorityMessageSenders, |
| 2081 |
int suppressedVisualEffects, @ConversationSenders int priorityConversationSenders) { |
| 2082 |
this(priorityCategories, priorityCallSenders, priorityMessageSenders, |
| 2083 |
suppressedVisualEffects, STATE_UNSET, priorityConversationSenders); |
| 2084 |
} |
| 2085 |
|
| 2086 |
|
| 2087 |
public Policy(int priorityCategories, int priorityCallSenders, int priorityMessageSenders, |
| 2088 |
int suppressedVisualEffects, int state, int priorityConversationSenders) { |
| 2089 |
this.priorityCategories = priorityCategories; |
| 2090 |
this.priorityCallSenders = priorityCallSenders; |
| 2091 |
this.priorityMessageSenders = priorityMessageSenders; |
| 2092 |
this.suppressedVisualEffects = suppressedVisualEffects; |
| 2093 |
this.state = state; |
| 2094 |
this.priorityConversationSenders = priorityConversationSenders; |
| 2095 |
} |
| 2096 |
|
| 2097 |
|
| 2098 |
|
| 2099 |
public Policy(Parcel source) { |
| 2100 |
this(source.readInt(), source.readInt(), source.readInt(), source.readInt(), |
| 2101 |
source.readInt(), source.readInt()); |
| 2102 |
} |
| 2103 |
|
| 2104 |
@Override |
| 2105 |
public void writeToParcel(Parcel dest, int flags) { |
| 2106 |
dest.writeInt(priorityCategories); |
| 2107 |
dest.writeInt(priorityCallSenders); |
| 2108 |
dest.writeInt(priorityMessageSenders); |
| 2109 |
dest.writeInt(suppressedVisualEffects); |
| 2110 |
dest.writeInt(state); |
| 2111 |
dest.writeInt(priorityConversationSenders); |
| 2112 |
} |
| 2113 |
|
| 2114 |
@Override |
| 2115 |
public int describeContents() { |
| 2116 |
return 0; |
| 2117 |
} |
| 2118 |
|
| 2119 |
@Override |
| 2120 |
public int hashCode() { |
| 2121 |
return Objects.hash(priorityCategories, priorityCallSenders, priorityMessageSenders, |
| 2122 |
suppressedVisualEffects, state, priorityConversationSenders); |
| 2123 |
} |
| 2124 |
|
| 2125 |
@Override |
| 2126 |
public boolean equals(@Nullable Object o) { |
| 2127 |
if (!(o instanceof Policy)) return false; |
| 2128 |
if (o == this) return true; |
| 2129 |
final Policy other = (Policy) o; |
| 2130 |
return other.priorityCategories == priorityCategories |
| 2131 |
&& other.priorityCallSenders == priorityCallSenders |
| 2132 |
&& other.priorityMessageSenders == priorityMessageSenders |
| 2133 |
&& suppressedVisualEffectsEqual(suppressedVisualEffects, |
| 2134 |
other.suppressedVisualEffects) |
| 2135 |
&& other.state == this.state |
| 2136 |
&& other.priorityConversationSenders == this.priorityConversationSenders; |
| 2137 |
} |
| 2138 |
|
| 2139 |
private boolean suppressedVisualEffectsEqual(int suppressedEffects, |
| 2140 |
int otherSuppressedVisualEffects) { |
| 2141 |
if (suppressedEffects == otherSuppressedVisualEffects) { |
| 2142 |
return true; |
| 2143 |
} |
| 2144 |
|
| 2145 |
if ((suppressedEffects & SUPPRESSED_EFFECT_SCREEN_ON) != 0) { |
| 2146 |
suppressedEffects |= SUPPRESSED_EFFECT_PEEK; |
| 2147 |
} |
| 2148 |
if ((suppressedEffects & SUPPRESSED_EFFECT_SCREEN_OFF) != 0) { |
| 2149 |
suppressedEffects |= SUPPRESSED_EFFECT_FULL_SCREEN_INTENT; |
| 2150 |
suppressedEffects |= SUPPRESSED_EFFECT_LIGHTS; |
| 2151 |
suppressedEffects |= SUPPRESSED_EFFECT_AMBIENT; |
| 2152 |
} |
| 2153 |
|
| 2154 |
if ((otherSuppressedVisualEffects & SUPPRESSED_EFFECT_SCREEN_ON) != 0) { |
| 2155 |
otherSuppressedVisualEffects |= SUPPRESSED_EFFECT_PEEK; |
| 2156 |
} |
| 2157 |
if ((otherSuppressedVisualEffects & SUPPRESSED_EFFECT_SCREEN_OFF) != 0) { |
| 2158 |
otherSuppressedVisualEffects |= SUPPRESSED_EFFECT_FULL_SCREEN_INTENT; |
| 2159 |
otherSuppressedVisualEffects |= SUPPRESSED_EFFECT_LIGHTS; |
| 2160 |
otherSuppressedVisualEffects |= SUPPRESSED_EFFECT_AMBIENT; |
| 2161 |
} |
| 2162 |
|
| 2163 |
if ((suppressedEffects & SUPPRESSED_EFFECT_SCREEN_ON) |
| 2164 |
!= (otherSuppressedVisualEffects & SUPPRESSED_EFFECT_SCREEN_ON)) { |
| 2165 |
int currSuppressedEffects = (suppressedEffects & SUPPRESSED_EFFECT_SCREEN_ON) != 0 |
| 2166 |
? otherSuppressedVisualEffects : suppressedEffects; |
| 2167 |
if ((currSuppressedEffects & SUPPRESSED_EFFECT_PEEK) == 0) { |
| 2168 |
return false; |
| 2169 |
} |
| 2170 |
} |
| 2171 |
|
| 2172 |
if ((suppressedEffects & SUPPRESSED_EFFECT_SCREEN_OFF) |
| 2173 |
!= (otherSuppressedVisualEffects & SUPPRESSED_EFFECT_SCREEN_OFF)) { |
| 2174 |
int currSuppressedEffects = (suppressedEffects & SUPPRESSED_EFFECT_SCREEN_OFF) != 0 |
| 2175 |
? otherSuppressedVisualEffects : suppressedEffects; |
| 2176 |
if ((currSuppressedEffects & SUPPRESSED_EFFECT_FULL_SCREEN_INTENT) == 0 |
| 2177 |
|| (currSuppressedEffects & SUPPRESSED_EFFECT_LIGHTS) == 0 |
| 2178 |
|| (currSuppressedEffects & SUPPRESSED_EFFECT_AMBIENT) == 0) { |
| 2179 |
return false; |
| 2180 |
} |
| 2181 |
} |
| 2182 |
|
| 2183 |
int thisWithoutOldEffects = suppressedEffects |
| 2184 |
& ~SUPPRESSED_EFFECT_SCREEN_ON |
| 2185 |
& ~SUPPRESSED_EFFECT_SCREEN_OFF; |
| 2186 |
int otherWithoutOldEffects = otherSuppressedVisualEffects |
| 2187 |
& ~SUPPRESSED_EFFECT_SCREEN_ON |
| 2188 |
& ~SUPPRESSED_EFFECT_SCREEN_OFF; |
| 2189 |
return thisWithoutOldEffects == otherWithoutOldEffects; |
| 2190 |
} |
| 2191 |
|
| 2192 |
@Override |
| 2193 |
public String toString() { |
| 2194 |
return "NotificationManager.Policy[" |
| 2195 |
+ "priorityCategories=" + priorityCategoriesToString(priorityCategories) |
| 2196 |
+ ",priorityCallSenders=" + prioritySendersToString(priorityCallSenders) |
| 2197 |
+ ",priorityMessageSenders=" + prioritySendersToString(priorityMessageSenders) |
| 2198 |
+ ",priorityConvSenders=" |
| 2199 |
+ conversationSendersToString(priorityConversationSenders) |
| 2200 |
+ ",suppressedVisualEffects=" |
| 2201 |
+ suppressedEffectsToString(suppressedVisualEffects) |
| 2202 |
+ ",areChannelsBypassingDnd=" + (state == STATE_UNSET |
| 2203 |
? "unset" |
| 2204 |
: ((state & STATE_CHANNELS_BYPASSING_DND) != 0) |
| 2205 |
? "true" |
| 2206 |
: "false") |
| 2207 |
+ "]"; |
| 2208 |
} |
| 2209 |
|
| 2210 |
|
| 2211 |
public void dumpDebug(ProtoOutputStream proto, long fieldId) { |
| 2212 |
final long pToken = proto.start(fieldId); |
| 2213 |
|
| 2214 |
bitwiseToProtoEnum(proto, PolicyProto.PRIORITY_CATEGORIES, priorityCategories); |
| 2215 |
proto.write(PolicyProto.PRIORITY_CALL_SENDER, priorityCallSenders); |
| 2216 |
proto.write(PolicyProto.PRIORITY_MESSAGE_SENDER, priorityMessageSenders); |
| 2217 |
bitwiseToProtoEnum( |
| 2218 |
proto, PolicyProto.SUPPRESSED_VISUAL_EFFECTS, suppressedVisualEffects); |
| 2219 |
|
| 2220 |
proto.end(pToken); |
| 2221 |
} |
| 2222 |
|
| 2223 |
private static void bitwiseToProtoEnum(ProtoOutputStream proto, long fieldId, int data) { |
| 2224 |
for (int i = 1; data > 0; ++i, data >>>= 1) { |
| 2225 |
if ((data & 1) == 1) { |
| 2226 |
proto.write(fieldId, i); |
| 2227 |
} |
| 2228 |
} |
| 2229 |
} |
| 2230 |
|
| 2231 |
|
| 2232 |
|
| 2233 |
|
| 2234 |
public static int getAllSuppressedVisualEffects() { |
| 2235 |
int effects = 0; |
| 2236 |
for (int i = 0; i < ALL_SUPPRESSED_EFFECTS.length; i++) { |
| 2237 |
effects |= ALL_SUPPRESSED_EFFECTS[i]; |
| 2238 |
} |
| 2239 |
return effects; |
| 2240 |
} |
| 2241 |
|
| 2242 |
|
| 2243 |
|
| 2244 |
|
| 2245 |
public static boolean areAllVisualEffectsSuppressed(int effects) { |
| 2246 |
for (int i = 0; i < ALL_SUPPRESSED_EFFECTS.length; i++) { |
| 2247 |
final int effect = ALL_SUPPRESSED_EFFECTS[i]; |
| 2248 |
if ((effects & effect) == 0) { |
| 2249 |
return false; |
| 2250 |
} |
| 2251 |
} |
| 2252 |
return true; |
| 2253 |
} |
| 2254 |
|
| 2255 |
private static int toggleEffects(int currentEffects, int[] effects, boolean suppress) { |
| 2256 |
for (int i = 0; i < effects.length; i++) { |
| 2257 |
final int effect = effects[i]; |
| 2258 |
if (suppress) { |
| 2259 |
currentEffects |= effect; |
| 2260 |
} else { |
| 2261 |
currentEffects &= ~effect; |
| 2262 |
} |
| 2263 |
} |
| 2264 |
return currentEffects; |
| 2265 |
} |
| 2266 |
|
| 2267 |
public static String suppressedEffectsToString(int effects) { |
| 2268 |
if (effects <= 0) return ""; |
| 2269 |
final StringBuilder sb = new StringBuilder(); |
| 2270 |
for (int i = 0; i < ALL_SUPPRESSED_EFFECTS.length; i++) { |
| 2271 |
final int effect = ALL_SUPPRESSED_EFFECTS[i]; |
| 2272 |
if ((effects & effect) != 0) { |
| 2273 |
if (sb.length() > 0) sb.append(','); |
| 2274 |
sb.append(effectToString(effect)); |
| 2275 |
} |
| 2276 |
effects &= ~effect; |
| 2277 |
} |
| 2278 |
if (effects != 0) { |
| 2279 |
if (sb.length() > 0) sb.append(','); |
| 2280 |
sb.append("UNKNOWN_").append(effects); |
| 2281 |
} |
| 2282 |
return sb.toString(); |
| 2283 |
} |
| 2284 |
|
| 2285 |
public static String priorityCategoriesToString(int priorityCategories) { |
| 2286 |
if (priorityCategories == 0) return ""; |
| 2287 |
final StringBuilder sb = new StringBuilder(); |
| 2288 |
for (int i = 0; i < ALL_PRIORITY_CATEGORIES.length; i++) { |
| 2289 |
final int priorityCategory = ALL_PRIORITY_CATEGORIES[i]; |
| 2290 |
if ((priorityCategories & priorityCategory) != 0) { |
| 2291 |
if (sb.length() > 0) sb.append(','); |
| 2292 |
sb.append(priorityCategoryToString(priorityCategory)); |
| 2293 |
} |
| 2294 |
priorityCategories &= ~priorityCategory; |
| 2295 |
} |
| 2296 |
if (priorityCategories != 0) { |
| 2297 |
if (sb.length() > 0) sb.append(','); |
| 2298 |
sb.append("PRIORITY_CATEGORY_UNKNOWN_").append(priorityCategories); |
| 2299 |
} |
| 2300 |
return sb.toString(); |
| 2301 |
} |
| 2302 |
|
| 2303 |
private static String effectToString(int effect) { |
| 2304 |
switch (effect) { |
| 2305 |
case SUPPRESSED_EFFECT_FULL_SCREEN_INTENT: |
| 2306 |
return "SUPPRESSED_EFFECT_FULL_SCREEN_INTENT"; |
| 2307 |
case SUPPRESSED_EFFECT_LIGHTS: |
| 2308 |
return "SUPPRESSED_EFFECT_LIGHTS"; |
| 2309 |
case SUPPRESSED_EFFECT_PEEK: |
| 2310 |
return "SUPPRESSED_EFFECT_PEEK"; |
| 2311 |
case SUPPRESSED_EFFECT_STATUS_BAR: |
| 2312 |
return "SUPPRESSED_EFFECT_STATUS_BAR"; |
| 2313 |
case SUPPRESSED_EFFECT_BADGE: |
| 2314 |
return "SUPPRESSED_EFFECT_BADGE"; |
| 2315 |
case SUPPRESSED_EFFECT_AMBIENT: |
| 2316 |
return "SUPPRESSED_EFFECT_AMBIENT"; |
| 2317 |
case SUPPRESSED_EFFECT_NOTIFICATION_LIST: |
| 2318 |
return "SUPPRESSED_EFFECT_NOTIFICATION_LIST"; |
| 2319 |
case SUPPRESSED_EFFECT_SCREEN_OFF: |
| 2320 |
return "SUPPRESSED_EFFECT_SCREEN_OFF"; |
| 2321 |
case SUPPRESSED_EFFECT_SCREEN_ON: |
| 2322 |
return "SUPPRESSED_EFFECT_SCREEN_ON"; |
| 2323 |
case SUPPRESSED_EFFECTS_UNSET: |
| 2324 |
return "SUPPRESSED_EFFECTS_UNSET"; |
| 2325 |
default: return "UNKNOWN_" + effect; |
| 2326 |
} |
| 2327 |
} |
| 2328 |
|
| 2329 |
private static String priorityCategoryToString(int priorityCategory) { |
| 2330 |
switch (priorityCategory) { |
| 2331 |
case PRIORITY_CATEGORY_REMINDERS: return "PRIORITY_CATEGORY_REMINDERS"; |
| 2332 |
case PRIORITY_CATEGORY_EVENTS: return "PRIORITY_CATEGORY_EVENTS"; |
| 2333 |
case PRIORITY_CATEGORY_MESSAGES: return "PRIORITY_CATEGORY_MESSAGES"; |
| 2334 |
case PRIORITY_CATEGORY_CALLS: return "PRIORITY_CATEGORY_CALLS"; |
| 2335 |
case PRIORITY_CATEGORY_REPEAT_CALLERS: return "PRIORITY_CATEGORY_REPEAT_CALLERS"; |
| 2336 |
case PRIORITY_CATEGORY_ALARMS: return "PRIORITY_CATEGORY_ALARMS"; |
| 2337 |
case PRIORITY_CATEGORY_MEDIA: return "PRIORITY_CATEGORY_MEDIA"; |
| 2338 |
case PRIORITY_CATEGORY_SYSTEM: return "PRIORITY_CATEGORY_SYSTEM"; |
| 2339 |
case PRIORITY_CATEGORY_CONVERSATIONS: return "PRIORITY_CATEGORY_CONVERSATIONS"; |
| 2340 |
default: return "PRIORITY_CATEGORY_UNKNOWN_" + priorityCategory; |
| 2341 |
} |
| 2342 |
} |
| 2343 |
|
| 2344 |
public static String prioritySendersToString(int prioritySenders) { |
| 2345 |
switch (prioritySenders) { |
| 2346 |
case PRIORITY_SENDERS_ANY: return "PRIORITY_SENDERS_ANY"; |
| 2347 |
case PRIORITY_SENDERS_CONTACTS: return "PRIORITY_SENDERS_CONTACTS"; |
| 2348 |
case PRIORITY_SENDERS_STARRED: return "PRIORITY_SENDERS_STARRED"; |
| 2349 |
default: return "PRIORITY_SENDERS_UNKNOWN_" + prioritySenders; |
| 2350 |
} |
| 2351 |
} |
| 2352 |
|
| 2353 |
|
| 2354 |
|
| 2355 |
|
| 2356 |
public static @NonNull String conversationSendersToString(int priorityConversationSenders) { |
| 2357 |
switch (priorityConversationSenders) { |
| 2358 |
case CONVERSATION_SENDERS_ANYONE: |
| 2359 |
return "anyone"; |
| 2360 |
case CONVERSATION_SENDERS_IMPORTANT: |
| 2361 |
return "important"; |
| 2362 |
case CONVERSATION_SENDERS_NONE: |
| 2363 |
return "none"; |
| 2364 |
case CONVERSATION_SENDERS_UNSET: |
| 2365 |
return "unset"; |
| 2366 |
} |
| 2367 |
return "invalidConversationType{" + priorityConversationSenders + "}"; |
| 2368 |
} |
| 2369 |
|
| 2370 |
public static final @android.annotation.NonNull Parcelable.Creator<Policy> CREATOR |
| 2371 |
= new Parcelable.Creator<Policy>() { |
| 2372 |
@Override |
| 2373 |
public Policy createFromParcel(Parcel in) { |
| 2374 |
return new Policy(in); |
| 2375 |
} |
| 2376 |
|
| 2377 |
@Override |
| 2378 |
public Policy[] newArray(int size) { |
| 2379 |
return new Policy[size]; |
| 2380 |
} |
| 2381 |
}; |
| 2382 |
|
| 2383 |
|
| 2384 |
public boolean allowAlarms() { |
| 2385 |
return (priorityCategories & PRIORITY_CATEGORY_ALARMS) != 0; |
| 2386 |
} |
| 2387 |
|
| 2388 |
|
| 2389 |
public boolean allowMedia() { |
| 2390 |
return (priorityCategories & PRIORITY_CATEGORY_MEDIA) != 0; |
| 2391 |
} |
| 2392 |
|
| 2393 |
|
| 2394 |
public boolean allowSystem() { |
| 2395 |
return (priorityCategories & PRIORITY_CATEGORY_SYSTEM) != 0; |
| 2396 |
} |
| 2397 |
|
| 2398 |
|
| 2399 |
public boolean allowRepeatCallers() { |
| 2400 |
return (priorityCategories & PRIORITY_CATEGORY_REPEAT_CALLERS) != 0; |
| 2401 |
} |
| 2402 |
|
| 2403 |
|
| 2404 |
public boolean allowCalls() { |
| 2405 |
return (priorityCategories & PRIORITY_CATEGORY_CALLS) != 0; |
| 2406 |
} |
| 2407 |
|
| 2408 |
|
| 2409 |
public boolean allowConversations() { |
| 2410 |
return (priorityCategories & PRIORITY_CATEGORY_CONVERSATIONS) != 0; |
| 2411 |
} |
| 2412 |
|
| 2413 |
|
| 2414 |
public boolean allowMessages() { |
| 2415 |
return (priorityCategories & PRIORITY_CATEGORY_MESSAGES) != 0; |
| 2416 |
} |
| 2417 |
|
| 2418 |
|
| 2419 |
public boolean allowEvents() { |
| 2420 |
return (priorityCategories & PRIORITY_CATEGORY_EVENTS) != 0; |
| 2421 |
} |
| 2422 |
|
| 2423 |
|
| 2424 |
public boolean allowReminders() { |
| 2425 |
return (priorityCategories & PRIORITY_CATEGORY_REMINDERS) != 0; |
| 2426 |
} |
| 2427 |
|
| 2428 |
|
| 2429 |
public int allowCallsFrom() { |
| 2430 |
return priorityCallSenders; |
| 2431 |
} |
| 2432 |
|
| 2433 |
|
| 2434 |
public int allowMessagesFrom() { |
| 2435 |
return priorityMessageSenders; |
| 2436 |
} |
| 2437 |
|
| 2438 |
|
| 2439 |
public int allowConversationsFrom() { |
| 2440 |
return priorityConversationSenders; |
| 2441 |
} |
| 2442 |
|
| 2443 |
|
| 2444 |
public boolean showFullScreenIntents() { |
| 2445 |
return (suppressedVisualEffects & SUPPRESSED_EFFECT_FULL_SCREEN_INTENT) == 0; |
| 2446 |
} |
| 2447 |
|
| 2448 |
|
| 2449 |
public boolean showLights() { |
| 2450 |
return (suppressedVisualEffects & SUPPRESSED_EFFECT_LIGHTS) == 0; |
| 2451 |
} |
| 2452 |
|
| 2453 |
|
| 2454 |
public boolean showPeeking() { |
| 2455 |
return (suppressedVisualEffects & SUPPRESSED_EFFECT_PEEK) == 0; |
| 2456 |
} |
| 2457 |
|
| 2458 |
|
| 2459 |
public boolean showStatusBarIcons() { |
| 2460 |
return (suppressedVisualEffects & SUPPRESSED_EFFECT_STATUS_BAR) == 0; |
| 2461 |
} |
| 2462 |
|
| 2463 |
|
| 2464 |
public boolean showAmbient() { |
| 2465 |
return (suppressedVisualEffects & SUPPRESSED_EFFECT_AMBIENT) == 0; |
| 2466 |
} |
| 2467 |
|
| 2468 |
|
| 2469 |
public boolean showBadges() { |
| 2470 |
return (suppressedVisualEffects & SUPPRESSED_EFFECT_BADGE) == 0; |
| 2471 |
} |
| 2472 |
|
| 2473 |
|
| 2474 |
public boolean showInNotificationList() { |
| 2475 |
return (suppressedVisualEffects & SUPPRESSED_EFFECT_NOTIFICATION_LIST) == 0; |
| 2476 |
} |
| 2477 |
|
| 2478 |
|
| 2479 |
|
| 2480 |
|
| 2481 |
|
| 2482 |
public Policy copy() { |
| 2483 |
final Parcel parcel = Parcel.obtain(); |
| 2484 |
try { |
| 2485 |
writeToParcel(parcel, 0); |
| 2486 |
parcel.setDataPosition(0); |
| 2487 |
return new Policy(parcel); |
| 2488 |
} finally { |
| 2489 |
parcel.recycle(); |
| 2490 |
} |
| 2491 |
} |
| 2492 |
} |
| 2493 |
|
| 2494 |
|
| 2495 |
|
| 2496 |
|
| 2497 |
|
| 2498 |
|
| 2499 |
|
| 2500 |
|
| 2501 |
|
| 2502 |
|
| 2503 |
|
| 2504 |
|
| 2505 |
|
| 2506 |
|
| 2507 |
|
| 2508 |
|
| 2509 |
|
| 2510 |
|
| 2511 |
|
| 2512 |
public StatusBarNotification[] getActiveNotifications() { |
| 2513 |
final INotificationManager service = getService(); |
| 2514 |
final String pkg = mContext.getPackageName(); |
| 2515 |
try { |
| 2516 |
final ParceledListSlice<StatusBarNotification> parceledList |
| 2517 |
= service.getAppActiveNotifications(pkg, mContext.getUserId()); |
| 2518 |
if (parceledList != null) { |
| 2519 |
final List<StatusBarNotification> list = parceledList.getList(); |
| 2520 |
return list.toArray(new StatusBarNotification[list.size()]); |
| 2521 |
} |
| 2522 |
} catch (RemoteException e) { |
| 2523 |
throw e.rethrowFromSystemServer(); |
| 2524 |
} |
| 2525 |
return new StatusBarNotification[0]; |
| 2526 |
} |
| 2527 |
|
| 2528 |
|
| 2529 |
|
| 2530 |
|
| 2531 |
|
| 2532 |
|
| 2533 |
|
| 2534 |
|
| 2535 |
public final @InterruptionFilter int getCurrentInterruptionFilter() { |
| 2536 |
final INotificationManager service = getService(); |
| 2537 |
try { |
| 2538 |
return zenModeToInterruptionFilter(service.getZenMode()); |
| 2539 |
} catch (RemoteException e) { |
| 2540 |
throw e.rethrowFromSystemServer(); |
| 2541 |
} |
| 2542 |
} |
| 2543 |
|
| 2544 |
|
| 2545 |
|
| 2546 |
|
| 2547 |
|
| 2548 |
|
| 2549 |
|
| 2550 |
|
| 2551 |
|
| 2552 |
|
| 2553 |
|
| 2554 |
public final void setInterruptionFilter(@InterruptionFilter int interruptionFilter) { |
| 2555 |
final INotificationManager service = getService(); |
| 2556 |
try { |
| 2557 |
service.setInterruptionFilter(mContext.getOpPackageName(), interruptionFilter); |
| 2558 |
} catch (RemoteException e) { |
| 2559 |
throw e.rethrowFromSystemServer(); |
| 2560 |
} |
| 2561 |
} |
| 2562 |
|
| 2563 |
|
| 2564 |
|
| 2565 |
|
| 2566 |
|
| 2567 |
|
| 2568 |
|
| 2569 |
|
| 2570 |
|
| 2571 |
|
| 2572 |
|
| 2573 |
|
| 2574 |
|
| 2575 |
|
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
|
| 2581 |
|
| 2582 |
|
| 2583 |
|
| 2584 |
|
| 2585 |
|
| 2586 |
|
| 2587 |
|
| 2588 |
|
| 2589 |
|
| 2590 |
|
| 2591 |
|
| 2592 |
|
| 2593 |
|
| 2594 |
|
| 2595 |
|
| 2596 |
|
| 2597 |
|
| 2598 |
|
| 2599 |
|
| 2600 |
|
| 2601 |
|
| 2602 |
|
| 2603 |
|
| 2604 |
@WorkerThread |
| 2605 |
public boolean matchesCallFilter(@NonNull Uri uri) { |
| 2606 |
Bundle extras = new Bundle(); |
| 2607 |
ArrayList<Person> pList = new ArrayList<>(); |
| 2608 |
pList.add(new Person.Builder().setUri(uri.toString()).build()); |
| 2609 |
extras.putParcelableArrayList(Notification.EXTRA_PEOPLE_LIST, pList); |
| 2610 |
|
| 2611 |
return matchesCallFilter(extras); |
| 2612 |
} |
| 2613 |
|
| 2614 |
|
| 2615 |
public static int zenModeToInterruptionFilter(int zen) { |
| 2616 |
switch (zen) { |
| 2617 |
case Global.ZEN_MODE_OFF: return INTERRUPTION_FILTER_ALL; |
| 2618 |
case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS: return INTERRUPTION_FILTER_PRIORITY; |
| 2619 |
case Global.ZEN_MODE_ALARMS: return INTERRUPTION_FILTER_ALARMS; |
| 2620 |
case Global.ZEN_MODE_NO_INTERRUPTIONS: return INTERRUPTION_FILTER_NONE; |
| 2621 |
default: return INTERRUPTION_FILTER_UNKNOWN; |
| 2622 |
} |
| 2623 |
} |
| 2624 |
|
| 2625 |
|
| 2626 |
public static int zenModeFromInterruptionFilter(int interruptionFilter, int defValue) { |
| 2627 |
switch (interruptionFilter) { |
| 2628 |
case INTERRUPTION_FILTER_ALL: return Global.ZEN_MODE_OFF; |
| 2629 |
case INTERRUPTION_FILTER_PRIORITY: return Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS; |
| 2630 |
case INTERRUPTION_FILTER_ALARMS: return Global.ZEN_MODE_ALARMS; |
| 2631 |
case INTERRUPTION_FILTER_NONE: return Global.ZEN_MODE_NO_INTERRUPTIONS; |
| 2632 |
default: return defValue; |
| 2633 |
} |
| 2634 |
} |
| 2635 |
} |