Fixed
Status Update
Comments
ra...@google.com <ra...@google.com> #2
In SystemJobService, it can expect null, and able to tolerance null from WorkManagerImpl.getInstance, due to auto-backup reason.
@Override
public void onCreate() {
super.onCreate();
mWorkManagerImpl = WorkManagerImpl.getInstance(getApplicationContext());
if (mWorkManagerImpl == null) {
// This can occur if...
// 1. The app is performing an auto-backup. Prior to O, JobScheduler could erroneously
// try to send commands to JobService in this state ( b/32180780 ). Since neither
// Application#onCreate nor ContentProviders have run, WorkManager won't be
// initialized. In this case, we should ignore all JobScheduler commands and tell it
// to retry.
But, current WorkManagerImpl.getInstance(Context context) implementation is that, it will never return null but throw IllegalStateException.
Isn't there's conflict among these 2 SystemJobService.onCreate logic, and WorkManagerImpl.getInstance logic?
@Override
public void onCreate() {
super.onCreate();
mWorkManagerImpl = WorkManagerImpl.getInstance(getApplicationContext());
if (mWorkManagerImpl == null) {
// This can occur if...
// 1. The app is performing an auto-backup. Prior to O, JobScheduler could erroneously
// try to send commands to JobService in this state (
// Application#onCreate nor ContentProviders have run, WorkManager won't be
// initialized. In this case, we should ignore all JobScheduler commands and tell it
// to retry.
But, current WorkManagerImpl.getInstance(Context context) implementation is that, it will never return null but throw IllegalStateException.
Isn't there's conflict among these 2 SystemJobService.onCreate logic, and WorkManagerImpl.getInstance logic?
su...@google.com <su...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-master-dev
commit e14104eb7008f82edd50b37e16bd119b307e0554
Author: Sumir Kataria <sumir@google.com>
Date: Mon Jun 24 10:50:57 2019
Fix for JobScheduler calls when backup is in progress.
The original fix (ag/Ia1604b7c4b98f6b31869e1161a0c1efce7fe46f2) relied
on a null-check, but the new version of WorkManager.getInstance(Context)
with the Context param doesn't return null; it throws an Exception. This
CL updates the three places where we explicitly check for the return value
internally:
1. SystemJobService (the main place where this would manifest)
2. RescheduleReceiver
3. WorkManagerTestInitHelper (for consistency)
Fixes: 135858602
Test: Ran existing tests
Change-Id: Ia232869712d0c78fd80e91d0a863b8c50a080400
M work/workmanager-testing/src/main/java/androidx/work/testing/WorkManagerTestInitHelper.java
M work/workmanager/src/main/java/androidx/work/impl/background/systemalarm/RescheduleReceiver.java
M work/workmanager/src/main/java/androidx/work/impl/background/systemjob/SystemJobService.java
https://android-review.googlesource.com/988026
https://goto.google.com/android-sha1/e14104eb7008f82edd50b37e16bd119b307e0554
Branch: androidx-master-dev
commit e14104eb7008f82edd50b37e16bd119b307e0554
Author: Sumir Kataria <sumir@google.com>
Date: Mon Jun 24 10:50:57 2019
Fix for JobScheduler calls when backup is in progress.
The original fix (ag/Ia1604b7c4b98f6b31869e1161a0c1efce7fe46f2) relied
on a null-check, but the new version of WorkManager.getInstance(Context)
with the Context param doesn't return null; it throws an Exception. This
CL updates the three places where we explicitly check for the return value
internally:
1. SystemJobService (the main place where this would manifest)
2. RescheduleReceiver
3. WorkManagerTestInitHelper (for consistency)
Fixes: 135858602
Test: Ran existing tests
Change-Id: Ia232869712d0c78fd80e91d0a863b8c50a080400
M work/workmanager-testing/src/main/java/androidx/work/testing/WorkManagerTestInitHelper.java
M work/workmanager/src/main/java/androidx/work/impl/background/systemalarm/RescheduleReceiver.java
M work/workmanager/src/main/java/androidx/work/impl/background/systemjob/SystemJobService.java
dr...@gmail.com <dr...@gmail.com> #4
Thanks you so much for the speedy fixed!
May I know when will it be ready for production? As, currently, this IllegalStateException is impacting our users.
May I know when will it be ready for production? As, currently, this IllegalStateException is impacting our users.
dr...@gmail.com <dr...@gmail.com> #5
Hello, please look for this later in the week. If you want to work around this bug specifically and don't need on-demand initialization, you can use the old (deprecated) WorkManager.getInstance() method for now.
dr...@gmail.com <dr...@gmail.com> #6
Hello. Thanks for respond. I surely will keep a pair of eye on the next release :)
Yes. We don't need on-demand initialization. May I know how does using old (deprecated) WorkManager.getInstance() in our app code, able to bypass this problem? Isn't the crash is origin from library internal SystemJobService?
We once thinking to bypass this problem, by switching back to Version 2.0.1 (The version just before WorkManager.getInstance(Context) is introduced). However, we notice Room version is being changed in between. Downgrading WorkManager version, might cause additional SQLite problem.
Yes. We don't need on-demand initialization. May I know how does using old (deprecated) WorkManager.getInstance() in our app code, able to bypass this problem? Isn't the crash is origin from library internal SystemJobService?
We once thinking to bypass this problem, by switching back to Version 2.0.1 (The version just before WorkManager.getInstance(Context) is introduced). However, we notice Room version is being changed in between. Downgrading WorkManager version, might cause additional SQLite problem.
dr...@gmail.com <dr...@gmail.com> #7
Sorry, you are correct that moving to the deprecated method will not help you here. I would advise waiting for the release later this week. And thank you very much for finding this bug and doing the research to find the underlying issue.
I am curious: do you actually have reports of this bug on Android 9? It should've been fixed in the platform layer at that point. If possible, can you share any Android 9 specific logs/bugreports/stacktraces with device models?
I am curious: do you actually have reports of this bug on Android 9? It should've been fixed in the platform layer at that point. If possible, can you share any Android 9 specific logs/bugreports/stacktraces with device models?
su...@google.com <su...@google.com> #8
OK. Finger crossed users will not leave our app. I will follow the Green Dinosaur in Twitter, to wait for his announcement.
Based on your code comment, I thought this problem shouldn't occur in new Android but it happens some how. This is the log
Asus ZenFone 5 (ZE620KL) (ASUS_X00QD), Android 9 (Happen 2 times)
Asus ZenFone 5Z (ZS620KL/ZS621KL) (ASUS_Z01R_1), Android 9 (Happen 1 time)
3 incidents are having same log trace as below
java.lang.RuntimeException:
at android.app.ActivityThread.handleCreateService (ActivityThread.java:3570)
at android.app.ActivityThread.access$1300 (ActivityThread.java:200)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1672)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:198)
at android.app.ActivityThread.main (ActivityThread.java:6732)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858)
Caused by: java.lang.IllegalStateException:
at androidx.work.impl.WorkManagerImpl.getInstance (WorkManagerImpl.java:142)
at androidx.work.impl.background.systemjob.SystemJobService.onCreate (SystemJobService.java:53)
at android.app.ActivityThread.handleCreateService (ActivityThread.java:3558)
at android.app.ActivityThread.access$1300 (ActivityThread.java:200)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1672)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:198)
at android.app.ActivityThread.main (ActivityThread.java:6732)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858)
I attach the screenshot of Google Play Console as well. (I expect the stack trace should print programmer's message side-by-side with IllegalStateException. But it doesn't)
Feel free to let me know if you need any information from my side. Happy to help.
Based on your code comment, I thought this problem shouldn't occur in new Android but it happens some how. This is the log
Asus ZenFone 5 (ZE620KL) (ASUS_X00QD), Android 9 (Happen 2 times)
Asus ZenFone 5Z (ZS620KL/ZS621KL) (ASUS_Z01R_1), Android 9 (Happen 1 time)
3 incidents are having same log trace as below
java.lang.RuntimeException:
at android.app.ActivityThread.handleCreateService (ActivityThread.java:3570)
at android.app.ActivityThread.access$1300 (ActivityThread.java:200)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1672)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:198)
at android.app.ActivityThread.main (ActivityThread.java:6732)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858)
Caused by: java.lang.IllegalStateException:
at androidx.work.impl.WorkManagerImpl.getInstance (WorkManagerImpl.java:142)
at androidx.work.impl.background.systemjob.SystemJobService.onCreate (SystemJobService.java:53)
at android.app.ActivityThread.handleCreateService (ActivityThread.java:3558)
at android.app.ActivityThread.access$1300 (ActivityThread.java:200)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1672)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:198)
at android.app.ActivityThread.main (ActivityThread.java:6732)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858)
I attach the screenshot of Google Play Console as well. (I expect the stack trace should print programmer's message side-by-side with IllegalStateException. But it doesn't)
Feel free to let me know if you need any information from my side. Happy to help.
ra...@google.com <ra...@google.com> #9
Thanks, we'll investigate this internally.
ra...@google.com <ra...@google.com> #10
Hello, wondering whether the fix will be released in another one, or two days. As, users start to complain and leaving our app, due to increased crash rate :(
Thanks.
Thanks.
dr...@gmail.com <dr...@gmail.com> #11
Hi, we're still aiming to get this out this week.
su...@google.com <su...@google.com> #12
still have bug:
trace:
5 java.lang.IllegalStateException:WorkManager needs to be initialized via a ContentProvider#onCreate() or an Application#onCreate().
6 androidx.work.impl.background.systemjob.SystemJobService.onCreate(SystemJobService.java:68)
7 android.app.ActivityThread.handleCreateService(ActivityThread.java:3133)
8 android.app.ActivityThread.access$1900(ActivityThread.java:196)
9 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1622)
10 com.android.tony.defenselib.hook.HookHandle$1.handleMessage(HookHandle.java:30)
11 android.os.Handler.dispatchMessage(Handler.java:107)
12 android.os.Looper.loop(Looper.java:210)
13 android.app.ActivityThread.main(ActivityThread.java:5982)
14 java.lang.reflect.Method.invoke(Native Method)
15 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:852)
16 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:742)
this code cause crash:
if (!Application.class.equals(getApplication().getClass())) {
// During auto-backup, we don't get a custom Application subclass. This code path
// indicates we are either performing auto-backup or the user never used a custom
// Application class (or both).
throw new IllegalStateException("WorkManager needs to be initialized via a "
+ "ContentProvider#onCreate() or an Application#onCreate().");
}
my analysis:
code in handleCreateService() in ActivityThread.java:
" Application app = packageInfo.makeApplication(false, mInstrumentation);
service.attach(context, this,data.info.name , data.token, app, ActivityManager.getService())
"
handleCreateService--->. Application app = packageInfo.makeApplication(false, mInstrumentation); ---> forceDefaultAppClass is always false-->if have custom Application,will make custom Application ---> service.attach(context, this,data.info.name , data.token, app, ActivityManager.getService()); ---> so getApplication() in service get custom application
--> if have customApplication, the code : "Application.class.equals(getApplication().getClass()" in Service will be false , even it's in backup mode
trace:
5 java.lang.IllegalStateException:WorkManager needs to be initialized via a ContentProvider#onCreate() or an Application#onCreate().
6 androidx.work.impl.background.systemjob.SystemJobService.onCreate(SystemJobService.java:68)
7 android.app.ActivityThread.handleCreateService(ActivityThread.java:3133)
8 android.app.ActivityThread.access$1900(ActivityThread.java:196)
9 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1622)
10 com.android.tony.defenselib.hook.HookHandle$1.handleMessage(HookHandle.java:30)
11 android.os.Handler.dispatchMessage(Handler.java:107)
12 android.os.Looper.loop(Looper.java:210)
13 android.app.ActivityThread.main(ActivityThread.java:5982)
14 java.lang.reflect.Method.invoke(Native Method)
15 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:852)
16 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:742)
this code cause crash:
if (!Application.class.equals(getApplication().getClass())) {
// During auto-backup, we don't get a custom Application subclass. This code path
// indicates we are either performing auto-backup or the user never used a custom
// Application class (or both).
throw new IllegalStateException("WorkManager needs to be initialized via a "
+ "ContentProvider#onCreate() or an Application#onCreate().");
}
my analysis:
code in handleCreateService() in ActivityThread.java:
" Application app = packageInfo.makeApplication(false, mInstrumentation);
service.attach(context, this,
"
handleCreateService--->. Application app = packageInfo.makeApplication(false, mInstrumentation); ---> forceDefaultAppClass is always false-->if have custom Application,will make custom Application ---> service.attach(context, this,
--> if have customApplication, the code : "Application.class.equals(getApplication().getClass()" in Service will be false , even it's in backup mode
dr...@gmail.com <dr...@gmail.com> #13
i'm also having the same crash, here is the relevant stacktrace:
compileSdkVersion 30
implementation 'androidx.work:work-runtime-ktx:2.4.0'
Crash
TCT (Alcatel) 5056D
Android 6.0 (SDK 23)
48.aab
2 hours ago
java.lang.RuntimeException:
at android.app.ActivityThread.handleCreateService (ActivityThread.java:2887)
at android.app.ActivityThread.access$1900 (ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1427)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:148)
at android.app.ActivityThread.main (ActivityThread.java:5417)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException:
at androidx.work.impl.background.systemjob.SystemJobService.onCreate (SystemJobService.java:2)
at android.app.ActivityThread.handleCreateService (ActivityThread.java:2877)
at android.app.ActivityThread.access$1900 (ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1427)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:148)
at android.app.ActivityThread.main (ActivityThread.java:5417)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)
What could the walkaround this issue? Is there another way to initialize the WorkManager instance? I'm using
private fun getWorkManager(): WorkManager =
try {
WorkManager.getInstance(App.context)
} catch (e: Exception) {
e.printStackTrace()
sleep(100)
getWorkManager()
}
compileSdkVersion 30
implementation 'androidx.work:work-runtime-ktx:2.4.0'
Crash
TCT (Alcatel) 5056D
Android 6.0 (SDK 23)
48.aab
2 hours ago
java.lang.RuntimeException:
at android.app.ActivityThread.handleCreateService (ActivityThread.java:2887)
at android.app.ActivityThread.access$1900 (ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1427)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:148)
at android.app.ActivityThread.main (ActivityThread.java:5417)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException:
at androidx.work.impl.background.systemjob.SystemJobService.onCreate (SystemJobService.java:2)
at android.app.ActivityThread.handleCreateService (ActivityThread.java:2877)
at android.app.ActivityThread.access$1900 (ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1427)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:148)
at android.app.ActivityThread.main (ActivityThread.java:5417)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)
What could the walkaround this issue? Is there another way to initialize the WorkManager instance? I'm using
private fun getWorkManager(): WorkManager =
try {
WorkManager.getInstance(App.context)
} catch (e: Exception) {
e.printStackTrace()
sleep(100)
getWorkManager()
}
su...@google.com <su...@google.com> #14
Same Error on production when call WorkManager.getInstance(context):
Library version: androidx.work:work-runtime:2.4.0
Samsung Galaxy S8 (dreamlte), 3840MB RAM, Android 9
java.lang.RuntimeException:
at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6227)
at android.app.ActivityThread.access$1200 (ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1785)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:214)
at android.app.ActivityThread.main (ActivityThread.java:7050)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:965)
Caused by: java.lang.IllegalStateException:
at androidx.work.impl.WorkManagerImpl.getInstance (WorkManagerImpl.java:150)
at androidx.work.WorkManager.getInstance (WorkManager.java:184)
at br.com.rcgm.dicaslotofacilfull.task.WorkRequestSincronizarConcurso.enfileirar (WorkRequestSincronizarConcurso.java:20)
at br.com.rcgm.dicaslotofacilfull.BaseApplication.onCreate (BaseApplication.java:23)
at android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1154)
at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6222)
Library version: androidx.work:work-runtime:2.4.0
Samsung Galaxy S8 (dreamlte), 3840MB RAM, Android 9
java.lang.RuntimeException:
at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6227)
at android.app.ActivityThread.access$1200 (ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1785)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:214)
at android.app.ActivityThread.main (ActivityThread.java:7050)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:965)
Caused by: java.lang.IllegalStateException:
at androidx.work.impl.WorkManagerImpl.getInstance (WorkManagerImpl.java:150)
at androidx.work.WorkManager.getInstance (WorkManager.java:184)
at br.com.rcgm.dicaslotofacilfull.task.WorkRequestSincronizarConcurso.enfileirar (WorkRequestSincronizarConcurso.java:20)
at br.com.rcgm.dicaslotofacilfull.BaseApplication.onCreate (BaseApplication.java:23)
at android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1154)
at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6222)
dr...@gmail.com <dr...@gmail.com> #15
Hi,
I'm also facing same issue, in few devices.
Instance access : WorkManager.getInstance()
I'm not doing on-demand Initialization.
version used: 'androidx.work:work-runtime:2.3.4'
Device details
Brand: samsung
Model: Galaxy J2 Pro
Android version: 6.0.1
Fatal Exception: java.lang.RuntimeException: Unable to create service androidx.work.impl.background.systemjob.SystemJobService: java.lang.IllegalStateException: WorkManager needs to be initialized via a ContentProvider#onCreate() or an Application#onCreate().
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3883)
at android.app.ActivityThread.-wrap8(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1909)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by java.lang.IllegalStateException: WorkManager needs to be initialized via a ContentProvider#onCreate() or an Application#onCreate().
at androidx.work.impl.background.systemjob.SystemJobService.onCreate(SystemJobService.java:73)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3873)
at android.app.ActivityThread.-wrap8(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1909)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
I'm also facing same issue, in few devices.
Instance access : WorkManager.getInstance()
I'm not doing on-demand Initialization.
version used: 'androidx.work:work-runtime:2.3.4'
Device details
Brand: samsung
Model: Galaxy J2 Pro
Android version: 6.0.1
Fatal Exception: java.lang.RuntimeException: Unable to create service androidx.work.impl.background.systemjob.SystemJobService: java.lang.IllegalStateException: WorkManager needs to be initialized via a ContentProvider#onCreate() or an Application#onCreate().
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3883)
at android.app.ActivityThread.-wrap8(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1909)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by java.lang.IllegalStateException: WorkManager needs to be initialized via a ContentProvider#onCreate() or an Application#onCreate().
at androidx.work.impl.background.systemjob.SystemJobService.onCreate(SystemJobService.java:73)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3873)
at android.app.ActivityThread.-wrap8(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1909)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
dr...@gmail.com <dr...@gmail.com> #16
i have the same issue
dr...@gmail.com <dr...@gmail.com> #17
deleted
su...@google.com <su...@google.com> #18
Still seeing this issue in 2.5.0 using default WorkManager.getInstance() initialization. How can we prevent this situation from occurring?
if (!Application.class.equals(getApplication().getClass())) {
// During auto-backup, we don't get a custom Application subclass. This code path
// indicates we are either performing auto-backup or the user never used a custom
// Application class (or both).
throw new IllegalStateException("WorkManager needs to be initialized via a "
+ "ContentProvider#onCreate() or an Application#onCreate().");
}
if (!Application.class.equals(getApplication().getClass())) {
// During auto-backup, we don't get a custom Application subclass. This code path
// indicates we are either performing auto-backup or the user never used a custom
// Application class (or both).
throw new IllegalStateException("WorkManager needs to be initialized via a "
+ "ContentProvider#onCreate() or an Application#onCreate().");
}
dr...@gmail.com <dr...@gmail.com> #19
this issue on workManager 2.5.0 when initialize WorkManager in background thread, bring it back to UI thread
ra...@google.com <ra...@google.com> #20
I begin to see this issue after using "on demand Initialization"
Stacktrace:
Caused by java.lang.IllegalStateException
WorkManager needs to be initialized via a ContentProvider#onCreate() or an Application#onCreate().
androidx.work.impl.background.systemjob.SystemJobService.onCreate (SystemJobService.java:73)
android.app.ActivityThread.handleCreateService (ActivityThread.java:3833)
android.app.ActivityThread.access$1500 (ActivityThread.java:229)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1881)
android.os.Handler.dispatchMessage (Handler.java:106)
android.os.Looper.loop (Looper.java:226)
android.app.ActivityThread.main (ActivityThread.java:7178)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:503)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:942)
For now, the device affected is
android 9 Realme.
Work Manager version: 2.6.0
Stacktrace:
Caused by java.lang.IllegalStateException
WorkManager needs to be initialized via a ContentProvider#onCreate() or an Application#onCreate().
androidx.work.impl.background.systemjob.SystemJobService.onCreate (SystemJobService.java:73)
android.app.ActivityThread.handleCreateService (ActivityThread.java:3833)
android.app.ActivityThread.access$1500 (ActivityThread.java:229)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1881)
android.os.Handler.dispatchMessage (Handler.java:106)
android.os.Looper.loop (Looper.java:226)
android.app.ActivityThread.main (ActivityThread.java:7178)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:503)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:942)
For now, the device affected is
android 9 Realme.
Work Manager version: 2.6.0
ra...@google.com <ra...@google.com> #21
Still happening with WorkManager 2.7.1 Samsung Galaxy S21 Ultra 5G Android 12 (SDK 31)
java.lang.RuntimeException:
at android.app.ActivityThread.handleCreateService (ActivityThread.java:4953)
at android.app.ActivityThread.access$1900 (ActivityThread.java:310)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2300)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loopOnce (Looper.java:226)
at android.os.Looper.loop (Looper.java:313)
at android.app.ActivityThread.main (ActivityThread.java:8669)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1135)
Caused by: java.lang.IllegalStateException:
at androidx.work.impl.WorkManagerImpl.getInstance (WorkManagerImpl.java:158)
at androidx.work.impl.foreground.SystemForegroundDispatcher.<init> (SystemForegroundDispatcher.java:105)
at androidx.work.impl.foreground.SystemForegroundService.initializeDispatcher (SystemForegroundService.java:96)
at androidx.work.impl.foreground.SystemForegroundService.onCreate (SystemForegroundService.java:59)
at android.app.ActivityThread.handleCreateService (ActivityThread.java:4940)
at android.app.ActivityThread.access$1900 (ActivityThread.java:310)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2300)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loopOnce (Looper.java:226)
at android.os.Looper.loop (Looper.java:313)
at android.app.ActivityThread.main (ActivityThread.java:8669)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1135)
dr...@gmail.com <dr...@gmail.com> #22
We recently moved our WorkManager initialization to the default pattern and have started seeing this same issue.
java.lang.RuntimeException: Unable to create service androidx.work.impl.background.systemjob.SystemJobService: java.lang.IllegalStateException: WorkManager needs to be initialized via a ContentProvider#onCreate() or an Application#onCreate().
at android.app.ActivityThread.handleCreateService(ActivityThread.java:5073)
at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2425)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8741)
at java.lang.reflect.Method.invoke(Method.java:-2)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
Caused by: java.lang.IllegalStateException: WorkManager needs to be initialized via a ContentProvider#onCreate() or an Application#onCreate().
at androidx.work.impl.background.systemjob.SystemJobService.onCreate(SystemJobService:73)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:5060)
at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2425)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8741)
at java.lang.reflect.Method.invoke(Method.java:-2)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
dr...@gmail.com <dr...@gmail.com> #23
I would check to make sure that the app is not a multi-process app. If it is, you will need your Application
to additionally sub-class Configuration.Provider
or additionally define a second provider for the other process.
dr...@gmail.com <dr...@gmail.com> #24
Hi all, I am also facing the same crash in Work Manager 2.7.1 with on-demand initialization in Samsung X-Cover Pro(31), sdk 32. There's no concrete scenario for this crash to happen, it happens randomly at any screen. Plus the auto-backup is disabled in my app which was listed as one of the factors responsible for the crash. Can someone please assist me with a way to fix/handle this crash?
dr...@gmail.com <dr...@gmail.com> #25
Hi all , i use workManager 2.7.0 face some crash "IllegalStateExceptionWorkManager needs to be initialized via a ContentProvider#onCreate() or an Application#onCreate()" . i am sure app manifest allowBackUp=false and initWorkManger in every process. Can someone please assist me with a way to fix/handle this crash?
ra...@google.com <ra...@google.com> #26
I'm experience the same problem. I used suspend function to init WorkManager and used Dispatchers.Default as a scope to launch. I'm going to use runBlocking instead
dr...@gmail.com <dr...@gmail.com> #27
This is excellent news... thanks for checking it out so carefully, and fingers crossed... look forward to the next beta and will report back either way.
Any ETA on the next beta?
Keep up the good work on this really useful library!
Any ETA on the next beta?
Keep up the good work on this really useful library!
ap...@google.com <ap...@google.com> #28
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 177837514245d5bb24cc8e9bc27f20503e23e308
Author: Rahul Ravikumar <rahulrav@google.com>
Date: Tue Jan 29 17:50:14 2019
Fixes ConstraintsCommandHandler that correctly enables and disables proxies.
* ConstraintsCommandHandler was only looking at work that was eligible to be scheduled.
This is incorrect, as we may have Workers that are scheduled, but are pending execution due
to an unmet constraint. We need to look at all scheduled work which is unfinished.
* The only reason why this worked before with integration tests was due to one of 2 reasons:
* The process was in the foreground anyway, and there was an active WorkConstraintTracker.
* Enabling / disabling airplane mode (to test Network Constraints) would have caused a
TIME_SET broadcast in some cases where we reschedule everything (RescheduleReceiver).
Test: Updated SystemAlarmDispatcherTests & integration tests on API 22 with the Battery charging
Constraint that has no other side effects.
Change-Id: Ib973931b47be915dd8f533e1e651b6c1a29843f9
Fixes: b/123379508
M work/workmanager/src/androidTest/java/androidx/work/impl/background/systemalarm/SystemAlarmDispatcherTest.java
M work/workmanager/src/main/java/androidx/work/impl/background/systemalarm/ConstraintsCommandHandler.java
M work/workmanager/src/main/java/androidx/work/impl/background/systemalarm/RescheduleReceiver.java
M work/workmanager/src/main/java/androidx/work/impl/model/WorkSpecDao.java
https://android-review.googlesource.com/889839
https://goto.google.com/android-sha1/177837514245d5bb24cc8e9bc27f20503e23e308
Branch: androidx-master-dev
commit 177837514245d5bb24cc8e9bc27f20503e23e308
Author: Rahul Ravikumar <rahulrav@google.com>
Date: Tue Jan 29 17:50:14 2019
Fixes ConstraintsCommandHandler that correctly enables and disables proxies.
* ConstraintsCommandHandler was only looking at work that was eligible to be scheduled.
This is incorrect, as we may have Workers that are scheduled, but are pending execution due
to an unmet constraint. We need to look at all scheduled work which is unfinished.
* The only reason why this worked before with integration tests was due to one of 2 reasons:
* The process was in the foreground anyway, and there was an active WorkConstraintTracker.
* Enabling / disabling airplane mode (to test Network Constraints) would have caused a
TIME_SET broadcast in some cases where we reschedule everything (RescheduleReceiver).
Test: Updated SystemAlarmDispatcherTests & integration tests on API 22 with the Battery charging
Constraint that has no other side effects.
Change-Id: Ib973931b47be915dd8f533e1e651b6c1a29843f9
Fixes:
M work/workmanager/src/androidTest/java/androidx/work/impl/background/systemalarm/SystemAlarmDispatcherTest.java
M work/workmanager/src/main/java/androidx/work/impl/background/systemalarm/ConstraintsCommandHandler.java
M work/workmanager/src/main/java/androidx/work/impl/background/systemalarm/RescheduleReceiver.java
M work/workmanager/src/main/java/androidx/work/impl/model/WorkSpecDao.java
dr...@gmail.com <dr...@gmail.com> #29
Any ETA for beta04? Am desperate to try it out..
ra...@google.com <ra...@google.com> #30
Looking at early next week.
dr...@gmail.com <dr...@gmail.com> #31
OK, thanks!
dr...@gmail.com <dr...@gmail.com> #32
I'm still seeing this problem, or seeing it again. I'm monitoring (at a server) requests from the device of the same user (Android 4.3), and can see that a periodic work request seems to run OK for a time, but when the device is idle and without network, when the device is given network again, not only does the late work not run, but no work ever seems to run again. And a log output of all work does still show that a periodic work is enqueued, but it just never seems to run again.
Are the tests you ran when fixing this before still working? Or has something subsequently messed it up? Or maybe I'm seeing another issue altogether.
Are the tests you ran when fixing this before still working? Or has something subsequently messed it up? Or maybe I'm seeing another issue altogether.
su...@google.com <su...@google.com> #33
Please give us a sample project. I think that's the simplest way for us to take a look at exactly what's happening for you. Which device are you running this on?
dr...@gmail.com <dr...@gmail.com> #34
Device is as per #16 -- Samsung Galaxy S3 running Android 4.3
su...@google.com <su...@google.com> #35
Can you reproduce the same behavior using a stock Android device/emulator?
dr...@gmail.com <dr...@gmail.com> #36
Not as yet; am trying now.
dr...@gmail.com <dr...@gmail.com> #37
Is there any way of querying a bit more information about enqueued work requests? The most information I can get at the moment is something like:
02-15 17:37:31.535 D/My_Worker(11599): workInfo: WorkInfo{mId='00db2ea7-07d6-42a1-a506-a26ff8e3217d', mState=ENQUEUED, mOutputData=androidx.work.Data@0, mTags=[com.example.myapp.MyWorker, widget-43806, periodic]}
02-15 17:37:31.535 D/My_Worker(11599): workInfo: WorkInfo{mId='08bce448-5d4a-4a17-89d2-6fdce6ef1091', mState=SUCCEEDED, mOutputData=androidx.work.Data@0, mTags=[com.example.myapp.MyWorker, widget-43806, backstop]}
And the only reason I can even tell if the work item is periodic or not is because I tag it with 'periodic' if it is. Otherwise, all I get is a work ID and a state... would be really handy to know when it last ran, when it is due to run next, etc. Would be very useful not least for debugging purposes.
As suggested:https://issuetracker.google.com/issues/123222823
02-15 17:37:31.535 D/My_Worker(11599): workInfo: WorkInfo{mId='00db2ea7-07d6-42a1-a506-a26ff8e3217d', mState=ENQUEUED, mOutputData=androidx.work.Data@0, mTags=[com.example.myapp.MyWorker, widget-43806, periodic]}
02-15 17:37:31.535 D/My_Worker(11599): workInfo: WorkInfo{mId='08bce448-5d4a-4a17-89d2-6fdce6ef1091', mState=SUCCEEDED, mOutputData=androidx.work.Data@0, mTags=[com.example.myapp.MyWorker, widget-43806, backstop]}
And the only reason I can even tell if the work item is periodic or not is because I tag it with 'periodic' if it is. Otherwise, all I get is a work ID and a state... would be really handy to know when it last ran, when it is due to run next, etc. Would be very useful not least for debugging purposes.
As suggested:
ra...@google.com <ra...@google.com> #38
You need to enable verbose logs. That will tell us a lot more.
ra...@google.com <ra...@google.com> #39
Also, if you are going into a SUCCEEDED state, that mean your Worker is actually not periodic. PeriodicWork never goes into a terminal state unless it has been cancelled.
It always goes back to ENQUEUED for the next interval.
It always goes back to ENQUEUED for the next interval.
dr...@gmail.com <dr...@gmail.com> #40
As per #9 above. Yes, the 4.3 user is currently running a test version with this verbose logging enabled to see if I can get something interesting from it.
ra...@google.com <ra...@google.com> #41
For reference all WorkManager logs are prefixed with a "WM-".
dr...@gmail.com <dr...@gmail.com> #42
#39: indeed, but the SUCCEEDED entry is a onetime worker... it is not tagged with 'periodic' but only 'backstop' (which is a onetime request).
dr...@gmail.com <dr...@gmail.com> #43
I've seen this behaviour now on the 4.3 emulator. I started a periodic work request (for updating a widget) with network constraint and interval of one hour (flex of 30 mins). I put the emulator into airplane mode and came back some time later. On disabling airplane mode the widget did update immediately but the trigger was ON_ENABLED for the widget and not the late work request. Thereafter, I left the widget for an hour, and nothing happened... the periodic work that was meant to trigger an update hasn't happened. I meant to dump the alarm state with "adb shell dumpsys alarm" but unfortunately I reset the widget before doing so. Will next time. Sorry it's a bit nebulous thus far... I will try to bring more concrete information next time but there's definitely still something not right with network-constrained periodic work on Android 4.3.
su...@google.com <su...@google.com> #44
Yes, please send us a sample project when you have it.
dr...@gmail.com <dr...@gmail.com> #45
I'll try, but am short of time over next few days. Tempting just to set minsdk to 21 and be done with it!
dr...@gmail.com <dr...@gmail.com> #46
I have some logs to post... would that be of assistance in lieu of a sample project for now?
ra...@google.com <ra...@google.com> #47
Yes, please send them
dr...@gmail.com <dr...@gmail.com> #48
Logs attached, from the user's Android 4.3 device. During the period in which the logs were generated, the periodic work concerned should have fired (to cause a widget to update) at least twice but failed to do so. The periodic work was on a 30 minute interval, with 15 minute flex interval. With network constraint. After enqueuing the periodic work, the device was without network for a time, then network was restored. But periodic work failed to trigger. I schedule the periodic work basically as described in #22 *except* that I now use a flex interval (to address a double running of work as per another issue).
There seems to be lots of "D/WM-" stuff in there that refers to constraints... hopefully something of interest.
There seems to be lots of "D/WM-" stuff in there that refers to constraints... hopefully something of interest.
dr...@gmail.com <dr...@gmail.com> #49
Some further information which may be of interest...
To see if it made a difference, I went back to NOT using a flexInterval, i.e. using:
workRequestBuilder = new PeriodicWorkRequest.Builder(MeteogramWorker.class, interval, TimeUnit.MILLISECONDS);
INSTEAD of:
workRequestBuilder = new PeriodicWorkRequest.Builder(MeteogramWorker.class, interval, TimeUnit.MILLISECONDS, flexInterval, TimeUnit.MILLISECONDS);
And without using flexInterval, behaviour seems to be FAR more reliable so far. The periodic work (with network constraint) has so far survived some degree of testing (on the user device): letting the periodic work fire a few times, then turning off network for one or more scheduled firings, then network back on... and each time so far the "missed" work runs straight away.
It's far from an extensive test yet, but it seems like it can't be coincidence... the above change (to NOT use flexInterval) is all I've changed, and it is performing better so far.
After *this current* issue (i.e. #123379508) was marked fixed on 30 Jan, a change was made to WorkManager flexInterval behaviour on 13 Feb as per the following:
https://issuetracker.google.com/issues/124274584
Would it have anything to do with that? Between #123379508 being fixed (30 Jan) and #124274584 being fixed (13 Feb), I think that things were going well. It seemed to be after #124274584 was fixed that things went downhill again. Again, I can't be certain, but it's a lead anyway.
P.S. the only reason I started using flexInterval in the first place was to address the issue reported here:
https://issuetracker.google.com/issues/123804615#comment8
To see if it made a difference, I went back to NOT using a flexInterval, i.e. using:
workRequestBuilder = new PeriodicWorkRequest.Builder(MeteogramWorker.class, interval, TimeUnit.MILLISECONDS);
INSTEAD of:
workRequestBuilder = new PeriodicWorkRequest.Builder(MeteogramWorker.class, interval, TimeUnit.MILLISECONDS, flexInterval, TimeUnit.MILLISECONDS);
And without using flexInterval, behaviour seems to be FAR more reliable so far. The periodic work (with network constraint) has so far survived some degree of testing (on the user device): letting the periodic work fire a few times, then turning off network for one or more scheduled firings, then network back on... and each time so far the "missed" work runs straight away.
It's far from an extensive test yet, but it seems like it can't be coincidence... the above change (to NOT use flexInterval) is all I've changed, and it is performing better so far.
After *this current* issue (i.e. #123379508) was marked fixed on 30 Jan, a change was made to WorkManager flexInterval behaviour on 13 Feb as per the following:
Would it have anything to do with that? Between #123379508 being fixed (30 Jan) and #124274584 being fixed (13 Feb), I think that things were going well. It seemed to be after #124274584 was fixed that things went downhill again. Again, I can't be certain, but it's a lead anyway.
P.S. the only reason I started using flexInterval in the first place was to address the issue reported here:
dr...@gmail.com <dr...@gmail.com> #50
BTW the logs in #48 were BEFORE I made the change mentioned in #49, i.e. using flexInterval
ra...@google.com <ra...@google.com> #51
I looked at the logs. It looks like the ConstraintTracker correctly tries to start the work, but the device subsequently reports that the constraints are unmet when trying to run the Worker.
02-17 14:02:25.255 D/WM-ConstraintTracker( 1608): NetworkStateTracker: initial state = [ Connected=false Validated=false Metered=false NotRoaming=false ]. This happens twice, like you described.
This is expected behavior. I think your disabling of flex has nothing to do with why the Worker was running when you had flex. I think the device does not have access to a reliable network as far as I can tell.
02-17 14:02:25.255 D/WM-ConstraintTracker( 1608): NetworkStateTracker: initial state = [ Connected=false Validated=false Metered=false NotRoaming=false ]. This happens twice, like you described.
This is expected behavior. I think your disabling of flex has nothing to do with why the Worker was running when you had flex. I think the device does not have access to a reliable network as far as I can tell.
dr...@gmail.com <dr...@gmail.com> #52
It's a WiFi network... not saying that is necessary "reliable" but it surely is unlikely to be consistently unreliable?
And how do you explain why NOT specifying a flexInterval results in completely reliable periodic behaviour? While specifying a flexInterval makes it fall apart?
I don't follow your comment about expected behaviour... in the period of the logs, the device had no WiFi for at least two expected periodic runs, but didn't run because there was no network. That's expected behaviour, yes. What is not expected is that even when network was restored, the work did not run, ever again. That is when specifying a flexInterval.
But when not specifying a flexInterval, it all works smoothly... that doesn't make sense does it?
Am getting reports in now from said user... it's running like clockwork with the version that doesn't specify flexInterval when setting up the periodic work request.
And how do you explain why NOT specifying a flexInterval results in completely reliable periodic behaviour? While specifying a flexInterval makes it fall apart?
I don't follow your comment about expected behaviour... in the period of the logs, the device had no WiFi for at least two expected periodic runs, but didn't run because there was no network. That's expected behaviour, yes. What is not expected is that even when network was restored, the work did not run, ever again. That is when specifying a flexInterval.
But when not specifying a flexInterval, it all works smoothly... that doesn't make sense does it?
Am getting reports in now from said user... it's running like clockwork with the version that doesn't specify flexInterval when setting up the periodic work request.
ra...@google.com <ra...@google.com> #53
Specifying flex does nothing except delay the Worker in the AlarmManager implementation.
There is absolutely no difference in how constraints are handled.
Also, from the logs that you attached, it is clear that the device was not connected to a network. That's what I am basing this on. (NetworkStateTracker: initial state = [ Connected=false Validated=false Metered=false NotRoaming=false ]).
If you still think there might be something else going on, I think the best thing to do is to send us a sample app to reproduce this on our end.
There is absolutely no difference in how constraints are handled.
Also, from the logs that you attached, it is clear that the device was not connected to a network. That's what I am basing this on. (NetworkStateTracker: initial state = [ Connected=false Validated=false Metered=false NotRoaming=false ]).
If you still think there might be something else going on, I think the best thing to do is to send us a sample app to reproduce this on our end.
dr...@gmail.com <dr...@gmail.com> #54
There are two such logs entries (one of which you quote above) that say "Connected=false".
But there is a third one, later, that says "Connected=true":
02-17 14:40:50.345 D/WM-ConstraintTracker( 3798): NetworkStateTracker: initial state = [ Connected=true Validated=false Metered=false NotRoaming=true ]
And then immediately after:
02-17 14:40:50.345 D/WM-WorkConstraintsTrack( 3798): Constraints met for 635bfec6-81c9-499a-a9d2-5e273f07573c
So why did the work not run?
But there is a third one, later, that says "Connected=true":
02-17 14:40:50.345 D/WM-ConstraintTracker( 3798): NetworkStateTracker: initial state = [ Connected=true Validated=false Metered=false NotRoaming=true ]
And then immediately after:
02-17 14:40:50.345 D/WM-WorkConstraintsTrack( 3798): Constraints met for 635bfec6-81c9-499a-a9d2-5e273f07573c
So why did the work not run?
su...@google.com <su...@google.com> #55
So I think we're going very very deep into a bug that we cannot reproduce. Please send us a sample project.
dr...@gmail.com <dr...@gmail.com> #56
Trouble is, I think this may be quite specific to that device. I can't reproduce it on the emulator (what I thought I was seeing in #43 was actually something else). So all we have to go on is the logs from the user device. I thought the D/WM- log entries would help... clearly not. Is it not possible to determine from those why the work constraints were met at 02-17 14:40:50.345 and yet the work did not execute?
dr...@gmail.com <dr...@gmail.com> #57
Here is another instance, today, where the network-constrained periodic work (widget update) failed to run on the user's Android 4.3 device after turning the WiFi back on first thing this morning... see attached logs, with relevant entries below:
02-20 10:28:12.735 D/WM-ConstraintProxy( 1227): onReceive : Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x8000010 cmp=com.cloud3squared.meteogram.devpro/androidx.work.impl.background.systemalarm.ConstraintProxy$NetworkStateProxy (has extras) }
02-20 10:28:14.770 D/WM-ConstraintTracker( 1227): NetworkStateTracker: initial state = [ Connected=true Validated=false Metered=false NotRoaming=true ]
02-20 10:28:14.815 D/WM-WorkConstraintsTrack( 1227): Constraints met for 5d210711-4c14-43cb-b6ea-2a6de910d76a
And yet, after this, the work doesn't run... there are no log entries from the startWork() function of the associated Worker.
02-20 10:28:12.735 D/WM-ConstraintProxy( 1227): onReceive : Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x8000010 cmp=com.cloud3squared.meteogram.devpro/androidx.work.impl.background.systemalarm.ConstraintProxy$NetworkStateProxy (has extras) }
02-20 10:28:14.770 D/WM-ConstraintTracker( 1227): NetworkStateTracker: initial state = [ Connected=true Validated=false Metered=false NotRoaming=true ]
02-20 10:28:14.815 D/WM-WorkConstraintsTrack( 1227): Constraints met for 5d210711-4c14-43cb-b6ea-2a6de910d76a
And yet, after this, the work doesn't run... there are no log entries from the startWork() function of the associated Worker.
Description
I think my issue is unrelated, hence this new bug report.
I am applying a network constrain to my PeriodicWorkRequest:
// ...
constraintsBuilder.setRequiredNetworkType(NetworkType.CONNECTED);
// ...
Constraints constraints = constraintsBuilder.build();
// ...
periodicWorkRequestBuilder.setConstraints(constraints);
// ...
PeriodicWorkRequest = periodicWorkRequestBuilder.build();
The idea is of course that the periodic work will run only if there is network. If there isn't, it will wait until there is, and then perform the work, and the subsequent periodic work will be scheduled after that.
This all works very well based on my own tests. But I have *one* user of an older Android 4.3 device where things break down (there may be others... but only one is reporting it... certainly it is not widespread).
From what I can determine, with a network constraint applied to the periodic work as above, if the periodic work is scheduled to run at time when there is no network, it appears on this user device that it does not run, as expected (because if if did, a "retry" work request would be scheduled by my code, which it isn't).
But it also appears that it NEVER RUNS AGAIN. In other words, the periodic work seems to be enqueued still, but just never runs again. It's as if the restoration of network doesn't kick it into running, and so it never does, ever again.
When this user runs an alternative version of the app where the network constraint is NOT applied to the periodic work (instead applying Constraints.NONE), the periodic work appears to survive the network downtime, and carry on ticking. It does attempt to run without network, which I can tell because a onetime "retry" work is scheduled, which surfaces later.
I have tried to reproduce this on an Android 4.3 emulator to no avail... seems to work as expected. So, this may not be enough information to go on.
It's almost as if CONNECTIVITY_CHANGE is not being received (I assume that WorkManager uses this signal)... or not acted on.
We don't need to add any special permissions or anything to make CONNECTIVITY_CHANGE work on all devices?