Skip to content

Commit

Permalink
[Mono.Android] Fix View.SystemUiVisibility enumification (dotnet#7730)
Browse files Browse the repository at this point in the history
Fixes: dotnet#4290

The [`View.getSystemUiVisibility()` method][0], bound as the
[`View.SystemUiVisibility` property][1], and the
[`WindowManager.LayoutParams.systemUiVisibility` field][2], bound as
the [`WindowManagerLayoutParams.SystemUiVisibility` property][3],
were incorrectly enumified to use the `StatusBarVisibility` enum when
they should have used the `SystemUiFlags` enum.

We cannot change the existing members, as that would be an ABI and
API break.  Furthermore, as these are properties, we cannot overload
them either.

"Fix" this by:

 1. Marking the existing properties as `[Obsolete]`, and
 2. Introduce *new* `SystemUiFlags` properties.

Additionally, these members were deprecated in API-30, so make sure
we reflect that on the new method.  It's still worth fixing this, as
people will be using this for pre-API-30 device support for years to
come.

These changes will only be present in API-34+.
The resulting API is:

	partial class View {
	    // Original property
	    [Obsolete ("This property has an incorrect enumeration type. Use the SystemUiFlags property instead.")]
	    public StatusBarVisibility SystemUiVisibility {get; set;}

	    // New hawtness
	    [ObsoletedOSPlatform ("android30.0", "…")]
	    public SystemUiFlags SystemUiFlags {get; set;}
	}
	partial class WindowManagerLayoutParams {
	    // Original property
	    [Obsolete ("This property has an incorrect enumeration type. Use the SystemUiFlags property instead.")]
	    public StatusBarVisibility SystemUiVisibility {get; set;}

	    // New hawtness
	    [ObsoletedOSPlatform ("android30.0", "…")]
	    public SystemUiFlags SystemUiFlags {get; set;}
	}

[0]: https://developer.android.com/reference/android/view/View#getSystemUiVisibility()
[1]: https://learn.microsoft.com/en-us/dotnet/api/android.views.view.systemuivisibility?view=xamarin-android-sdk-12
[2]: https://developer.android.com/reference/android/view/WindowManager.LayoutParams#systemUiVisibility
[3]: https://learn.microsoft.com/en-us/dotnet/api/android.views
  • Loading branch information
jpobst authored Jan 27, 2023
1 parent b00185c commit c1752ca
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Mono.Android/Android.Telecom/InCallService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Android.Telecom
public abstract partial class InCallService : Android.App.Service
{
#if ANDROID_23
[Obsolete ("Incorrect enum parameter, use the overload that takes a CallAudioRoute paramter instead.")]
[Obsolete ("Incorrect enum parameter, use the overload that takes a CallAudioRoute parameter instead.")]
[global::System.Runtime.Versioning.SupportedOSPlatformAttribute ("android23.0")]
public void SetAudioRoute ([global::Android.Runtime.GeneratedEnum] Android.Telecom.VideoQuality route)
{
Expand Down
8 changes: 8 additions & 0 deletions src/Mono.Android/Android.Views/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,13 @@ public bool FitsSystemWindows ()
return InvokeFitsSystemWindows ();
}
#endif

#if NET && ANDROID_34
[global::System.Runtime.Versioning.ObsoletedOSPlatform ("android30.0", "These flags are deprecated. Use WindowInsetsController instead.")]
public SystemUiFlags SystemUiFlags {
get => (SystemUiFlags) SystemUiVisibility;
set => SystemUiVisibility = (Android.Views.StatusBarVisibility) value;
}
#endif
}
}
15 changes: 15 additions & 0 deletions src/Mono.Android/Android.Views/WindowManagerLayoutParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace Android.Views
{
partial class WindowManagerLayoutParams
{
#if NET && ANDROID_34
[global::System.Runtime.Versioning.ObsoletedOSPlatform ("android30.0", "These flags are deprecated. Use WindowInsetsController instead.")]
public SystemUiFlags SystemUiFlags {
get => (SystemUiFlags) SystemUiVisibility;
set => SystemUiVisibility = (Android.Views.StatusBarVisibility) value;
}
#endif
}
}
1 change: 1 addition & 0 deletions src/Mono.Android/Mono.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<Compile Include="Android.Runtime\DynamicMethodNameCounter.cs" />
<Compile Include="Android.Runtime\IJavaObjectValueMarshaler.cs" />
<Compile Include="Android.Telecom\InCallService.cs" />
<Compile Include="Android.Views\WindowManagerLayoutParams.cs" />
</ItemGroup>

<Import Project="..\Xamarin.Android.NamingCustomAttributes\Xamarin.Android.NamingCustomAttributes.projitems" Label="Shared" Condition="Exists('..\Xamarin.Android.NamingCustomAttributes\Xamarin.Android.NamingCustomAttributes.projitems')" />
Expand Down
7 changes: 7 additions & 0 deletions src/Mono.Android/metadata
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,13 @@
<remove-node api-since="33" path="/api/package[@name='java.util.concurrent']/class[@name='TimeUnit']/method[@name='of' and count(parameter)=1 and parameter[1][@type='java.time.temporal.ChronoUnit']]" />
<remove-node api-since="33" path="/api/package[@name='java.util.concurrent']/class[@name='TimeUnit']/method[@name='toChronoUnit' and count(parameter)=0]" />

<attr api-since="34" path="/api/package[@name='android.view']/class[@name='WindowManager.LayoutParams']/field[@name='systemUiVisibility']" name="deprecated">This property has an incorrect enumeration type. Use the SystemUiFlags property instead.</attr>
<attr api-since="34" path="/api/package[@name='android.view']/class[@name='WindowManager.LayoutParams']/field[@name='systemUiVisibility']" name="deprecated-since">0</attr>
<attr api-since="34" path="/api/package[@name='android.view']/class[@name='View']/method[@name='getSystemUiVisibility']" name="deprecated">This property has an incorrect enumeration type. Use the SystemUiFlags property instead.</attr>
<attr api-since="34" path="/api/package[@name='android.view']/class[@name='View']/method[@name='getSystemUiVisibility']" name="deprecated-since">0</attr>
<attr api-since="34" path="/api/package[@name='android.view']/class[@name='View']/method[@name='setSystemUiVisibility']" name="deprecated">This property has an incorrect enumeration type. Use the SystemUiFlags property instead.</attr>
<attr api-since="34" path="/api/package[@name='android.view']/class[@name='View']/method[@name='setSystemUiVisibility']" name="deprecated-since">0</attr>

<!--
***********************************************************************
THE FOLLOWING LINES MUST BE CREATED FOR ANY NEW PLATFORM THAT IS ADDED.
Expand Down

0 comments on commit c1752ca

Please sign in to comment.