[Android] Drops semantics query when app is not attached (flutter/engine#52040)
Is seems automatic test may send a11y query before the engine is attached. Add a guard to guard against it. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
@@ -873,7 +873,13 @@ public class FlutterJNI {
|
||||
@UiThread
|
||||
public void setSemanticsEnabled(boolean enabled) {
|
||||
ensureRunningOnMainThread();
|
||||
ensureAttachedToNative();
|
||||
if (isAttached()) {
|
||||
setSemanticsEnabledInNative(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void setSemanticsEnabledInNative(boolean enabled) {
|
||||
nativeSetSemanticsEnabled(nativeShellHolderId, enabled);
|
||||
}
|
||||
|
||||
@@ -884,7 +890,13 @@ public class FlutterJNI {
|
||||
@UiThread
|
||||
public void setAccessibilityFeatures(int flags) {
|
||||
ensureRunningOnMainThread();
|
||||
ensureAttachedToNative();
|
||||
if (isAttached()) {
|
||||
setAccessibilityFeaturesInNative(flags);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void setAccessibilityFeaturesInNative(int flags) {
|
||||
nativeSetAccessibilityFeatures(nativeShellHolderId, flags);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package io.flutter.embedding.engine;
|
||||
|
||||
import static io.flutter.Build.API_LEVELS;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -151,6 +153,32 @@ public class FlutterJNITest {
|
||||
assertEquals(result[2], "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAccessibilityIfAttached() {
|
||||
// --- Test Setup ---
|
||||
FlutterJNITester flutterJNI = new FlutterJNITester(true);
|
||||
int expectedFlag = 100;
|
||||
|
||||
flutterJNI.setAccessibilityFeatures(expectedFlag);
|
||||
assertEquals(flutterJNI.flags, expectedFlag);
|
||||
|
||||
flutterJNI.setSemanticsEnabled(true);
|
||||
assertTrue(flutterJNI.semanticsEnabled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotSetAccessibilityIfNotAttached() {
|
||||
// --- Test Setup ---
|
||||
FlutterJNITester flutterJNI = new FlutterJNITester(false);
|
||||
int flags = 100;
|
||||
|
||||
flutterJNI.setAccessibilityFeatures(flags);
|
||||
assertEquals(flutterJNI.flags, 0);
|
||||
|
||||
flutterJNI.setSemanticsEnabled(true);
|
||||
assertFalse(flutterJNI.semanticsEnabled);
|
||||
}
|
||||
|
||||
public void onDisplayPlatformView_callsPlatformViewsController() {
|
||||
PlatformViewsController platformViewsController = mock(PlatformViewsController.class);
|
||||
|
||||
@@ -256,4 +284,29 @@ public class FlutterJNITest {
|
||||
// --- Verify Results ---
|
||||
verify(flutterJNI, times(1)).updateRefreshRate();
|
||||
}
|
||||
|
||||
static class FlutterJNITester extends FlutterJNI {
|
||||
FlutterJNITester(boolean attached) {
|
||||
this.isAttached = attached;
|
||||
}
|
||||
|
||||
final boolean isAttached;
|
||||
boolean semanticsEnabled = false;
|
||||
int flags = 0;
|
||||
|
||||
@Override
|
||||
public boolean isAttached() {
|
||||
return isAttached;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSemanticsEnabledInNative(boolean enabled) {
|
||||
semanticsEnabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAccessibilityFeaturesInNative(int flags) {
|
||||
this.flags = flags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user