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

Audit Mono.Android enums for missing [Flags] #7416

Closed
jpobst opened this issue Sep 27, 2022 · 2 comments · Fixed by #8310
Closed

Audit Mono.Android enums for missing [Flags] #7416

jpobst opened this issue Sep 27, 2022 · 2 comments · Fixed by #8310
Assignees
Labels
Area: Mono.Android Issues with the Android API binding (Mono.Android.dll).
Milestone

Comments

@jpobst
Copy link
Contributor

jpobst commented Sep 27, 2022

Context: #7409

I suspect there are many enums that are intended to be [Flags] but are missing the attribute.

It would be nice to write something that looks at the integer values of each enum and gave us a heads-up if the values look "flag-like" but the attribute has not been specified.

@jpobst jpobst added the Area: Mono.Android Issues with the Android API binding (Mono.Android.dll). label Sep 27, 2022
@jpobst jpobst added this to the .NET 8 milestone Sep 27, 2022
@jpobst jpobst self-assigned this Sep 27, 2022
@ghost ghost added the needs-triage Issues that need to be assigned. label Sep 27, 2022
@jpobst jpobst removed the needs-triage Issues that need to be assigned. label Sep 27, 2022
@rgroenewoudt
Copy link

There are a lot of missing flag attributes if I take a look in map.csv.

It could be autodetected by parsing the Java class annotations:
For example in the Android source for TextUtils.SAFE_STRING_FLAG_TRIM :

public class TextUtils {
...
@IntDef(flag = true, prefix = "CLEAN_STRING_FLAG_",
            value = {SAFE_STRING_FLAG_TRIM, SAFE_STRING_FLAG_SINGLE_LINE,
                    SAFE_STRING_FLAG_FIRST_LINE})
...
public static final int SAFE_STRING_FLAG_TRIM = 0x1;

flag = true indicates it's a flag.

More documentation: https://developer.android.com/reference/androidx/annotation/IntDef

@jpobst
Copy link
Contributor Author

jpobst commented Jan 12, 2023

I explored using the annotations, and while it gives us hints, there appear to be plenty of examples where they are wrong, so we can't just automatically trust them. For example, it lists these microphone locations as a set of flags:

https://developer.android.com/reference/android/media/MicrophoneInfo?hl=en#getLocation()

The values are:

- LOCATION_UNKNOWN - 0
- LOCATION_MAINBODY - 1
- LOCATION_MAINBODY_MOVABLE - 2
- LOCATION_PERIPHERAL - 3

I do not think a mic located on a "peripheral" is a combination of a mic on the "mainbody" and a movable mic on the "mainbody".

Some more examples that annotations declare as flags that I am skeptical about:

@jpobst jpobst modified the milestones: .NET 8, .NET 9 Planning Aug 21, 2023
jonpryor pushed a commit that referenced this issue Sep 1, 2023
…8310)

Fixes: #7416

We were hoping we could use the data that Google provides in
`annotations.xml` to create a better process for identifying which
sets of constants should be a `[Flags]` enum.  However, the data is
too dirty to create anything automatically (incorrect data from Google,
constants groups that don't map 1:1 to our enums, etc.).

However, it did provide a large list of potential candidates.  These
candidates were manually compared to the Android documentation and
appropriate ones have been updated to be generated with the `[Flags]`
attribute.
@jpobst jpobst modified the milestones: .NET 9 Planning, .NET 8 Sep 7, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: Mono.Android Issues with the Android API binding (Mono.Android.dll).
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants