Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running action fails #20

Open
FineFindus opened this issue Feb 12, 2023 · 9 comments
Open

Running action fails #20

FineFindus opened this issue Feb 12, 2023 · 9 comments

Comments

@FineFindus
Copy link

FineFindus commented Feb 12, 2023

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)
@joaomgcd
Copy link
Owner

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

@FineFindus
Copy link
Author

targetSDK is set to 33.

@joaomgcd
Copy link
Owner

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.

@FineFindus
Copy link
Author

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)

@joaomgcd
Copy link
Owner

joaomgcd commented Feb 14, 2023

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

@FineFindus
Copy link
Author

FineFindus commented Feb 14, 2023

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.

@joaomgcd
Copy link
Owner

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

@FineFindus
Copy link
Author

FineFindus commented Feb 18, 2023

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. 

@SimoneAvogadro
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants