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

Missing SupportedOSPlatformAttribute for enum members, const members #1037

Closed
rgroenewoudt opened this issue Sep 15, 2022 · 2 comments · Fixed by #1066
Closed

Missing SupportedOSPlatformAttribute for enum members, const members #1037

rgroenewoudt opened this issue Sep 15, 2022 · 2 comments · Fixed by #1066
Assignees
Labels
enhancement Proposed change to current functionality generator Issues binding a Java library (generator, class-parse, etc.)
Milestone

Comments

@rgroenewoudt
Copy link

rgroenewoudt commented Sep 15, 2022

Android application type

Android for .NET (net6.0-android, etc.)

Affected platform version

VS 2022 17.3.3

Description

In .NET 6 Android the consts are missing SupportedOSPlatformAttribute.

Examples:

  • Manifest.Permission.PostNotifications:
  • Vibrator.VibrationEffectSupportNo
  • TelecomManager.ActionPostCall

APILevel is already present in RegisterAttribute.ApiSince.

[Register("ACTION_POST_CALL", ApiSince=30)]
public const string ActionPostCall = "android.telecom.action.POST_CALL";

I would also expect that the new enum VibrationEffectSupport also has the SupportedOSPlatformAttribute as the values are only available since API 30.

public enum VibrationEffectSupport
{
  [IntDefinition("Android.OS.Vibrator.VibrationEffectSupportUnknown", JniField="android/os/Vibrator.VIBRATION_EFFECT_SUPPORT_UNKNOWN")]
  Unknown = 0,
  [IntDefinition("Android.OS.Vibrator.VibrationEffectSupportYes", JniField="android/os/Vibrator.VIBRATION_EFFECT_SUPPORT_YES")]
  Yes = 1,
  [IntDefinition("Android.OS.Vibrator.VibrationEffectSupportNo", JniField="android/os/Vibrator.VIBRATION_EFFECT_SUPPORT_NO")]
  No = 2
}

Steps to Reproduce

Create new .NET 6 Android project and use Android consts/enums.

Did you find any workaround?

No response

Relevant log output

No response

@jpobst jpobst transferred this issue from dotnet/android Sep 15, 2022
@jpobst jpobst added enhancement Proposed change to current functionality generator Issues binding a Java library (generator, class-parse, etc.) and removed needs-triage labels Sep 15, 2022
@jpobst jpobst added this to the 8.0.0 milestone Sep 15, 2022
@jpobst
Copy link
Contributor

jpobst commented Sep 15, 2022

Yep, we should add support for these attributes for const's and enum's in generator.

@jonpryor jonpryor changed the title Missing SupportedOSPlatformAttribute for enums Missing SupportedOSPlatformAttribute for enum members, const members Sep 15, 2022
@rgroenewoudt
Copy link
Author

ObsoletedInOSPlatformAttribute would also be good to have.

jonpryor pushed a commit that referenced this issue Oct 20, 2022
Context: #1037

Currently we do not add `[SupportedOSPlatform]` attributes to bound
`const` fields, which can lead to customers using them on platforms
where they are not supported:

	namespace Android.Telecom {
	    public partial class TelecomManager : Java.Lang.Object {
	        [Register("ACTION_POST_CALL", ApiSince=30)]
	        public const string ActionPostCall = "android.telecom.action.POST_CALL";
	    }
	}

Update `generator` so that `[SupportedOSPlatform]` is emitted for
such `const` fields:

	namespace Android.Telecom {
	    public partial class TelecomManager : Java.Lang.Object {
	        [Register("ACTION_POST_CALL", ApiSince=30)]
	        [global::System.Runtime.Versioning.SupportedOSPlatformAttribute ("android30.0")]
	        public const string ActionPostCall = "android.telecom.action.POST_CALL";
	    }
	}

Note this does not address the `enum` part of #1037, which will
require a much more involved fix.
jonpryor pushed a commit that referenced this issue Dec 8, 2022
Context: #1037

Refactor `EnumGenerator` to use `SourceWriters` instead of
`TextWriter`.  This will make it possible to use our existing code to
apply `[PlatformOSSupported]` attributes to enums in a future PR.

This is a separate PR to help verify there was no output changed from
the refactor.
jonpryor pushed a commit that referenced this issue Dec 14, 2022
…1066)

Fixes: #1037

Adds support for emitting `[Obsolete]`, `[ObsoletedOSPlatform]`, and
`[SupportedOSPlatform]` custom attributes on enum members.

~~ [SupportedOSPlatform] ~~

The data for `[SupportedOSPlatform]` comes from the values provided
in the enum-mapping file (b00e644), e.g.
[`xamarin-android/src/Mono.Android/map.csv`][0]:

	// src/Mono.Android/map.csv
	E,29,android/media/MediaRecorder$AudioEncoder.OPUS,7,Android.Media.AudioEncoder,Opus,keep,

The `29` is the API in which we added the enum, which becomes
`[SupportedOSPlatform("android-29.0")]`.

~~ [Obsolete] and [ObsoletedOSPlatform] ~~

The data for the "obsolete" attributes comes from the `deprecated`
and `deprecated-since` attributes on the original field in the
`api.xml`, if it can be found.  For example, given:

	<class name="AccessibilityServiceInfo" jni-signature="Landroid/accessibilityservice/AccessibilityServiceInfo;" …>
	    <field
	            deprecated="deprecated"
	            final="true"
	            name="CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITY"
	            jni-signature="I"
	            static="true"
	            transient="false"
	            type="int"
	            type-generic-aware="int"
	            value="4"
	            visibility="public"
	            volatile="false"
	            deprecated-since="26"
	    />
	</class>

in combination with these `map.csv` (b00e644) entries:

	A,0,,0,Android.AccessibilityServices.AccessibilityServiceCapabilities,None,remove,
	E,18,android/accessibilityservice/AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITY,4,Android.AccessibilityServices.AccessibilityServiceCapabilities,CanRequestEnhancedWebAccessibility,remove,

results in:

	/* partial */ enum AccessibilityServiceCapabilities {
	    // When using classic obsolete attributes:
	    [global::System.Obsolete("deprecated")]

	    // When using new obsolete attributes:
	    [global::System.Runtime.Versioning.ObsoletedOSPlatform("android31.0")]
	    CanRequestEnhancedWebAccessibility = 4,
	}

One wrinkle is we may have obsoleted the field because we want the
user to use the enum instead:

	<field
	    deprecated='This constant will be removed in the future version. Use Android.App.RecentTaskFlags enum directly instead of this field.'
	    name='RECENT_IGNORE_UNAVAILABLE'
	    …
	/>

We need to detect this message and not obsolete the enum in this case.

[0]: https://github.com/xamarin/xamarin-android/blob/17213ea184e23a9020451b265fec459558278489/src/Mono.Android/map.csv
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Proposed change to current functionality generator Issues binding a Java library (generator, class-parse, etc.)
Projects
None yet
2 participants