HaylLtd / cordova-background-geolocation-plugin

Background and foreground geolocation plugin for Cordova.
Apache License 2.0
56 stars 66 forks source link

Feature request: Plugin does not cause app to exit when the user removes required permissions #199

Open ibcomputing opened 2 weeks ago

ibcomputing commented 2 weeks ago

FEATURE REQUEST

Is your feature request related to a problem? Please describe. On Android 14 if the user removes the location or notification permissions whilst the plugin is running, the app exits immediately. I guess it is crashing due to some unhandled exception.

Describe the solution you'd like It would be really nice if the plugin could handle this scenario more gracefully. It would be good if the tracking just stopped without causing the app to exit. I am using another plugin to monitor the permissions that the user has granted and I would like to use this to capture when the user disabled the location or notification permission and then log that in the app. But because the app just exits I am unable to accomplish this aim.

Describe alternatives you've considered I tried looking at the debug logs but could not find any exceptions being raised when the app exits. Otherwise I would have liked to suggest a solution for the problem.

Additional context None

HarelM commented 2 weeks ago

I would advise to run the scenario in a simulator or app in debug mode and look at the logcat to see where the exception is raised. Feel free to submit a PR if you are interested in solving this.

ibcomputing commented 2 weeks ago

Thanks I will have a go at that.

ibcomputing commented 2 weeks ago

I was able to capture the exception from logcat:

10-03 11:04:59.643 22388 22388 I com.marianhello.bgloc.service.LocationServiceImpl: Creating LocationServiceImpl
10-03 11:04:59.645  1391  4357 V AccountManagerService: addAccountExplicitly: caller's uid=10360, pid=22388, packageName=com.redacted-app-name, accountType=com.redacted-app-name.account
10-03 11:04:59.645  1391  4357 W AccountManagerService: insertAccountIntoDatabase: Account {name=xxx-xxx, type=com.10-03 11:04:59.643 22388 22388 I com.marianhello.bgloc.service.LocationServiceImpl: Creating LocationServiceImpl
10-03 11:04:59.645  1391  4357 V AccountManagerService: addAccountExplicitly: caller's uid=10360, pid=22388, packageName=com.redacted-app-name, accountType=com.redacted-app-name.account
10-03 11:04:59.645  1391  4357 W AccountManagerService: insertAccountIntoDatabase: Account {name=xxx-xxx, type=com.redacted-app-name.account}, skipping since the account already exists
10-03 11:04:59.646  1391  4357 D CompatibilityChangeReporter: Compat change id reported: 201794303; UID 10360; state: ENABLED
10-03 11:04:59.646  1391  4357 D CompatibilityChangeReporter: Compat change id reported: 207133734; UID 10360; state: ENABLED
10-03 11:04:59.648 22388 22388 I com.marianhello.bgloc.PostLocationTask: Creating PostLocationTask
10-03 11:04:59.650  1391  4357 D CompatibilityChangeReporter: Compat change id reported: 161145287; UID 10360; state: ENABLED
10-03 11:04:59.651 22388 22388 W com.marianhello.bgloc.service.LocationServiceImpl: Attempt to start unconfigured service. Will use stored or default.
10-03 11:04:59.660 22388 22388 D com.marianhello.bgloc.service.LocationServiceImpl: Will start service with: Config[distanceFilter=10 stationaryRadius=20.0 desiredAccuracy=0 interval=7692 fastestInterval=7692 activitiesInterval=10000 isDebugging=false stopOnTerminate=true stopOnStillActivity=false startOnBoot=false startForeground=true notificationsEnabled=true locationProvider=0 nTitle=Background tracking nText=ENABLED nIconLarge= nIconSmall= nIconColor=#6BA6D0 url= syncUrl= syncThreshold=100 httpHeaders={} maxLocations=10000 postTemplate=null]
10-03 11:04:59.662 22388 22388 I com.marianhello.bgloc.provider.DistanceFilterLocationProvider: Creating DistanceFilterLocationProvider
10-03 11:04:59.663 22388 22388 D CompatibilityChangeReporter: Compat change id reported: 160794467; UID 10360; state: ENABLED
10-03 11:04:59.668 22388 22388 I com.marianhello.bgloc.provider.DistanceFilterLocationProvider: Start recording
10-03 11:04:59.668 22388 22388 I com.marianhello.bgloc.provider.DistanceFilterLocationProvider: Setting pace: false
10-03 11:04:59.668 22388 22388 I com.marianhello.bgloc.provider.DistanceFilterLocationProvider: Requesting location updates from provider passive
10-03 11:04:59.669 22388 22388 E com.marianhello.bgloc.provider.DistanceFilterLocationProvider: Security exception: uid 10360 does not have android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.
10-03 11:04:59.674 22388 22388 I com.marianhello.bgloc.provider.DistanceFilterLocationProvider: Setting pace: true
10-03 11:04:59.675 22388 22388 I com.marianhello.bgloc.provider.DistanceFilterLocationProvider: Requesting location updates from provider passive
10-03 11:04:59.676 22388 22388 E com.marianhello.bgloc.provider.DistanceFilterLocationProvider: Security exception: uid 10360 does not have android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.
10-03 11:04:59.677  1391  4357 D CompatibilityChangeReporter: Compat change id reported: 170668199; UID 10360; state: ENABLED
10-03 11:04:59.677  1391  4357 D CompatibilityChangeReporter: Compat change id reported: 254662522; UID 10360; state: ENABLED
10-03 11:04:59.677 22388 22388 D AndroidRuntime: Shutting down VM
10-03 11:04:59.679 22388 22388 E AndroidRuntime: FATAL EXCEPTION: main
10-03 11:04:59.679 22388 22388 E AndroidRuntime: Process: com.redacted-app-name, PID: 22388
10-03 11:04:59.679 22388 22388 E AndroidRuntime: java.lang.RuntimeException: Unable to start service com.marianhello.bgloc.service.LocationServiceImpl@e963e98 with null: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{69630af 22388:com.redacted-app-name/u0a360} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_LOCATION] any of the permissions allOf=false [android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION]  and the app must be in the eligible state/exemptions to access the foreground only permission
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5100)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2432)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:107)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.os.Looper.loopOnce(Looper.java:232)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:317)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:8592)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)
10-03 11:04:59.679 22388 22388 E AndroidRuntime: Caused by: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{69630af 22388:com.redacted-app-name/u0a360} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_LOCATION] any of the permissions allOf=false [android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION]  and the app must be in the eligible state/exemptions to access the foreground only permission
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.os.Parcel.createExceptionOrNull(Parcel.java:3183)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.os.Parcel.createException(Parcel.java:3167)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.os.Parcel.readException(Parcel.java:3150)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.os.Parcel.readException(Parcel.java:3092)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6960)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.app.Service.startForeground(Service.java:776)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at com.marianhello.bgloc.service.LocationServiceImpl.startForeground(LocationServiceImpl.java:420)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at com.marianhello.bgloc.service.LocationServiceImpl$3.run(LocationServiceImpl.java:371)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at org.chromium.content.browser.ThreadUtils.runOnUiThreadBlocking(ThreadUtils.java:27)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at com.marianhello.bgloc.service.LocationServiceImpl.start(LocationServiceImpl.java:366)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at com.marianhello.bgloc.service.LocationServiceImpl.onStartCommand(LocationServiceImpl.java:274)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5082)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    ... 9 more
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger: FATAL EXCEPTION: mainjava.lang.RuntimeException: Unable to start service com.marianhello.bgloc.service.LocationServiceImpl@e963e98 with null: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{69630af 22388:com.redacted-app-name/u0a360} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_LOCATION] any of the permissions allOf=false [android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION]  and the app must be in the eligible state/exemptions to access the foreground only permission
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5100)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2432)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.os.Handler.dispatchMessage(Handler.java:107)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.os.Looper.loopOnce(Looper.java:232)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.os.Looper.loop(Looper.java:317)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.app.ActivityThread.main(ActivityThread.java:8592)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at java.lang.reflect.Method.invoke(Native Method)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger: Caused by: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{69630af 22388:com.redacted-app-name/u0a360} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_LOCATION] any of the permissions allOf=false [android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION]  and the app must be in the eligible state/exemptions to access the foreground only permission
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.os.Parcel.createExceptionOrNull(Parcel.java:3183)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.os.Parcel.createException(Parcel.java:3167)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.os.Parcel.readException(Parcel.java:3150)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.os.Parcel.readException(Parcel.java:3092)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6960)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.app.Service.startForeground(Service.java:776)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at com.marianhello.bgloc.service.LocationServiceImpl.startForeground(LocationServiceImpl.java:420)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at com.marianhello.bgloc.service.LocationServiceImpl$3.run(LocationServiceImpl.java:371)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at org.chromium.content.browser.ThreadUtils.runOnUiThreadBlocking(ThreadUtils.java:27)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at com.marianhello.bgloc.service.LocationServiceImpl.start(LocationServiceImpl.java:366)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at com.marianhello.bgloc.service.LocationServiceImpl.onStartCommand(LocationServiceImpl.java:274)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5082)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   ... 9 common frames omitted
10-03 11:04:59.684  1391 22404 I DropBoxManagerService: add tag=data_app_crash isTagEnabled=true flags=0x2
10-03 11:04:59.684  1391  1578 I ActivityManager: Showing crash dialog for package com.redacted-app-name u0
.account}, skipping since the account already exists
10-03 11:04:59.646  1391  4357 D CompatibilityChangeReporter: Compat change id reported: 201794303; UID 10360; state: ENABLED
10-03 11:04:59.646  1391  4357 D CompatibilityChangeReporter: Compat change id reported: 207133734; UID 10360; state: ENABLED
10-03 11:04:59.648 22388 22388 I com.marianhello.bgloc.PostLocationTask: Creating PostLocationTask
10-03 11:04:59.650  1391  4357 D CompatibilityChangeReporter: Compat change id reported: 161145287; UID 10360; state: ENABLED
10-03 11:04:59.651 22388 22388 W com.marianhello.bgloc.service.LocationServiceImpl: Attempt to start unconfigured service. Will use stored or default.
10-03 11:04:59.660 22388 22388 D com.marianhello.bgloc.service.LocationServiceImpl: Will start service with: Config[distanceFilter=10 stationaryRadius=20.0 desiredAccuracy=0 interval=7692 fastestInterval=7692 activitiesInterval=10000 isDebugging=false stopOnTerminate=true stopOnStillActivity=false startOnBoot=false startForeground=true notificationsEnabled=true locationProvider=0 nTitle=Background tracking nText=ENABLED nIconLarge= nIconSmall= nIconColor=#6BA6D0 url= syncUrl= syncThreshold=100 httpHeaders={} maxLocations=10000 postTemplate=null]
10-03 11:04:59.662 22388 22388 I com.marianhello.bgloc.provider.DistanceFilterLocationProvider: Creating DistanceFilterLocationProvider
10-03 11:04:59.663 22388 22388 D CompatibilityChangeReporter: Compat change id reported: 160794467; UID 10360; state: ENABLED
10-03 11:04:59.668 22388 22388 I com.marianhello.bgloc.provider.DistanceFilterLocationProvider: Start recording
10-03 11:04:59.668 22388 22388 I com.marianhello.bgloc.provider.DistanceFilterLocationProvider: Setting pace: false
10-03 11:04:59.668 22388 22388 I com.marianhello.bgloc.provider.DistanceFilterLocationProvider: Requesting location updates from provider passive
10-03 11:04:59.669 22388 22388 E com.marianhello.bgloc.provider.DistanceFilterLocationProvider: Security exception: uid 10360 does not have android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.
10-03 11:04:59.674 22388 22388 I com.marianhello.bgloc.provider.DistanceFilterLocationProvider: Setting pace: true
10-03 11:04:59.675 22388 22388 I com.marianhello.bgloc.provider.DistanceFilterLocationProvider: Requesting location updates from provider passive
10-03 11:04:59.676 22388 22388 E com.marianhello.bgloc.provider.DistanceFilterLocationProvider: Security exception: uid 10360 does not have android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.
10-03 11:04:59.677  1391  4357 D CompatibilityChangeReporter: Compat change id reported: 170668199; UID 10360; state: ENABLED
10-03 11:04:59.677  1391  4357 D CompatibilityChangeReporter: Compat change id reported: 254662522; UID 10360; state: ENABLED
10-03 11:04:59.677 22388 22388 D AndroidRuntime: Shutting down VM
10-03 11:04:59.679 22388 22388 E AndroidRuntime: FATAL EXCEPTION: main
10-03 11:04:59.679 22388 22388 E AndroidRuntime: Process: com.redacted-app-name, PID: 22388
10-03 11:04:59.679 22388 22388 E AndroidRuntime: java.lang.RuntimeException: Unable to start service com.marianhello.bgloc.service.LocationServiceImpl@e963e98 with null: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{69630af 22388:com.redacted-app-name/u0a360} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_LOCATION] any of the permissions allOf=false [android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION]  and the app must be in the eligible state/exemptions to access the foreground only permission
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5100)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2432)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:107)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.os.Looper.loopOnce(Looper.java:232)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:317)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:8592)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)
10-03 11:04:59.679 22388 22388 E AndroidRuntime: Caused by: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{69630af 22388:com.redacted-app-name/u0a360} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_LOCATION] any of the permissions allOf=false [android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION]  and the app must be in the eligible state/exemptions to access the foreground only permission
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.os.Parcel.createExceptionOrNull(Parcel.java:3183)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.os.Parcel.createException(Parcel.java:3167)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.os.Parcel.readException(Parcel.java:3150)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.os.Parcel.readException(Parcel.java:3092)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6960)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.app.Service.startForeground(Service.java:776)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at com.marianhello.bgloc.service.LocationServiceImpl.startForeground(LocationServiceImpl.java:420)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at com.marianhello.bgloc.service.LocationServiceImpl$3.run(LocationServiceImpl.java:371)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at org.chromium.content.browser.ThreadUtils.runOnUiThreadBlocking(ThreadUtils.java:27)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at com.marianhello.bgloc.service.LocationServiceImpl.start(LocationServiceImpl.java:366)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at com.marianhello.bgloc.service.LocationServiceImpl.onStartCommand(LocationServiceImpl.java:274)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5082)
10-03 11:04:59.679 22388 22388 E AndroidRuntime:    ... 9 more
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger: FATAL EXCEPTION: mainjava.lang.RuntimeException: Unable to start service com.marianhello.bgloc.service.LocationServiceImpl@e963e98 with null: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{69630af 22388:com.redacted-app-name/u0a360} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_LOCATION] any of the permissions allOf=false [android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION]  and the app must be in the eligible state/exemptions to access the foreground only permission
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5100)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2432)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.os.Handler.dispatchMessage(Handler.java:107)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.os.Looper.loopOnce(Looper.java:232)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.os.Looper.loop(Looper.java:317)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.app.ActivityThread.main(ActivityThread.java:8592)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at java.lang.reflect.Method.invoke(Native Method)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger: Caused by: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{69630af 22388:com.redacted-app-name/u0a360} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_LOCATION] any of the permissions allOf=false [android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION]  and the app must be in the eligible state/exemptions to access the foreground only permission
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.os.Parcel.createExceptionOrNull(Parcel.java:3183)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.os.Parcel.createException(Parcel.java:3167)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.os.Parcel.readException(Parcel.java:3150)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.os.Parcel.readException(Parcel.java:3092)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6960)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.app.Service.startForeground(Service.java:776)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at com.marianhello.bgloc.service.LocationServiceImpl.startForeground(LocationServiceImpl.java:420)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at com.marianhello.bgloc.service.LocationServiceImpl$3.run(LocationServiceImpl.java:371)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at org.chromium.content.browser.ThreadUtils.runOnUiThreadBlocking(ThreadUtils.java:27)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at com.marianhello.bgloc.service.LocationServiceImpl.start(LocationServiceImpl.java:366)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at com.marianhello.bgloc.service.LocationServiceImpl.onStartCommand(LocationServiceImpl.java:274)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5082)
10-03 11:04:59.681 22388 22388 E com.marianhello.logging.UncaughtExceptionLogger:   ... 9 common frames omitted
10-03 11:04:59.684  1391 22404 I DropBoxManagerService: add tag=data_app_crash isTagEnabled=true flags=0x2
10-03 11:04:59.684  1391  1578 I ActivityManager: Showing crash dialog for package com.redacted-app-name u0

I am not a native app developer, so if anyone has any tips on where I need to look or how to try and prevent the exception from crashing the app that would be great.

ibcomputing commented 2 weeks ago

I'm thinking maybe we can put this line in a try/catch but I'm not sure of any negative implications of doing that.

HarelM commented 2 weeks ago

You should be able to create a fork, update the code and use it using npm install. If this fixes the issue we can discuss if this is the right approach. I would also recommend chatting with Gimini or an equivalent GenAI tool to see what should be done in similar cases...

ibcomputing commented 6 days ago

I tried to make this change to prevent the exception but it didn't work. Here is the stacktrace after the change:

10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl: startForeground: exceptionjava.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{c3b7125 22295:com.prodeliverymanager.app.pharmacy/u0a114} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_LOCATION] any of the permissions allOf=false [android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION]  and the app must be in the eligible state/exemptions to access the foreground only permission
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at android.os.Parcel.createExceptionOrNull(Parcel.java:3183)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at android.os.Parcel.createException(Parcel.java:3167)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at android.os.Parcel.readException(Parcel.java:3150)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at android.os.Parcel.readException(Parcel.java:3092)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6960)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at android.app.Service.startForeground(Service.java:776)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at com.marianhello.bgloc.service.LocationServiceImpl.startForeground(LocationServiceImpl.java:421)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at com.marianhello.bgloc.service.LocationServiceImpl$3.run(LocationServiceImpl.java:371)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at org.chromium.content.browser.ThreadUtils.runOnUiThreadBlocking(ThreadUtils.java:27)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at com.marianhello.bgloc.service.LocationServiceImpl.start(LocationServiceImpl.java:366)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at com.marianhello.bgloc.service.LocationServiceImpl.onStartCommand(LocationServiceImpl.java:274)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5082)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2432)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at android.os.Handler.dispatchMessage(Handler.java:107)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at android.os.Looper.loopOnce(Looper.java:232)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at android.os.Looper.loop(Looper.java:317)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at android.app.ActivityThread.main(ActivityThread.java:8592)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at java.lang.reflect.Method.invoke(Native Method)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl: Caused by: android.os.RemoteException: Remote stack trace:
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at com.android.server.am.ActiveServices.validateForegroundServiceType(ActiveServices.java:2842)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked(ActiveServices.java:2530)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at com.android.server.am.ActiveServices.setServiceForegroundLocked(ActiveServices.java:1806)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at com.android.server.am.ActivityManagerService.setServiceForeground(ActivityManagerService.java:13795)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl:     at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:3483)
10-11 10:50:56.841 22295 22295 E com.marianhello.bgloc.service.LocationServiceImpl: 
10-11 10:50:56.850  1404  2751 D CompatibilityChangeReporter: Compat change id reported: 261072174; UID 10114; state: ENABLED
10-11 10:50:56.867 22295 22295 D com.marianhello.bgloc.provider.ActivityRecognitionLocationProvider: Connected to Google Play Services
10-11 10:50:56.871 22295 22295 E com.marianhello.bgloc.provider.ActivityRecognitionLocationProvider: Security exception: uid 10114 does not have any of [android.permission.ACCESS_FINE_LOCATION, android.permission.ACCESS_COARSE_LOCATION].

I have very little experience with native code, so I don't know what to try next.

HarelM commented 6 days ago

Try cloude, maybe it can help...