| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package android.app.usage; |
| 17 |
|
| 18 |
import android.annotation.CurrentTimeMillisLong; |
| 19 |
import android.annotation.IntDef; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.annotation.SystemApi; |
| 22 |
import android.compat.annotation.UnsupportedAppUsage; |
| 23 |
import android.content.res.Configuration; |
| 24 |
import android.os.Build; |
| 25 |
import android.os.Parcel; |
| 26 |
import android.os.Parcelable; |
| 27 |
|
| 28 |
import java.lang.annotation.Retention; |
| 29 |
import java.lang.annotation.RetentionPolicy; |
| 30 |
import java.util.Arrays; |
| 31 |
import java.util.List; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public final class UsageEvents implements Parcelable { |
| 38 |
|
| 39 |
|
| 40 |
public static final String INSTANT_APP_PACKAGE_NAME = "android.instant_app"; |
| 41 |
|
| 42 |
|
| 43 |
public static final String INSTANT_APP_CLASS_NAME = "android.instant_class"; |
| 44 |
|
| 45 |
|
| 46 |
public static final String OBFUSCATED_NOTIFICATION_CHANNEL_ID = "unknown_channel_id"; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public static final int SHOW_ALL_EVENT_DATA = 0x00000000; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public static final int OBFUSCATE_INSTANT_APPS = 0x00000001; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public static final int HIDE_SHORTCUT_EVENTS = 0x00000002; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public static final int OBFUSCATE_NOTIFICATION_EVENTS = 0x00000004; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public static final int HIDE_LOCUS_EVENTS = 0x00000008; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
public static final class Event { |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public static final int NONE = 0; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
public static final String DEVICE_EVENT_PACKAGE_NAME = "android"; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
@Deprecated |
| 104 |
public static final int MOVE_TO_FOREGROUND = 1; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
public static final int ACTIVITY_RESUMED = MOVE_TO_FOREGROUND; |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
@Deprecated |
| 121 |
public static final int MOVE_TO_BACKGROUND = 2; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
public static final int ACTIVITY_PAUSED = MOVE_TO_BACKGROUND; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
public static final int END_OF_DAY = 3; |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
public static final int CONTINUE_PREVIOUS_DAY = 4; |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
public static final int CONFIGURATION_CHANGE = 5; |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
@SystemApi |
| 159 |
public static final int SYSTEM_INTERACTION = 6; |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
public static final int USER_INTERACTION = 7; |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
public static final int SHORTCUT_INVOCATION = 8; |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
public static final int CHOOSER_ACTION = 9; |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
@SystemApi |
| 184 |
public static final int NOTIFICATION_SEEN = 10; |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
public static final int STANDBY_BUCKET_CHANGED = 11; |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
@SystemApi |
| 200 |
public static final int NOTIFICATION_INTERRUPTION = 12; |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
@SystemApi |
| 207 |
public static final int SLICE_PINNED_PRIV = 13; |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
@SystemApi |
| 214 |
public static final int SLICE_PINNED = 14; |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
public static final int SCREEN_INTERACTIVE = 15; |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
public static final int SCREEN_NON_INTERACTIVE = 16; |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
public static final int KEYGUARD_SHOWN = 17; |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
public static final int KEYGUARD_HIDDEN = 18; |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
public static final int FOREGROUND_SERVICE_START = 19; |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
public static final int FOREGROUND_SERVICE_STOP = 20; |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
public static final int CONTINUING_FOREGROUND_SERVICE = 21; |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
public static final int ROLLOVER_FOREGROUND_SERVICE = 22; |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
public static final int ACTIVITY_STOPPED = 23; |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
public static final int ACTIVITY_DESTROYED = 24; |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
public static final int FLUSH_TO_DISK = 25; |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
public static final int DEVICE_SHUTDOWN = 26; |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
public static final int DEVICE_STARTUP = 27; |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
public static final int USER_UNLOCKED = 28; |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
public static final int USER_STOPPED = 29; |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
public static final int LOCUS_ID_SET = 30; |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
public static final int APP_COMPONENT_USED = 31; |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
public static final int MAX_EVENT_TYPE = 31; |
| 351 |
|
| 352 |
|
| 353 |
public static final int FLAG_IS_PACKAGE_INSTANT_APP = 1 << 0; |
| 354 |
|
| 355 |
|
| 356 |
@IntDef(flag = true, prefix = { "FLAG_" }, value = { |
| 357 |
FLAG_IS_PACKAGE_INSTANT_APP, |
| 358 |
}) |
| 359 |
@Retention(RetentionPolicy.SOURCE) |
| 360 |
public @interface EventFlags {} |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
public static final int VALID_FLAG_BITS = FLAG_IS_PACKAGE_INSTANT_APP; |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
private static final int UNASSIGNED_TOKEN = -1; |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 377 |
public String mPackage; |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
public int mPackageToken = UNASSIGNED_TOKEN; |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 388 |
public String mClass; |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
public int mClassToken = UNASSIGNED_TOKEN; |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
public int mInstanceId; |
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
public String mTaskRootPackage; |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
public int mTaskRootPackageToken = UNASSIGNED_TOKEN; |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
public String mTaskRootClass; |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
public int mTaskRootClassToken = UNASSIGNED_TOKEN; |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 428 |
public long mTimeStamp; |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 434 |
public int mEventType; |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 441 |
public Configuration mConfiguration; |
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
public String mShortcutId; |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
public int mShortcutIdToken = UNASSIGNED_TOKEN; |
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
public String mAction; |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
public String mContentType; |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
public String[] mContentAnnotations; |
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
public int mBucketAndReason; |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
public String mNotificationChannelId; |
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
public int mNotificationChannelIdToken = UNASSIGNED_TOKEN; |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
public String mLocusId; |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
public int mLocusIdToken = UNASSIGNED_TOKEN; |
| 508 |
|
| 509 |
|
| 510 |
@EventFlags |
| 511 |
public int mFlags; |
| 512 |
|
| 513 |
public Event() { |
| 514 |
} |
| 515 |
|
| 516 |
|
| 517 |
public Event(int type, long timeStamp) { |
| 518 |
mEventType = type; |
| 519 |
mTimeStamp = timeStamp; |
| 520 |
} |
| 521 |
|
| 522 |
|
| 523 |
public Event(Event orig) { |
| 524 |
copyFrom(orig); |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
public String getPackageName() { |
| 531 |
return mPackage; |
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
@SystemApi |
| 539 |
public boolean isInstantApp() { |
| 540 |
return (mFlags & FLAG_IS_PACKAGE_INSTANT_APP) == FLAG_IS_PACKAGE_INSTANT_APP; |
| 541 |
} |
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
public String getClassName() { |
| 548 |
return mClass; |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
@SystemApi |
| 557 |
public int getInstanceId() { |
| 558 |
return mInstanceId; |
| 559 |
} |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
@SystemApi |
| 568 |
public @Nullable String getTaskRootPackageName() { |
| 569 |
return mTaskRootPackage; |
| 570 |
} |
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
@SystemApi |
| 579 |
public @Nullable String getTaskRootClassName() { |
| 580 |
return mTaskRootClass; |
| 581 |
} |
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
@CurrentTimeMillisLong |
| 589 |
public long getTimeStamp() { |
| 590 |
return mTimeStamp; |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
public int getEventType() { |
| 605 |
return mEventType; |
| 606 |
} |
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
public Configuration getConfiguration() { |
| 613 |
return mConfiguration; |
| 614 |
} |
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
public String getShortcutId() { |
| 623 |
return mShortcutId; |
| 624 |
} |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
public int getAppStandbyBucket() { |
| 632 |
return (mBucketAndReason & 0xFFFF0000) >>> 16; |
| 633 |
} |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
public int getStandbyReason() { |
| 644 |
return mBucketAndReason & 0x0000FFFF; |
| 645 |
} |
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
@Nullable |
| 653 |
@SystemApi |
| 654 |
public String getNotificationChannelId() { |
| 655 |
return mNotificationChannelId; |
| 656 |
} |
| 657 |
|
| 658 |
|
| 659 |
public Event getObfuscatedIfInstantApp() { |
| 660 |
if (!isInstantApp()) { |
| 661 |
return this; |
| 662 |
} |
| 663 |
final Event ret = new Event(this); |
| 664 |
ret.mPackage = INSTANT_APP_PACKAGE_NAME; |
| 665 |
ret.mClass = INSTANT_APP_CLASS_NAME; |
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
return ret; |
| 670 |
} |
| 671 |
|
| 672 |
|
| 673 |
public Event getObfuscatedNotificationEvent() { |
| 674 |
final Event ret = new Event(this); |
| 675 |
ret.mNotificationChannelId = OBFUSCATED_NOTIFICATION_CHANNEL_ID; |
| 676 |
return ret; |
| 677 |
} |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
@Nullable |
| 685 |
public String getLocusId() { |
| 686 |
return mLocusId; |
| 687 |
} |
| 688 |
|
| 689 |
private void copyFrom(Event orig) { |
| 690 |
mPackage = orig.mPackage; |
| 691 |
mClass = orig.mClass; |
| 692 |
mInstanceId = orig.mInstanceId; |
| 693 |
mTaskRootPackage = orig.mTaskRootPackage; |
| 694 |
mTaskRootClass = orig.mTaskRootClass; |
| 695 |
mTimeStamp = orig.mTimeStamp; |
| 696 |
mEventType = orig.mEventType; |
| 697 |
mConfiguration = orig.mConfiguration; |
| 698 |
mShortcutId = orig.mShortcutId; |
| 699 |
mAction = orig.mAction; |
| 700 |
mContentType = orig.mContentType; |
| 701 |
mContentAnnotations = orig.mContentAnnotations; |
| 702 |
mFlags = orig.mFlags; |
| 703 |
mBucketAndReason = orig.mBucketAndReason; |
| 704 |
mNotificationChannelId = orig.mNotificationChannelId; |
| 705 |
mLocusId = orig.mLocusId; |
| 706 |
} |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 711 |
private List<Event> mEventsToWrite = null; |
| 712 |
|
| 713 |
|
| 714 |
@UnsupportedAppUsage |
| 715 |
private Parcel mParcel = null; |
| 716 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 717 |
private final int mEventCount; |
| 718 |
|
| 719 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 720 |
private int mIndex = 0; |
| 721 |
|
| 722 |
|
| 723 |
private final boolean mIncludeTaskRoots; |
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 730 |
private String[] mStringPool; |
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 737 |
public UsageEvents(Parcel in) { |
| 738 |
byte[] bytes = in.readBlob(); |
| 739 |
Parcel data = Parcel.obtain(); |
| 740 |
data.unmarshall(bytes, 0, bytes.length); |
| 741 |
data.setDataPosition(0); |
| 742 |
mEventCount = data.readInt(); |
| 743 |
mIndex = data.readInt(); |
| 744 |
if (mEventCount > 0) { |
| 745 |
mStringPool = data.createStringArray(); |
| 746 |
|
| 747 |
final int listByteLength = data.readInt(); |
| 748 |
final int positionInParcel = data.readInt(); |
| 749 |
mParcel = Parcel.obtain(); |
| 750 |
mParcel.setDataPosition(0); |
| 751 |
mParcel.appendFrom(data, data.dataPosition(), listByteLength); |
| 752 |
mParcel.setDataSize(mParcel.dataPosition()); |
| 753 |
mParcel.setDataPosition(positionInParcel); |
| 754 |
} |
| 755 |
mIncludeTaskRoots = true; |
| 756 |
} |
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
UsageEvents() { |
| 763 |
mEventCount = 0; |
| 764 |
mIncludeTaskRoots = true; |
| 765 |
} |
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
public UsageEvents(List<Event> events, String[] stringPool) { |
| 773 |
this(events, stringPool, false); |
| 774 |
} |
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
public UsageEvents(List<Event> events, String[] stringPool, boolean includeTaskRoots) { |
| 781 |
mStringPool = stringPool; |
| 782 |
mEventCount = events.size(); |
| 783 |
mEventsToWrite = events; |
| 784 |
mIncludeTaskRoots = includeTaskRoots; |
| 785 |
} |
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
public boolean hasNextEvent() { |
| 794 |
return mIndex < mEventCount; |
| 795 |
} |
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
public boolean getNextEvent(Event eventOut) { |
| 806 |
if (eventOut == null) { |
| 807 |
throw new IllegalArgumentException("Given eventOut must not be null"); |
| 808 |
} |
| 809 |
if (mIndex >= mEventCount) { |
| 810 |
return false; |
| 811 |
} |
| 812 |
|
| 813 |
if (mParcel != null) { |
| 814 |
readEventFromParcel(mParcel, eventOut); |
| 815 |
} else { |
| 816 |
eventOut.copyFrom(mEventsToWrite.get(mIndex)); |
| 817 |
} |
| 818 |
|
| 819 |
mIndex++; |
| 820 |
if (mIndex >= mEventCount && mParcel != null) { |
| 821 |
mParcel.recycle(); |
| 822 |
mParcel = null; |
| 823 |
} |
| 824 |
return true; |
| 825 |
} |
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
public void resetToStart() { |
| 834 |
mIndex = 0; |
| 835 |
if (mParcel != null) { |
| 836 |
mParcel.setDataPosition(0); |
| 837 |
} |
| 838 |
} |
| 839 |
|
| 840 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 841 |
private int findStringIndex(String str) { |
| 842 |
final int index = Arrays.binarySearch(mStringPool, str); |
| 843 |
if (index < 0) { |
| 844 |
throw new IllegalStateException("String '" + str + "' is not in the string pool"); |
| 845 |
} |
| 846 |
return index; |
| 847 |
} |
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 853 |
private void writeEventToParcel(Event event, Parcel p, int flags) { |
| 854 |
final int packageIndex; |
| 855 |
if (event.mPackage != null) { |
| 856 |
packageIndex = findStringIndex(event.mPackage); |
| 857 |
} else { |
| 858 |
packageIndex = -1; |
| 859 |
} |
| 860 |
|
| 861 |
final int classIndex; |
| 862 |
if (event.mClass != null) { |
| 863 |
classIndex = findStringIndex(event.mClass); |
| 864 |
} else { |
| 865 |
classIndex = -1; |
| 866 |
} |
| 867 |
|
| 868 |
final int taskRootPackageIndex; |
| 869 |
if (mIncludeTaskRoots && event.mTaskRootPackage != null) { |
| 870 |
taskRootPackageIndex = findStringIndex(event.mTaskRootPackage); |
| 871 |
} else { |
| 872 |
taskRootPackageIndex = -1; |
| 873 |
} |
| 874 |
|
| 875 |
final int taskRootClassIndex; |
| 876 |
if (mIncludeTaskRoots && event.mTaskRootClass != null) { |
| 877 |
taskRootClassIndex = findStringIndex(event.mTaskRootClass); |
| 878 |
} else { |
| 879 |
taskRootClassIndex = -1; |
| 880 |
} |
| 881 |
p.writeInt(packageIndex); |
| 882 |
p.writeInt(classIndex); |
| 883 |
p.writeInt(event.mInstanceId); |
| 884 |
p.writeInt(taskRootPackageIndex); |
| 885 |
p.writeInt(taskRootClassIndex); |
| 886 |
p.writeInt(event.mEventType); |
| 887 |
p.writeLong(event.mTimeStamp); |
| 888 |
|
| 889 |
switch (event.mEventType) { |
| 890 |
case Event.CONFIGURATION_CHANGE: |
| 891 |
event.mConfiguration.writeToParcel(p, flags); |
| 892 |
break; |
| 893 |
case Event.SHORTCUT_INVOCATION: |
| 894 |
p.writeString(event.mShortcutId); |
| 895 |
break; |
| 896 |
case Event.CHOOSER_ACTION: |
| 897 |
p.writeString(event.mAction); |
| 898 |
p.writeString(event.mContentType); |
| 899 |
p.writeStringArray(event.mContentAnnotations); |
| 900 |
break; |
| 901 |
case Event.STANDBY_BUCKET_CHANGED: |
| 902 |
p.writeInt(event.mBucketAndReason); |
| 903 |
break; |
| 904 |
case Event.NOTIFICATION_INTERRUPTION: |
| 905 |
p.writeString(event.mNotificationChannelId); |
| 906 |
break; |
| 907 |
case Event.LOCUS_ID_SET: |
| 908 |
p.writeString(event.mLocusId); |
| 909 |
break; |
| 910 |
} |
| 911 |
p.writeInt(event.mFlags); |
| 912 |
} |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 918 |
private void readEventFromParcel(Parcel p, Event eventOut) { |
| 919 |
final int packageIndex = p.readInt(); |
| 920 |
if (packageIndex >= 0) { |
| 921 |
eventOut.mPackage = mStringPool[packageIndex]; |
| 922 |
} else { |
| 923 |
eventOut.mPackage = null; |
| 924 |
} |
| 925 |
|
| 926 |
final int classIndex = p.readInt(); |
| 927 |
if (classIndex >= 0) { |
| 928 |
eventOut.mClass = mStringPool[classIndex]; |
| 929 |
} else { |
| 930 |
eventOut.mClass = null; |
| 931 |
} |
| 932 |
eventOut.mInstanceId = p.readInt(); |
| 933 |
|
| 934 |
final int taskRootPackageIndex = p.readInt(); |
| 935 |
if (taskRootPackageIndex >= 0) { |
| 936 |
eventOut.mTaskRootPackage = mStringPool[taskRootPackageIndex]; |
| 937 |
} else { |
| 938 |
eventOut.mTaskRootPackage = null; |
| 939 |
} |
| 940 |
|
| 941 |
final int taskRootClassIndex = p.readInt(); |
| 942 |
if (taskRootClassIndex >= 0) { |
| 943 |
eventOut.mTaskRootClass = mStringPool[taskRootClassIndex]; |
| 944 |
} else { |
| 945 |
eventOut.mTaskRootClass = null; |
| 946 |
} |
| 947 |
|
| 948 |
eventOut.mEventType = p.readInt(); |
| 949 |
eventOut.mTimeStamp = p.readLong(); |
| 950 |
|
| 951 |
|
| 952 |
eventOut.mConfiguration = null; |
| 953 |
eventOut.mShortcutId = null; |
| 954 |
eventOut.mAction = null; |
| 955 |
eventOut.mContentType = null; |
| 956 |
eventOut.mContentAnnotations = null; |
| 957 |
eventOut.mNotificationChannelId = null; |
| 958 |
eventOut.mLocusId = null; |
| 959 |
|
| 960 |
switch (eventOut.mEventType) { |
| 961 |
case Event.CONFIGURATION_CHANGE: |
| 962 |
|
| 963 |
eventOut.mConfiguration = Configuration.CREATOR.createFromParcel(p); |
| 964 |
break; |
| 965 |
case Event.SHORTCUT_INVOCATION: |
| 966 |
eventOut.mShortcutId = p.readString(); |
| 967 |
break; |
| 968 |
case Event.CHOOSER_ACTION: |
| 969 |
eventOut.mAction = p.readString(); |
| 970 |
eventOut.mContentType = p.readString(); |
| 971 |
eventOut.mContentAnnotations = p.createStringArray(); |
| 972 |
break; |
| 973 |
case Event.STANDBY_BUCKET_CHANGED: |
| 974 |
eventOut.mBucketAndReason = p.readInt(); |
| 975 |
break; |
| 976 |
case Event.NOTIFICATION_INTERRUPTION: |
| 977 |
eventOut.mNotificationChannelId = p.readString(); |
| 978 |
break; |
| 979 |
case Event.LOCUS_ID_SET: |
| 980 |
eventOut.mLocusId = p.readString(); |
| 981 |
break; |
| 982 |
} |
| 983 |
eventOut.mFlags = p.readInt(); |
| 984 |
} |
| 985 |
|
| 986 |
@Override |
| 987 |
public int describeContents() { |
| 988 |
return 0; |
| 989 |
} |
| 990 |
|
| 991 |
@Override |
| 992 |
public void writeToParcel(Parcel dest, int flags) { |
| 993 |
Parcel data = Parcel.obtain(); |
| 994 |
data.writeInt(mEventCount); |
| 995 |
data.writeInt(mIndex); |
| 996 |
if (mEventCount > 0) { |
| 997 |
data.writeStringArray(mStringPool); |
| 998 |
|
| 999 |
if (mEventsToWrite != null) { |
| 1000 |
|
| 1001 |
Parcel p = Parcel.obtain(); |
| 1002 |
try { |
| 1003 |
p.setDataPosition(0); |
| 1004 |
for (int i = 0; i < mEventCount; i++) { |
| 1005 |
final Event event = mEventsToWrite.get(i); |
| 1006 |
writeEventToParcel(event, p, flags); |
| 1007 |
} |
| 1008 |
|
| 1009 |
final int listByteLength = p.dataPosition(); |
| 1010 |
|
| 1011 |
|
| 1012 |
data.writeInt(listByteLength); |
| 1013 |
|
| 1014 |
|
| 1015 |
data.writeInt(0); |
| 1016 |
|
| 1017 |
|
| 1018 |
data.appendFrom(p, 0, listByteLength); |
| 1019 |
} finally { |
| 1020 |
p.recycle(); |
| 1021 |
} |
| 1022 |
|
| 1023 |
} else if (mParcel != null) { |
| 1024 |
|
| 1025 |
data.writeInt(mParcel.dataSize()); |
| 1026 |
|
| 1027 |
|
| 1028 |
data.writeInt(mParcel.dataPosition()); |
| 1029 |
|
| 1030 |
|
| 1031 |
data.appendFrom(mParcel, 0, mParcel.dataSize()); |
| 1032 |
} else { |
| 1033 |
throw new IllegalStateException( |
| 1034 |
"Either mParcel or mEventsToWrite must not be null"); |
| 1035 |
} |
| 1036 |
} |
| 1037 |
|
| 1038 |
|
| 1039 |
dest.writeBlob(data.marshall()); |
| 1040 |
data.recycle(); |
| 1041 |
} |
| 1042 |
|
| 1043 |
public static final @android.annotation.NonNull Creator<UsageEvents> CREATOR = new Creator<UsageEvents>() { |
| 1044 |
@Override |
| 1045 |
public UsageEvents createFromParcel(Parcel source) { |
| 1046 |
return new UsageEvents(source); |
| 1047 |
} |
| 1048 |
|
| 1049 |
@Override |
| 1050 |
public UsageEvents[] newArray(int size) { |
| 1051 |
return new UsageEvents[size]; |
| 1052 |
} |
| 1053 |
}; |
| 1054 |
} |