fix: support Android 17 (getActiveSessionsForUser(ComponentName, int) was removed) - #293
Conversation
|
A couple of small cleanup points before merging:
The class introduces its own Could you please avoid introducing a separate logging mechanism here? If this error does not need to be logged, I'd prefer to just remove the At the very least, please don't duplicate the The Android 17 compatibility fix itself looks good to me. |
|
I made the fix as you suggested:
The only remaining companion member is USER_ALL = -1 (used twice for the reflective calls). |
Problem
On Android 17 (SDK 37) the module stops switching tracks: every volume key event throws
java.lang.NoSuchMethodException for
android.media.session.MediaSessionManager.getActiveSessionsForUser [ComponentName, int].
Root cause
AOSP refactored MediaSessionManager:
a @SystemApi (ComponentName, UserHandle) overload, and a new getActiveSessionsForPackage().
Fix
Replace the single reflective call with a fallback chain:
UserHandle.ALL is resolved reflectively because it is not part of the public SDK.
Compatibility / Testing
Tested on HyperOS 4 (Android 17, SDK 37), module scope = system:
long-press volume keys with screen off switches tracks as expected.