Skip to content

fix-huawei-imagereader-166481#181931

Merged
auto-submit[bot] merged 10 commits intoflutter:masterfrom
serbandin:fix-huawei-imagereader-166481
Feb 25, 2026
Merged

fix-huawei-imagereader-166481#181931
auto-submit[bot] merged 10 commits intoflutter:masterfrom
serbandin:fix-huawei-imagereader-166481

Conversation

@serbandin
Copy link
Contributor

@serbandin serbandin commented Feb 4, 2026

Fixes video playback issues on Huawei devices running Android API level 29 or below by falling back to SurfaceTextureSurfaceProducer instead of ImageReaderSurfaceProducer.

Problem

On certain Huawei devices with Android 10 (API 29), video playback fails when using ImageReaderSurfaceProducer. This is due to issues with AHB (Android Hardware Buffer) imports on these devices, similar to the Vulkan fallback already implemented in android_context_dynamic_impeller.cc. Fixes #166481

Solution

Added a new JNI method shouldDisableImageReader() that detects Huawei devices by checking the ro.com.google.clientidbase system property for the value "android-huawei" when the API level is 29 or below. When this method returns true, FlutterRenderer.createSurfaceProducer() uses SurfaceTextureSurfaceProducer instead of ImageReaderSurfaceProducer, which resolves the video playback issue.

Changes

FlutterJNI.java: Added shouldDisableImageReader() method and native bridge
platform_view_android_jni_impl.cc: Native implementation using __system_property_get() and android_get_device_api_level()
FlutterRenderer.java: Integration in createSurfaceProducer() condition (line 230)
FlutterRendererTest.java: Unit test for the new behavior

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@serbandin serbandin requested a review from a team as a code owner February 4, 2026 23:51
@github-actions github-actions bot added platform-android Android applications specifically engine flutter/engine related. See also e: labels. team-android Owned by Android platform team labels Feb 4, 2026
@serbandin
Copy link
Contributor Author

The issue this PR tries to solve appeared in flutter 3.29.2 released on 13/03/2025. From my investigations I believe it was introduced by this PR: #164201

The PR disabled Vulkan on Huawei api 29 so it falls back to OpenGLES but OpenGLES still uses ImageReader. So I tried to add back the logic from && !flutterJNI.ShouldDisableAHB()

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a fix for video playback issues on certain Huawei devices running Android API level 29 or below. The solution involves adding a native check to detect this specific device configuration and then falling back to SurfaceTextureSurfaceProducer instead of ImageReaderSurfaceProducer. The implementation is well-contained, spanning Java and C++ with the necessary JNI bindings, and is accompanied by a unit test to validate the new behavior. The changes appear correct and effectively address the reported issue.

@camsim99 camsim99 self-requested a review February 5, 2026 00:28
@serbandin serbandin force-pushed the fix-huawei-imagereader-166481 branch 2 times, most recently from cad4f69 to 401c39b Compare February 5, 2026 21:38
@reidbaker
Copy link
Contributor

reidbaker commented Feb 6, 2026

Adding @gaaclarke TL of the engine team since the author of that pr is no longer a full time contributor to flutter.

@gaaclarke if you are not the right person to review this can you find someone on your team who is? Second question what test should we author to prevent a regression on this issue in the engine? Do you need the android team to add huawei emulators or is there something lower level that should be tested.

@reidbaker reidbaker requested a review from gaaclarke February 6, 2026 18:49
@reidbaker
Copy link
Contributor

@serbandin thank you so much for your contribution.

private native boolean nativeShouldDisableImageReader();

/**
* Checks if ImageReader should be disabled for this device.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you link to the source for which ImageReader that is keyword that can lead to a lot of different types of code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/**
* Checks if ImageReader should be disabled for this device.
*
* <p>Returns true for Huawei devices on API level 29 or below due to known issues with
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than than the bug is there any other source we can point to that says that imagereader is known to not work on huawei devices?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of old issue with Huawei not playing videos on api 29.
#156459
#154068
Also here's an old PR that fixed it initially: flutter/engine#54879
Seems to be related to the OMX.hisi.* Decoder. It happens on Kirin 710/970/980 from what I saw in the comments / tested myself.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reidbaker I don't know about wether we want to disable the image reader or not on certain devices. I'll let the Android team decide on that. Ideally the linked issue should provide enough documentation.

I think we should avoid doing JNI here since the check can happen with the java apis.

Comment on lines 839 to 840
// SurfaceTextureSurfaceProducer handles crop and rotation, ImageReaderSurfaceProducer does not.
assertTrue(producer.handlesCropAndRotation());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer a more apropos assertion instead of relying on secondary information to test what you really want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 557 to 571
// Huawei devices on API level 29 and below have known issues with
// ImageReader. This check is used to disable ImageReader on affected devices.
static jboolean ShouldDisableImageReader(JNIEnv* env, jobject jcaller) {
constexpr int kHuaweiMaxApiLevel = 29;
constexpr char kAndroidHuawei[] = "android-huawei";
constexpr char kClientIdBaseProperty[] = "ro.com.google.clientidbase";

if (android_get_device_api_level() > kHuaweiMaxApiLevel) {
return false;
}

char property[PROP_VALUE_MAX];
__system_property_get(kClientIdBaseProperty, property);
return strcmp(property, kAndroidHuawei) == 0;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe there is any reason we have to use JNI for this. I think this same test can be performed from java.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a check like this in java would be better?

return Build.VERSION.SDK_INT <= API_LEVELS.API_29
    && "HUAWEI".equalsIgnoreCase(Build.MANUFACTURER);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, avoiding JNI is a win.

@serbandin serbandin force-pushed the fix-huawei-imagereader-166481 branch from 401c39b to 3163712 Compare February 7, 2026 00:04
Copy link
Contributor

@camsim99 camsim99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me overall--just one nit and a question!

*
* @see <a href="https://github.com/flutter/flutter/issues/166481">#166481</a>
*/
private static boolean hasImageReaderIssue() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small thing: I would prefer a name that is more specific to the issue at hand like hasAndroidHardwareBufferDefect or requiresSurfaceTextureSurfaceProducer.

@serbandin serbandin force-pushed the fix-huawei-imagereader-166481 branch 5 times, most recently from dca1aa6 to 8e0eb93 Compare February 14, 2026 04:01
Copy link
Contributor

@camsim99 camsim99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach LGTM thanks for the fixes!

// Verify: Should return SurfaceTextureSurfaceProducer instead of ImageReaderSurfaceProducer.
assertTrue(
"Expected SurfaceTextureSurfaceProducer on Huawei API <= 29 due to HardwareBuffer defect causing video playback failures",
producer instanceof FlutterRenderer.SurfaceTextureSurfaceProducer);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you're missing an import

/b/s/w/ir/cache/builder/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/engine/renderer/FlutterRendererTest.java:842: error: cannot find symbol
          producer instanceof FlutterRenderer.SurfaceTextureSurfaceProducer);
                                             ^
    symbol:   class SurfaceTextureSurfaceProducer
    location: class FlutterRenderer
  1 error

@reidbaker
Copy link
Contributor

After the test pass we would like @gaaclarke or another engine team member approval.
Engine team fwiw this is a pretty bad bug on a non trivial number of devices that has been broken for a while. If we dont take this pr we will want to do something else.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes looks good, the code is adequately tested. I don't know if we can definitively know all the values of Build.MANUFACTURER to make sure we catch everything, but this is progress regardless. I'll defer to the Android team as to wether they want the change or not (sounds like they do!)

serbandin and others added 3 commits February 19, 2026 23:30
Co-authored-by: Reid Baker <1063596+reidbaker@users.noreply.github.com>
Co-authored-by: Reid Baker <1063596+reidbaker@users.noreply.github.com>
@reidbaker reidbaker added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 20, 2026
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 20, 2026
@auto-submit
Copy link
Contributor

auto-submit bot commented Feb 20, 2026

auto label is removed for flutter/flutter/181931, Failed to enqueue flutter/flutter/181931 with HTTP 400: GraphQL mutate failed.

@serbandin
Copy link
Contributor Author

auto label is removed for flutter/flutter/181931, Failed to enqueue flutter/flutter/181931 with HTTP 400: GraphQL mutate failed.

@reidbaker, first of all thanks for the review + all the suggestions! Wanted to ask you if you have idea why the bot removed the auto-submit label? Should I do an interactive rebase on master and remove the merge commits?

@reidbaker
Copy link
Contributor

reidbaker commented Feb 20, 2026

I don't have a link handy but we are having an outage on our side. Don't worry about it and I will try to get this landed Monday after our outage is resolved. No action needed from you

@camsim99 camsim99 added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 24, 2026
@auto-submit
Copy link
Contributor

auto-submit bot commented Feb 24, 2026

autosubmit label was removed for flutter/flutter/181931, because - The status or check suite Linux linux_unopt has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 24, 2026
@camsim99
Copy link
Contributor

@serbandin
Copy link
Contributor Author

@serbandin the failure is legitimate; looks like you need to run the formatter! https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8688955671889939393/+/u/test:_test:_Check_formatting/stdout#:~:text=To%20fix%2C%20run%20%60et%20format%60%20or has the fix

hmm seems that it happened after last comments pushed via suggestion. Thanks! I will run it

@serbandin serbandin force-pushed the fix-huawei-imagereader-166481 branch from 6c547f0 to fa0473d Compare February 24, 2026 22:23
@serbandin
Copy link
Contributor Author

@camsim99 I applied the format suggestion, now the tests are passing

@reidbaker reidbaker added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 25, 2026
@auto-submit auto-submit bot added this pull request to the merge queue Feb 25, 2026
Merged via the queue into flutter:master with commit bcdd691 Feb 25, 2026
183 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 25, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 25, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine flutter/engine related. See also e: labels. platform-android Android applications specifically team-android Owned by Android platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Video player on Android 29 device does not play media

4 participants