googlearchive / firebase-jobdispatcher-android

DEPRECATED please see the README.md below for details.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Job not reschedule after device reboot

nikthakkar opened this issue · comments

I'm using the following configuration to build the job.

Job job = dispatcher.newJobBuilder()
               .setTag(LocationSyncService.TAG)
               .setLifetime(Lifetime.FOREVER)
               .setRecurring(true)
               .setReplaceCurrent(true)
               .setService(LocationSyncService.class)
               .setTrigger(Trigger.executionWindow((int) TimeUnit.MINUTES.toSeconds(1), (int) TimeUnit.MINUTES.toSeconds(2)))
               .setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
               .setConstraints(Constraint.ON_ANY_NETWORK)
               .build();
       dispatcher.mustSchedule(job);

It works fine until the device is rebooted. I'm running Nougat 7.1.1 for testing. If I open the app after device reboot, the task is scheduled and running successfully.
Please let me know if something is amiss.
Any help would be greatly appreciated.

Why not just register an on boot complete receiver and reschedule the jobs?

The problem is my app is not receiving the BOOT_COMPLETE intent even though I have registered the receiver in mainfest. Otherwise I would have followed the same approach as suggested by you.
Thanks for the help.

you added the <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> permission?

Yes. :). I switched to evernote's android-job library and it seems to work fine. Though I have to settle for 15min window between job execution. Hopefully you guys will fix this soon as I'm already using firebase auth and database and this would have completed the fire base stack.. :)

@nikthakkar evernote library merges the RECEIVE_BOOT_COMPLETED permission from the library manifest

I kinda thought that I would be able to avoid declaring new permissions for this and use the gms built in functions instead...

I am experiencing this same problem. I cannot get my job to start up after reboot even after using LIfetime.Forever and adding the RECEIVE_BOOT_COMPLETED permission

Should I perform rescheduling manual or adding RECEIVE_BOOT_COMPLETED permission to manifest will fix this issue? @FabianTerhorst

Same issue. I am not able to get the job working in both the scenarios:

  1. if app is closed
  2. post reboot

I added RECEIVE_BOOT_COMPLETED as well.
Could you help how we can debug it?

I dumped log and I found this:

06-22 12:07:44.116 2570 3348 E NetworkScheduler.TED: Couldn't start service: Intent { act=com.google.android.gms.gcm.ACTION_TASK_READY cmp=co.wepact.rupie/com.firebase.jobdispatcher.GooglePlayReceiver (has extras) }

Everybody who is affected by this problem, could you check the following command while your app is closed (after a reboot or after swiping) ?

adb shell dumpsys package MY-PACKAGE | grep stopped

if you can read stopped=true it means that the manufacturer of your device implemented a non standard behavior consisting in "force-stopping" applications when they are swiped.

force-stopping is very similar to disabling the app until the user opens it again.
while the app is in that state many android behaviors will not work (broadcasts, alarms..)

If this is the root cause of behavior you are seeing you should contact the manufacturer and request that they fix the device by removing this non-standard behavior

@ogeidix I'm also experiencing this issue.

I've executed the command you suggested and the output contains stopped=false, and a job is not restored:

$ adb shell dumpsys package <package> | grep stopped
    User 0:  installed=true hidden=false stopped=false notLaunched=false enabled=0

Any fix for this yet??

Same issue here, will try to debug..

this just killed a product for me. its device specific and mostly not the main manufactural. Please fix!

full info here: http://edit.sumimasen.com/naosu.html?site=stackoverflow&id=45066610

Experiencing the same issue here not just after device reboot but also in standby.

When I leave my app running in the background I get the following response from the suggested command:

User 0: installed=true hidden=false stopped=false notLaunched=false enabled=0
User 999: installed=false hidden=false stopped=true notLaunched=true enabled=0

Now when I select the "clear all" from overview screen or reboot my device and then execute this command again I get this:

User 0: installed=true hidden=false stopped=true notLaunched=false enabled=0
User 999: installed=false hidden=false stopped=true notLaunched=true enabled=0

My device is Xiaomi RedMi Pro running android 6.0

I also having a problem where, after a reboot on a oneplus, the job is scheduled according to adb shell dumpsys activity service GcmService but the service does not start and this shows in the log

01-16 14:56:51.646 2806-5673/? E/NetworkScheduler.TED: Unable to bind to task service: ComponentInfo{com.atlassian.android.jira.core/com.firebase.jobdispatcher.GooglePlayReceiver}
01-16 14:56:51.678 2806-5680/? E/NetworkScheduler: Unknown result code received: 4
01-16 14:56:54.343 2806-5455/? E/NetworkScheduler.TED: Couldn't start service: Intent { act=com.google.android.gms.gcm.ACTION_TASK_READY cmp=com.thundermaps.staging.main/com.firebase.jobdispatcher.GooglePlayReceiver (has extras) }
01-16 14:56:54.343 2806-5680/? E/NetworkScheduler: Unknown result code received: 4
01-16 14:57:11.490 2806-5455/? E/NetworkScheduler: ignoring stale queue check message
01-16 14:57:11.771 2806-5455/? E/NetworkScheduler: ignoring stale queue check message
01-16 14:57:14.368 2806-5455/? E/NetworkScheduler: ignoring stale queue check message
01-16 14:57:14.959 2806-5455/? E/NetworkScheduler: ignoring stale queue check message
01-16 14:57:15.369 2806-5455/? E/NetworkScheduler: ignoring stale queue check message
01-16 14:57:16.316 2806-5455/? E/NetworkScheduler: ignoring stale queue check message
01-16 14:57:16.436 2806-5455/? E/NetworkScheduler: ignoring stale queue check message
01-16 14:57:17.737 2806-5676/? E/NetworkScheduler.ATC: Received callback from client for task that is already complete. ComponentInfo{com.google.android.gms/com.google.android.gms.gcm.gmsproc.GcmInGmsTaskService} groups_upload
01-16 14:57:22.986 2806-5673/? E/NetworkScheduler.TED: Unable to bind to task service: ComponentInfo{com.atlassian.android.jira.core/com.firebase.jobdispatcher.GooglePlayReceiver}
01-16 14:57:22.991 2806-5680/? E/NetworkScheduler: Unknown result code received: 4
01-16 14:57:24.872 2806-5455/? E/NetworkScheduler.TED: Couldn't start service: Intent { act=com.google.android.gms.gcm.ACTION_TASK_READY cmp=com.thundermaps.staging.main/com.firebase.jobdispatcher.GooglePlayReceiver (has extras) }
01-16 14:57:24.876 2806-5680/? E/NetworkScheduler: Unknown result code received: 4
01-16 14:58:23.334 2806-5680/? E/NetworkScheduler.TED: Unable to bind to task service: ComponentInfo{com.atlassian.android.jira.core/com.firebase.jobdispatcher.GooglePlayReceiver}
01-16 14:58:23.336 2806-9170/? E/NetworkScheduler: Unknown result code received: 4
01-16 14:58:26.542 2806-5455/? E/NetworkScheduler.TED: Couldn't start service: Intent { act=com.google.android.gms.gcm.ACTION_TASK_READY cmp=com.thundermaps.staging.main/com.firebase.jobdispatcher.GooglePlayReceiver (has extras) }
01-16 14:58:26.542 2806-5680/? E/NetworkScheduler: Unknown result code received: 4
01-16 15:00:07.184 2806-5455/? E/NetworkScheduler.TED: Couldn't start service: Intent { act=com.google.android.gms.gcm.ACTION_TASK_READY cmp=com.thundermaps.staging.main/com.firebase.jobdispatcher.GooglePlayReceiver (has extras) }
01-16 15:00:07.197 2806-9170/? E/NetworkScheduler: Unknown result code received: 4

and:

01-16 14:57:52.332 1254-1730/? W/ActivityManager: Unable to start service Intent { act=com.google.android.gms.drive.ApiService.RESET_AFTER_BOOT flg=0x4 cmp=com.google.android.gms/.drive.api.ApiService (has extras) } U=0: not found

I can see this in the logcat (some of it may not be relevant to this library:

01-11 10:01:16.889 9296-9296/? E/BroadcastReceiver: 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:682)
                                                        at android.content.BroadcastReceiver.setResult(BroadcastReceiver.java:557)
                                                        at com.google.android.gcm.GCMBroadcastReceiver.onReceive(GCMBroadcastReceiver.java:61)
                                                        at android.app.ActivityThread.handleReceiver(ActivityThread.java:3410)
                                                        at android.app.ActivityThread.-wrap17(Unknown Source:0)
                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1772)
                                                        at android.os.Handler.dispatchMessage(Handler.java:105)
                                                        at android.os.Looper.loop(Looper.java:164)
                                                        at android.app.ActivityThread.main(ActivityThread.java:6809)
                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
01-11 10:01:16.891 7488-7999/? V/AlarmManager: Triggering alarm #0: 2 when =1209212 package =com.google.android.gms operation =*walarm*:com.google.android.location.ALARM_WAKEUP_BURST_COLLECTION_TRIGGER flags =0x0
01-11 10:01:16.891 7488-7999/? V/AlarmManager: Triggering alarm #1: 2 when =1252381 package =android operation = null listenTag =WifiConnectivityManager Schedule Periodic Scan Timer flags =0x8
01-11 10:01:16.891 7488-7999/? V/AlarmManager: Triggering alarm #2: 3 when =1280510 package =com.google.android.gms operation =*alarm*:com.google.android.gms/.lockbox.LockboxAlarmReceiver flags =0x0
01-11 10:01:16.891 7488-7999/? V/AlarmManager: Triggering alarm #3: 1 when =1515618000000 package =com.google.android.calendar operation =*alarm*:com.google.android.calendar.APPWIDGET_SCHEDULED_UPDATE flags =0x0
01-11 10:01:16.892 9296-19565/? I/SubscribedFeeds: Received message
01-11 10:01:16.910 7488-8628/? W/BroadcastQueue: Background execution not allowed: receiving Intent { act=com.google.android.calendar.APPWIDGET_SCHEDULED_UPDATE dat=content://com.android.calendar typ=vnd.android.data/update flg=0x14 (has extras) } to com.google.android.calendar/com.android.calendar.widget.CalendarAppWidgetProvider
01-11 10:01:16.915 9260-11668/? E/NetworkScheduler.TED: Couldn't start service: Intent { act=com.google.android.gms.gcm.ACTION_TASK_READY cmp=com.thundermaps.staging.main/com.firebase.jobdispatcher.GooglePlayReceiver (has extras) }
01-11 10:01:16.916 9260-11705/? E/NetworkScheduler: Unknown result code received: 4
01-11 10:01:16.923 9260-18722/? E/NetworkScheduler.TED: Unable to bind to task service: ComponentInfo{com.atlassian.android.jira.core/com.firebase.jobdispatcher.GooglePlayReceiver}
01-11 10:01:16.925 7488-14577/? W/ActivityManager: Unbind failed: could not find connection for android.os.BinderProxy@bfa7b49
01-11 10:01:16.932 9260-11705/? E/NetworkScheduler: Unknown result code received: 4

I can confirm this error shows up in the logcat when to service tries to start (most of the above logs then are probably irrelevant):

01-11 10:18:16.983 9260-11668/? E/NetworkScheduler.TED: Couldn't start service: Intent { act=com.google.android.gms.gcm.ACTION_TASK_READY cmp=com.thundermaps.staging.main/com.firebase.jobdispatcher.GooglePlayReceiver (has extras) }
01-11 10:18:16.984 9260-17433/? E/NetworkScheduler: Unknown result code received: 4

I can tell that the service tried to start because of the scheduled time suddenly changing

    (finished) [com.thundermaps.staging.main/com.firebase.jobdispatcher.GooglePlayReceiver:on-device-boot,u0]
    (scheduled) com.thundermaps.staging.main/com.firebase.jobdispatcher.GooglePlayReceiver{u=0 tag="on-device-boot" trigger=window{start=0s,end=60s,earliest=-57s,latest=2s} requirements=[NET_ANY] attributes=[PERSISTED,RECURRING] scheduled=-57s last_run=N/A jid=N/A status=PENDING retries=6 client_lib=FIREBASE_JOB_DISPATCHER-1}
    (finished) [com.thundermaps.staging.main/com.firebase.jobdispatcher.GooglePlayReceiver:on-device-boot,u0]
    (scheduled) com.thundermaps.staging.main/com.firebase.jobdispatcher.GooglePlayReceiver{u=0 tag="on-device-boot" trigger=window{start=0s,end=60s,earliest=-58s,latest=1s} requirements=[NET_ANY] attributes=[PERSISTED,RECURRING] scheduled=-58s last_run=N/A jid=N/A status=PENDING retries=6 client_lib=FIREBASE_JOB_DISPATCHER-1}
    (finished) [com.thundermaps.staging.main/com.firebase.jobdispatcher.GooglePlayReceiver:on-device-boot,u0]
    (scheduled) com.thundermaps.staging.main/com.firebase.jobdispatcher.GooglePlayReceiver{u=0 tag="on-device-boot" trigger=window{start=0s,end=60s,earliest=-59s,latest=0s} requirements=[NET_ANY] attributes=[PERSISTED,RECURRING] scheduled=-59s last_run=N/A jid=N/A status=PENDING retries=6 client_lib=FIREBASE_JOB_DISPATCHER-1}
    (finished) [com.thundermaps.staging.main/com.firebase.jobdispatcher.GooglePlayReceiver:on-device-boot,u0]
    (scheduled) com.thundermaps.staging.main/com.firebase.jobdispatcher.GooglePlayReceiver{u=0 tag="on-device-boot" trigger=window{start=0s,end=60s,earliest=1919s,latest=1979s} requirements=[NET_ANY] attributes=[PERSISTED,RECURRING] scheduled=1919s last_run=N/A jid=N/A status=PENDING retries=7 client_lib=FIREBASE_JOB_DISPATCHER-1}
    (finished) [com.thundermaps.staging.main/com.firebase.jobdispatcher.GooglePlayReceiver:on-device-boot,u0]
    (scheduled) com.thundermaps.staging.main/com.firebase.jobdispatcher.GooglePlayReceiver{u=0 tag="on-device-boot" trigger=window{start=0s,end=60s,earliest=1918s,latest=1978s} requirements=[NET_ANY] attributes=[PERSISTED,RECURRING] scheduled=1918s last_run=N/A jid=N/A status=PENDING retries=7 client_lib=FIREBASE_JOB_DISPATCHER-1}
    (finished) [com.thundermaps.staging.main/com.firebase.jobdispatcher.GooglePlayReceiver:on-device-boot,u0]
    (scheduled) com.thundermaps.staging.main/com.firebase.jobdispatcher.GooglePlayReceiver{u=0 tag="on-device-boot"

I also get this

> adb shell dumpsys package com.thundermaps.staging.main | grep stopped
    User 0: ceDataInode=1991332 installed=true hidden=false suspended=false stopped=false notLaunched=false enabled=0 instant=false
    User 10: ceDataInode=0 installed=true hidden=false suspended=false stopped=true notLaunched=true enabled=0 instant=false
    User 11: ceDataInode=0 installed=true hidden=false suspended=false stopped=true notLaunched=true enabled=0 instant=false

stopped=false on the user zero is probably a good sign

@dhirenpratap looks like you had the same problem and error as me. Did you find anything in the last 6 months?

same error here, job cannot start after reboot

I can confirm, any workaround? Lifetime.FOREVER is inteded job to be rescheduled automatically after reboot, right? There should be no any action needed to do so

Adding <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> solved the problem for me. No other action needed.

In April 2019 we announced that Firebase Job Dispatcher would be deprecated today, April 7th 2020. For this reason we are going to close all open issues and archive the repository. We will also stop supporting FJD for new app installations (such as those targeting sdk versions greater than Android Q). Existing apps that rely on FJD should continue to function as usual.

While we will no longer work on FJD, we encourage you to migrate to Work Manager which is a superior tool and fully supported by the Android team.

Thank you for taking the time to try the library and provide this feedback. We sincerely appreciate your effort and we apologize for not addressing it in time.