Skip to content

[Android] Controls Disappear When WebView is Used with Hardware Acceleration Disabled #28934

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

Merged
merged 10 commits into from
Jun 25, 2025

Conversation

praveenkumarkarunanithi
Copy link
Contributor

Root Cause

When android:hardwareAccelerated="false" is set in Android applications, standard UI elements switch to software rendering, but WebView may continue using hardware optimization. This inconsistency causes WebView to occasionally render above other UI elements, disrupting the expected visual hierarchy.

Description of Change

The solution involves setting the WebView to use the software rendering pipeline by applying SetLayerType(Android.Views.LayerType.Software, null) when hardware acceleration is disabled. This ensures that WebView aligns with the rendering behavior of other UI elements, maintaining correct layering and preventing any UI components from being obscured.

Issues Fixed

Fixes #28902

Tested the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Note

This issue is specific to Android, as hardware acceleration settings are not applicable on other platforms.

Screenshots

Before Issue Fix After Issue Fix
withoutfix withfix

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Apr 11, 2025
Copy link
Contributor

Hey there @@praveenkumarkarunanithi! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Apr 11, 2025
@praveenkumarkarunanithi praveenkumarkarunanithi marked this pull request as ready for review April 14, 2025 12:54
@Copilot Copilot AI review requested due to automatic review settings April 14, 2025 12:54
@praveenkumarkarunanithi praveenkumarkarunanithi requested a review from a team as a code owner April 14, 2025 12:54
Copilot

This comment was marked as outdated.

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mattleibow mattleibow requested a review from Copilot June 24, 2025 21:36
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses an Android-specific rendering issue where WebView appears above other UI controls when hardware acceleration is disabled. The changes include modifying the WebViewHandler on Android to enforce software rendering and adding test cases in both Shared.Tests and HostApp to validate the fix.

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.

File Description
src/Core/src/Handlers/WebView/WebViewHandler.Android.cs Updates WebView creation to call SetLayerType() for software rendering when hardware acceleration is disabled.
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28798.cs Adds a test case to verify that controls remain visible under the issue conditions on Android.
src/Controls/tests/TestCases.HostApp/Issues/Issue28798.cs Provides a sample page for manual testing of the WebView rendering fix.
Comments suppressed due to low confidence (2)

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28798.cs:8

  • [nitpick] The test case class is named 'Issue28798', but the PR metadata references issue #28902. Consider aligning the identifiers for clarity.
internal class Issue28798 : _IssuesUITest

src/Controls/tests/TestCases.HostApp/Issues/Issue28798.cs:1

  • [nitpick] The file name uses 'Issue28798' whereas the PR metadata mentions issue #28902. It would be clearer if the identifiers were consistent.
namespace Maui.Controls.Sample.Issues;

Copy link
Member

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

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

AI says this will ot work, but so far your screenshot says it does.

From AI:

Doesn’t fix layout compositing problems between WebView and other views, because WebView uses a separate surface or texture layer, which is not affected by SetLayerType.

WebView itself ignores SetLayerType(), as it uses a separate SurfaceView or TextureView internally.

So since this can't make it worse, it is OK.

But Android may be wrong:

https://github.com/aosp-mirror/platform_frameworks_base/blob/1cdfff555f4a21f71ccc978290e2e212e2f8b168/core/java/android/webkit/WebView.java#L3045-L3049

It looks like it is doing somehting with this method:

    @Override
    public void setLayerType(int layerType, Paint paint) {
        super.setLayerType(layerType, paint);
        mProvider.getViewDelegate().setLayerType(layerType, paint);
    }

@mattleibow
Copy link
Member

/rebase

@mattleibow
Copy link
Member

mattleibow commented Jun 24, 2025

I guess it may work since CI is accelerated... So technically the test is not doing much.

@praveenkumarkarunanithi did you verify this works when using the android:hardwareAccelerated="false" on the activity or in the manifest?

@mattleibow
Copy link
Member

I tested it here and it works. AI is wrong. So sad.

@mattleibow mattleibow requested a review from jsuarezruiz June 24, 2025 22:42
if (OperatingSystem.IsAndroidVersionAtLeast(23) && Context?.ApplicationInfo?.Flags.HasFlag(Android.Content.PM.ApplicationInfoFlags.HardwareAccelerated) == false)
{
platformView.SetLayerType(Android.Views.LayerType.Software, null);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

(Optional) Could be nice to log this:

 System.Diagnostics.Debug.WriteLine(
                "WebView set to software rendering due to disabled hardware acceleration");

@@ -29,6 +29,11 @@ protected override AWebView CreatePlatformView()
platformView.Settings.DomStorageEnabled = true;
platformView.Settings.SetSupportMultipleWindows(true);

if (OperatingSystem.IsAndroidVersionAtLeast(23) && Context?.ApplicationInfo?.Flags.HasFlag(Android.Content.PM.ApplicationInfoFlags.HardwareAccelerated) == false)
Copy link
Contributor

Choose a reason for hiding this comment

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

The activities can have different hardware acceleration settings that override the app-level setting, but in out case, I think checking at app level is enough.

@PureWeen PureWeen changed the base branch from main to inflight/current June 25, 2025 21:54
@PureWeen PureWeen merged commit d271a63 into dotnet:inflight/current Jun 25, 2025
3 checks passed
github-actions bot pushed a commit that referenced this pull request Jun 26, 2025
…eration Disabled (#28934)

* Update WebViewHandler.Android.cs

* Test case added

* Update WebView.cs

* fix updated

* Update WebView.cs

* Create ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

* updated test case codes

* Update ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

* Update Issue28798.cs

* Update ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

updated google with example.com as google logo keeps changing.
PureWeen pushed a commit that referenced this pull request Jun 27, 2025
…eration Disabled (#28934)

* Update WebViewHandler.Android.cs

* Test case added

* Update WebView.cs

* fix updated

* Update WebView.cs

* Create ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

* updated test case codes

* Update ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

* Update Issue28798.cs

* Update ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

updated google with example.com as google logo keeps changing.
PureWeen pushed a commit that referenced this pull request Jun 28, 2025
…eration Disabled (#28934)

* Update WebViewHandler.Android.cs

* Test case added

* Update WebView.cs

* fix updated

* Update WebView.cs

* Create ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

* updated test case codes

* Update ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

* Update Issue28798.cs

* Update ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

updated google with example.com as google logo keeps changing.
github-actions bot pushed a commit that referenced this pull request Jun 29, 2025
…eration Disabled (#28934)

* Update WebViewHandler.Android.cs

* Test case added

* Update WebView.cs

* fix updated

* Update WebView.cs

* Create ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

* updated test case codes

* Update ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

* Update Issue28798.cs

* Update ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

updated google with example.com as google logo keeps changing.
github-actions bot pushed a commit that referenced this pull request Jun 29, 2025
…eration Disabled (#28934)

* Update WebViewHandler.Android.cs

* Test case added

* Update WebView.cs

* fix updated

* Update WebView.cs

* Create ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

* updated test case codes

* Update ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

* Update Issue28798.cs

* Update ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

updated google with example.com as google logo keeps changing.
github-actions bot pushed a commit that referenced this pull request Jul 1, 2025
…eration Disabled (#28934)

* Update WebViewHandler.Android.cs

* Test case added

* Update WebView.cs

* fix updated

* Update WebView.cs

* Create ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

* updated test case codes

* Update ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

* Update Issue28798.cs

* Update ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

updated google with example.com as google logo keeps changing.
github-actions bot pushed a commit that referenced this pull request Jul 2, 2025
…eration Disabled (#28934)

* Update WebViewHandler.Android.cs

* Test case added

* Update WebView.cs

* fix updated

* Update WebView.cs

* Create ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

* updated test case codes

* Update ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

* Update Issue28798.cs

* Update ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

updated google with example.com as google logo keeps changing.
github-actions bot pushed a commit that referenced this pull request Jul 2, 2025
…eration Disabled (#28934)

* Update WebViewHandler.Android.cs

* Test case added

* Update WebView.cs

* fix updated

* Update WebView.cs

* Create ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

* updated test case codes

* Update ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

* Update Issue28798.cs

* Update ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png

updated google with example.com as google logo keeps changing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-webview WebView community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Control disappears when android:hardwareAccelerated="false"
4 participants