privatelocation
privatelocation copied to clipboard
unfortunatley doesnt work and crashes on start/stop widget on android 13
type: crash osVersion: google/oriole/oriole:13/TP1A.220624.021/2022083000:user/release-keys package: com.wesaphzt.privatelocation:4 process: com.wesaphzt.privatelocation
java.lang.RuntimeException: Unable to start service com.wesaphzt.privatelocation.service.LocationService@c658872 with Intent { act=ACTION_STOP_FOREGROUND_SERVICE cmp=com.wesaphzt.privatelocation/.service.LocationService }: java.lang.SecurityException: Not allowed to delete channel location_notification_channel_id with a foreground service at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4709) at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2182) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7904) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ExecInit.main(ExecInit.java:49) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:355) Caused by: java.lang.SecurityException: Not allowed to delete channel location_notification_channel_id with a foreground service at android.os.Parcel.createExceptionOrNull(Parcel.java:3012) at android.os.Parcel.createException(Parcel.java:2996) at android.os.Parcel.readException(Parcel.java:2979) at android.os.Parcel.readException(Parcel.java:2921) at android.app.INotificationManager$Stub$Proxy.deleteNotificationChannel(INotificationManager.java:3777) at android.app.NotificationManager.deleteNotificationChannel(NotificationManager.java:1003) at com.wesaphzt.privatelocation.service.LocationService.shutdown(LocationService.java:206) at com.wesaphzt.privatelocation.service.LocationService.onStartCommand(LocationService.java:91) at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4691) ... 11 more
Same bug for me on android 13 (GrapheneOS)
type: crash
osVersion: google/bluejay/bluejay:13/TQ2A.230305.008.E1/2023040400:user/release-keys
package: com.wesaphzt.privatelocation:4
process: com.wesaphzt.privatelocation
processUptime: 415 + 322 ms
java.lang.RuntimeException: Unable to start service com.wesaphzt.privatelocation.service.LocationService@94e1b8a with Intent { act=ACTION_STOP_FOREGROUND_SERVICE cmp=com.wesaphzt.privatelocation/.service.LocationService }: java.lang.SecurityException: Not allowed to delete channel location_notification_channel_id with a foreground service
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4677)
at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2177)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7891)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ExecInit.main(ExecInit.java:49)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:355)
Caused by: java.lang.SecurityException: Not allowed to delete channel location_notification_channel_id with a foreground service
at android.os.Parcel.createExceptionOrNull(Parcel.java:3021)
at android.os.Parcel.createException(Parcel.java:3005)
at android.os.Parcel.readException(Parcel.java:2981)
at android.os.Parcel.readException(Parcel.java:2923)
at android.app.INotificationManager$Stub$Proxy.deleteNotificationChannel(INotificationManager.java:3792)
at android.app.NotificationManager.deleteNotificationChannel(NotificationManager.java:1003)
at com.wesaphzt.privatelocation.service.LocationService.shutdown(LocationService.java:206)
at com.wesaphzt.privatelocation.service.LocationService.onStartCommand(LocationService.java:91)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4659)
... 11 more
FYI, a similar issue got fixed at https://github.com/warren-bank/Android-Mock-Location/issues/14 for my Pixel 6a with GrapheneOS. The code workaround is dumb, but it works for me. Maybe it works here too?
FWIW, I see 2 issues:
- [approx. Android 13.2.1+] when attempting to start the service
- same issue as Mock my GPS, and FakeTraveler
- specifically, that this line of code can.. on some devices (ie: Pixel 6+).. throw an IllegalStateException
- a fairly "dumb" workaround is to catch this exception and try again.. for example
- [approx. Android 10+] when attempting to stop the service
- specific only to this app.. you're trying to remove the foreground service notification (and its notification channel) before stopping the foreground service
- specifically, simply swapping the order of these 2 lines of code should do the trick
Also, I should probably mention.. with regard to the question of why an IllegalStateException is being thrown.. Daniel Micay, the founder and lead developer of GrapheneOS, offered a bit of a warning.. though not an explanation, he did say that he doesn't believe this is limited to the Pixel.. that there's nothing special about its hardware to cause this.. but rather, that it happens to be one of only a few devices that runs bleeding-edge AOSP code.. and in time, once device makers catch up, and update the version of Android 13 that's running on their products.. this issue will (most likely) be far more common.
Also, the (above) example implementation will fix issue #32
because its added call to shutdown()
from within startup()
has the same effect as the patch in PR #33