TaskerPluginSample icon indicating copy to clipboard operation
TaskerPluginSample copied to clipboard

Running action fails

Open FineFindus opened this issue 2 years ago • 9 comments

Following the documentation, I'm trying to add an action to this app, but when triggering the action, it fails with the following stacktace. The emulator is running Android 13 and the FOREGROUND_SERVICE permission has been added to the manifest.

2023-02-12 13:06:25.451   619-808   NotificationService     system_process                       E  Suppressing toast from package com.porg.blocker by user request.
2023-02-12 13:06:38.693  2578-2578  System.err              com.porg.blocker                     W  android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service com.porg.blocker/com.joaomgcd.taskerpluginlibrary.action.IntentServiceAction
2023-02-12 13:06:38.700  2578-2578  System.err              com.porg.blocker                     W  	at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
2023-02-12 13:06:38.700  2578-2578  System.err              com.porg.blocker                     W  	at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
2023-02-12 13:06:38.700  2578-2578  System.err              com.porg.blocker                     W  	at android.os.Parcel.readParcelableInternal(Parcel.java:4813)
2023-02-12 13:06:38.700  2578-2578  System.err              com.porg.blocker                     W  	at android.os.Parcel.readParcelable(Parcel.java:4775)
2023-02-12 13:06:38.700  2578-2578  System.err              com.porg.blocker                     W  	at android.os.Parcel.createExceptionOrNull(Parcel.java:3006)
2023-02-12 13:06:38.700  2578-2578  System.err              com.porg.blocker                     W  	at android.os.Parcel.createException(Parcel.java:2995)
2023-02-12 13:06:38.700  2578-2578  System.err              com.porg.blocker                     W  	at android.os.Parcel.readException(Parcel.java:2978)
2023-02-12 13:06:38.700  2578-2578  System.err              com.porg.blocker                     W  	at android.os.Parcel.readException(Parcel.java:2920)
2023-02-12 13:06:38.700  2578-2578  System.err              com.porg.blocker                     W  	at android.app.IActivityManager$Stub$Proxy.startService(IActivityManager.java:5302)
2023-02-12 13:06:38.700  2578-2578  System.err              com.porg.blocker                     W  	at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1894)
2023-02-12 13:06:38.701  2578-2578  System.err              com.porg.blocker                     W  	at android.app.ContextImpl.startForegroundService(ContextImpl.java:1870)
2023-02-12 13:06:38.701  2578-2578  System.err              com.porg.blocker                     W  	at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:822)
2023-02-12 13:06:38.701  2578-2578  System.err              com.porg.blocker                     W  	at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:822)
2023-02-12 13:06:38.701  2578-2578  System.err              com.porg.blocker                     W  	at com.joaomgcd.taskerpluginlibrary.extensions.InternalKt.startServiceDependingOnTargetApi(Internal.kt:59)
2023-02-12 13:06:38.701  2578-2578  System.err              com.porg.blocker                     W  	at com.joaomgcd.taskerpluginlibrary.action.BroadcastReceiverAction.onReceive(ActionReceivers.kt:33)
2023-02-12 13:06:38.701  2578-2578  System.err              com.porg.blocker                     W  	at android.app.ActivityThread.handleReceiver(ActivityThread.java:4306)
2023-02-12 13:06:38.701  2578-2578  System.err              com.porg.blocker                     W  	at android.app.ActivityThread.-$$Nest$mhandleReceiver(Unknown Source:0)
2023-02-12 13:06:38.701  2578-2578  System.err              com.porg.blocker                     W  	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2153)
2023-02-12 13:06:38.701  2578-2578  System.err              com.porg.blocker                     W  	at android.os.Handler.dispatchMessage(Handler.java:106)
2023-02-12 13:06:38.701  2578-2578  System.err              com.porg.blocker                     W  	at android.os.Looper.loopOnce(Looper.java:201)
2023-02-12 13:06:38.701  2578-2578  System.err              com.porg.blocker                     W  	at android.os.Looper.loop(Looper.java:288)
2023-02-12 13:06:38.701  2578-2578  System.err              com.porg.blocker                     W  	at android.app.ActivityThread.main(ActivityThread.java:7872)
2023-02-12 13:06:38.701  2578-2578  System.err              com.porg.blocker                     W  	at java.lang.reflect.Method.invoke(Native Method)
2023-02-12 13:06:38.701  2578-2578  System.err              com.porg.blocker                     W  	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
2023-02-12 13:06:38.701  2578-2578  System.err              com.porg.blocker                     W  	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

FineFindus avatar Feb 12 '23 12:02 FineFindus

Hi. Thanks for the report. What Target API did you set on your app? Thanks

joaomgcd avatar Feb 13 '23 09:02 joaomgcd

targetSDK is set to 33.

FineFindus avatar Feb 13 '23 12:02 FineFindus

Hhmm, I just tried changing the TaskerPluginSample app's target API to 33 and adding the <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> permission to its manifest and I could run its actions normally. Could you please try that on your device and see how it goes? Thanks in advance.

joaomgcd avatar Feb 13 '23 18:02 joaomgcd

Interesting, I followed your steps and had the same result.

Logs
2023-02-13 20:03:17.360   629-3156  NotificationService     system_process                       E  Suppressing toast from package com.joaomgcd.taskerpluginsample by user request.
2023-02-13 20:03:21.272  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service com.joaomgcd.taskerpluginsample/com.joaomgcd.taskerpluginlibrary.action.IntentServiceAction
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.os.Parcel.readParcelableInternal(Parcel.java:4813)
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.os.Parcel.readParcelable(Parcel.java:4775)
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.os.Parcel.createExceptionOrNull(Parcel.java:3006)
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.os.Parcel.createException(Parcel.java:2995)
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.os.Parcel.readException(Parcel.java:2978)
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.os.Parcel.readException(Parcel.java:2920)
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.app.IActivityManager$Stub$Proxy.startService(IActivityManager.java:5302)
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1894)
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.app.ContextImpl.startForegroundService(ContextImpl.java:1870)
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:822)
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:822)
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at com.joaomgcd.taskerpluginlibrary.extensions.InternalKt.startServiceDependingOnTargetApi(Internal.kt:59)
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at com.joaomgcd.taskerpluginlibrary.action.BroadcastReceiverAction.onReceive(ActionReceivers.kt:33)
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.app.ActivityThread.handleReceiver(ActivityThread.java:4306)
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.app.ActivityThread.-$$Nest$mhandleReceiver(Unknown Source:0)
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2153)
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.os.Handler.dispatchMessage(Handler.java:106)
2023-02-13 20:03:21.280  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.os.Looper.loopOnce(Looper.java:201)
2023-02-13 20:03:21.281  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.os.Looper.loop(Looper.java:288)
2023-02-13 20:03:21.281  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at android.app.ActivityThread.main(ActivityThread.java:7872)
2023-02-13 20:03:21.281  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at java.lang.reflect.Method.invoke(Native Method)
2023-02-13 20:03:21.281  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
2023-02-13 20:03:21.281  8182-8182  System.err              com.joaomgcd.taskerpluginsample      W  	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

FineFindus avatar Feb 13 '23 19:02 FineFindus

Weird. Did you try running it on a physical device yet?

joaomgcd avatar Feb 14 '23 09:02 joaomgcd

Just tested it on a physical device running android 10 and it worked. It could be very well also related to the android version, as if memory serves me correctly, there have been some changes to this in the last versions.

FineFindus avatar Feb 14 '23 20:02 FineFindus

But I actually tested it on an Android 13 device and it worked for me... Did you disable battery optimization for your app?

joaomgcd avatar Feb 15 '23 08:02 joaomgcd

Sorry for the silence.

I did not. With battery optimizations it has no longer the android.app.ForegroundServiceStartNotAllowedException: startForegroundService() error, but it still does not work.

Logs
2023-02-18 11:58:20.605  5550-5550  BroadcastReceiver       com.joaomgcd.taskerpluginsample      E  BroadcastReceiver trying to return result during a non-ordered broadcast
                                                                                                    java.lang.RuntimeException: BroadcastReceiver trying to return result during a non-ordered broadcast
                                                                                                    	at android.content.BroadcastReceiver.checkSynchronousHint(BroadcastReceiver.java:699)
                                                                                                    	at android.content.BroadcastReceiver.setResultCode(BroadcastReceiver.java:449)
                                                                                                    	at com.joaomgcd.taskerpluginlibrary.action.BroadcastReceiverAction.onReceive(ActionReceivers.kt:13)
                                                                                                    	at android.app.ActivityThread.handleReceiver(ActivityThread.java:4306)
                                                                                                    	at android.app.ActivityThread.-$$Nest$mhandleReceiver(Unknown Source:0)
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2153)
                                                                                                    	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:7872)
                                                                                                    	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:936)
2023-02-18 11:58:20.621  5550-5550  Compatibil...geReporter com.joaomgcd.taskerpluginsample      D  Compat change id reported: 147798919; UID 10161; state: ENABLED
2023-02-18 11:58:37.119  5550-5575  EGL_emulation           com.joaomgcd.taskerpluginsample      D  app_time_stats: avg=1697.44ms min=8.62ms max=16816.68ms count=10
2023-02-18 11:58:41.081   628-1682  NotificationService     system_process                       E  Suppressing toast from package com.joaomgcd.taskerpluginsample by user request.
2023-02-18 11:58:46.109  5550-5564  System                  com.joaomgcd.taskerpluginsample      W  A resource failed to call close. 

FineFindus avatar Feb 18 '23 11:02 FineFindus

I too had the same issue and disabling battery optimization solved it. However it would be useful to know that there's this failure so thaty next time the app is opened I can show a message and warn the user about that.

SimoneAvogadro avatar Feb 09 '24 20:02 SimoneAvogadro