Skip to content

Commit 0cd6107

Browse files
authored
[stable] Fix AccessibilityBridge startup crash on vendor-modified Android (#189759)
Cherry-picks #184630 (fixes #184286) to `flutter-3.44-candidate.0`. ## Impacted Users Devices on vendor-modified Android 11 ROMs that report `SDK_INT >= 31` but ship a `Configuration` class without the API-31 `fontWeightAdjustment` field. Confirmed in production on OnePlus 8 Pro (Android 11); the OnePlus/Oppo/Realme ROM family is the likely blast radius. #184286 cited 95 fatal events, 100% OnePlus 8 Pro / Android 11. ## Impact Description Hard crash at startup. `NoSuchFieldError` is thrown from `AccessibilityBridge.setBoldTextFlag` inside the `AccessibilityBridge` constructor during `FlutterActivity.onCreate`, so the process dies before any Dart runs — the app never opens on affected devices. ## Workaround None from app code. The field read happens inside the engine's `AccessibilityBridge` constructor before the Dart isolate starts, so the embedding app cannot guard or catch it. ## Risk Low. +20/-4 in a single file (`AccessibilityBridge.java`): moves the `fontWeightAdjustment` read into an `@RequiresApi(31)` `Api31Impl` inner class so ART's class verifier no longer eagerly resolves the field at class-load time on older or vendor-modified runtimes. Mirrors the hardening AndroidX Compose applied for the same crash (AOSP b/353988277). Only touches the already-failing path. ## Test Coverage No automated test — the trigger is a device/ROM-specific `NoSuchFieldError` that isn't reproducible in CI. The change is defensive and validated against the production crash signature in #184286. ## Validation Steps Launch the app on an affected device (OnePlus 8 Pro / Android 11). Before: immediate startup crash. After: app launches normally; bold-text accessibility is simply treated as unavailable.
1 parent 7c42df0 commit 0cd6107

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

‎engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import android.view.accessibility.AccessibilityManager;
2626
import android.view.accessibility.AccessibilityNodeInfo;
2727
import android.view.accessibility.AccessibilityNodeProvider;
28+
import androidx.annotation.DoNotInline;
2829
import androidx.annotation.NonNull;
2930
import androidx.annotation.Nullable;
3031
import androidx.annotation.RequiresApi;
@@ -658,11 +659,8 @@ private void setBoldTextFlag() {
658659
if (rootAccessibilityView == null || rootAccessibilityView.getResources() == null) {
659660
return;
660661
}
661-
int fontWeightAdjustment =
662-
rootAccessibilityView.getResources().getConfiguration().fontWeightAdjustment;
663662
boolean shouldBold =
664-
fontWeightAdjustment != Configuration.FONT_WEIGHT_ADJUSTMENT_UNDEFINED
665-
&& fontWeightAdjustment >= BOLD_TEXT_WEIGHT_ADJUSTMENT;
663+
Api31Impl.isBoldText(rootAccessibilityView.getResources().getConfiguration());
666664

667665
if (shouldBold) {
668666
accessibilityFeatureFlags |= AccessibilityFeature.BOLD_TEXT.value;
@@ -3256,4 +3254,22 @@ public boolean externalViewRequestSendAccessibilityEvent(
32563254
}
32573255
return true;
32583256
}
3257+
3258+
/**
3259+
* Isolates API-31 field references so that ART's class verifier does not attempt to resolve them
3260+
* when loading {@link AccessibilityBridge} on older API levels. Without this separation, the
3261+
* verifier eagerly resolves {@link Configuration#fontWeightAdjustment} at class-load time,
3262+
* causing a {@link NoSuchFieldError} crash on Android 11 devices (observed on Pixel 4a and
3263+
* OnePlus 8 Pro). This mirrors the fix AndroidX Compose applied for the same crash (AOSP
3264+
* b/353988277).
3265+
*/
3266+
@RequiresApi(API_LEVELS.API_31)
3267+
private static class Api31Impl {
3268+
@DoNotInline
3269+
static boolean isBoldText(Configuration configuration) {
3270+
int fontWeightAdjustment = configuration.fontWeightAdjustment;
3271+
return fontWeightAdjustment != Configuration.FONT_WEIGHT_ADJUSTMENT_UNDEFINED
3272+
&& fontWeightAdjustment >= BOLD_TEXT_WEIGHT_ADJUSTMENT;
3273+
}
3274+
}
32593275
}

0 commit comments

Comments
 (0)