| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view.accessibility; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.annotation.TestApi; |
| 22 |
import android.app.ActivityTaskManager; |
| 23 |
import android.graphics.Rect; |
| 24 |
import android.graphics.Region; |
| 25 |
import android.os.Parcel; |
| 26 |
import android.os.Parcelable; |
| 27 |
import android.text.TextUtils; |
| 28 |
import android.util.LongArray; |
| 29 |
import android.util.Pools.SynchronizedPool; |
| 30 |
import android.util.SparseArray; |
| 31 |
import android.view.Display; |
| 32 |
import android.view.accessibility.AccessibilityEvent.WindowsChangeTypes; |
| 33 |
|
| 34 |
import java.util.ArrayList; |
| 35 |
import java.util.List; |
| 36 |
import java.util.Objects; |
| 37 |
import java.util.concurrent.atomic.AtomicInteger; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public final class AccessibilityWindowInfo implements Parcelable { |
| 47 |
|
| 48 |
private static final boolean DEBUG = false; |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public static final int TYPE_APPLICATION = 1; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public static final int TYPE_INPUT_METHOD = 2; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public static final int TYPE_SYSTEM = 3; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public static final int TYPE_ACCESSIBILITY_OVERLAY = 4; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
public static final int TYPE_SPLIT_SCREEN_DIVIDER = 5; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
public static final int TYPE_MAGNIFICATION_OVERLAY = 6; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public static final int ACTIVE_WINDOW_ID = Integer.MAX_VALUE; |
| 96 |
|
| 97 |
public static final int UNDEFINED_CONNECTION_ID = -1; |
| 98 |
|
| 99 |
public static final int UNDEFINED_WINDOW_ID = -1; |
| 100 |
|
| 101 |
public static final int ANY_WINDOW_ID = -2; |
| 102 |
|
| 103 |
public static final int PICTURE_IN_PICTURE_ACTION_REPLACER_WINDOW_ID = -3; |
| 104 |
|
| 105 |
private static final int BOOLEAN_PROPERTY_ACTIVE = 1 << 0; |
| 106 |
private static final int BOOLEAN_PROPERTY_FOCUSED = 1 << 1; |
| 107 |
private static final int BOOLEAN_PROPERTY_ACCESSIBILITY_FOCUSED = 1 << 2; |
| 108 |
private static final int BOOLEAN_PROPERTY_PICTURE_IN_PICTURE = 1 << 3; |
| 109 |
|
| 110 |
|
| 111 |
private static final int MAX_POOL_SIZE = 10; |
| 112 |
private static final SynchronizedPool<AccessibilityWindowInfo> sPool = |
| 113 |
new SynchronizedPool<AccessibilityWindowInfo>(MAX_POOL_SIZE); |
| 114 |
|
| 115 |
private static AtomicInteger sNumInstancesInUse; |
| 116 |
|
| 117 |
|
| 118 |
private int mDisplayId = Display.INVALID_DISPLAY; |
| 119 |
private int mType = UNDEFINED_WINDOW_ID; |
| 120 |
private int mLayer = UNDEFINED_WINDOW_ID; |
| 121 |
private int mBooleanProperties; |
| 122 |
private int mId = UNDEFINED_WINDOW_ID; |
| 123 |
private int mParentId = UNDEFINED_WINDOW_ID; |
| 124 |
private int mTaskId = ActivityTaskManager.INVALID_TASK_ID; |
| 125 |
private Region mRegionInScreen = new Region(); |
| 126 |
private LongArray mChildIds; |
| 127 |
private CharSequence mTitle; |
| 128 |
private long mAnchorId = AccessibilityNodeInfo.UNDEFINED_NODE_ID; |
| 129 |
|
| 130 |
private int mConnectionId = UNDEFINED_CONNECTION_ID; |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
public AccessibilityWindowInfo() { |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
public AccessibilityWindowInfo(@NonNull AccessibilityWindowInfo info) { |
| 145 |
init(info); |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
@Nullable |
| 154 |
public CharSequence getTitle() { |
| 155 |
return mTitle; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
public void setTitle(CharSequence title) { |
| 166 |
mTitle = title; |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
public int getType() { |
| 180 |
return mType; |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
public void setType(int type) { |
| 191 |
mType = type; |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
public int getLayer() { |
| 201 |
return mLayer; |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
public void setLayer(int layer) { |
| 213 |
mLayer = layer; |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
public AccessibilityNodeInfo getRoot() { |
| 222 |
return getRoot(AccessibilityNodeInfo.FLAG_PREFETCH_DESCENDANTS_HYBRID); |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
@Nullable |
| 234 |
public AccessibilityNodeInfo getRoot( |
| 235 |
@AccessibilityNodeInfo.PrefetchingStrategy int prefetchingStrategy) { |
| 236 |
if (mConnectionId == UNDEFINED_WINDOW_ID) { |
| 237 |
return null; |
| 238 |
} |
| 239 |
AccessibilityInteractionClient client = AccessibilityInteractionClient.getInstance(); |
| 240 |
return client.findAccessibilityNodeInfoByAccessibilityId(mConnectionId, |
| 241 |
mId, AccessibilityNodeInfo.ROOT_NODE_ID, |
| 242 |
true, prefetchingStrategy, null); |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
public void setAnchorId(long anchorId) { |
| 253 |
mAnchorId = anchorId; |
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
public AccessibilityNodeInfo getAnchor() { |
| 262 |
if ((mConnectionId == UNDEFINED_WINDOW_ID) |
| 263 |
|| (mAnchorId == AccessibilityNodeInfo.UNDEFINED_NODE_ID) |
| 264 |
|| (mParentId == UNDEFINED_WINDOW_ID)) { |
| 265 |
return null; |
| 266 |
} |
| 267 |
|
| 268 |
AccessibilityInteractionClient client = AccessibilityInteractionClient.getInstance(); |
| 269 |
return client.findAccessibilityNodeInfoByAccessibilityId(mConnectionId, |
| 270 |
mParentId, mAnchorId, true, 0, null); |
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
public void setPictureInPicture(boolean pictureInPicture) { |
| 275 |
setBooleanProperty(BOOLEAN_PROPERTY_PICTURE_IN_PICTURE, pictureInPicture); |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
public boolean isInPictureInPictureMode() { |
| 284 |
return getBooleanProperty(BOOLEAN_PROPERTY_PICTURE_IN_PICTURE); |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
public AccessibilityWindowInfo getParent() { |
| 293 |
if (mConnectionId == UNDEFINED_WINDOW_ID || mParentId == UNDEFINED_WINDOW_ID) { |
| 294 |
return null; |
| 295 |
} |
| 296 |
AccessibilityInteractionClient client = AccessibilityInteractionClient.getInstance(); |
| 297 |
return client.getWindow(mConnectionId, mParentId); |
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
public void setParentId(int parentId) { |
| 308 |
mParentId = parentId; |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
public int getId() { |
| 317 |
return mId; |
| 318 |
} |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
public void setId(int id) { |
| 328 |
mId = id; |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
public int getTaskId() { |
| 339 |
return mTaskId; |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
public void setTaskId(int taskId) { |
| 350 |
mTaskId = taskId; |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
public void setConnectionId(int connectionId) { |
| 362 |
mConnectionId = connectionId; |
| 363 |
} |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
public void getRegionInScreen(@NonNull Region outRegion) { |
| 371 |
outRegion.set(mRegionInScreen); |
| 372 |
} |
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
public void setRegionInScreen(Region region) { |
| 382 |
mRegionInScreen.set(region); |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
public void getBoundsInScreen(Rect outBounds) { |
| 392 |
outBounds.set(mRegionInScreen.getBounds()); |
| 393 |
} |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
public boolean isActive() { |
| 411 |
return getBooleanProperty(BOOLEAN_PROPERTY_ACTIVE); |
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
public void setActive(boolean active) { |
| 424 |
setBooleanProperty(BOOLEAN_PROPERTY_ACTIVE, active); |
| 425 |
} |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
public boolean isFocused() { |
| 433 |
return getBooleanProperty(BOOLEAN_PROPERTY_FOCUSED); |
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
public void setFocused(boolean focused) { |
| 444 |
setBooleanProperty(BOOLEAN_PROPERTY_FOCUSED, focused); |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
public boolean isAccessibilityFocused() { |
| 453 |
return getBooleanProperty(BOOLEAN_PROPERTY_ACCESSIBILITY_FOCUSED); |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
public void setAccessibilityFocused(boolean focused) { |
| 464 |
setBooleanProperty(BOOLEAN_PROPERTY_ACCESSIBILITY_FOCUSED, focused); |
| 465 |
} |
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
public int getChildCount() { |
| 473 |
return (mChildIds != null) ? mChildIds.size() : 0; |
| 474 |
} |
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
public AccessibilityWindowInfo getChild(int index) { |
| 483 |
if (mChildIds == null) { |
| 484 |
throw new IndexOutOfBoundsException(); |
| 485 |
} |
| 486 |
if (mConnectionId == UNDEFINED_WINDOW_ID) { |
| 487 |
return null; |
| 488 |
} |
| 489 |
final int childId = (int) mChildIds.get(index); |
| 490 |
AccessibilityInteractionClient client = AccessibilityInteractionClient.getInstance(); |
| 491 |
return client.getWindow(mConnectionId, childId); |
| 492 |
} |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
public void addChild(int childId) { |
| 502 |
if (mChildIds == null) { |
| 503 |
mChildIds = new LongArray(); |
| 504 |
} |
| 505 |
mChildIds.add(childId); |
| 506 |
} |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
public void setDisplayId(int displayId) { |
| 516 |
mDisplayId = displayId; |
| 517 |
} |
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
public int getDisplayId() { |
| 526 |
return mDisplayId; |
| 527 |
} |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
public static AccessibilityWindowInfo obtain() { |
| 539 |
AccessibilityWindowInfo info = sPool.acquire(); |
| 540 |
if (info == null) { |
| 541 |
info = new AccessibilityWindowInfo(); |
| 542 |
} |
| 543 |
if (sNumInstancesInUse != null) { |
| 544 |
sNumInstancesInUse.incrementAndGet(); |
| 545 |
} |
| 546 |
return info; |
| 547 |
} |
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
public static AccessibilityWindowInfo obtain(AccessibilityWindowInfo info) { |
| 561 |
AccessibilityWindowInfo infoClone = obtain(); |
| 562 |
infoClone.init(info); |
| 563 |
return infoClone; |
| 564 |
} |
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
@TestApi |
| 572 |
public static void setNumInstancesInUseCounter(AtomicInteger counter) { |
| 573 |
if (sNumInstancesInUse != null) { |
| 574 |
sNumInstancesInUse = counter; |
| 575 |
} |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
public void recycle() { |
| 589 |
clear(); |
| 590 |
sPool.release(this); |
| 591 |
if (sNumInstancesInUse != null) { |
| 592 |
sNumInstancesInUse.decrementAndGet(); |
| 593 |
} |
| 594 |
} |
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
public boolean refresh() { |
| 606 |
if (mConnectionId == UNDEFINED_CONNECTION_ID || mId == UNDEFINED_WINDOW_ID) { |
| 607 |
return false; |
| 608 |
} |
| 609 |
final AccessibilityInteractionClient client = AccessibilityInteractionClient.getInstance(); |
| 610 |
final AccessibilityWindowInfo refreshedInfo = client.getWindow(mConnectionId, |
| 611 |
mId, true); |
| 612 |
if (refreshedInfo == null) { |
| 613 |
return false; |
| 614 |
} |
| 615 |
init(refreshedInfo); |
| 616 |
refreshedInfo.recycle(); |
| 617 |
return true; |
| 618 |
} |
| 619 |
|
| 620 |
@Override |
| 621 |
public int describeContents() { |
| 622 |
return 0; |
| 623 |
} |
| 624 |
|
| 625 |
@Override |
| 626 |
public void writeToParcel(Parcel parcel, int flags) { |
| 627 |
parcel.writeInt(mDisplayId); |
| 628 |
parcel.writeInt(mType); |
| 629 |
parcel.writeInt(mLayer); |
| 630 |
parcel.writeInt(mBooleanProperties); |
| 631 |
parcel.writeInt(mId); |
| 632 |
parcel.writeInt(mParentId); |
| 633 |
parcel.writeInt(mTaskId); |
| 634 |
mRegionInScreen.writeToParcel(parcel, flags); |
| 635 |
parcel.writeCharSequence(mTitle); |
| 636 |
parcel.writeLong(mAnchorId); |
| 637 |
|
| 638 |
final LongArray childIds = mChildIds; |
| 639 |
if (childIds == null) { |
| 640 |
parcel.writeInt(0); |
| 641 |
} else { |
| 642 |
final int childCount = childIds.size(); |
| 643 |
parcel.writeInt(childCount); |
| 644 |
for (int i = 0; i < childCount; i++) { |
| 645 |
parcel.writeInt((int) childIds.get(i)); |
| 646 |
} |
| 647 |
} |
| 648 |
|
| 649 |
parcel.writeInt(mConnectionId); |
| 650 |
} |
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
private void init(AccessibilityWindowInfo other) { |
| 658 |
mDisplayId = other.mDisplayId; |
| 659 |
mType = other.mType; |
| 660 |
mLayer = other.mLayer; |
| 661 |
mBooleanProperties = other.mBooleanProperties; |
| 662 |
mId = other.mId; |
| 663 |
mParentId = other.mParentId; |
| 664 |
mTaskId = other.mTaskId; |
| 665 |
mRegionInScreen.set(other.mRegionInScreen); |
| 666 |
mTitle = other.mTitle; |
| 667 |
mAnchorId = other.mAnchorId; |
| 668 |
|
| 669 |
if (mChildIds != null) mChildIds.clear(); |
| 670 |
if (other.mChildIds != null && other.mChildIds.size() > 0) { |
| 671 |
if (mChildIds == null) { |
| 672 |
mChildIds = other.mChildIds.clone(); |
| 673 |
} else { |
| 674 |
mChildIds.addAll(other.mChildIds); |
| 675 |
} |
| 676 |
} |
| 677 |
|
| 678 |
mConnectionId = other.mConnectionId; |
| 679 |
} |
| 680 |
|
| 681 |
private void initFromParcel(Parcel parcel) { |
| 682 |
mDisplayId = parcel.readInt(); |
| 683 |
mType = parcel.readInt(); |
| 684 |
mLayer = parcel.readInt(); |
| 685 |
mBooleanProperties = parcel.readInt(); |
| 686 |
mId = parcel.readInt(); |
| 687 |
mParentId = parcel.readInt(); |
| 688 |
mTaskId = parcel.readInt(); |
| 689 |
mRegionInScreen = Region.CREATOR.createFromParcel(parcel); |
| 690 |
mTitle = parcel.readCharSequence(); |
| 691 |
mAnchorId = parcel.readLong(); |
| 692 |
|
| 693 |
final int childCount = parcel.readInt(); |
| 694 |
if (childCount > 0) { |
| 695 |
if (mChildIds == null) { |
| 696 |
mChildIds = new LongArray(childCount); |
| 697 |
} |
| 698 |
for (int i = 0; i < childCount; i++) { |
| 699 |
final int childId = parcel.readInt(); |
| 700 |
mChildIds.add(childId); |
| 701 |
} |
| 702 |
} |
| 703 |
|
| 704 |
mConnectionId = parcel.readInt(); |
| 705 |
} |
| 706 |
|
| 707 |
@Override |
| 708 |
public int hashCode() { |
| 709 |
return mId; |
| 710 |
} |
| 711 |
|
| 712 |
@Override |
| 713 |
public boolean equals(@Nullable Object obj) { |
| 714 |
if (this == obj) { |
| 715 |
return true; |
| 716 |
} |
| 717 |
if (obj == null) { |
| 718 |
return false; |
| 719 |
} |
| 720 |
if (getClass() != obj.getClass()) { |
| 721 |
return false; |
| 722 |
} |
| 723 |
AccessibilityWindowInfo other = (AccessibilityWindowInfo) obj; |
| 724 |
return (mId == other.mId); |
| 725 |
} |
| 726 |
|
| 727 |
@Override |
| 728 |
public String toString() { |
| 729 |
StringBuilder builder = new StringBuilder(); |
| 730 |
builder.append("AccessibilityWindowInfo["); |
| 731 |
builder.append("title=").append(mTitle); |
| 732 |
builder.append(", displayId=").append(mDisplayId); |
| 733 |
builder.append(", id=").append(mId); |
| 734 |
builder.append(", taskId=").append(mTaskId); |
| 735 |
builder.append(", type=").append(typeToString(mType)); |
| 736 |
builder.append(", layer=").append(mLayer); |
| 737 |
builder.append(", region=").append(mRegionInScreen); |
| 738 |
builder.append(", bounds=").append(mRegionInScreen.getBounds()); |
| 739 |
builder.append(", focused=").append(isFocused()); |
| 740 |
builder.append(", active=").append(isActive()); |
| 741 |
builder.append(", pictureInPicture=").append(isInPictureInPictureMode()); |
| 742 |
if (DEBUG) { |
| 743 |
builder.append(", parent=").append(mParentId); |
| 744 |
builder.append(", children=["); |
| 745 |
if (mChildIds != null) { |
| 746 |
final int childCount = mChildIds.size(); |
| 747 |
for (int i = 0; i < childCount; i++) { |
| 748 |
builder.append(mChildIds.get(i)); |
| 749 |
if (i < childCount - 1) { |
| 750 |
builder.append(','); |
| 751 |
} |
| 752 |
} |
| 753 |
} else { |
| 754 |
builder.append("null"); |
| 755 |
} |
| 756 |
builder.append(']'); |
| 757 |
} else { |
| 758 |
builder.append(", hasParent=").append(mParentId != UNDEFINED_WINDOW_ID); |
| 759 |
builder.append(", isAnchored=") |
| 760 |
.append(mAnchorId != AccessibilityNodeInfo.UNDEFINED_NODE_ID); |
| 761 |
builder.append(", hasChildren=").append(mChildIds != null |
| 762 |
&& mChildIds.size() > 0); |
| 763 |
} |
| 764 |
builder.append(']'); |
| 765 |
return builder.toString(); |
| 766 |
} |
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
private void clear() { |
| 772 |
mDisplayId = Display.INVALID_DISPLAY; |
| 773 |
mType = UNDEFINED_WINDOW_ID; |
| 774 |
mLayer = UNDEFINED_WINDOW_ID; |
| 775 |
mBooleanProperties = 0; |
| 776 |
mId = UNDEFINED_WINDOW_ID; |
| 777 |
mParentId = UNDEFINED_WINDOW_ID; |
| 778 |
mTaskId = ActivityTaskManager.INVALID_TASK_ID; |
| 779 |
mRegionInScreen.setEmpty(); |
| 780 |
mChildIds = null; |
| 781 |
mConnectionId = UNDEFINED_WINDOW_ID; |
| 782 |
mAnchorId = AccessibilityNodeInfo.UNDEFINED_NODE_ID; |
| 783 |
mTitle = null; |
| 784 |
} |
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
private boolean getBooleanProperty(int property) { |
| 793 |
return (mBooleanProperties & property) != 0; |
| 794 |
} |
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
private void setBooleanProperty(int property, boolean value) { |
| 805 |
if (value) { |
| 806 |
mBooleanProperties |= property; |
| 807 |
} else { |
| 808 |
mBooleanProperties &= ~property; |
| 809 |
} |
| 810 |
} |
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
public static String typeToString(int type) { |
| 816 |
switch (type) { |
| 817 |
case TYPE_APPLICATION: { |
| 818 |
return "TYPE_APPLICATION"; |
| 819 |
} |
| 820 |
case TYPE_INPUT_METHOD: { |
| 821 |
return "TYPE_INPUT_METHOD"; |
| 822 |
} |
| 823 |
case TYPE_SYSTEM: { |
| 824 |
return "TYPE_SYSTEM"; |
| 825 |
} |
| 826 |
case TYPE_ACCESSIBILITY_OVERLAY: { |
| 827 |
return "TYPE_ACCESSIBILITY_OVERLAY"; |
| 828 |
} |
| 829 |
case TYPE_SPLIT_SCREEN_DIVIDER: { |
| 830 |
return "TYPE_SPLIT_SCREEN_DIVIDER"; |
| 831 |
} |
| 832 |
case TYPE_MAGNIFICATION_OVERLAY: { |
| 833 |
return "TYPE_MAGNIFICATION_OVERLAY"; |
| 834 |
} |
| 835 |
default: |
| 836 |
return "<UNKNOWN:" + type + ">"; |
| 837 |
} |
| 838 |
} |
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
@WindowsChangeTypes |
| 851 |
public int differenceFrom(AccessibilityWindowInfo other) { |
| 852 |
if (other.mId != mId) { |
| 853 |
throw new IllegalArgumentException("Not same window."); |
| 854 |
} |
| 855 |
if (other.mType != mType) { |
| 856 |
throw new IllegalArgumentException("Not same type."); |
| 857 |
} |
| 858 |
int changes = 0; |
| 859 |
if (!TextUtils.equals(mTitle, other.mTitle)) { |
| 860 |
changes |= AccessibilityEvent.WINDOWS_CHANGE_TITLE; |
| 861 |
} |
| 862 |
if (!mRegionInScreen.equals(other.mRegionInScreen)) { |
| 863 |
changes |= AccessibilityEvent.WINDOWS_CHANGE_BOUNDS; |
| 864 |
} |
| 865 |
if (mLayer != other.mLayer) { |
| 866 |
changes |= AccessibilityEvent.WINDOWS_CHANGE_LAYER; |
| 867 |
} |
| 868 |
if (getBooleanProperty(BOOLEAN_PROPERTY_ACTIVE) |
| 869 |
!= other.getBooleanProperty(BOOLEAN_PROPERTY_ACTIVE)) { |
| 870 |
changes |= AccessibilityEvent.WINDOWS_CHANGE_ACTIVE; |
| 871 |
} |
| 872 |
if (getBooleanProperty(BOOLEAN_PROPERTY_FOCUSED) |
| 873 |
!= other.getBooleanProperty(BOOLEAN_PROPERTY_FOCUSED)) { |
| 874 |
changes |= AccessibilityEvent.WINDOWS_CHANGE_FOCUSED; |
| 875 |
} |
| 876 |
if (getBooleanProperty(BOOLEAN_PROPERTY_ACCESSIBILITY_FOCUSED) |
| 877 |
!= other.getBooleanProperty(BOOLEAN_PROPERTY_ACCESSIBILITY_FOCUSED)) { |
| 878 |
changes |= AccessibilityEvent.WINDOWS_CHANGE_ACCESSIBILITY_FOCUSED; |
| 879 |
} |
| 880 |
if (getBooleanProperty(BOOLEAN_PROPERTY_PICTURE_IN_PICTURE) |
| 881 |
!= other.getBooleanProperty(BOOLEAN_PROPERTY_PICTURE_IN_PICTURE)) { |
| 882 |
changes |= AccessibilityEvent.WINDOWS_CHANGE_PIP; |
| 883 |
} |
| 884 |
if (mParentId != other.mParentId) { |
| 885 |
changes |= AccessibilityEvent.WINDOWS_CHANGE_PARENT; |
| 886 |
} |
| 887 |
if (!Objects.equals(mChildIds, other.mChildIds)) { |
| 888 |
changes |= AccessibilityEvent.WINDOWS_CHANGE_CHILDREN; |
| 889 |
} |
| 890 |
|
| 891 |
return changes; |
| 892 |
} |
| 893 |
|
| 894 |
public static final @android.annotation.NonNull Parcelable.Creator<AccessibilityWindowInfo> CREATOR = |
| 895 |
new Creator<AccessibilityWindowInfo>() { |
| 896 |
@Override |
| 897 |
public AccessibilityWindowInfo createFromParcel(Parcel parcel) { |
| 898 |
AccessibilityWindowInfo info = obtain(); |
| 899 |
info.initFromParcel(parcel); |
| 900 |
return info; |
| 901 |
} |
| 902 |
|
| 903 |
@Override |
| 904 |
public AccessibilityWindowInfo[] newArray(int size) { |
| 905 |
return new AccessibilityWindowInfo[size]; |
| 906 |
} |
| 907 |
}; |
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
public static final class WindowListSparseArray |
| 916 |
extends SparseArray<List<AccessibilityWindowInfo>> implements Parcelable { |
| 917 |
|
| 918 |
@Override |
| 919 |
public int describeContents() { |
| 920 |
return 0; |
| 921 |
} |
| 922 |
|
| 923 |
@Override |
| 924 |
public void writeToParcel(Parcel dest, int flags) { |
| 925 |
final int count = size(); |
| 926 |
dest.writeInt(count); |
| 927 |
for (int i = 0; i < count; i++) { |
| 928 |
dest.writeParcelableList(valueAt(i), 0); |
| 929 |
dest.writeInt(keyAt(i)); |
| 930 |
} |
| 931 |
} |
| 932 |
|
| 933 |
public static final Parcelable.Creator<WindowListSparseArray> CREATOR = |
| 934 |
new Parcelable.Creator<WindowListSparseArray>() { |
| 935 |
public WindowListSparseArray createFromParcel( |
| 936 |
Parcel source) { |
| 937 |
final WindowListSparseArray array = new WindowListSparseArray(); |
| 938 |
final ClassLoader loader = array.getClass().getClassLoader(); |
| 939 |
final int count = source.readInt(); |
| 940 |
for (int i = 0; i < count; i++) { |
| 941 |
List<AccessibilityWindowInfo> windows = new ArrayList<>(); |
| 942 |
source.readParcelableList(windows, loader, android.view.accessibility.AccessibilityWindowInfo.class); |
| 943 |
array.put(source.readInt(), windows); |
| 944 |
} |
| 945 |
return array; |
| 946 |
} |
| 947 |
|
| 948 |
public WindowListSparseArray[] newArray(int size) { |
| 949 |
return new WindowListSparseArray[size]; |
| 950 |
} |
| 951 |
}; |
| 952 |
} |
| 953 |
} |