Skip to content

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

Description

@jpobst

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.

Activity

  1. added this to the .NET 8 milestone on Sep 27, 2022
  2. self-assigned this
    on Sep 27, 2022
  3. ghost added
    needs-triageIssues that need to be assigned.
    on Sep 27, 2022
  4. rgroenewoudt commented on Oct 7, 2022

    @rgroenewoudt

    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

  5. jpobst commented on Jan 12, 2023

    @jpobst
    ContributorAuthor

    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:

  6. modified the milestones: .NET 8, .NET 9 Planning on Aug 21, 2023
  7. modified the milestones: .NET 9 Planning, .NET 8 on Sep 7, 2023
  8. locked and limited conversation to collaborators on Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area: Mono.AndroidIssues with the Android API binding (Mono.Android.dll).

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions