19
19
import static androidx .test .espresso .matcher .RootMatchers .isDialog ;
20
20
import static androidx .test .internal .util .Checks .checkState ;
21
21
import static java .util .Collections .unmodifiableList ;
22
+ import static java .util .concurrent .TimeUnit .MILLISECONDS ;
23
+ import static java .util .concurrent .TimeUnit .SECONDS ;
22
24
23
25
import android .app .Activity ;
24
26
import android .content .Context ;
25
27
import android .os .Looper ;
28
+ import android .os .SystemClock ;
26
29
import android .util .Log ;
27
30
import android .view .View ;
28
31
import androidx .test .espresso .EspressoException ;
@@ -103,9 +106,9 @@ public View get() {
103
106
* root view is not being requested and the root view has window focus or is focusable.
104
107
*/
105
108
private Root waitForRootToBeReady (Root pickedRoot ) {
106
- long timeout = System . currentTimeMillis () + TimeUnit . SECONDS .toMillis (10 ) /* 10 seconds */ ;
109
+ long timeout = SystemClock . uptimeMillis () + SECONDS .toMillis (10 ) /* 10 seconds */ ;
107
110
BackOff rootReadyBackoff = new RootReadyBackoff ();
108
- while (System . currentTimeMillis () <= timeout ) {
111
+ while (SystemClock . uptimeMillis () <= timeout ) {
109
112
if (pickedRoot .isReady ()) {
110
113
return pickedRoot ;
111
114
} else {
@@ -125,11 +128,11 @@ private Root waitForRootToBeReady(Root pickedRoot) {
125
128
}
126
129
127
130
private Root pickARoot () {
128
- long timeout = System . currentTimeMillis () + TimeUnit . SECONDS .toMillis (60 ) /* 60 seconds */ ;
131
+ long timeout = SystemClock . uptimeMillis () + SECONDS .toMillis (60 ) /* 60 seconds */ ;
129
132
RootResults rootResults = rootResultFetcher .fetch ();
130
133
BackOff noActiveRootsBackoff = new NoActiveRootsBackoff ();
131
134
BackOff noMatchingRootBackoff = new NoMatchingRootBackoff ();
132
- while (System . currentTimeMillis () <= timeout ) {
135
+ while (SystemClock . uptimeMillis () <= timeout ) {
133
136
switch (rootResults .getState ()) {
134
137
case ROOTS_PICKED :
135
138
return rootResults .getPickedRoot ();
@@ -341,7 +344,7 @@ private static final class NoActiveRootsBackoff extends BackOff {
341
344
unmodifiableList (Arrays .asList (10 , 10 , 20 , 30 , 50 , 80 , 130 , 210 , 340 ));
342
345
343
346
public NoActiveRootsBackoff () {
344
- super (NO_ACTIVE_ROOTS_BACKOFF , TimeUnit . MILLISECONDS );
347
+ super (NO_ACTIVE_ROOTS_BACKOFF , MILLISECONDS );
345
348
}
346
349
347
350
@ Override
@@ -358,7 +361,7 @@ private static final class NoMatchingRootBackoff extends BackOff {
358
361
unmodifiableList (Arrays .asList (10 , 20 , 200 , 400 , 1000 , 2000 /* 2sec */ ));
359
362
360
363
public NoMatchingRootBackoff () {
361
- super (NO_MATCHING_ROOT_BACKOFF , TimeUnit . MILLISECONDS );
364
+ super (NO_MATCHING_ROOT_BACKOFF , MILLISECONDS );
362
365
}
363
366
364
367
@ Override
@@ -379,7 +382,7 @@ private static final class RootReadyBackoff extends BackOff {
379
382
unmodifiableList (Arrays .asList (10 , 25 , 50 , 100 , 200 , 400 , 800 , 1000 /* 1sec */ ));
380
383
381
384
public RootReadyBackoff () {
382
- super (ROOT_READY_BACKOFF , TimeUnit . MILLISECONDS );
385
+ super (ROOT_READY_BACKOFF , MILLISECONDS );
383
386
}
384
387
385
388
@ Override
0 commit comments