rekabhq / background_locator

A Flutter plugin for updating location in background.
MIT License
289 stars 330 forks source link

Plugin crashes on Android S / 12 with SDK 31 #288

Open srmncnk opened 2 years ago

srmncnk commented 2 years ago

Plugin crashes if it targets SDK level 31:

D/BackgroundLocatorPlugin(11926): start locator with Android client
D/CompatibilityChangeReporter(11926): Compat change id reported: 160794467; UID 10247; state: ENABLED
D/AndroidRuntime(11926): Shutting down VM
E/AndroidRuntime(11926): FATAL EXCEPTION: main
E/AndroidRuntime(11926): Process: com.vendor.mytestapp, PID: 11926
E/AndroidRuntime(11926): java.lang.RuntimeException: Unable to create service rekab.app.background_locator.IsolateHolderService: java.lang.IllegalArgumentException: com.vendor.mytestapp: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
E/AndroidRuntime(11926): 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.
E/AndroidRuntime(11926):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:4500)
E/AndroidRuntime(11926):    at android.app.ActivityThread.access$1700(ActivityThread.java:247)
E/AndroidRuntime(11926):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2072)
E/AndroidRuntime(11926):    at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(11926):    at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime(11926):    at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime(11926):    at android.app.ActivityThread.main(ActivityThread.java:7839)
E/AndroidRuntime(11926):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(11926):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/AndroidRuntime(11926):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/AndroidRuntime(11926): Caused by: java.lang.IllegalArgumentException: com.vendor.mytestapp: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
E/AndroidRuntime(11926): 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.
E/AndroidRuntime(11926):    at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
E/AndroidRuntime(11926):    at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:458)
E/AndroidRuntime(11926):    at android.app.PendingIntent.getActivity(PendingIntent.java:444)
E/AndroidRuntime(11926):    at android.app.PendingIntent.getActivity(PendingIntent.java:408)
E/AndroidRuntime(11926):    at rekab.app.background_locator.IsolateHolderService.getNotification(IsolateHolderService.kt:98)
E/AndroidRuntime(11926):    at rekab.app.background_locator.IsolateHolderService.onCreate(IsolateHolderService.kt:65)
E/AndroidRuntime(11926):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:4487)
E/AndroidRuntime(11926):    ... 9 more
I/Process (11926): Sending signal. PID: 11926 SIG: 9
Lost connection to device.

When requesting a PendingIntent it is now mandatory to additionally supply either a FLAG_IMMUTABLE or a FLAG_MUTABLE. https://github.com/rekab-app/background_locator/blob/master/android/src/main/kotlin/rekab/app/background_locator/IsolateHolderService.kt#L99 This is a poor design choice by Google but it nevertheless crashes the consumer app.