File tree Expand file tree Collapse file tree 5 files changed +25
-3
lines changed
java/androidx/test/core/view Expand file tree Collapse file tree 5 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 6
6
7
7
** Bug Fixes**
8
8
9
+ * make ViewCapture use ControlledLooper API instead of hardcoding is Robolectric check
10
+
9
11
** New Features**
10
12
11
13
** Breaking Changes**
Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ import androidx.annotation.RequiresApi
35
35
import androidx.concurrent.futures.ResolvableFuture
36
36
import androidx.test.annotation.ExperimentalTestApi
37
37
import androidx.test.core.internal.os.HandlerExecutor
38
+ import androidx.test.internal.platform.ServiceLoaderWrapper
39
+ import androidx.test.internal.platform.os.ControlledLooper
38
40
import androidx.test.internal.platform.reflect.ReflectiveField
39
41
import androidx.test.internal.platform.reflect.ReflectiveMethod
40
42
import androidx.test.platform.graphics.HardwareRendererCompat
@@ -74,17 +76,23 @@ fun View.captureToBitmap(rect: Rect? = null): ListenableFuture<Bitmap> {
74
76
}
75
77
76
78
mainExecutor.execute {
77
- if (Build .FINGERPRINT .contains(" robolectric" )) {
78
- generateBitmap(bitmapFuture, rect)
79
- } else {
79
+ if (getControlledLooper().areDrawCallbacksSupported()) {
80
80
val forceRedrawFuture = forceRedraw()
81
81
forceRedrawFuture.addListener({ generateBitmap(bitmapFuture, rect) }, mainExecutor)
82
+ } else {
83
+ generateBitmap(bitmapFuture, rect)
82
84
}
83
85
}
84
86
85
87
return bitmapFuture
86
88
}
87
89
90
+ private fun getControlledLooper (): ControlledLooper {
91
+ return ServiceLoaderWrapper .loadSingleService(ControlledLooper ::class .java) {
92
+ ControlledLooper .NO_OP_CONTROLLED_LOOPER
93
+ }
94
+ }
95
+
88
96
/* *
89
97
* Equivalent to [captureToBitmap] for now. In the future [captureToBitmap] will be changed to a
90
98
* suspend function.
Original file line number Diff line number Diff line change 16
16
* Upstream TestStorage.getInputFileUri and getOutputFileUri to PlatformTestStorage
17
17
* Change PlatformTestStorage methods to throw FileNotFoundException instead of
18
18
IOException
19
+ * Add internal ControlledLooper#isDrawCallbacksSupported.
19
20
20
21
** Breaking API Changes**
21
22
Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ package androidx.test.internal.platform.content {
53
53
package androidx.test.internal.platform.os {
54
54
55
55
@RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP) public interface ControlledLooper {
56
+ method public default boolean areDrawCallbacksSupported();
56
57
method public void drainMainThreadUntilIdle();
57
58
method public void simulateWindowFocus(android.view.View!);
58
59
field public static final androidx.test.internal.platform.os.ControlledLooper! NO_OP_CONTROLLED_LOOPER;
Original file line number Diff line number Diff line change @@ -39,12 +39,22 @@ public interface ControlledLooper {
39
39
/** Generate window focus event for given view. */
40
40
void simulateWindowFocus (View decorView );
41
41
42
+ /** Returns true if registerFrameCommitCallback() and addOnDrawListener callbacks are supported */
43
+ default boolean areDrawCallbacksSupported () {
44
+ return false ;
45
+ }
46
+
42
47
public static final ControlledLooper NO_OP_CONTROLLED_LOOPER =
43
48
new ControlledLooper () {
44
49
@ Override
45
50
public void drainMainThreadUntilIdle () {}
46
51
47
52
@ Override
48
53
public void simulateWindowFocus (View decorView ) {}
54
+
55
+ @ Override
56
+ public boolean areDrawCallbacksSupported () {
57
+ return true ;
58
+ }
49
59
};
50
60
}
You can’t perform that action at this time.
0 commit comments