ingageco / capacitor-music-controls-plugin

An update to Cordova Music Controls plugin to support Capacitor
16 stars 3 forks source link

Android API level 34: new mutable implicit PendingIntent will be blocked targetting U+ #8

Closed NorthFred closed 1 year ago

NorthFred commented 1 year ago

When testing this capacitor plugin with Android API level 34 ("UpsideDownCake"), there are new errors shown related to the PendingIntents. Below is an example.

W/PendingIntent: android.app.StackTrace: New mutable implicit PendingIntent: pkg=xx.xxxxxxxx.xxxx, action=music-controls-media-button, featureId=null. This will be blocked once the app targets U+ for security reasons.

V/Capacitor/Plugin: To native (Capacitor plugin): callbackId: 27798462, pluginId: CapacitorMusicControls, methodName: create
V/Capacitor: callback: 27798462, pluginId: CapacitorMusicControls, methodName: create, methodData: {"ticker":"XXXXXX","album":"XXXXXX","track":"XXXXXX","artist":"XXXXXX","cover":"https:\/\/www.xxxxxx.xx\/xxxxxx\/music_player_default.jpg","isPlaying":true,"dismissable":true,"hasPrev":false,"hasNext":false,"hasClose":true,"playIcon":"ic_stat_play","pauseIcon":"ic_stat_stop","closeIcon":"ic_stat_close","notificationIcon":"ic_stat_notification"}
V/Capacitor/Plugin: To native (Capacitor plugin): callbackId: 27798463, pluginId: Http, methodName: request
V/Capacitor: callback: 27798463, pluginId: Http, methodName: request, methodData: {"url":"http:\/\/xx.xxxxxxxxxx.com:xxxxx\/stats?sid=1&json=1","method":"GET","headers":{"Accept":"application\/json"}}
W/MediaSessionCompat: Couldn't find a unique registered media button receiver in the given context.
D/CompatibilityChangeReporter: Compat change id reported: 236704164; UID 10168; state: DISABLED
W/PendingIntent: android.app.StackTrace: New mutable implicit PendingIntent: pkg=xx.xxxxxxxx.xxxx, action=music-controls-media-button, featureId=null. This will be blocked once the app targets U+ for security reasons.
        at android.app.PendingIntent.checkPendingIntent(PendingIntent.java:442)
        at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:724)
        at android.app.PendingIntent.getBroadcast(PendingIntent.java:711)
        at com.ingageco.capacitormusiccontrols.CapacitorMusicControls.initialize(CapacitorMusicControls.java:159)
        at com.ingageco.capacitormusiccontrols.CapacitorMusicControls.create(CapacitorMusicControls.java:71)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138)
        at com.getcapacitor.Bridge.lambda$callPluginMethod$0$com-getcapacitor-Bridge(Bridge.java:763)
        at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8)
        at android.os.Handler.handleCallback(Handler.java:958)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:205)
        at android.os.Looper.loop(Looper.java:294)
        at android.os.HandlerThread.run(HandlerThread.java:67)
ingageco commented 1 year ago

This is possibly because i changed the PendingIntents to Mutable instead of Immutable. I'll switch them to Immutable and see if this make s the difference. The error seems to have a problem specifically with the Mutable option.

Markus-Brand commented 1 year ago

I have some similar issues. The app crashes when executing the CapacitorMusicControls.create call with this log:

04-12 14:00:03.654  4886  4886 V Capacitor: callback: 102284134, pluginId: CapacitorMusicControls, methodName: create, methodData: {"track":"Track Title","artist":"Artist Name","isPlaying":true,"hasPrev":false,"hasNext":false,"hasClose":true,"dismissable":true}
04-12 14:00:03.661  4886  5035 E Capacitor: Serious error executing plugin
04-12 14:00:03.661  4886  5035 E Capacitor: java.lang.reflect.InvocationTargetException
04-12 14:00:03.661  4886  5035 E Capacitor:     at java.lang.reflect.Method.invoke(Native Method)
04-12 14:00:03.661  4886  5035 E Capacitor:     at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138)
04-12 14:00:03.661  4886  5035 E Capacitor:     at com.getcapacitor.Bridge.lambda$callPluginMethod$0$com-getcapacitor-Bridge(Bridge.java:767)
04-12 14:00:03.661  4886  5035 E Capacitor:     at com.getcapacitor.Bridge$$ExternalSyntheticLambda5.run(Unknown Source:8)
04-12 14:00:03.661  4886  5035 E Capacitor:     at android.os.Handler.handleCallback(Handler.java:942)
04-12 14:00:03.661  4886  5035 E Capacitor:     at android.os.Handler.dispatchMessage(Handler.java:99)
04-12 14:00:03.661  4886  5035 E Capacitor:     at android.os.Looper.loopOnce(Looper.java:226)
04-12 14:00:03.661  4886  5035 E Capacitor:     at android.os.Looper.loop(Looper.java:313)
04-12 14:00:03.661  4886  5035 E Capacitor:     at android.os.HandlerThread.run(HandlerThread.java:67)
04-12 14:00:03.661  4886  5035 E Capacitor: Caused by: java.lang.IllegalArgumentException: --readcted--: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
04-12 14:00:03.661  4886  5035 E Capacitor: Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
04-12 14:00:03.661  4886  5035 E Capacitor:     at android.app.PendingIntent.checkFlags(PendingIntent.java:408)
04-12 14:00:03.661  4886  5035 E Capacitor:     at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:688)
04-12 14:00:03.661  4886  5035 E Capacitor:     at android.app.PendingIntent.getBroadcast(PendingIntent.java:675)
04-12 14:00:03.661  4886  5035 E Capacitor:     at android.support.v4.media.session.MediaSessionCompat.<init>(MediaSessionCompat.java:489)
04-12 14:00:03.661  4886  5035 E Capacitor:     at android.support.v4.media.session.MediaSessionCompat.<init>(MediaSessionCompat.java:456)
04-12 14:00:03.661  4886  5035 E Capacitor:     at com.ingageco.capacitormusiccontrols.CapacitorMusicControls.initialize(CapacitorMusicControls.java:145)
04-12 14:00:03.661  4886  5035 E Capacitor:     at com.ingageco.capacitormusiccontrols.CapacitorMusicControls.create(CapacitorMusicControls.java:71)
04-12 14:00:03.661  4886  5035 E Capacitor:     ... 9 more
04-12 14:00:03.661  4886  5035 E AndroidRuntime: FATAL EXCEPTION: CapacitorPlugins
04-12 14:00:03.661  4886  5035 E AndroidRuntime: Process: --redacted--, PID: 4886
04-12 14:00:03.661  4886  5035 E AndroidRuntime: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
04-12 14:00:03.661  4886  5035 E AndroidRuntime:        at com.getcapacitor.Bridge.lambda$callPluginMethod$0$com-getcapacitor-Bridge(Bridge.java:776)
04-12 14:00:03.661  4886  5035 E AndroidRuntime:        at com.getcapacitor.Bridge$$ExternalSyntheticLambda5.run(Unknown Source:8)
04-12 14:00:03.661  4886  5035 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:942)
04-12 14:00:03.661  4886  5035 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:99)
04-12 14:00:03.661  4886  5035 E AndroidRuntime:        at android.os.Looper.loopOnce(Looper.java:226)
04-12 14:00:03.661  4886  5035 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:313)
04-12 14:00:03.661  4886  5035 E AndroidRuntime:        at android.os.HandlerThread.run(HandlerThread.java:67)
04-12 14:00:03.661  4886  5035 E AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException
04-12 14:00:03.661  4886  5035 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
04-12 14:00:03.661  4886  5035 E AndroidRuntime:        at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138)
04-12 14:00:03.661  4886  5035 E AndroidRuntime:        at com.getcapacitor.Bridge.lambda$callPluginMethod$0$com-getcapacitor-Bridge(Bridge.java:767)
04-12 14:00:03.661  4886  5035 E AndroidRuntime:        ... 6 more
04-12 14:00:03.661  4886  5035 E AndroidRuntime: Caused by: java.lang.IllegalArgumentException: --redacted--: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
04-12 14:00:03.661  4886  5035 E AndroidRuntime: Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
04-12 14:00:03.661  4886  5035 E AndroidRuntime:        at android.app.PendingIntent.checkFlags(PendingIntent.java:408)
04-12 14:00:03.661  4886  5035 E AndroidRuntime:        at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:688)
04-12 14:00:03.661  4886  5035 E AndroidRuntime:        at android.app.PendingIntent.getBroadcast(PendingIntent.java:675)
04-12 14:00:03.661  4886  5035 E AndroidRuntime:        at android.support.v4.media.session.MediaSessionCompat.<init>(MediaSessionCompat.java:489)
04-12 14:00:03.661  4886  5035 E AndroidRuntime:        at android.support.v4.media.session.MediaSessionCompat.<init>(MediaSessionCompat.java:456)
04-12 14:00:03.661  4886  5035 E AndroidRuntime:        at com.ingageco.capacitormusiccontrols.CapacitorMusicControls.initialize(CapacitorMusicControls.java:145)
04-12 14:00:03.661  4886  5035 E AndroidRuntime:        at com.ingageco.capacitormusiccontrols.CapacitorMusicControls.create(CapacitorMusicControls.java:71)
04-12 14:00:03.661  4886  5035 E AndroidRuntime:        ... 9 more

Are there any updates on this @ingageco ?

ingageco commented 1 year ago

@NorthFred @Markus-Brand Check 1.0.14 and see if this fixes the issue. I have changed all FLAG_MUTABLE to FLAG_IMMUTABLE but I have not tested yet in any of my apps

ingageco commented 1 year ago

Of course, Mutable means something can be changed and Immutable means it can't, so this might cause some issues. That's why i went mutable. But i could be wrong and I think that since the controls are destroyed/recreated on update, that it may not cause problems.

NorthFred commented 1 year ago

@ingageco Reference on StackOverflow: https://stackoverflow.com/questions/67045607/how-to-resolve-missing-pendingintent-mutability-flag-lint-warning-in-android-a

I'll test your fix in v.1.0.14 tomorrow!

ingageco commented 1 year ago

@NorthFred Added that workmanager fix in 1.0.16

Markus-Brand commented 1 year ago

Thanks a lot for the quick answer! Sadly, the issue still persists for me. Just a random guess, but could the reason be that in CapacitorMusicControls.java:145 the mediaButtonPendingIntent is not initalized yet, when creating the MediaSessionCompat? mediaSessionCompat = new MediaSessionCompat(context, "capacitor-music-controls-media-session", null, mediaButtonPendingIntent);

ingageco commented 1 year ago

@Markus-Brand it's possible! i am clearly not a java developer - just finding my way through this to enable the functionality for us capacitor/hybrid devs!

NorthFred commented 1 year ago

@Markus-Brand I can't reproduce this bug any longer with the latest version (1.0.16) on API level 34. Could you double-check?

NorthFred commented 1 year ago

@ingageco The update of the workmanager (implementation 'androidx.work:work-runtime:2.8.1') is now forcing the app to be compiled against API level 33. Compiling against API 33 is causing this bug to be visible: https://github.com/ingageco/capacitor-music-controls-plugin-v3/issues/7

ingageco commented 1 year ago

@NorthFred @Markus-Brand 1.0.17 reverts the workmanager update. So hopefully this means this is resolved! let me know for both of you.

NorthFred commented 1 year ago

@ingageco @Markus-Brand The bug is no longer reproducible when running the app on API level 34. Note that the notification is still missing though, but that has been reported separately.

Markus-Brand commented 1 year ago

@ingageco @NorthFred I can also no longer reproduce this! Thank you :)