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

Android: ASensorManager_getInstance() deprecated since API level 26 #11404

Open
hhromic opened this issue Nov 3, 2024 · 3 comments
Open

Android: ASensorManager_getInstance() deprecated since API level 26 #11404

hhromic opened this issue Nov 3, 2024 · 3 comments
Milestone

Comments

@hhromic
Copy link

hhromic commented Nov 3, 2024

The SDL Sensor API in Android currently uses ASensorManager_getInstance() to initialize sensors. However, this function has been deprecated since API level 26 and replaced with ASensorManager_getInstanceForPackage() instead. More info here.

This deprecation generates the following warning when building:

C/C++: src/sensor/android/SDL_androidsensor.c:56:26: warning: 'ASensorManager_getInstance' is deprecated: first deprecated in Android 26 - Use ASensorManager_getInstanceForPackage instead [-Wdeprecated-declarations]
C/C++:    56 |     SDL_sensor_manager = ASensorManager_getInstance();
C/C++:       |                          ^
C/C++: /opt/android-sdk/ndk/27.2.12479018/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/android/sensor.h:751:17: note: 'ASensorManager_getInstance' has been explicitly marked deprecated here
C/C++:   751 | ASensorManager* ASensorManager_getInstance()
C/C++:       |                 ^
C/C++: 1 warning generated.

This is the only warning we can see about SDL (using version 2.30.9, but the same code is used in SDL3) at the moment.

Perhaps a pre-processor condition could be used to use the older function if API level < 26 and the new one otherwise?

@slouken
Copy link
Collaborator

slouken commented Nov 3, 2024

It's not quite that simple, it needs to be a runtime check, and you need to dynamically load the new function so that SDL continues to function on older devices. We also need some way of identifying what package is used for loading.

Feel free to submit a PR. :)

@slouken slouken added this to the 3.2.0 milestone Nov 3, 2024
@hhromic
Copy link
Author

hhromic commented Nov 3, 2024

Doh, indeed it has to be a runtime check, not a compiler preprocessor one. Brain glitch! :)
I also agree about the problem of having to determine what package name to use. I'm not really an Android developer, so I didn't know about also having to dynamically load one function or the other, but makes sense.

While I would love to contribute to fixing this deprecation warning, I'm probably not the right person given that I am not experienced enough in Android applications at the required level for these considerations.

I just checked the Deprecation Policy for Android 15, and looks like deprecated APIs are not expected to be removed:

Deprecation means that we've ended official support for the APIs, but they will continue to remain available to developers.

So at least fixing the deprecation has no immediate urgency.

@slouken
Copy link
Collaborator

slouken commented Nov 3, 2024

Yep!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants