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

Incorrect enum ApplicationExitInfoReason #9000

Closed
rgroenewoudt opened this issue Jun 4, 2024 · 1 comment · Fixed by #9003
Closed

Incorrect enum ApplicationExitInfoReason #9000

rgroenewoudt opened this issue Jun 4, 2024 · 1 comment · Fixed by #9003
Assignees
Labels
Area: Mono.Android Issues with the Android API binding (Mono.Android.dll). bug Component does not function as intended.
Milestone

Comments

@rgroenewoudt
Copy link

rgroenewoudt commented Jun 4, 2024

Android framework version

net8.0-android

Affected platform version

VS2022 17.10.1

Description

The enum Android.App.ApplicationExitInfoReason contains value Other but it has the incorrect numeric value.

Defined with value 10:

[IntDefinition("Android.App.ApplicationExitInfo.ReasonOther", JniField = "android/app/ApplicationExitInfo.REASON_OTHER"), SupportedOSPlatform("android30.0")]
Other = 10, // 0x0000000A

which is duplicate with:

[IntDefinition("Android.App.ApplicationExitInfo.ReasonUserRequested", JniField = "android/app/ApplicationExitInfo.REASON_USER_REQUESTED"), SupportedOSPlatform("android30.0")] 
UserRequested = 10, // 0x0000000A

According to Android documentation it should be value 13

We noticed this we have a lot of ApplicationExitInfo records with value '13' instead of a pretty enum name.

@rgroenewoudt rgroenewoudt added Area: Mono.Android Issues with the Android API binding (Mono.Android.dll). needs-triage Issues that need to be assigned. labels Jun 4, 2024
@jpobst jpobst removed the needs-triage Issues that need to be assigned. label Jun 4, 2024
@jpobst jpobst added this to the .NET 9 milestone Jun 4, 2024
@jpobst
Copy link
Contributor

jpobst commented Jun 4, 2024

Wrote a quick script to compare map.csv to api-34.xml to find all instances where our enum values do not match what is actually in API-34. It would appear that api-merge does not update constant values if they change when building api.xml.

// Changed value in API-26:
// https://developer.android.com/sdk/api_diff/26/changes/android.app.ActivityManager.RunningAppProcessInfo#android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE
// We have the correct value, api-34.xml is incorrect.
android/app/ActivityManager$RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE 230 != 130 [API-10]

// Changed value in API-28:
// https://developer.android.com/sdk/api_diff/28/changes/android.app.ActivityManager.RunningAppProcessInfo
// We have the correct value, api-34.xml is incorrect.
android/app/ActivityManager$RunningAppProcessInfo.IMPORTANCE_TOP_SLEEPING 325 != 150 [API-23]

// We bound this constant when API-30 was only Developer Preview 2, and it changed afterwards.
// Nowadays we do not do enumification until Google marks the API as "stable".
android/app/ApplicationExitInfo.REASON_OTHER 10 != 13 [API-30]

// https://developer.android.com/reference/android/content/pm/PermissionInfo#PROTECTION_MASK_FLAGS
// We have the correct value, api-34.xml is incorrect.
android/content/pm/PermissionInfo.PROTECTION_MASK_FLAGS 65520 != 240 [API-16]

// This "constant" is deprecated and documented as "can change from release to release":
// https://developer.android.com/reference/android/net/http/SslError#SSL_MAX_ERROR
// We have the correct value, api-34.xml is incorrect.
android/net/http/SslError.SSL_MAX_ERROR 6 != 4 [API-10]

// These values are correct, not sure why api-34.xml is missing them
android/view/animation/Transformation.TYPE_ALPHA 1 !=  [API-10]
android/view/animation/Transformation.TYPE_BOTH 3 !=  [API-10]
android/view/animation/Transformation.TYPE_IDENTITY 0 !=  [API-10]
android/view/animation/Transformation.TYPE_MATRIX 2 !=  [API-10]

@jpobst jpobst added the bug Component does not function as intended. label Jun 5, 2024
jonpryor pushed a commit that referenced this issue Jun 7, 2024
…9003)

Fixes: #9000

Context: 3ca2a07
Context: 379f7cd

The field [`ApplicationExitInfo.REASON_OTHER`][0] was added in API-30,
and in our infinite wisdom we enumified this member in
API-R Developer Preview 2 (3ca2a07) instead of waiting for the final
API contract.

In API-R DP2, `ApplicationExitInfo.REASON_OTHER` had the value 10,
and was enumified as `ApplicationExitInfoReasonType.ReasonUnknown`
with value 10.

`ApplicationExitInfoReasonType` was renamed to
`ApplicationExitInfoReason` in 379f7cd with API-R Developer Preview 4.

The value of `ApplicationExitInfo.REASON_OTHER` [changed to 13][1]
in API-R Developer Preview 3, but we did not notice and did not
update the previous enumification.

This process has been mitigated since, as we no longer enumify
unstable API levels: we wait until Google marks the API as "stable"
before we perform enumification.

Update the enum to the correct value so it will be correct in .NET 9+.

[0]: https://developer.android.com/reference/android/app/ApplicationExitInfo#REASON_OTHER
[1]: https://developer.android.com/sdk/api_diff/r-dp3-incr/changes/android.app.ApplicationExitInfo
jonpryor pushed a commit that referenced this issue Jun 7, 2024
Context: #9000
Context: ac3b405

In Issue #9000, we learned that:

  - Constant values can change between Android API levels
  - `api-merge` does not update constant values in the final `api.xml`
    if they do change

Update `api-merge` to update constant values if they change, and update
`api-VanillaIceCream.xml` with the new `api-merge` logic.
@github-actions github-actions bot locked and limited conversation to collaborators Jul 8, 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). bug Component does not function as intended.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants