syncthing-android
syncthing-android copied to clipboard
Start intent no longer working
I use Tasker to start syncthing via an intent as described here: https://github.com/syncthing/syncthing-android/wiki/Remote-Control-by-Broadcast-Intents
I noticed that syncthing was not starting as expected recently (it has worked fine for months).
In looking into the logs, I see the following:
12-10 22:00:42.890 1454 9513 W ActivityManager: Background started FGS: Disallowed [callingPackage: com.nutomic.syncthingandroid; callingUid: 10257; uidState: RCVR; in
tent: Intent { cmp=com.nutomic.syncthingandroid/.service.SyncthingService }; code:DENIED; tempAllowListReason:<null>; targetSdkVersion:31; callerTargetSdkVersion:31; sta
rtForegroundCount:0; bindFromPackage:null]
12-10 22:00:42.890 1454 9513 D CompatibilityChangeReporter: Compat change id reported: 170668199; UID 10257; state: ENABLED
12-10 22:00:42.890 1454 9513 W ActivityManager: startForegroundService() not allowed due to mAllowStartForeground false: service com.nutomic.syncthingandroid/.service.
SyncthingService
12-10 22:00:42.890 1454 9513 D CompatibilityChangeReporter: Compat change id reported: 174041399; UID 10257; state: ENABLED
12-10 22:00:42.892 31317 31317 E AndroidRuntime: FATAL EXCEPTION: main
12-10 22:00:42.892 31317 31317 E AndroidRuntime: Process: com.nutomic.syncthingandroid, PID: 31317
12-10 22:00:42.892 31317 31317 E AndroidRuntime: java.lang.RuntimeException: Unable to start receiver com.nutomic.syncthingandroid.receiver.AppConfigReceiver: android.ap
p.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service com.nutomic.syncthingandroid/.service.SyncthingService
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.app.ActivityThread.handleReceiver(ActivityThread.java:4315)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.app.ActivityThread.-$$Nest$mhandleReceiver(Unknown Source:0)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2153)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:201)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.os.Looper.loop(Looper.java:288)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7872)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: Caused by: android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service com.nutomic.syncthingandroid/.service.SyncthingService
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.os.Parcel.readParcelableInternal(Parcel.java:4816)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.os.Parcel.readParcelable(Parcel.java:4778)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.os.Parcel.createExceptionOrNull(Parcel.java:3006)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.os.Parcel.createException(Parcel.java:2995)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:2978)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:2920)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.app.IActivityManager$Stub$Proxy.startService(IActivityManager.java:5302)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1894)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.app.ContextImpl.startForegroundService(ContextImpl.java:1870)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:822)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:822)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at com.nutomic.syncthingandroid.receiver.BootReceiver.startServiceCompat(BootReceiver.java:35)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at com.nutomic.syncthingandroid.receiver.AppConfigReceiver.onReceive(AppConfigReceiver.java:40)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: at android.app.ActivityThread.handleReceiver(ActivityThread.java:4306)
12-10 22:00:42.892 31317 31317 E AndroidRuntime: ... 9 more
The issue appears to have started after the 1.22.2 upgrade.
More info here: https://developer.android.com/guide/components/foreground-services#background-start-restrictions
Version Information
App Version: 1.22.2
Syncthing Version: 1.22.2
Android Version: 13 (Pixel 6)
From here:
In the following situations, your app can start foreground services even while your app is running in the background: ... The user turns off battery optimizations for your app.
Doing so seems to allow the intent to work again.
I see some code here which prompts to disable optimizations, which I probably turned off when I installed syncthing earlier in the year.
This might be coincidental - I also installed an Android update earlier in the week, and doing so typically resets my battery optimization overrides and storage access settings (among other things).