/
ShadowAccessibilityNodeInfo.java
1350 lines (1104 loc) · 38.5 KB
/
ShadowAccessibilityNodeInfo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
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
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package org.robolectric.shadows;
import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;
import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
import static android.os.Build.VERSION_CODES.KITKAT;
import static android.os.Build.VERSION_CODES.LOLLIPOP;
import static android.os.Build.VERSION_CODES.LOLLIPOP_MR1;
import static android.os.Build.VERSION_CODES.N;
import static android.os.Build.VERSION_CODES.Q;
import static org.robolectric.RuntimeEnvironment.getApiLevel;
import static org.robolectric.util.reflector.Reflector.reflector;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Pair;
import android.util.SparseArray;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
import android.view.accessibility.AccessibilityNodeInfo.CollectionInfo;
import android.view.accessibility.AccessibilityNodeInfo.CollectionItemInfo;
import android.view.accessibility.AccessibilityNodeInfo.RangeInfo;
import android.view.accessibility.AccessibilityWindowInfo;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.RealObject;
import org.robolectric.annotation.Resetter;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.util.ReflectionHelpers;
import org.robolectric.util.reflector.Accessor;
import org.robolectric.util.reflector.ForType;
import org.robolectric.util.reflector.Static;
/**
* Properties of {@link android.view.accessibility.AccessibilityNodeInfo} that are normally locked
* may be changed using test APIs.
*
* Calls to {@code obtain()} and {@code recycle()} are tracked to help spot bugs.
*/
@Implements(AccessibilityNodeInfo.class)
public class ShadowAccessibilityNodeInfo {
// Map of obtained instances of the class along with stack traces of how they were obtained
private static final Map<StrictEqualityNodeWrapper, StackTraceElement[]> obtainedInstances =
new HashMap<>();
private static final SparseArray<StrictEqualityNodeWrapper> orderedInstances =
new SparseArray<>();
// Bitmasks for actions
public static final int UNDEFINED_SELECTION_INDEX = -1;
public static final Parcelable.Creator<AccessibilityNodeInfo> CREATOR =
new Parcelable.Creator<AccessibilityNodeInfo>() {
@Override
public AccessibilityNodeInfo createFromParcel(Parcel source) {
return obtain(orderedInstances.get(source.readInt()).mInfo);
}
@Override
public AccessibilityNodeInfo[] newArray(int size) {
return new AccessibilityNodeInfo[size];
}};
private static int sAllocationCount = 0;
private static final int CLICKABLE_MASK = 0x00000001;
private static final int LONGCLICKABLE_MASK = 0x00000002;
private static final int FOCUSABLE_MASK = 0x00000004;
private static final int FOCUSED_MASK = 0x00000008;
private static final int VISIBLE_TO_USER_MASK = 0x00000010;
private static final int SCROLLABLE_MASK = 0x00000020;
private static final int PASTEABLE_MASK = 0x00000040;
private static final int EDITABLE_MASK = 0x00000080;
private static final int TEXT_SELECTION_SETABLE_MASK = 0x00000100;
private static final int CHECKABLE_MASK = 0x00001000; //14
private static final int CHECKED_MASK = 0x00002000; //14
private static final int ENABLED_MASK = 0x00010000; //14
private static final int PASSWORD_MASK = 0x00040000; //14
private static final int SELECTED_MASK = 0x00080000; //14
private static final int A11YFOCUSED_MASK = 0x00000800; //16
private static final int MULTILINE_MASK = 0x00020000; //19
private static final int CONTENT_INVALID_MASK = 0x00004000; //19
private static final int DISMISSABLE_MASK = 0x00008000; //19
private static final int CAN_OPEN_POPUP_MASK = 0x00100000; //19
private static final int TEXT_ENTRY_KEY_MASK = 0x00200000; // 29
private static final int IMPORTANT_MASK = 0x00400000; // 24
/**
* Uniquely identifies the origin of the AccessibilityNodeInfo for equality
* testing. Two instances that come from the same node info should have the
* same ID.
*/
private long mOriginNodeId;
private List<AccessibilityNodeInfo> children;
private Rect boundsInScreen = new Rect();
private Rect boundsInParent = new Rect();
private List<Pair<Integer, Bundle>> performedActionAndArgsList;
// In API prior to 21, actions are stored in a flag, after 21 they are stored in array of
// AccessibilityAction so custom actions can be supported.
private ArrayList<AccessibilityAction> actionsArray;
private int actionsMask;
// Storage of flags
private int propertyFlags;
private AccessibilityNodeInfo parent;
private AccessibilityNodeInfo labelFor;
private AccessibilityNodeInfo labeledBy;
private View view;
private CharSequence contentDescription;
private CharSequence text;
private CharSequence className;
private int textSelectionStart = UNDEFINED_SELECTION_INDEX;
private int textSelectionEnd = UNDEFINED_SELECTION_INDEX;
private boolean refreshReturnValue = true;
private int movementGranularities; //16
private CharSequence packageName; //14
private String viewIdResourceName; //18
private CollectionInfo collectionInfo; //19
private CollectionItemInfo collectionItemInfo; //19
private int inputType; //19
private int liveRegion; //19
private RangeInfo rangeInfo; //19
private int maxTextLength; //21
private CharSequence error; //21
private AccessibilityWindowInfo accessibilityWindowInfo;
private AccessibilityNodeInfo traversalAfter; //22
private AccessibilityNodeInfo traversalBefore; //22
private OnPerformActionListener actionListener;
private int drawingOrder; // 24
@RealObject
private AccessibilityNodeInfo realAccessibilityNodeInfo;
@Implementation
protected void __constructor__() {
reflector(AccessibilityNodeInfoReflector.class).setCreator(ShadowAccessibilityNodeInfo.CREATOR);
}
@Implementation
protected static AccessibilityNodeInfo obtain(AccessibilityNodeInfo info) {
final ShadowAccessibilityNodeInfo shadowInfo = Shadow.extract(info);
final AccessibilityNodeInfo obtainedInstance = shadowInfo.getClone();
sAllocationCount++;
if (shadowInfo.mOriginNodeId == 0) {
shadowInfo.mOriginNodeId = sAllocationCount;
}
StrictEqualityNodeWrapper wrapper = new StrictEqualityNodeWrapper(obtainedInstance);
obtainedInstances.put(wrapper, Thread.currentThread().getStackTrace());
orderedInstances.put(sAllocationCount, wrapper);
return obtainedInstance;
}
@Implementation
protected static AccessibilityNodeInfo obtain(View view) {
// We explicitly avoid allocating the AccessibilityNodeInfo from the actual pool by using the
// private constructor. Not doing so affects test suites which use both shadow and
// non-shadow objects.
final AccessibilityNodeInfo obtainedInstance =
ReflectionHelpers.callConstructor(AccessibilityNodeInfo.class);
final ShadowAccessibilityNodeInfo shadowObtained = Shadow.extract(obtainedInstance);
/*
* We keep a separate list of actions for each object newly obtained
* from a view, and perform a shallow copy during getClone. That way the
* list of actions performed contains all actions performed on the view
* by the tree of nodes initialized from it. Note that initializing two
* nodes with the same view will not merge the two lists, as so the list
* of performed actions will not contain all actions performed on the
* underlying view.
*/
shadowObtained.performedActionAndArgsList = new ArrayList<>();
shadowObtained.view = view;
sAllocationCount++;
if (shadowObtained.mOriginNodeId == 0) {
shadowObtained.mOriginNodeId = sAllocationCount;
}
StrictEqualityNodeWrapper wrapper = new StrictEqualityNodeWrapper(obtainedInstance);
obtainedInstances.put(wrapper, Thread.currentThread().getStackTrace());
orderedInstances.put(sAllocationCount, wrapper);
return obtainedInstance;
}
@Implementation
protected static AccessibilityNodeInfo obtain() {
return obtain(new View(RuntimeEnvironment.getApplication().getApplicationContext()));
}
@Implementation
protected static AccessibilityNodeInfo obtain(View root, int virtualDescendantId) {
AccessibilityNodeInfo node = obtain(root);
return node;
}
/**
* Check for leaked objects that were {@code obtain}ed but never
* {@code recycle}d.
*
* @param printUnrecycledNodesToSystemErr - if true, stack traces of calls
* to {@code obtain} that lack matching calls to {@code recycle} are
* dumped to System.err.
* @return {@code true} if there are unrecycled nodes
*/
public static boolean areThereUnrecycledNodes(boolean printUnrecycledNodesToSystemErr) {
if (printUnrecycledNodesToSystemErr) {
for (final StrictEqualityNodeWrapper wrapper : obtainedInstances.keySet()) {
final ShadowAccessibilityNodeInfo shadow = Shadow.extract(wrapper.mInfo);
System.err.println(String.format(
"Leaked contentDescription = %s. Stack trace:", shadow.getContentDescription()));
for (final StackTraceElement stackTraceElement : obtainedInstances.get(wrapper)) {
System.err.println(stackTraceElement.toString());
}
}
}
return (obtainedInstances.size() != 0);
}
/**
* Clear list of obtained instance objects. {@code areThereUnrecycledNodes}
* will always return false if called immediately afterwards.
*/
@Resetter
public static void resetObtainedInstances() {
obtainedInstances.clear();
orderedInstances.clear();
}
@Implementation
protected void recycle() {
final StrictEqualityNodeWrapper wrapper =
new StrictEqualityNodeWrapper(realAccessibilityNodeInfo);
if (!obtainedInstances.containsKey(wrapper)) {
throw new IllegalStateException();
}
if (labelFor != null) {
labelFor.recycle();
}
if (labeledBy != null) {
labeledBy.recycle();
}
if (getApiLevel() >= LOLLIPOP_MR1) {
if (traversalAfter != null) {
traversalAfter.recycle();
}
if (traversalBefore != null) {
traversalBefore.recycle();
}
}
obtainedInstances.remove(wrapper);
int keyOfWrapper = -1;
for (int i = 0; i < orderedInstances.size(); i++) {
int key = orderedInstances.keyAt(i);
if (orderedInstances.get(key).equals(wrapper)) {
keyOfWrapper = key;
break;
}
}
orderedInstances.remove(keyOfWrapper);
}
@Implementation
protected int getChildCount() {
if (children == null) {
return 0;
}
return children.size();
}
@Implementation
protected AccessibilityNodeInfo getChild(int index) {
if (children == null) {
return null;
}
final AccessibilityNodeInfo child = children.get(index);
if (child == null) {
return null;
}
return obtain(child);
}
@Implementation
protected AccessibilityNodeInfo getParent() {
if (parent == null) {
return null;
}
return obtain(parent);
}
@Implementation(minSdk = JELLY_BEAN_MR2)
protected boolean refresh() {
return refreshReturnValue;
}
public void setRefreshReturnValue(boolean refreshReturnValue) {
this.refreshReturnValue = refreshReturnValue;
}
@Implementation
protected boolean isClickable() {
return ((propertyFlags & CLICKABLE_MASK) != 0);
}
@Implementation
protected boolean isLongClickable() {
return ((propertyFlags & LONGCLICKABLE_MASK) != 0);
}
@Implementation
protected boolean isFocusable() {
return ((propertyFlags & FOCUSABLE_MASK) != 0);
}
@Implementation
protected boolean isFocused() {
return ((propertyFlags & FOCUSED_MASK) != 0);
}
@Implementation
protected boolean isVisibleToUser() {
return ((propertyFlags & VISIBLE_TO_USER_MASK) != 0);
}
@Implementation
protected boolean isScrollable() {
return ((propertyFlags & SCROLLABLE_MASK) != 0);
}
public boolean isPasteable() {
return ((propertyFlags & PASTEABLE_MASK) != 0);
}
@Implementation(minSdk = JELLY_BEAN_MR2)
protected boolean isEditable() {
return ((propertyFlags & EDITABLE_MASK) != 0);
}
public boolean isTextSelectionSetable() {
return ((propertyFlags & TEXT_SELECTION_SETABLE_MASK) != 0);
}
@Implementation(minSdk = Q)
protected boolean isTextEntryKey() {
return ((propertyFlags & TEXT_ENTRY_KEY_MASK) != 0);
}
@Implementation
protected boolean isCheckable() {
return ((propertyFlags & CHECKABLE_MASK) != 0);
}
@Implementation
protected void setCheckable(boolean checkable) {
propertyFlags = (propertyFlags & ~CHECKABLE_MASK) |
(checkable ? CHECKABLE_MASK : 0);
}
@Implementation
protected void setChecked(boolean checked) {
propertyFlags = (propertyFlags & ~CHECKED_MASK) |
(checked ? CHECKED_MASK : 0);
}
@Implementation
protected boolean isChecked() {
return ((propertyFlags & CHECKED_MASK) != 0);
}
@Implementation
protected void setEnabled(boolean enabled) {
propertyFlags = (propertyFlags & ~ENABLED_MASK) |
(enabled ? ENABLED_MASK : 0);
}
@Implementation
protected boolean isEnabled() {
return ((propertyFlags & ENABLED_MASK) != 0);
}
@Implementation
protected void setPassword(boolean password) {
propertyFlags = (propertyFlags & ~PASSWORD_MASK) |
(password ? PASSWORD_MASK : 0);
}
@Implementation
protected boolean isPassword() {
return ((propertyFlags & PASSWORD_MASK) != 0);
}
@Implementation
protected void setSelected(boolean selected) {
propertyFlags = (propertyFlags & ~SELECTED_MASK) |
(selected ? SELECTED_MASK : 0);
}
@Implementation
protected boolean isSelected() {
return ((propertyFlags & SELECTED_MASK) != 0);
}
@Implementation
protected void setAccessibilityFocused(boolean focused) {
propertyFlags = (propertyFlags & ~A11YFOCUSED_MASK) |
(focused ? A11YFOCUSED_MASK : 0);
}
@Implementation
protected boolean isAccessibilityFocused() {
return ((propertyFlags & A11YFOCUSED_MASK) != 0);
}
@Implementation(minSdk = LOLLIPOP)
protected void setMultiLine(boolean multiLine) {
propertyFlags = (propertyFlags & ~MULTILINE_MASK) |
(multiLine ? MULTILINE_MASK : 0);
}
@Implementation(minSdk = LOLLIPOP)
protected boolean isMultiLine() {
return ((propertyFlags & MULTILINE_MASK) != 0);
}
@Implementation(minSdk = LOLLIPOP)
protected void setContentInvalid(boolean contentInvalid) {
propertyFlags = (propertyFlags & ~CONTENT_INVALID_MASK) |
(contentInvalid ? CONTENT_INVALID_MASK : 0);
}
@Implementation(minSdk = LOLLIPOP)
protected boolean isContentInvalid() {
return ((propertyFlags & CONTENT_INVALID_MASK) != 0);
}
@Implementation(minSdk = LOLLIPOP)
protected void setDismissable(boolean dismissable) {
propertyFlags = (propertyFlags & ~DISMISSABLE_MASK) |
(dismissable ? DISMISSABLE_MASK : 0);
}
@Implementation(minSdk = LOLLIPOP)
protected boolean isDismissable() {
return ((propertyFlags & DISMISSABLE_MASK) != 0);
}
@Implementation(minSdk = LOLLIPOP)
protected void setCanOpenPopup(boolean opensPopup) {
propertyFlags = (propertyFlags & ~CAN_OPEN_POPUP_MASK) |
(opensPopup ? CAN_OPEN_POPUP_MASK : 0);
}
@Implementation(minSdk = LOLLIPOP)
protected boolean canOpenPopup() {
return ((propertyFlags & CAN_OPEN_POPUP_MASK) != 0);
}
public void setTextSelectionSetable(boolean isTextSelectionSetable) {
propertyFlags = (propertyFlags & ~TEXT_SELECTION_SETABLE_MASK) |
(isTextSelectionSetable ? TEXT_SELECTION_SETABLE_MASK : 0);
}
@Implementation
protected void setClickable(boolean isClickable) {
propertyFlags = (propertyFlags & ~CLICKABLE_MASK) | (isClickable ? CLICKABLE_MASK : 0);
}
@Implementation
protected void setLongClickable(boolean isLongClickable) {
propertyFlags =
(propertyFlags & ~LONGCLICKABLE_MASK) | (isLongClickable ? LONGCLICKABLE_MASK : 0);
}
@Implementation
protected void setFocusable(boolean isFocusable) {
propertyFlags = (propertyFlags & ~FOCUSABLE_MASK) | (isFocusable ? FOCUSABLE_MASK : 0);
}
@Implementation
protected void setFocused(boolean isFocused) {
propertyFlags = (propertyFlags & ~FOCUSED_MASK) | (isFocused ? FOCUSED_MASK : 0);
}
@Implementation
protected void setScrollable(boolean isScrollable) {
propertyFlags = (propertyFlags & ~SCROLLABLE_MASK) | (isScrollable ? SCROLLABLE_MASK : 0);
}
public void setPasteable(boolean isPasteable) {
propertyFlags = (propertyFlags & ~PASTEABLE_MASK) | (isPasteable ? PASTEABLE_MASK : 0);
}
@Implementation(minSdk = JELLY_BEAN_MR2)
protected void setEditable(boolean isEditable) {
propertyFlags = (propertyFlags & ~EDITABLE_MASK) | (isEditable ? EDITABLE_MASK : 0);
}
@Implementation
protected void setVisibleToUser(boolean isVisibleToUser) {
propertyFlags =
(propertyFlags & ~VISIBLE_TO_USER_MASK) | (isVisibleToUser ? VISIBLE_TO_USER_MASK : 0);
}
@Implementation(minSdk = Q)
protected void setTextEntryKey(boolean isTextEntrykey) {
propertyFlags =
(propertyFlags & ~TEXT_ENTRY_KEY_MASK) | (isTextEntrykey ? TEXT_ENTRY_KEY_MASK : 0);
}
@Implementation(minSdk = N)
protected void setImportantForAccessibility(boolean important) {
propertyFlags = (propertyFlags & ~IMPORTANT_MASK) | (important ? IMPORTANT_MASK : 0);
}
@Implementation(minSdk = N)
protected boolean isImportantForAccessibility() {
return ((propertyFlags & IMPORTANT_MASK) != 0);
}
@Implementation
protected void setContentDescription(CharSequence description) {
contentDescription = description;
}
@Implementation
protected CharSequence getContentDescription() {
return contentDescription;
}
@Implementation
protected void setClassName(CharSequence name) {
className = name;
}
@Implementation
protected CharSequence getClassName() {
return className;
}
@Implementation
protected void setText(CharSequence t) {
text = t;
}
@Implementation
protected CharSequence getText() {
return text;
}
@Implementation(minSdk = JELLY_BEAN_MR2)
protected void setTextSelection(int start, int end) {
textSelectionStart = start;
textSelectionEnd = end;
}
/**
* Gets the text selection start.
*
* @return The text selection start if there is selection or UNDEFINED_SELECTION_INDEX.
*/
@Implementation(minSdk = JELLY_BEAN_MR2)
protected int getTextSelectionStart() {
return textSelectionStart;
}
/**
* Gets the text selection end.
*
* @return The text selection end if there is selection or UNDEFINED_SELECTION_INDEX.
*/
@Implementation(minSdk = JELLY_BEAN_MR2)
protected int getTextSelectionEnd() {
return textSelectionEnd;
}
@Implementation(minSdk = JELLY_BEAN_MR2)
protected AccessibilityNodeInfo getLabelFor() {
if (labelFor == null) {
return null;
}
return obtain(labelFor);
}
public void setLabelFor(AccessibilityNodeInfo info) {
if (labelFor != null) {
labelFor.recycle();
}
labelFor = obtain(info);
}
@Implementation(minSdk = JELLY_BEAN_MR1)
protected AccessibilityNodeInfo getLabeledBy() {
if (labeledBy == null) {
return null;
}
return obtain(labeledBy);
}
public void setLabeledBy(AccessibilityNodeInfo info) {
if (labeledBy != null) {
labeledBy.recycle();
}
labeledBy = obtain(info);
}
@Implementation
protected int getMovementGranularities() {
return movementGranularities;
}
@Implementation
protected void setMovementGranularities(int movementGranularities) {
this.movementGranularities = movementGranularities;
}
@Implementation
protected CharSequence getPackageName() {
return packageName;
}
@Implementation
protected void setPackageName(CharSequence packageName) {
this.packageName = packageName;
}
@Implementation(minSdk = JELLY_BEAN_MR2)
protected String getViewIdResourceName() {
return viewIdResourceName;
}
@Implementation(minSdk = JELLY_BEAN_MR2)
protected void setViewIdResourceName(String viewIdResourceName) {
this.viewIdResourceName = viewIdResourceName;
}
@Implementation(minSdk = KITKAT)
protected CollectionInfo getCollectionInfo() {
return collectionInfo;
}
@Implementation(minSdk = KITKAT)
protected void setCollectionInfo(CollectionInfo collectionInfo) {
this.collectionInfo = collectionInfo;
}
@Implementation(minSdk = KITKAT)
protected CollectionItemInfo getCollectionItemInfo() {
return collectionItemInfo;
}
@Implementation(minSdk = KITKAT)
protected void setCollectionItemInfo(CollectionItemInfo collectionItemInfo) {
this.collectionItemInfo = collectionItemInfo;
}
@Implementation(minSdk = KITKAT)
protected int getInputType() {
return inputType;
}
@Implementation(minSdk = KITKAT)
protected void setInputType(int inputType) {
this.inputType = inputType;
}
@Implementation(minSdk = KITKAT)
protected int getLiveRegion() {
return liveRegion;
}
@Implementation(minSdk = KITKAT)
protected void setLiveRegion(int liveRegion) {
this.liveRegion = liveRegion;
}
@Implementation(minSdk = KITKAT)
protected RangeInfo getRangeInfo() {
return rangeInfo;
}
@Implementation(minSdk = KITKAT)
protected void setRangeInfo(RangeInfo rangeInfo) {
this.rangeInfo = rangeInfo;
}
@Implementation(minSdk = LOLLIPOP)
protected int getMaxTextLength() {
return maxTextLength;
}
@Implementation(minSdk = LOLLIPOP)
protected void setMaxTextLength(int maxTextLength) {
this.maxTextLength = maxTextLength;
}
@Implementation(minSdk = LOLLIPOP)
protected CharSequence getError() {
return error;
}
@Implementation(minSdk = LOLLIPOP)
protected void setError(CharSequence error) {
this.error = error;
}
@Implementation(minSdk = LOLLIPOP_MR1)
protected AccessibilityNodeInfo getTraversalAfter() {
if (traversalAfter == null) {
return null;
}
return obtain(traversalAfter);
}
@Implementation(minSdk = LOLLIPOP_MR1)
protected void setTraversalAfter(View view, int virtualDescendantId) {
if (this.traversalAfter != null) {
this.traversalAfter.recycle();
}
this.traversalAfter = obtain(view);
}
/**
* Sets the view whose node is visited after this one in accessibility traversal.
*
* This may be useful for configuring traversal order in tests before the corresponding
* views have been inflated.
*
* @param info The previous node.
* @see #getTraversalAfter()
*/
public void setTraversalAfter(AccessibilityNodeInfo info) {
if (this.traversalAfter != null) {
this.traversalAfter.recycle();
}
this.traversalAfter = obtain(info);
}
@Implementation(minSdk = LOLLIPOP_MR1)
protected AccessibilityNodeInfo getTraversalBefore() {
if (traversalBefore == null) {
return null;
}
return obtain(traversalBefore);
}
@Implementation(minSdk = LOLLIPOP_MR1)
protected void setTraversalBefore(View info, int virtualDescendantId) {
if (this.traversalBefore != null) {
this.traversalBefore.recycle();
}
this.traversalBefore = obtain(info);
}
/**
* Sets the view before whose node this one should be visited during traversal.
*
* This may be useful for configuring traversal order in tests before the corresponding
* views have been inflated.
*
* @param info The view providing the preceding node.
* @see #getTraversalBefore()
*/
public void setTraversalBefore(AccessibilityNodeInfo info) {
if (this.traversalBefore != null) {
this.traversalBefore.recycle();
}
this.traversalBefore = obtain(info);
}
@Implementation
protected void setSource(View source) {
this.view = source;
}
@Implementation
protected void setSource(View root, int virtualDescendantId) {
this.view = root;
}
@Implementation
protected void getBoundsInScreen(Rect outBounds) {
if (boundsInScreen == null) {
boundsInScreen = new Rect();
}
outBounds.set(boundsInScreen);
}
@Implementation
protected void getBoundsInParent(Rect outBounds) {
if (boundsInParent == null) {
boundsInParent = new Rect();
}
outBounds.set(boundsInParent);
}
@Implementation
protected void setBoundsInScreen(Rect b) {
if (boundsInScreen == null) {
boundsInScreen = new Rect(b);
} else {
boundsInScreen.set(b);
}
}
@Implementation
protected void setBoundsInParent(Rect b) {
if (boundsInParent == null) {
boundsInParent = new Rect(b);
} else {
boundsInParent.set(b);
}
}
@Implementation
protected void addAction(int action) {
if (getApiLevel() >= LOLLIPOP) {
if ((action & getActionTypeMaskFromFramework()) != 0) {
throw new IllegalArgumentException("Action is not a combination of the standard " +
"actions: " + action);
}
int remainingIds = action;
while (remainingIds > 0) {
final int id = 1 << Integer.numberOfTrailingZeros(remainingIds);
remainingIds &= ~id;
AccessibilityAction convertedAction = getActionFromIdFromFrameWork(id);
addAction(convertedAction);
}
} else {
actionsMask |= action;
}
}
@Implementation(minSdk = LOLLIPOP)
protected void addAction(AccessibilityAction action) {
if (action == null) {
return;
}
if (actionsArray == null) {
actionsArray = new ArrayList<>();
}
actionsArray.remove(action);
actionsArray.add(action);
}
@Implementation(minSdk = LOLLIPOP)
protected void removeAction(int action) {
AccessibilityAction convertedAction = getActionFromIdFromFrameWork(action);
removeAction(convertedAction);
}
@Implementation(minSdk = LOLLIPOP)
protected boolean removeAction(AccessibilityAction action) {
if (action == null || actionsArray == null) {
return false;
}
return actionsArray.remove(action);
}
/**
* Obtain flags for actions supported. Currently only supports {@link
* AccessibilityNodeInfo#ACTION_CLICK}, {@link AccessibilityNodeInfo#ACTION_LONG_CLICK}, {@link
* AccessibilityNodeInfo#ACTION_SCROLL_FORWARD}, {@link AccessibilityNodeInfo#ACTION_PASTE},
* {@link AccessibilityNodeInfo#ACTION_FOCUS}, {@link AccessibilityNodeInfo#ACTION_SET_SELECTION},
* {@link AccessibilityNodeInfo#ACTION_SCROLL_BACKWARD} Returned value is derived from the
* getters.
*
* @return Action mask. 0 if no actions supported.
*/
@Implementation
protected int getActions() {
if (getApiLevel() >= LOLLIPOP) {
int returnValue = 0;
if (actionsArray == null) {
return returnValue;
}
// Custom actions are only returned by getActionsList
final int actionSize = actionsArray.size();
for (int i = 0; i < actionSize; i++) {
int actionId = actionsArray.get(i).getId();
if (actionId <= getLastLegacyActionFromFrameWork()) {
returnValue |= actionId;
}
}
return returnValue;
} else {
return actionsMask;
}
}
/** Returns the drawing order of the view corresponding to this node. */
@Implementation(minSdk = N)
protected int getDrawingOrder() {
return drawingOrder;
}
/** Sets the drawing order of the view corresponding to this node. */
@Implementation(minSdk = N)
protected void setDrawingOrder(int drawingOrder) {
this.drawingOrder = drawingOrder;
}
@Implementation(minSdk = LOLLIPOP)
protected AccessibilityWindowInfo getWindow() {
return accessibilityWindowInfo;
}
/** Returns the id of the window from which the info comes. */
@Implementation
protected int getWindowId() {
return (accessibilityWindowInfo == null) ? -1 : accessibilityWindowInfo.getId();
}
public void setAccessibilityWindowInfo(AccessibilityWindowInfo info) {
accessibilityWindowInfo = info;
}
@Implementation(minSdk = LOLLIPOP)
protected List<AccessibilityAction> getActionList() {