Skip to content

AndroidView is offsetted and clipped on some Xiaomi devices with a notch #24657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
yoavrofe opened this issue Nov 22, 2018 · 21 comments
Open
Labels
a: platform-views Embedding Android/iOS views in Flutter apps e: device-specific Only manifests on certain devices engine flutter/engine repository. See also e: labels. P3 Issues that are less important to the Flutter project platform-android Android applications specifically team-android Owned by Android platform team triaged-android Triaged by Android platform team

Comments

@yoavrofe
Copy link

When running the webview_flutter example on a device with a notch, a blank bar apears on the top of the native view, below the app bar. The platform view responds to touches with a vertical offset (one must touch above the point). #19030

screenshot_2018-11-22-15-39-43-001_com example webviewtest

@zoechi zoechi added the a: platform-views Embedding Android/iOS views in Flutter apps label Nov 22, 2018
@zoechi zoechi added this to the Goals milestone Nov 22, 2018
@amirh amirh added the platform-android Android applications specifically label Nov 29, 2018
@amirh amirh modified the milestones: Goals, January 2019 Nov 29, 2018
@amirh
Copy link
Contributor

amirh commented Dec 10, 2018

I can't reproduce this on an emulator with a notch.

@yoavrofe which device are you seeing this on?
Can you post the output of flutter doctor.
Do you see the issue on latest master?

@kf6gpe
Copy link
Contributor

kf6gpe commented Dec 10, 2018

I can't reproduce this on a Pixel 3 XL, either --- I did a sync to head this morning and a flutter run of the webview example, and it worked. @amirh and I are wondering if it's a device-specific issue?
flutter_01

@amirh amirh added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 10, 2018
@CaiJingLong
Copy link
Contributor

same problem #25152 .

View will have a padding on this Android screen.
图片

code example is

https://github.com/CaiJingLong/androidview-notch-error

And touching events can also be offset.

Other androidview is also have the problem . I just extracted the smallest repository of code.

flutter doctor -v

flutter doctor -v
[✓] Flutter (Channel dev, v1.0.0, on Mac OS X 10.13.6 17G65, locale zh-Hans-CN)
    • Flutter version 1.0.0 at /Users/cai/fluttersdk/flutter
    • Framework revision 5391447fae (10 days ago), 2018-11-29 19:41:26 -0800
    • Engine revision 7375a0f414
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at /Users/cai/Library/Android/sdk
    • Android NDK at /Users/cai/Library/Android/sdk/ndk-bundle
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /Volumes/Evo512/application/develop/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 9.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.2, Build version 9C40b
    • ios-deploy 2.0.0
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 29.0.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[✓] Android Studio (version 3.2)
    • Android Studio at /Volumes/Evo512/application/develop/Android Studio.app/Contents
    • Flutter plugin version 30.0.1
    • Dart plugin version 181.5656
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[✓] IntelliJ IDEA Ultimate Edition (version 2018.2.5)
    • IntelliJ at /Users/cai/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 31.1.3
    • Dart plugin version 182.5124

[✓] VS Code (version 1.29.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 2.21.1

[✓] Connected device (1 available)
    • MI 8 • b6ec3684 • android-arm64 • Android 8.1.0 (API 27)

my device photo
image

I will test the master channel.

@yoavrofe
Copy link
Author

yoavrofe commented Dec 11, 2018

My device is a Pocophone F1.
The problem exists when using the master channel, but does not exist when not using the AppBar.

flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, v1.0.1-pre.15, on Mac OS X 10.14.1 18B75, locale en-IL)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[✓] Android Studio (version 3.2)
[✓] VS Code (version 1.29.1)
[✓] Connected device (2 available)
• No issues found!

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 11, 2018
@zoechi zoechi added the engine flutter/engine repository. See also e: labels. label Dec 11, 2018
@yoavrofe
Copy link
Author

I upgraded to Android 9.0, and could not reproduce the problem. It seams like a problem related to the app bar before 9.0.

@CaiJingLong
Copy link
Contributor

@yoavrofe
My device is Android 8.1.0 (API 27), The developer of my mobile phone system hasn't released an Android 9.0 version yet. So my problem still exists.

@amirh
Copy link
Contributor

amirh commented Dec 18, 2018

It looks like prior to API 28 (where Android introduced support for DisplayCutouts) Xiaomi had some custom Android changes to support display cutouts.

What I'm observing on a Xiaomi Pocophone F1 running API 27 is that windows attached to virtual displays are offsetted by the height of the notch.

I'm not sure how does the display cutout support works on these Xiaomi devices, I tried setting full screen window flags, and setting setFitSystemWindows to false (thinking that full screen windows will not be offsetted, as the main display's window is not offsetted when it's full screen) but the virtual display's window is still being offset.

It does look like we can detect the offset at runtime (calling getOnScreenLocation on the VD's root view shows the offset), so one workaround could be to allocate a bigger VD than needed and have Flutter clip the texture. I'm not a big fan of this workaround as it is tailored for a very specific fork of Android, and as we workaround without fully understanding the issue.

I'm open for cleaner fix/workaround suggestions if anyone has such.

@amirh amirh changed the title Android platform view leaves a blank bar on screens with a notch AndroidView is offsetted and clipped on some Xiaomi devices with a notch Dec 19, 2018
@amirh amirh self-assigned this Dec 19, 2018
@zoechi zoechi added the e: device-specific Only manifests on certain devices label Dec 19, 2018
@amirh
Copy link
Contributor

amirh commented Dec 19, 2018

The Pocophone F1 I got yesterday to investigate the issue auto-upgraded to Android 9 over night (without asking for my confirmation), and with Android 9 the issue is indeed fixed.

I'm trying to reach out to relevant folks to see if there's a better workaround than allocating a bigger virtual display and clipping it.

As we learned that this is a vendor specific bug, and as it seems to have been already fixed by the vendor I'm de-prioritizing this issue and moving out of the January 2019 milestone.

We should still look for a reasonable workaround for the affected Xiaomi devices that are still running older Android versions.

@amirh amirh modified the milestones: January 2019, Near-term Goals Dec 19, 2018
@amirh amirh assigned amirh and unassigned amirh Dec 19, 2018
@CaiJingLong
Copy link
Contributor

If you can, try to contact Xiaomi Development Engineer?

@jicg
Copy link

jicg commented Aug 13, 2019

older Android versions have any solution to avoid it? @amirh

@jicg
Copy link

jicg commented Aug 13, 2019

In addition to upgrading android9, is there any other way to solve it temporarily? Simple, quick way?

@amirh
Copy link
Contributor

amirh commented Aug 13, 2019

See the proposed workaround at #24657 (comment) if you're willing to fork the engine you can probably give it a shot.

@yusheng-jia
Copy link

Is there a solution?

@yusheng-jia
Copy link

I have update Android version to 9,and this problem has solved

@luoei
Copy link

luoei commented Jan 19, 2020

Is there a solution?

@SixSheeppp
Copy link

Current solution is

Modify SingleViewPresentation which is create PlatformView

code:

int flag = 0x00000100 | 0x00000200 | 0x00000400;
try {
    Method method = Window.class.getMethod("addExtraFlags",
            int.class);
    method.invoke(getWindow(), flag);
} catch (Exception e) {
    Log.i(TAG, "addExtraFlags not found.");
}

document: https://dev.mi.com/console/doc/detail?pId=1293#_3_3

@kf6gpe kf6gpe added the P1 High-priority issues at the top of the work list label May 29, 2020
@kf6gpe kf6gpe modified the milestone: Near-term Goals Jun 1, 2020
@kf6gpe kf6gpe modified the milestone: [DEPRECATED] Near-term Goals Jul 7, 2020
@kf6gpe kf6gpe removed this from the [DEPRECATED] Near-term Goals milestone Jul 22, 2020
@Hixie Hixie removed this from the None milestone Aug 17, 2020
@xyh256
Copy link

xyh256 commented Dec 2, 2020

Current solution is

Modify SingleViewPresentation which is create PlatformView

code:

int flag = 0x00000100 | 0x00000200 | 0x00000400;
try {
    Method method = Window.class.getMethod("addExtraFlags",
            int.class);
    method.invoke(getWindow(), flag);
} catch (Exception e) {
    Log.i(TAG, "addExtraFlags not found.");
}

document: https://dev.mi.com/console/doc/detail?pId=1293#_3_3

android:screenOrientation="landscape" ,This problem has not been solved

@icofans
Copy link

icofans commented Jan 9, 2021

AndroidManifest.xml

<meta-data android:name="notch.config" android:value="portrait"/>
document: https://dev.mi.com/console/doc/detail?pId=1293#_3_3

@flutter-triage-bot flutter-triage-bot bot added multiteam-retriage-candidate team-android Owned by Android platform team triaged-android Triaged by Android platform team labels Jul 7, 2023
@mossmana mossmana added P2 Important issues not at the top of the work list and removed P1 High-priority issues at the top of the work list labels Oct 23, 2023
@mossmana
Copy link
Contributor

mossmana commented Oct 23, 2023

Bumping this issue down to a P3 since it is fixed with a later version of Android and has a posted workaround. If this issue gains additional thumbs up we may reconsider the priority.

@mossmana mossmana added P3 Issues that are less important to the Flutter project and removed P2 Important issues not at the top of the work list labels Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: platform-views Embedding Android/iOS views in Flutter apps e: device-specific Only manifests on certain devices engine flutter/engine repository. See also e: labels. P3 Issues that are less important to the Flutter project platform-android Android applications specifically team-android Owned by Android platform team triaged-android Triaged by Android platform team
Projects
None yet
Development

No branches or pull requests