| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.service.notification; |
| 18 |
|
| 19 |
import android.annotation.IntDef; |
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.annotation.Nullable; |
| 22 |
import android.app.Notification; |
| 23 |
import android.app.NotificationChannel; |
| 24 |
import android.os.Parcel; |
| 25 |
import android.os.Parcelable; |
| 26 |
import android.util.proto.ProtoOutputStream; |
| 27 |
|
| 28 |
import java.io.ByteArrayOutputStream; |
| 29 |
import java.lang.annotation.Retention; |
| 30 |
import java.lang.annotation.RetentionPolicy; |
| 31 |
import java.util.ArrayList; |
| 32 |
import java.util.Collections; |
| 33 |
import java.util.Objects; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public final class ZenPolicy implements Parcelable { |
| 42 |
private ArrayList<Integer> mPriorityCategories; |
| 43 |
private ArrayList<Integer> mVisualEffects; |
| 44 |
private @PeopleType int mPriorityMessages = PEOPLE_TYPE_UNSET; |
| 45 |
private @PeopleType int mPriorityCalls = PEOPLE_TYPE_UNSET; |
| 46 |
private @ConversationSenders int mConversationSenders = CONVERSATION_SENDERS_UNSET; |
| 47 |
|
| 48 |
|
| 49 |
@IntDef(prefix = { "PRIORITY_CATEGORY_" }, value = { |
| 50 |
PRIORITY_CATEGORY_REMINDERS, |
| 51 |
PRIORITY_CATEGORY_EVENTS, |
| 52 |
PRIORITY_CATEGORY_MESSAGES, |
| 53 |
PRIORITY_CATEGORY_CALLS, |
| 54 |
PRIORITY_CATEGORY_REPEAT_CALLERS, |
| 55 |
PRIORITY_CATEGORY_ALARMS, |
| 56 |
PRIORITY_CATEGORY_MEDIA, |
| 57 |
PRIORITY_CATEGORY_SYSTEM, |
| 58 |
PRIORITY_CATEGORY_CONVERSATIONS, |
| 59 |
}) |
| 60 |
@Retention(RetentionPolicy.SOURCE) |
| 61 |
public @interface PriorityCategory {} |
| 62 |
|
| 63 |
|
| 64 |
public static final int PRIORITY_CATEGORY_REMINDERS = 0; |
| 65 |
|
| 66 |
public static final int PRIORITY_CATEGORY_EVENTS = 1; |
| 67 |
|
| 68 |
public static final int PRIORITY_CATEGORY_MESSAGES = 2; |
| 69 |
|
| 70 |
public static final int PRIORITY_CATEGORY_CALLS = 3; |
| 71 |
|
| 72 |
public static final int PRIORITY_CATEGORY_REPEAT_CALLERS = 4; |
| 73 |
|
| 74 |
public static final int PRIORITY_CATEGORY_ALARMS = 5; |
| 75 |
|
| 76 |
public static final int PRIORITY_CATEGORY_MEDIA = 6; |
| 77 |
|
| 78 |
public static final int PRIORITY_CATEGORY_SYSTEM = 7; |
| 79 |
|
| 80 |
public static final int PRIORITY_CATEGORY_CONVERSATIONS = 8; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
public static final int NUM_PRIORITY_CATEGORIES = 9; |
| 87 |
|
| 88 |
|
| 89 |
@IntDef(prefix = { "VISUAL_EFFECT_" }, value = { |
| 90 |
VISUAL_EFFECT_FULL_SCREEN_INTENT, |
| 91 |
VISUAL_EFFECT_LIGHTS, |
| 92 |
VISUAL_EFFECT_PEEK, |
| 93 |
VISUAL_EFFECT_STATUS_BAR, |
| 94 |
VISUAL_EFFECT_BADGE, |
| 95 |
VISUAL_EFFECT_AMBIENT, |
| 96 |
VISUAL_EFFECT_NOTIFICATION_LIST, |
| 97 |
}) |
| 98 |
@Retention(RetentionPolicy.SOURCE) |
| 99 |
public @interface VisualEffect {} |
| 100 |
|
| 101 |
|
| 102 |
public static final int VISUAL_EFFECT_FULL_SCREEN_INTENT = 0; |
| 103 |
|
| 104 |
public static final int VISUAL_EFFECT_LIGHTS = 1; |
| 105 |
|
| 106 |
public static final int VISUAL_EFFECT_PEEK = 2; |
| 107 |
|
| 108 |
public static final int VISUAL_EFFECT_STATUS_BAR = 3; |
| 109 |
|
| 110 |
public static final int VISUAL_EFFECT_BADGE = 4; |
| 111 |
|
| 112 |
public static final int VISUAL_EFFECT_AMBIENT = 5; |
| 113 |
|
| 114 |
public static final int VISUAL_EFFECT_NOTIFICATION_LIST = 6; |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
public static final int NUM_VISUAL_EFFECTS = 7; |
| 121 |
|
| 122 |
|
| 123 |
@IntDef(prefix = { "PEOPLE_TYPE_" }, value = { |
| 124 |
PEOPLE_TYPE_UNSET, |
| 125 |
PEOPLE_TYPE_ANYONE, |
| 126 |
PEOPLE_TYPE_CONTACTS, |
| 127 |
PEOPLE_TYPE_STARRED, |
| 128 |
PEOPLE_TYPE_NONE, |
| 129 |
}) |
| 130 |
@Retention(RetentionPolicy.SOURCE) |
| 131 |
public @interface PeopleType {} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
public static final int PEOPLE_TYPE_UNSET = 0; |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
public static final int PEOPLE_TYPE_ANYONE = 1; |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
public static final int PEOPLE_TYPE_CONTACTS = 2; |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
public static final int PEOPLE_TYPE_STARRED = 3; |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
public static final int PEOPLE_TYPE_NONE = 4; |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
@IntDef(prefix = { "CONVERSATION_SENDERS_" }, value = { |
| 162 |
CONVERSATION_SENDERS_UNSET, |
| 163 |
CONVERSATION_SENDERS_ANYONE, |
| 164 |
CONVERSATION_SENDERS_IMPORTANT, |
| 165 |
CONVERSATION_SENDERS_NONE, |
| 166 |
}) |
| 167 |
@Retention(RetentionPolicy.SOURCE) |
| 168 |
public @interface ConversationSenders {} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
public static final int CONVERSATION_SENDERS_UNSET = 0; |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
public static final int CONVERSATION_SENDERS_ANYONE = 1; |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
public static final int CONVERSATION_SENDERS_IMPORTANT = 2; |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
public static final int CONVERSATION_SENDERS_NONE = 3; |
| 189 |
|
| 190 |
|
| 191 |
@IntDef(prefix = { "STATE_" }, value = { |
| 192 |
STATE_UNSET, |
| 193 |
STATE_ALLOW, |
| 194 |
STATE_DISALLOW, |
| 195 |
}) |
| 196 |
@Retention(RetentionPolicy.SOURCE) |
| 197 |
public @interface State {} |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
public static final int STATE_UNSET = 0; |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
public static final int STATE_ALLOW = 1; |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
public static final int STATE_DISALLOW = 2; |
| 214 |
|
| 215 |
|
| 216 |
public ZenPolicy() { |
| 217 |
mPriorityCategories = new ArrayList<>(Collections.nCopies(NUM_PRIORITY_CATEGORIES, 0)); |
| 218 |
mVisualEffects = new ArrayList<>(Collections.nCopies(NUM_VISUAL_EFFECTS, 0)); |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
public @PeopleType int getPriorityConversationSenders() { |
| 227 |
return mConversationSenders; |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
public @PeopleType int getPriorityMessageSenders() { |
| 236 |
return mPriorityMessages; |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
public @PeopleType int getPriorityCallSenders() { |
| 245 |
return mPriorityCalls; |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
public @State int getPriorityCategoryConversations() { |
| 255 |
return mPriorityCategories.get(PRIORITY_CATEGORY_CONVERSATIONS); |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
public @State int getPriorityCategoryReminders() { |
| 265 |
return mPriorityCategories.get(PRIORITY_CATEGORY_REMINDERS); |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
public @State int getPriorityCategoryEvents() { |
| 275 |
return mPriorityCategories.get(PRIORITY_CATEGORY_EVENTS); |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
public @State int getPriorityCategoryMessages() { |
| 286 |
return mPriorityCategories.get(PRIORITY_CATEGORY_MESSAGES); |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
public @State int getPriorityCategoryCalls() { |
| 297 |
return mPriorityCategories.get(PRIORITY_CATEGORY_CALLS); |
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
public @State int getPriorityCategoryRepeatCallers() { |
| 307 |
return mPriorityCategories.get(PRIORITY_CATEGORY_REPEAT_CALLERS); |
| 308 |
} |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
public @State int getPriorityCategoryAlarms() { |
| 319 |
return mPriorityCategories.get(PRIORITY_CATEGORY_ALARMS); |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
public @State int getPriorityCategoryMedia() { |
| 330 |
return mPriorityCategories.get(PRIORITY_CATEGORY_MEDIA); |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
public @State int getPriorityCategorySystem() { |
| 339 |
return mPriorityCategories.get(PRIORITY_CATEGORY_SYSTEM); |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
public @State int getVisualEffectFullScreenIntent() { |
| 347 |
return mVisualEffects.get(VISUAL_EFFECT_FULL_SCREEN_INTENT); |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
public @State int getVisualEffectLights() { |
| 355 |
return mVisualEffects.get(VISUAL_EFFECT_LIGHTS); |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
public @State int getVisualEffectPeek() { |
| 362 |
return mVisualEffects.get(VISUAL_EFFECT_PEEK); |
| 363 |
} |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
public @State int getVisualEffectStatusBar() { |
| 370 |
return mVisualEffects.get(VISUAL_EFFECT_STATUS_BAR); |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
public @State int getVisualEffectBadge() { |
| 378 |
return mVisualEffects.get(VISUAL_EFFECT_BADGE); |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
public @State int getVisualEffectAmbient() { |
| 386 |
return mVisualEffects.get(VISUAL_EFFECT_AMBIENT); |
| 387 |
} |
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
public @State int getVisualEffectNotificationList() { |
| 395 |
return mVisualEffects.get(VISUAL_EFFECT_NOTIFICATION_LIST); |
| 396 |
} |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
public boolean shouldHideAllVisualEffects() { |
| 403 |
for (int i = 0; i < mVisualEffects.size(); i++) { |
| 404 |
if (mVisualEffects.get(i) != STATE_DISALLOW) { |
| 405 |
return false; |
| 406 |
} |
| 407 |
} |
| 408 |
return true; |
| 409 |
} |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
public boolean shouldShowAllVisualEffects() { |
| 416 |
for (int i = 0; i < mVisualEffects.size(); i++) { |
| 417 |
if (mVisualEffects.get(i) != STATE_ALLOW) { |
| 418 |
return false; |
| 419 |
} |
| 420 |
} |
| 421 |
return true; |
| 422 |
} |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
public static final class Builder { |
| 430 |
private ZenPolicy mZenPolicy; |
| 431 |
|
| 432 |
public Builder() { |
| 433 |
mZenPolicy = new ZenPolicy(); |
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
public Builder(ZenPolicy policy) { |
| 440 |
if (policy != null) { |
| 441 |
mZenPolicy = policy.copy(); |
| 442 |
} else { |
| 443 |
mZenPolicy = new ZenPolicy(); |
| 444 |
} |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
public @NonNull ZenPolicy build() { |
| 451 |
return mZenPolicy.copy(); |
| 452 |
} |
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
public @NonNull Builder allowAllSounds() { |
| 458 |
for (int i = 0; i < mZenPolicy.mPriorityCategories.size(); i++) { |
| 459 |
mZenPolicy.mPriorityCategories.set(i, STATE_ALLOW); |
| 460 |
} |
| 461 |
mZenPolicy.mPriorityMessages = PEOPLE_TYPE_ANYONE; |
| 462 |
mZenPolicy.mPriorityCalls = PEOPLE_TYPE_ANYONE; |
| 463 |
mZenPolicy.mConversationSenders = CONVERSATION_SENDERS_ANYONE; |
| 464 |
return this; |
| 465 |
} |
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
public @NonNull Builder disallowAllSounds() { |
| 475 |
for (int i = 0; i < mZenPolicy.mPriorityCategories.size(); i++) { |
| 476 |
mZenPolicy.mPriorityCategories.set(i, STATE_DISALLOW); |
| 477 |
} |
| 478 |
mZenPolicy.mPriorityMessages = PEOPLE_TYPE_NONE; |
| 479 |
mZenPolicy.mPriorityCalls = PEOPLE_TYPE_NONE; |
| 480 |
mZenPolicy.mConversationSenders = CONVERSATION_SENDERS_NONE; |
| 481 |
return this; |
| 482 |
} |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
public @NonNull Builder showAllVisualEffects() { |
| 488 |
for (int i = 0; i < mZenPolicy.mVisualEffects.size(); i++) { |
| 489 |
mZenPolicy.mVisualEffects.set(i, STATE_ALLOW); |
| 490 |
} |
| 491 |
return this; |
| 492 |
} |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
public @NonNull Builder hideAllVisualEffects() { |
| 498 |
for (int i = 0; i < mZenPolicy.mVisualEffects.size(); i++) { |
| 499 |
mZenPolicy.mVisualEffects.set(i, STATE_DISALLOW); |
| 500 |
} |
| 501 |
return this; |
| 502 |
} |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
public @NonNull Builder unsetPriorityCategory(@PriorityCategory int category) { |
| 510 |
mZenPolicy.mPriorityCategories.set(category, STATE_UNSET); |
| 511 |
|
| 512 |
if (category == PRIORITY_CATEGORY_MESSAGES) { |
| 513 |
mZenPolicy.mPriorityMessages = PEOPLE_TYPE_UNSET; |
| 514 |
} else if (category == PRIORITY_CATEGORY_CALLS) { |
| 515 |
mZenPolicy.mPriorityCalls = PEOPLE_TYPE_UNSET; |
| 516 |
} else if (category == PRIORITY_CATEGORY_CONVERSATIONS) { |
| 517 |
mZenPolicy.mConversationSenders = CONVERSATION_SENDERS_UNSET; |
| 518 |
} |
| 519 |
|
| 520 |
return this; |
| 521 |
} |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
public @NonNull Builder unsetVisualEffect(@VisualEffect int effect) { |
| 529 |
mZenPolicy.mVisualEffects.set(effect, STATE_UNSET); |
| 530 |
return this; |
| 531 |
} |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
public @NonNull Builder allowReminders(boolean allow) { |
| 538 |
mZenPolicy.mPriorityCategories.set(PRIORITY_CATEGORY_REMINDERS, |
| 539 |
allow ? STATE_ALLOW : STATE_DISALLOW); |
| 540 |
return this; |
| 541 |
} |
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
public @NonNull Builder allowEvents(boolean allow) { |
| 548 |
mZenPolicy.mPriorityCategories.set(PRIORITY_CATEGORY_EVENTS, |
| 549 |
allow ? STATE_ALLOW : STATE_DISALLOW); |
| 550 |
return this; |
| 551 |
} |
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
public @NonNull Builder allowConversations(@ConversationSenders int audienceType) { |
| 561 |
if (audienceType == STATE_UNSET) { |
| 562 |
return unsetPriorityCategory(PRIORITY_CATEGORY_CONVERSATIONS); |
| 563 |
} |
| 564 |
|
| 565 |
if (audienceType == CONVERSATION_SENDERS_NONE) { |
| 566 |
mZenPolicy.mPriorityCategories.set(PRIORITY_CATEGORY_CONVERSATIONS, STATE_DISALLOW); |
| 567 |
} else if (audienceType == CONVERSATION_SENDERS_ANYONE |
| 568 |
|| audienceType == CONVERSATION_SENDERS_IMPORTANT) { |
| 569 |
mZenPolicy.mPriorityCategories.set(PRIORITY_CATEGORY_CONVERSATIONS, STATE_ALLOW); |
| 570 |
} else { |
| 571 |
return this; |
| 572 |
} |
| 573 |
|
| 574 |
mZenPolicy.mConversationSenders = audienceType; |
| 575 |
return this; |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
public @NonNull Builder allowMessages(@PeopleType int audienceType) { |
| 585 |
if (audienceType == STATE_UNSET) { |
| 586 |
return unsetPriorityCategory(PRIORITY_CATEGORY_MESSAGES); |
| 587 |
} |
| 588 |
|
| 589 |
if (audienceType == PEOPLE_TYPE_NONE) { |
| 590 |
mZenPolicy.mPriorityCategories.set(PRIORITY_CATEGORY_MESSAGES, STATE_DISALLOW); |
| 591 |
} else if (audienceType == PEOPLE_TYPE_ANYONE || audienceType == PEOPLE_TYPE_CONTACTS |
| 592 |
|| audienceType == PEOPLE_TYPE_STARRED) { |
| 593 |
mZenPolicy.mPriorityCategories.set(PRIORITY_CATEGORY_MESSAGES, STATE_ALLOW); |
| 594 |
} else { |
| 595 |
return this; |
| 596 |
} |
| 597 |
|
| 598 |
mZenPolicy.mPriorityMessages = audienceType; |
| 599 |
return this; |
| 600 |
} |
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
public @NonNull Builder allowCalls(@PeopleType int audienceType) { |
| 609 |
if (audienceType == STATE_UNSET) { |
| 610 |
return unsetPriorityCategory(PRIORITY_CATEGORY_CALLS); |
| 611 |
} |
| 612 |
|
| 613 |
if (audienceType == PEOPLE_TYPE_NONE) { |
| 614 |
mZenPolicy.mPriorityCategories.set(PRIORITY_CATEGORY_CALLS, STATE_DISALLOW); |
| 615 |
} else if (audienceType == PEOPLE_TYPE_ANYONE || audienceType == PEOPLE_TYPE_CONTACTS |
| 616 |
|| audienceType == PEOPLE_TYPE_STARRED) { |
| 617 |
mZenPolicy.mPriorityCategories.set(PRIORITY_CATEGORY_CALLS, STATE_ALLOW); |
| 618 |
} else { |
| 619 |
return this; |
| 620 |
} |
| 621 |
|
| 622 |
mZenPolicy.mPriorityCalls = audienceType; |
| 623 |
return this; |
| 624 |
} |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
public @NonNull Builder allowRepeatCallers(boolean allow) { |
| 632 |
mZenPolicy.mPriorityCategories.set(PRIORITY_CATEGORY_REPEAT_CALLERS, |
| 633 |
allow ? STATE_ALLOW : STATE_DISALLOW); |
| 634 |
return this; |
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
public @NonNull Builder allowAlarms(boolean allow) { |
| 643 |
mZenPolicy.mPriorityCategories.set(PRIORITY_CATEGORY_ALARMS, |
| 644 |
allow ? STATE_ALLOW : STATE_DISALLOW); |
| 645 |
return this; |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
public @NonNull Builder allowMedia(boolean allow) { |
| 654 |
mZenPolicy.mPriorityCategories.set(PRIORITY_CATEGORY_MEDIA, |
| 655 |
allow ? STATE_ALLOW : STATE_DISALLOW); |
| 656 |
return this; |
| 657 |
} |
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
public @NonNull Builder allowSystem(boolean allow) { |
| 664 |
mZenPolicy.mPriorityCategories.set(PRIORITY_CATEGORY_SYSTEM, |
| 665 |
allow ? STATE_ALLOW : STATE_DISALLOW); |
| 666 |
return this; |
| 667 |
} |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
public @NonNull Builder allowCategory(@PriorityCategory int category, boolean allow) { |
| 674 |
switch (category) { |
| 675 |
case PRIORITY_CATEGORY_ALARMS: |
| 676 |
allowAlarms(allow); |
| 677 |
break; |
| 678 |
case PRIORITY_CATEGORY_MEDIA: |
| 679 |
allowMedia(allow); |
| 680 |
break; |
| 681 |
case PRIORITY_CATEGORY_SYSTEM: |
| 682 |
allowSystem(allow); |
| 683 |
break; |
| 684 |
case PRIORITY_CATEGORY_REMINDERS: |
| 685 |
allowReminders(allow); |
| 686 |
break; |
| 687 |
case PRIORITY_CATEGORY_EVENTS: |
| 688 |
allowEvents(allow); |
| 689 |
break; |
| 690 |
case PRIORITY_CATEGORY_REPEAT_CALLERS: |
| 691 |
allowRepeatCallers(allow); |
| 692 |
break; |
| 693 |
} |
| 694 |
return this; |
| 695 |
} |
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
public @NonNull Builder showFullScreenIntent(boolean show) { |
| 702 |
mZenPolicy.mVisualEffects.set(VISUAL_EFFECT_FULL_SCREEN_INTENT, |
| 703 |
show ? STATE_ALLOW : STATE_DISALLOW); |
| 704 |
return this; |
| 705 |
} |
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
public @NonNull Builder showLights(boolean show) { |
| 712 |
mZenPolicy.mVisualEffects.set(VISUAL_EFFECT_LIGHTS, |
| 713 |
show ? STATE_ALLOW : STATE_DISALLOW); |
| 714 |
return this; |
| 715 |
} |
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
public @NonNull Builder showPeeking(boolean show) { |
| 721 |
mZenPolicy.mVisualEffects.set(VISUAL_EFFECT_PEEK, |
| 722 |
show ? STATE_ALLOW : STATE_DISALLOW); |
| 723 |
return this; |
| 724 |
} |
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
public @NonNull Builder showStatusBarIcons(boolean show) { |
| 731 |
mZenPolicy.mVisualEffects.set(VISUAL_EFFECT_STATUS_BAR, |
| 732 |
show ? STATE_ALLOW : STATE_DISALLOW); |
| 733 |
return this; |
| 734 |
} |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
public @NonNull Builder showBadges(boolean show) { |
| 741 |
mZenPolicy.mVisualEffects.set(VISUAL_EFFECT_BADGE, |
| 742 |
show ? STATE_ALLOW : STATE_DISALLOW); |
| 743 |
return this; |
| 744 |
} |
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
public @NonNull Builder showInAmbientDisplay(boolean show) { |
| 751 |
mZenPolicy.mVisualEffects.set(VISUAL_EFFECT_AMBIENT, |
| 752 |
show ? STATE_ALLOW : STATE_DISALLOW); |
| 753 |
return this; |
| 754 |
} |
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
public @NonNull Builder showInNotificationList(boolean show) { |
| 762 |
mZenPolicy.mVisualEffects.set(VISUAL_EFFECT_NOTIFICATION_LIST, |
| 763 |
show ? STATE_ALLOW : STATE_DISALLOW); |
| 764 |
return this; |
| 765 |
} |
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
public @NonNull Builder showVisualEffect(@VisualEffect int effect, boolean show) { |
| 773 |
switch (effect) { |
| 774 |
case VISUAL_EFFECT_FULL_SCREEN_INTENT: |
| 775 |
showFullScreenIntent(show); |
| 776 |
break; |
| 777 |
case VISUAL_EFFECT_LIGHTS: |
| 778 |
showLights(show); |
| 779 |
break; |
| 780 |
case VISUAL_EFFECT_PEEK: |
| 781 |
showPeeking(show); |
| 782 |
break; |
| 783 |
case VISUAL_EFFECT_STATUS_BAR: |
| 784 |
showStatusBarIcons(show); |
| 785 |
break; |
| 786 |
case VISUAL_EFFECT_BADGE: |
| 787 |
showBadges(show); |
| 788 |
break; |
| 789 |
case VISUAL_EFFECT_AMBIENT: |
| 790 |
showInAmbientDisplay(show); |
| 791 |
break; |
| 792 |
case VISUAL_EFFECT_NOTIFICATION_LIST: |
| 793 |
showInNotificationList(show); |
| 794 |
break; |
| 795 |
} |
| 796 |
return this; |
| 797 |
} |
| 798 |
} |
| 799 |
|
| 800 |
@Override |
| 801 |
public int describeContents() { |
| 802 |
return 0; |
| 803 |
} |
| 804 |
|
| 805 |
@Override |
| 806 |
public void writeToParcel(Parcel dest, int flags) { |
| 807 |
dest.writeList(mPriorityCategories); |
| 808 |
dest.writeList(mVisualEffects); |
| 809 |
dest.writeInt(mPriorityCalls); |
| 810 |
dest.writeInt(mPriorityMessages); |
| 811 |
dest.writeInt(mConversationSenders); |
| 812 |
} |
| 813 |
|
| 814 |
public static final @android.annotation.NonNull Parcelable.Creator<ZenPolicy> CREATOR = |
| 815 |
new Parcelable.Creator<ZenPolicy>() { |
| 816 |
@Override |
| 817 |
public ZenPolicy createFromParcel(Parcel source) { |
| 818 |
ZenPolicy policy = new ZenPolicy(); |
| 819 |
policy.mPriorityCategories = trimList( |
| 820 |
source.readArrayList(Integer.class.getClassLoader(), java.lang.Integer.class), |
| 821 |
NUM_PRIORITY_CATEGORIES); |
| 822 |
policy.mVisualEffects = trimList( |
| 823 |
source.readArrayList(Integer.class.getClassLoader(), java.lang.Integer.class), |
| 824 |
NUM_VISUAL_EFFECTS); |
| 825 |
policy.mPriorityCalls = source.readInt(); |
| 826 |
policy.mPriorityMessages = source.readInt(); |
| 827 |
policy.mConversationSenders = source.readInt(); |
| 828 |
return policy; |
| 829 |
} |
| 830 |
|
| 831 |
@Override |
| 832 |
public ZenPolicy[] newArray(int size) { |
| 833 |
return new ZenPolicy[size]; |
| 834 |
} |
| 835 |
}; |
| 836 |
|
| 837 |
@Override |
| 838 |
public String toString() { |
| 839 |
return new StringBuilder(ZenPolicy.class.getSimpleName()) |
| 840 |
.append('{') |
| 841 |
.append("priorityCategories=[").append(priorityCategoriesToString()) |
| 842 |
.append("], visualEffects=[").append(visualEffectsToString()) |
| 843 |
.append("], priorityCallsSenders=").append(peopleTypeToString(mPriorityCalls)) |
| 844 |
.append(", priorityMessagesSenders=").append(peopleTypeToString(mPriorityMessages)) |
| 845 |
.append(", priorityConversationSenders=").append( |
| 846 |
conversationTypeToString(mConversationSenders)) |
| 847 |
.append('}') |
| 848 |
.toString(); |
| 849 |
} |
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
private static ArrayList<Integer> trimList(ArrayList<Integer> list, int maxLength) { |
| 855 |
if (list == null || list.size() <= maxLength) { |
| 856 |
return list; |
| 857 |
} |
| 858 |
return new ArrayList<>(list.subList(0, maxLength)); |
| 859 |
} |
| 860 |
|
| 861 |
private String priorityCategoriesToString() { |
| 862 |
StringBuilder builder = new StringBuilder(); |
| 863 |
for (int i = 0; i < mPriorityCategories.size(); i++) { |
| 864 |
if (mPriorityCategories.get(i) != STATE_UNSET) { |
| 865 |
builder.append(indexToCategory(i)) |
| 866 |
.append("=") |
| 867 |
.append(stateToString(mPriorityCategories.get(i))) |
| 868 |
.append(" "); |
| 869 |
} |
| 870 |
|
| 871 |
} |
| 872 |
return builder.toString(); |
| 873 |
} |
| 874 |
|
| 875 |
private String visualEffectsToString() { |
| 876 |
StringBuilder builder = new StringBuilder(); |
| 877 |
for (int i = 0; i < mVisualEffects.size(); i++) { |
| 878 |
if (mVisualEffects.get(i) != STATE_UNSET) { |
| 879 |
builder.append(indexToVisualEffect(i)) |
| 880 |
.append("=") |
| 881 |
.append(stateToString(mVisualEffects.get(i))) |
| 882 |
.append(" "); |
| 883 |
} |
| 884 |
|
| 885 |
} |
| 886 |
return builder.toString(); |
| 887 |
} |
| 888 |
|
| 889 |
private String indexToVisualEffect(@VisualEffect int visualEffectIndex) { |
| 890 |
switch (visualEffectIndex) { |
| 891 |
case VISUAL_EFFECT_FULL_SCREEN_INTENT: |
| 892 |
return "fullScreenIntent"; |
| 893 |
case VISUAL_EFFECT_LIGHTS: |
| 894 |
return "lights"; |
| 895 |
case VISUAL_EFFECT_PEEK: |
| 896 |
return "peek"; |
| 897 |
case VISUAL_EFFECT_STATUS_BAR: |
| 898 |
return "statusBar"; |
| 899 |
case VISUAL_EFFECT_BADGE: |
| 900 |
return "badge"; |
| 901 |
case VISUAL_EFFECT_AMBIENT: |
| 902 |
return "ambient"; |
| 903 |
case VISUAL_EFFECT_NOTIFICATION_LIST: |
| 904 |
return "notificationList"; |
| 905 |
} |
| 906 |
return null; |
| 907 |
} |
| 908 |
|
| 909 |
private String indexToCategory(@PriorityCategory int categoryIndex) { |
| 910 |
switch (categoryIndex) { |
| 911 |
case PRIORITY_CATEGORY_REMINDERS: |
| 912 |
return "reminders"; |
| 913 |
case PRIORITY_CATEGORY_EVENTS: |
| 914 |
return "events"; |
| 915 |
case PRIORITY_CATEGORY_MESSAGES: |
| 916 |
return "messages"; |
| 917 |
case PRIORITY_CATEGORY_CALLS: |
| 918 |
return "calls"; |
| 919 |
case PRIORITY_CATEGORY_REPEAT_CALLERS: |
| 920 |
return "repeatCallers"; |
| 921 |
case PRIORITY_CATEGORY_ALARMS: |
| 922 |
return "alarms"; |
| 923 |
case PRIORITY_CATEGORY_MEDIA: |
| 924 |
return "media"; |
| 925 |
case PRIORITY_CATEGORY_SYSTEM: |
| 926 |
return "system"; |
| 927 |
case PRIORITY_CATEGORY_CONVERSATIONS: |
| 928 |
return "convs"; |
| 929 |
} |
| 930 |
return null; |
| 931 |
} |
| 932 |
|
| 933 |
private String stateToString(@State int state) { |
| 934 |
switch (state) { |
| 935 |
case STATE_UNSET: |
| 936 |
return "unset"; |
| 937 |
case STATE_DISALLOW: |
| 938 |
return "disallow"; |
| 939 |
case STATE_ALLOW: |
| 940 |
return "allow"; |
| 941 |
} |
| 942 |
return "invalidState{" + state + "}"; |
| 943 |
} |
| 944 |
|
| 945 |
private String peopleTypeToString(@PeopleType int peopleType) { |
| 946 |
switch (peopleType) { |
| 947 |
case PEOPLE_TYPE_ANYONE: |
| 948 |
return "anyone"; |
| 949 |
case PEOPLE_TYPE_CONTACTS: |
| 950 |
return "contacts"; |
| 951 |
case PEOPLE_TYPE_NONE: |
| 952 |
return "none"; |
| 953 |
case PEOPLE_TYPE_STARRED: |
| 954 |
return "starred_contacts"; |
| 955 |
case STATE_UNSET: |
| 956 |
return "unset"; |
| 957 |
} |
| 958 |
return "invalidPeopleType{" + peopleType + "}"; |
| 959 |
} |
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
public static String conversationTypeToString(@ConversationSenders int conversationType) { |
| 965 |
switch (conversationType) { |
| 966 |
case CONVERSATION_SENDERS_ANYONE: |
| 967 |
return "anyone"; |
| 968 |
case CONVERSATION_SENDERS_IMPORTANT: |
| 969 |
return "important"; |
| 970 |
case CONVERSATION_SENDERS_NONE: |
| 971 |
return "none"; |
| 972 |
case CONVERSATION_SENDERS_UNSET: |
| 973 |
return "unset"; |
| 974 |
} |
| 975 |
return "invalidConversationType{" + conversationType + "}"; |
| 976 |
} |
| 977 |
|
| 978 |
@Override |
| 979 |
public boolean equals(@Nullable Object o) { |
| 980 |
if (!(o instanceof ZenPolicy)) return false; |
| 981 |
if (o == this) return true; |
| 982 |
final ZenPolicy other = (ZenPolicy) o; |
| 983 |
|
| 984 |
return Objects.equals(other.mPriorityCategories, mPriorityCategories) |
| 985 |
&& Objects.equals(other.mVisualEffects, mVisualEffects) |
| 986 |
&& other.mPriorityCalls == mPriorityCalls |
| 987 |
&& other.mPriorityMessages == mPriorityMessages |
| 988 |
&& other.mConversationSenders == mConversationSenders; |
| 989 |
} |
| 990 |
|
| 991 |
@Override |
| 992 |
public int hashCode() { |
| 993 |
return Objects.hash(mPriorityCategories, mVisualEffects, mPriorityCalls, mPriorityMessages, |
| 994 |
mConversationSenders); |
| 995 |
} |
| 996 |
|
| 997 |
private @ZenPolicy.State int getZenPolicyPriorityCategoryState(@PriorityCategory int |
| 998 |
category) { |
| 999 |
switch (category) { |
| 1000 |
case PRIORITY_CATEGORY_REMINDERS: |
| 1001 |
return getPriorityCategoryReminders(); |
| 1002 |
case PRIORITY_CATEGORY_EVENTS: |
| 1003 |
return getPriorityCategoryEvents(); |
| 1004 |
case PRIORITY_CATEGORY_MESSAGES: |
| 1005 |
return getPriorityCategoryMessages(); |
| 1006 |
case PRIORITY_CATEGORY_CALLS: |
| 1007 |
return getPriorityCategoryCalls(); |
| 1008 |
case PRIORITY_CATEGORY_REPEAT_CALLERS: |
| 1009 |
return getPriorityCategoryRepeatCallers(); |
| 1010 |
case PRIORITY_CATEGORY_ALARMS: |
| 1011 |
return getPriorityCategoryAlarms(); |
| 1012 |
case PRIORITY_CATEGORY_MEDIA: |
| 1013 |
return getPriorityCategoryMedia(); |
| 1014 |
case PRIORITY_CATEGORY_SYSTEM: |
| 1015 |
return getPriorityCategorySystem(); |
| 1016 |
case PRIORITY_CATEGORY_CONVERSATIONS: |
| 1017 |
return getPriorityCategoryConversations(); |
| 1018 |
} |
| 1019 |
return -1; |
| 1020 |
} |
| 1021 |
|
| 1022 |
private @ZenPolicy.State int getZenPolicyVisualEffectState(@VisualEffect int effect) { |
| 1023 |
switch (effect) { |
| 1024 |
case VISUAL_EFFECT_FULL_SCREEN_INTENT: |
| 1025 |
return getVisualEffectFullScreenIntent(); |
| 1026 |
case VISUAL_EFFECT_LIGHTS: |
| 1027 |
return getVisualEffectLights(); |
| 1028 |
case VISUAL_EFFECT_PEEK: |
| 1029 |
return getVisualEffectPeek(); |
| 1030 |
case VISUAL_EFFECT_STATUS_BAR: |
| 1031 |
return getVisualEffectStatusBar(); |
| 1032 |
case VISUAL_EFFECT_BADGE: |
| 1033 |
return getVisualEffectBadge(); |
| 1034 |
case VISUAL_EFFECT_AMBIENT: |
| 1035 |
return getVisualEffectAmbient(); |
| 1036 |
case VISUAL_EFFECT_NOTIFICATION_LIST: |
| 1037 |
return getVisualEffectNotificationList(); |
| 1038 |
} |
| 1039 |
return -1; |
| 1040 |
} |
| 1041 |
|
| 1042 |
|
| 1043 |
public boolean isCategoryAllowed(@PriorityCategory int category, boolean defaultVal) { |
| 1044 |
switch (getZenPolicyPriorityCategoryState(category)) { |
| 1045 |
case ZenPolicy.STATE_ALLOW: |
| 1046 |
return true; |
| 1047 |
case ZenPolicy.STATE_DISALLOW: |
| 1048 |
return false; |
| 1049 |
default: |
| 1050 |
return defaultVal; |
| 1051 |
} |
| 1052 |
} |
| 1053 |
|
| 1054 |
|
| 1055 |
public boolean isVisualEffectAllowed(@VisualEffect int effect, boolean defaultVal) { |
| 1056 |
switch (getZenPolicyVisualEffectState(effect)) { |
| 1057 |
case ZenPolicy.STATE_ALLOW: |
| 1058 |
return true; |
| 1059 |
case ZenPolicy.STATE_DISALLOW: |
| 1060 |
return false; |
| 1061 |
default: |
| 1062 |
return defaultVal; |
| 1063 |
} |
| 1064 |
} |
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
public void apply(ZenPolicy policyToApply) { |
| 1071 |
if (policyToApply == null) { |
| 1072 |
return; |
| 1073 |
} |
| 1074 |
|
| 1075 |
|
| 1076 |
for (int category = 0; category < mPriorityCategories.size(); category++) { |
| 1077 |
if (mPriorityCategories.get(category) == STATE_DISALLOW) { |
| 1078 |
|
| 1079 |
continue; |
| 1080 |
} |
| 1081 |
|
| 1082 |
@State int newState = policyToApply.mPriorityCategories.get(category); |
| 1083 |
if (newState != STATE_UNSET) { |
| 1084 |
mPriorityCategories.set(category, newState); |
| 1085 |
|
| 1086 |
if (category == PRIORITY_CATEGORY_MESSAGES |
| 1087 |
&& mPriorityMessages < policyToApply.mPriorityMessages) { |
| 1088 |
mPriorityMessages = policyToApply.mPriorityMessages; |
| 1089 |
} else if (category == PRIORITY_CATEGORY_CALLS |
| 1090 |
&& mPriorityCalls < policyToApply.mPriorityCalls) { |
| 1091 |
mPriorityCalls = policyToApply.mPriorityCalls; |
| 1092 |
} else if (category == PRIORITY_CATEGORY_CONVERSATIONS |
| 1093 |
&& mConversationSenders < policyToApply.mConversationSenders) { |
| 1094 |
mConversationSenders = policyToApply.mConversationSenders; |
| 1095 |
} |
| 1096 |
} |
| 1097 |
} |
| 1098 |
|
| 1099 |
|
| 1100 |
for (int visualEffect = 0; visualEffect < mVisualEffects.size(); visualEffect++) { |
| 1101 |
if (mVisualEffects.get(visualEffect) == STATE_DISALLOW) { |
| 1102 |
|
| 1103 |
continue; |
| 1104 |
} |
| 1105 |
|
| 1106 |
if (policyToApply.mVisualEffects.get(visualEffect) != STATE_UNSET) { |
| 1107 |
mVisualEffects.set(visualEffect, policyToApply.mVisualEffects.get(visualEffect)); |
| 1108 |
} |
| 1109 |
} |
| 1110 |
} |
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
public void dumpDebug(ProtoOutputStream proto, long fieldId) { |
| 1116 |
final long token = proto.start(fieldId); |
| 1117 |
|
| 1118 |
proto.write(ZenPolicyProto.REMINDERS, getPriorityCategoryReminders()); |
| 1119 |
proto.write(ZenPolicyProto.EVENTS, getPriorityCategoryEvents()); |
| 1120 |
proto.write(ZenPolicyProto.MESSAGES, getPriorityCategoryMessages()); |
| 1121 |
proto.write(ZenPolicyProto.CALLS, getPriorityCategoryCalls()); |
| 1122 |
proto.write(ZenPolicyProto.REPEAT_CALLERS, getPriorityCategoryRepeatCallers()); |
| 1123 |
proto.write(ZenPolicyProto.ALARMS, getPriorityCategoryAlarms()); |
| 1124 |
proto.write(ZenPolicyProto.MEDIA, getPriorityCategoryMedia()); |
| 1125 |
proto.write(ZenPolicyProto.SYSTEM, getPriorityCategorySystem()); |
| 1126 |
|
| 1127 |
proto.write(ZenPolicyProto.FULL_SCREEN_INTENT, getVisualEffectFullScreenIntent()); |
| 1128 |
proto.write(ZenPolicyProto.LIGHTS, getVisualEffectLights()); |
| 1129 |
proto.write(ZenPolicyProto.PEEK, getVisualEffectPeek()); |
| 1130 |
proto.write(ZenPolicyProto.STATUS_BAR, getVisualEffectStatusBar()); |
| 1131 |
proto.write(ZenPolicyProto.BADGE, getVisualEffectBadge()); |
| 1132 |
proto.write(ZenPolicyProto.AMBIENT, getVisualEffectAmbient()); |
| 1133 |
proto.write(ZenPolicyProto.NOTIFICATION_LIST, getVisualEffectNotificationList()); |
| 1134 |
|
| 1135 |
proto.write(ZenPolicyProto.PRIORITY_MESSAGES, getPriorityMessageSenders()); |
| 1136 |
proto.write(ZenPolicyProto.PRIORITY_CALLS, getPriorityCallSenders()); |
| 1137 |
proto.end(token); |
| 1138 |
} |
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
public byte[] toProto() { |
| 1145 |
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); |
| 1146 |
ProtoOutputStream proto = new ProtoOutputStream(bytes); |
| 1147 |
|
| 1148 |
proto.write(DNDPolicyProto.CALLS, getPriorityCategoryCalls()); |
| 1149 |
proto.write(DNDPolicyProto.REPEAT_CALLERS, getPriorityCategoryRepeatCallers()); |
| 1150 |
proto.write(DNDPolicyProto.MESSAGES, getPriorityCategoryMessages()); |
| 1151 |
proto.write(DNDPolicyProto.CONVERSATIONS, getPriorityCategoryConversations()); |
| 1152 |
proto.write(DNDPolicyProto.REMINDERS, getPriorityCategoryReminders()); |
| 1153 |
proto.write(DNDPolicyProto.EVENTS, getPriorityCategoryEvents()); |
| 1154 |
proto.write(DNDPolicyProto.ALARMS, getPriorityCategoryAlarms()); |
| 1155 |
proto.write(DNDPolicyProto.MEDIA, getPriorityCategoryMedia()); |
| 1156 |
proto.write(DNDPolicyProto.SYSTEM, getPriorityCategorySystem()); |
| 1157 |
|
| 1158 |
proto.write(DNDPolicyProto.FULLSCREEN, getVisualEffectFullScreenIntent()); |
| 1159 |
proto.write(DNDPolicyProto.LIGHTS, getVisualEffectLights()); |
| 1160 |
proto.write(DNDPolicyProto.PEEK, getVisualEffectPeek()); |
| 1161 |
proto.write(DNDPolicyProto.STATUS_BAR, getVisualEffectStatusBar()); |
| 1162 |
proto.write(DNDPolicyProto.BADGE, getVisualEffectBadge()); |
| 1163 |
proto.write(DNDPolicyProto.AMBIENT, getVisualEffectAmbient()); |
| 1164 |
proto.write(DNDPolicyProto.NOTIFICATION_LIST, getVisualEffectNotificationList()); |
| 1165 |
|
| 1166 |
proto.write(DNDPolicyProto.ALLOW_CALLS_FROM, getPriorityCallSenders()); |
| 1167 |
proto.write(DNDPolicyProto.ALLOW_MESSAGES_FROM, getPriorityMessageSenders()); |
| 1168 |
proto.write(DNDPolicyProto.ALLOW_CONVERSATIONS_FROM, getPriorityConversationSenders()); |
| 1169 |
|
| 1170 |
proto.flush(); |
| 1171 |
return bytes.toByteArray(); |
| 1172 |
} |
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
public @NonNull ZenPolicy copy() { |
| 1179 |
final Parcel parcel = Parcel.obtain(); |
| 1180 |
try { |
| 1181 |
writeToParcel(parcel, 0); |
| 1182 |
parcel.setDataPosition(0); |
| 1183 |
return CREATOR.createFromParcel(parcel); |
| 1184 |
} finally { |
| 1185 |
parcel.recycle(); |
| 1186 |
} |
| 1187 |
} |
| 1188 |
} |