sschueller / peertube-android

Thorium, a PeerTube Android Client
https://github.com/Chocobozzz/PeerTube
GNU Affero General Public License v3.0
341 stars 53 forks source link

fix: set required (im)mutable flag when creating pending intent #284

Closed dheineman closed 2 years ago

dheineman commented 2 years ago

When targeting SDK S+ (version 31 and above) a (im)mutable flag is required when creating a PendingIntent.

As the current minSdkVersion is 21 a SDK version check is included to ensure the device is at least SDK M (version 23) which is when the flags were added.

https://developer.android.com/reference/android/app/PendingIntent#FLAG_IMMUTABLE

Exception trace from a android 12 device:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: net.schueller.peertube, PID: 25925
    java.lang.IllegalArgumentException: net.schueller.peertube: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
    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.
        at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
        at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:458)
        at android.app.PendingIntent.getActivity(PendingIntent.java:444)
        at android.app.PendingIntent.getActivity(PendingIntent.java:408)
        at net.schueller.peertube.service.VideoPlayerService$playVideo$1.createCurrentContentIntent(VideoPlayerService.kt:223)
        at com.google.android.exoplayer2.ui.PlayerNotificationManager.createNotification(PlayerNotificationManager.java:1276)
        at com.google.android.exoplayer2.ui.PlayerNotificationManager.startOrUpdateNotification(PlayerNotificationManager.java:1151)
        at com.google.android.exoplayer2.ui.PlayerNotificationManager.handleMessage(PlayerNotificationManager.java:1409)
        at com.google.android.exoplayer2.ui.PlayerNotificationManager.$r8$lambda$hDN6RMWHvTCSAt_reWH1_HHmp5E(Unknown Source:0)
        at com.google.android.exoplayer2.ui.PlayerNotificationManager$$ExternalSyntheticLambda0.handleMessage(Unknown Source:2)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7842)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
sschueller commented 2 years ago

Thank you