Razeeman / Android-SimpleTimeTracker

Simple app that tracks time.
GNU General Public License v3.0
536 stars 68 forks source link

[Bug] Background execution not allowed: receiving Intent #152

Closed mshavliuk closed 3 months ago

mshavliuk commented 5 months ago

Hello, I'm trying to set up the automation feature with the time tracker, but having following issue.

What I do

I send an intent with adb like this:

adb shell am broadcast -a com.razeeman.util.simpletimetracker.ACTION_STOP_ALL_ACTIVITIES

#result
Broadcasting: Intent { act=com.razeeman.util.simpletimetracker.ACTION_STOP_ALL_ACTIVITIES flg=0x400000 }
Broadcast completed: result=0

Meanwhile, in another terminal I run the following command to monitor intents activity:

adb logcat | grep "BroadcastQueue"

What I expect

  1. The ongoing activity stops
  2. See some success message in the logs

What actually happens

  1. Nothing happens in the app
  2. I see the following error in logs: 01-24 08:46:13.908 1713 1796 W BroadcastQueue: Background execution not allowed: receiving Intent { act=com.razeeman.util.simpletimetracker.ACTION_STOP_ALL_ACTIVITIES flg=0x400010 } to com.razeeman.util.simpletimetracker/com.example.util.simpletimetracker.feature_notification.recevier.NotificationReceiver

Extra info

mshavliuk commented 5 months ago

Another try with [-n <COMPONENT_NAME>] parameter:

adb shell am broadcast -a com.razeeman.util.simpletimetracker.ACTION_STOP_ALL_ACTIVITIES -n com.razeeman.util.simpletimetracker

# result

Exception occurred while executing 'broadcast':
java.lang.IllegalArgumentException: Bad component name: com.razeeman.util.simpletimetracker
    at android.content.Intent.parseCommandArgs(Intent.java:8236)
    at com.android.server.am.ActivityManagerShellCommand.makeIntent(ActivityManagerShellCommand.java:381)
    at com.android.server.am.ActivityManagerShellCommand.runSendBroadcast(ActivityManagerShellCommand.java:797)
    at com.android.server.am.ActivityManagerShellCommand.onCommand(ActivityManagerShellCommand.java:221)
    at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97)
    at android.os.ShellCommand.exec(ShellCommand.java:38)
    at com.android.server.am.ActivityManagerService.onShellCommand(ActivityManagerService.java:9285)
    at android.os.Binder.shellCommand(Binder.java:1049)
    at android.os.Binder.onTransact(Binder.java:877)
    at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:4731)
    at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2628)
    at android.os.Binder.execTransactInternal(Binder.java:1285)
    at android.os.Binder.execTransact(Binder.java:1244)
mshavliuk commented 5 months ago

Successful try 🎉

adb shell am broadcast -a com.razeeman.util.simpletimetracker.ACTION_STOP_ALL_ACTIVITIES -n com.razeeman.util.simpletimetracker/com.example.util.simpletimetracker.feature_notification.recevier.NotificationReceiver

# result

Broadcasting: Intent { act=com.razeeman.util.simpletimetracker.ACTION_STOP_ALL_ACTIVITIES flg=0x400000 cmp=com.razeeman.util.simpletimetracker/com.example.util.simpletimetracker.feature_notification.recevier.NotificationReceiver }
Broadcast completed: result=0

And finally the activity has stopped!

But the problem is that none of the automation apps I've tried so far (Automation, Easer) allow to specifically set the target app for broadcast intent. Any hints how to solve this? Or is it possible to allow the app to respond to a general broadcast without component parameter?

Razeeman commented 5 months ago

Hello! It should work with specified package. With adb it would look like this:

adb shell am broadcast -a com.razeeman.util.simpletimetracker.ACTION_STOP_ALL_ACTIVITIES com.razeeman.util.simpletimetracker

Automation apps should also support setting a package on broadcasted intent. Not familiar with Automation or Easer but Macrodroid for example has this feature, see #68. Hope this helps!

Razeeman commented 3 months ago

Probably the issue is resolved. If it is not, please reopen.