Skip to content
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

[Mono.Android] Fix some incorrect enums. #7670

Merged
merged 1 commit into from
Jan 18, 2023
Merged

[Mono.Android] Fix some incorrect enums. #7670

merged 1 commit into from
Jan 18, 2023

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Jan 5, 2023

Using Android's API-33 annotations.zip, some missing and incorrect enum mappings were found.

Missed Enumeration

Enums that were previously left as constants have been enumified and have had the old members added back to the API with manual additions code marked with [Obsolete].

I,23,android/hardware/camera2/CameraAccessException.MAX_CAMERAS_IN_USE,5,,,,

to

E,23,android/hardware/camera2/CameraAccessException.MAX_CAMERAS_IN_USE,5,Android.Hardware.Camera2.CameraAccessErrorType,MaxCameraInUse,keep,

[Obsolete ("This constant will be removed in the future version. Use Android.Hardware.Camera2.CameraAccessErrorType enum directly instead of this field.")]
[Register ("MAX_CAMERAS_IN_USE", ApiSince=23)]
public const int MaxCamerasInUse = 5;

Incorrect Enumeration

Other constants were assigned to the wrong enumeration. These have been marked as [Obsolete] and new values have been added to the correct enumeration.

Example:

E,30,android/app/usage/UsageStatsManager.STANDBY_BUCKET_RESTRICTED,45,Android.App.Usage.UsageStatsInterval,Restricted,remove,

to:

E,30,android/app/usage/UsageStatsManager.STANDBY_BUCKET_RESTRICTED,45,Android.App.Usage.UsageStatsInterval,Restricted,remove,,-1
A,30,,45,Android.App.Usage.StandbyBucket,Restricted,remove,,

@jpobst jpobst force-pushed the enum-audit branch 3 times, most recently from cfac5b0 to 0396dfa Compare January 5, 2023 20:52
jonpryor pushed a commit to dotnet/java-interop that referenced this pull request Jan 7, 2023
…1070)

Context: dotnet/android#7670

While auditing the `Mono.Android.dll`, we've found that some constants
were added to the wrong enums.

Consider [`xamarin-android/src/Mono.Android/map.csv`][0],
lines 739-743:

	E,28,android/app/usage/UsageStatsManager.STANDBY_BUCKET_ACTIVE,10,Android.App.Usage.StandbyBucket,Active,remove,
	E,28,android/app/usage/UsageStatsManager.STANDBY_BUCKET_FREQUENT,30,Android.App.Usage.StandbyBucket,Frequent,remove,
	E,28,android/app/usage/UsageStatsManager.STANDBY_BUCKET_RARE,40,Android.App.Usage.StandbyBucket,Rare,remove,
	E,30,android/app/usage/UsageStatsManager.STANDBY_BUCKET_RESTRICTED,45,Android.App.Usage.UsageStatsInterval,Restricted,remove,
	E,28,android/app/usage/UsageStatsManager.STANDBY_BUCKET_WORKING_SET,20,Android.App.Usage.StandbyBucket,WorkingSet,remove,


`STANDBY_BUCKET_RESTRICTED` should have been added to `StandbyBucket`
instead of `UsageStatsInterval`.

To fix this in a backwards-compatible way, we can add it to both enums:

	E,30,android/app/usage/UsageStatsManager.STANDBY_BUCKET_RESTRICTED,45,Android.App.Usage.StandbyBucket,Restricted,remove,
	A,30,,45,Android.App.Usage.UsageStatsInterval,Restricted,remove,

However, we have no way to mark `UsageStatsInterval.Restricted` as
`[Obsolete]`, so people may still unintentionally use it.

Add a new field to our csv that allows us to set a constant's
`@deprecated-since` field, the `30` at the end:

	A,30,,45,Android.App.Usage.UsageStatsInterval,Restricted,remove,,30

This allows us to generate:

	[global::System.Runtime.Versioning.ObsoletedOSPlatform ("android30.0")]
	Restricted = 45

Additionally, when the cause is that we accidentally added an invalid
value to the enum, we should provide a better obsolete message, letting
the user know that the value will not function.  This is done by
setting `@deprecated-since` to `-1`:

	A,30,,45,Android.App.Usage.UsageStatsInterval,Restricted,remove,,-1

resulting in:

	[global::System.Obsolete (@"This value was incorrectly added to the enumeration and is not a valid value")]
	Restricted = 45

[0]: https://github.com/xamarin/xamarin-android/blob/cc70ce20aff6934532a8cb6a7bddbf3710fd7e1c/src/Mono.Android/map.csv
@jpobst jpobst force-pushed the enum-audit branch 3 times, most recently from deb7119 to c0c5c93 Compare January 12, 2023 15:21
@jpobst jpobst marked this pull request as ready for review January 17, 2023 15:04
@jpobst jpobst requested a review from jonpryor as a code owner January 17, 2023 15:04
@jonpryor jonpryor merged commit 8cb94dc into main Jan 18, 2023
@jonpryor jonpryor deleted the enum-audit branch January 18, 2023 01:59
grendello added a commit to grendello/xamarin-android that referenced this pull request Jan 18, 2023
* main:
  [Mono.Android] Android.Telecom.InCallService.SetAudioRoute() + enum (dotnet#7711)
  [Mono.Android] Fix some incorrect enums. (dotnet#7670)
  [Xamarin.Android.Build.Tasks] _Microsoft.Android.Resource.Designer namespace (dotnet#7681)
  LEGO: Merge pull request 7713
  [Xamarin.Android.Build.Tasks] lazily populate Resource lookup (dotnet#7686)
grendello added a commit to grendello/xamarin-android that referenced this pull request Jan 19, 2023
* main:
  [ci] Pass token when building Designer tests (dotnet#7715)
  [Mono.Android] Android.Telecom.InCallService.SetAudioRoute() + enum (dotnet#7711)
  [Mono.Android] Fix some incorrect enums. (dotnet#7670)
  [Xamarin.Android.Build.Tasks] _Microsoft.Android.Resource.Designer namespace (dotnet#7681)
  LEGO: Merge pull request 7713
  [Xamarin.Android.Build.Tasks] lazily populate Resource lookup (dotnet#7686)
grendello added a commit to grendello/xamarin-android that referenced this pull request Jan 26, 2023
* main: (32 commits)
  [monodroid] Replace `exit()` with `abort()` in native code (dotnet#7734)
  Bump to xamarin/Java.Interop/main@8a1ae57 (dotnet#7738)
  [build] bump `$(AndroidNet7Version)` (dotnet#7737)
  Bump to xamarin/Java.Interop/main@1366d99 (dotnet#7718)
  [Xamarin.Android.Build.Tasks] fix AndroidGenerateResourceDesigner (dotnet#7721)
  Bump to xamarin/monodroid@50faac94 (dotnet#7725)
  Revert "[Xamarin.Android.Build.Tasks] fix cases of missing `@(Reference)` (dotnet#7642)" (dotnet#7726)
  [marshal methods] Properly support arrays of arrays (dotnet#7707)
  Bump to dotnet/installer@9962c6a 8.0.100-alpha.1.23063.11 (dotnet#7677)
  [Actions] Add action to bump the hash used for the unified pipeline (dotnet#7712)
  Bump to xamarin/xamarin-android-tools/main@099fd95 (dotnet#7709)
  [ci] Move build stages into yaml templates (dotnet#7553)
  [Xamarin.Android.Build.Tasks] fix NRE in `<GenerateResourceCaseMap/>` (dotnet#7716)
  [ci] Pass token when building Designer tests (dotnet#7715)
  [Mono.Android] Android.Telecom.InCallService.SetAudioRoute() + enum (dotnet#7711)
  [Mono.Android] Fix some incorrect enums. (dotnet#7670)
  [Xamarin.Android.Build.Tasks] _Microsoft.Android.Resource.Designer namespace (dotnet#7681)
  LEGO: Merge pull request 7713
  [Xamarin.Android.Build.Tasks] lazily populate Resource lookup (dotnet#7686)
  [Xamarin.Android.Build.Tasks] skip XA1034 logic in some cases (dotnet#7680)
  ...
@github-actions github-actions bot locked and limited conversation to collaborators Jan 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants