Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Risk state only updated when starting the app or after long idle time (deep sleep/ doze) for certain devices and manufacturers #756

Closed
DannySchumann opened this issue Jun 26, 2020 · 28 comments
Assignees
Labels
bug Something isn't working community Tag issues created by community members mirrored-to-jira This item is also tracked internally in JIRA UX Issue related to UX aspects

Comments

@DannySchumann
Copy link

DannySchumann commented Jun 26, 2020

Describe the bug

The risk state seems to be only updated after starting the app. When opening the app the first time a day it always displays the current time, independent if it is in the morning or in the evening.

Expected behaviour

Risk state should also update in background. Sometimes the risk update time should lie in the past, especially when opening the app later than 10 pm.

Steps to reproduce the issue

Open the app the first time a day.

Technical details

  • Mobile device: Honor 10
  • Android version: Android 10 (EMUI)

Workaround

Switch battery saving settings from automatic to manual and allow auto-start and background activity explicitly.

Additional context

This is a follow up ticket of #621 taking this comment into account.


Internal Tracking ID: EXPOSUREAPP-1922

@DannySchumann DannySchumann added the bug Something isn't working label Jun 26, 2020
@crcsn
Copy link

crcsn commented Jun 26, 2020

+1, experiencing the same for the last ~48 hours.

Samsung Galaxy S10, Android 10, Power Mode set to "Optimized", CWA is allowed to run in the background.

@jakobmoellerdev
Copy link

Can you check whether CWA is impacted by battery optimizations on your devices? It would help to know that you are affected by your device restrictions and we will take this into account on the decision of #621

@crcsn
Copy link

crcsn commented Jun 26, 2020

On my Samsung S10, the app was impacted by battery optimizations. However, for the first ~6 days, the app updated the risk status without opening the app, even though battery optimizations were active then as well.

I have now excluded the app from battery optimizations to check whether this was the root cause.

@jakobmoellerdev
Copy link

So just to clarify here, the battery optimizations will not always kill the job as they are general restrictions that are applied as soon as the device decides it needs to save power. the harder the restrictions, the more likely this job-killing is. This could mean that for you it worked for a certain time, and then the job was killed.

@jakobmoellerdev jakobmoellerdev self-assigned this Jun 26, 2020
@DannySchumann
Copy link
Author

I use the default setup of my smartphone. The menu "Details zur Akkunutzung" states "App-Start: Hintergrundaktivität nicht eingeschränkt" and "Automatisch verwalten". I will change it to manual and check if it is working then.

Before:
Screenshot_20200626_105729_com huawei systemmanager

After:
Screenshot_20200626_105735_com huawei systemmanager

@jakobmoellerdev
Copy link

Related and possible Duplicate of #626

@DannySchumann
Copy link
Author

Changing the battery saving settings worked for me.

@jakobmoellerdev jakobmoellerdev changed the title Risk state seems to be only updated when starting the app. Risk state only updated when starting the app or after long idle time (deep sleep/ doze) for certain devices and manufacturers Jun 29, 2020
@crcsn
Copy link

crcsn commented Jul 1, 2020

Continued to have the same problem during the last two days, even though I changed the battery settings.

Current settings:
Screenshot_20200701-091639_Settings

@jakobmoellerdev
Copy link

@crcsn please enter the app and wait up to 24 hours if not done already.

@crcsn
Copy link

crcsn commented Jul 1, 2020

@jakobmoellersap did that already. Opened the app regularly during the last two days, after I had modified the battery settings.

@jkrwdf
Copy link

jkrwdf commented Jul 1, 2020

This comment might sound very naive, but shouldn't it be possible to "register" an app in the system for a kind of "wake up" after some time later?

Imagine an alarm clock application. Once the alarm is set, you can even kill the app, but it wakes you anyway.

Is it really the only possible way to go to avoid at all cost that an app once started gets displaced by various hacks in energy management to achive this?

@tuxmobil
Copy link

tuxmobil commented Jul 1, 2020

I experience this as well (Pixel 4). App always shows the date of when I opened it manually.

Is it really the only possible way to go to avoid at all cost that an app once started gets displaced by various hacks in energy management to achive this?

Definitely not. Android provides foreground services to do this (which require a notification being shown while it's active, you can see this on other google apps as well) or various APIs which build on top of it.

https://developer.android.com/guide/components/services

I do not know whether this may actually be the issue here. However I haven't seen a foreground service notification of the app yet, so it maybe the case.

@SebastianWolf-SAP SebastianWolf-SAP added community Tag issues created by community members UX Issue related to UX aspects labels Jul 10, 2020
@casore735
Copy link

casore735 commented Jul 23, 2020

Same issue with Samsung Galaxy A3 (2017) with Android 8.0.0, I allowed CWA to work in the background via "Nicht überwachte Apps" in "Gerätewartung" as well as not optimizing battery settings via Apps -> "Spezieller Zugriff" already 2 weeks ago. Update time is always the first time that I open the app. I did experience the issue of Not having enough storage even though having around 500Mb available, but that was solved by deleting even more stuff.

Edited to add that I have version 1.1.1 of the CWA

@MikeMcC399
Copy link
Contributor

MikeMcC399 commented Jul 24, 2020

I still have this issue with CWA 1.1.1 that the risk status is not being updated in the background.

  • Mobile device: Samsung Galaxy A5 (2017) SM-A520F
  • Android version: 8.0.0
  • CWA Version: 1.1.1
  • Google Play Services: 20.26.13 (040408-319035724)
  • Exposure Notifications: 15202902003

After updating to CWA 1.1.1 I used the CWA settings to switch Prioritized Background Activity to On. Then to check, I looked in Android > Settings > Apps > Corona-Warn > Battery usage in section
MANAGE BATTERY USAGE
Optimise battery usage
the setting is
"Not optimised"
as expected.

In Android > Settings > Google > COVID-19 exposure notifications
It shows: "Last checked for potential exposure on yesterday at 07:09".
It is currently 14:09 so the last check was 31 hours ago. I have not opened the CWA app today (so no manual update was triggered). This is on purpose, to check whether background updates are working.

So there must still be something else preventing the risk state being updated in the background. Let me know if there is anything additional you would like me to check. I'm just using this device for testing. It's not my "production" phone that I take with me when I am coming into contact with other people.

EDIT:
I left the phone running and it did in fact update today at 18:20, so there was a gap of 35:11 between risk state updates (or one complete day of 24 hours plus an additional 11 hours. Is that expected behavior? I assumed it would be roughly 24 hours between updates +/- 1 hour.

@vaubaehn
Copy link
Contributor

@MikeMcC399

I'm just using this device for testing. It's not my "production" phone that I take with me when I am coming into contact with other people.

Taking a wild guess... Are both phones using the same (main) google account?

@MikeMcC399
Copy link
Contributor

@vaubaehn
Your guess is correct. I have only one Google account and it is used by all my devices (phones and tablets). I assume you are asking because it is relevant, so please let me know what influence it would have on the risk state update. Thanks!

@vaubaehn
Copy link
Contributor

vaubaehn commented Jul 24, 2020

@MikeMcC399 I suppose that you know, that there is a rate limitation from Google's side, on how often the EN Api may be called per day (20 times). If API is called too often, exception 39508 is thrown.
The question is, where is that counter stored? If it's stored inside your Google account on their servers (stored remotely), there might be the chance that only one device may check all exposures (14 API calls), while the other device fails (not enough calls left).
If the counter should be stored locally (ENF data store, inside Google Play Services' data, rate limit of call to API is device dependent only), then we might be sure we have the problem of background priority hindering automatic update.

I saw your edit from your preceeding post now... That would point to priorization problem then, imho - if your 'production' device also was updating.

But like I wrote, that was just a wild guess.

@MikeMcC399
Copy link
Contributor

@vaubaehn
Since there was never any problem getting risk updates to be carried out on previous days by opening CWA, which triggered a manual update, I assume that the rate limitation is per device and not per Google account. I actually have three devices running CWA on the same Google account.

@vaubaehn
Copy link
Contributor

@MikeMcC399 thanks for your reply. Then at least on possible reason may be excluded.

@mbw83
Copy link

mbw83 commented Jul 25, 2020

I also still got the issue, that the risk state is just updated when opening the app (the respective setting is set). But somehow I don't care anymore in the meantime.
My device: Xiaomi Mi 9 Lite.

@MikeJayDee
Copy link

MikeJayDee commented Jul 25, 2020

Edit: after almost two days without update, my phone updated in the background again this early morning. When looking at calendar days in UTC, no day was actually missed; but the consistent checking around 7am in the morning does not seem to happen anymore. I edited the log timeline below in the original post and will update it for a few more days for completeness.

Original post:

I'm afraid that something has changed one to three days ago (possibly update to 1.1.1) so the automatic background updates stopped working for me as well:

  • My phone is a Pixel 2 with Android 10 and always the latest updates; not routed or anything special (no restrictions on data use or background data are turned on, no battery saver is used);
  • I had the CWA installed from the day of release and always updated it;
  • I think I manually switched the app to not be battery optimised on one of the first days after release. In any case, the battery optimisation has been disabled in the app for at least the last few weeks;
  • If I did not open the app manually, the background check of keys always happened between 07:00 and 08:00 in the morning;
  • In the beginning of July I switched to Google Play Services Beta;
  • I noticed yesterday that Google had updated the ENF to v1.5 (could have happened weeks earlier as I didn't know I could check)
  • I had the time zone bug so got an error when opening between 00:00 and 02:00 CEST
  • This bug was resolved with CWA update to 1.1.1, which I received in the evening of 21 July;
  • I then opened the app manually shortly before 02:00 and after 02:00 in the early morning of 22 and 23 July to confirm that the time zone bug is in fact resolved; it is therefore as expected that no automatic check took place around 07:00 of 22 and 23 July;
  • On 24 July, I opened the app manually at 09:00, noting that unexpectedly, no check had taken place between 07:00 and 08:00 despite internet connection and being fully charged on a charger;
  • I have since not opened the app manually (it is now the evening of 25 July), but can see in the log that no further checks have taken place in the last 1.5 days:
    [times in CEST (24 hour clock)]
    17 July 07;31 (automatic in background) [only 3 packages checked]
    18 July 07:33 (automatic in background)
    19 July 07:53 (automatic in background)
    20 July 07:46 (automatic in background)
    21 July 07:43 (automatic in background)
    22 July 02:02 (manual when opening app)
    23 July 02:10 (manual when opening app)
    24 July 09:00 (manual when opening app)
    25 July nothing
    26 July 01:43 (automatic in background)
    27 July 01:56 (automatic in background)
    28 July 01:55 (automatic in background)
  • The phone was with internet connection, fully charged and on a charger on 25 July between 06:00 and 09:00;
  • I don't understand why the first log entry is 17 July, and then with only 3 packages but I don't think there is a relation to the bug

I'm a little concerned as this behaviour is not usual on a Pixel phone, and everything has worked fine for more than a month. In fact, the timeline of my log is consistent with this behaviour appearing in version 1.1.1.

@matherm
Copy link

matherm commented Jul 25, 2020

I was curious about the implementation of the background processing and looked through the code. https://github.com/corona-warn-app/cwa-app-android/tree/dev/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker wraps the android specific APIs. It seems that WorkManager API is used for task scheduling. This is a new interface to JobScheduler and AlarmManager. I couldn't find out how or when the API chooses one over the other. A known limitation of JobScheduler is, that it does not work when dozing. Honestly, I would expect that WorkManager does handle that case. Question is, what is the battery optimization of the mentioned manufacturers doing that breaks such a vital API?! Does it also break AlarmManager itself? P.S. On my Nokia 7 Plus and Pixel 3a the background update works as expected.

@w-flo
Copy link

w-flo commented Jul 27, 2020

the consistent checking around 7am in the morning does not seem to happen anymore

I believe this is not a bug. Daily update time slots seem to vary between users. My phone used to to them at ~6pm, but now I just manually open the app in the morning, so that I notice warnings early and to be sure that no background service failures affect me. Your phone seems to have switched to ~2am checks recently.

@MarlisFriedl MarlisFriedl added the mirrored-to-jira This item is also tracked internally in JIRA label Jul 28, 2020
@cengelke
Copy link

cengelke commented Aug 3, 2020

Just wanted to update that it is working now on my Samsung Galaxy A3 (2017) with Android 8.0.0, CWA version 1.1.1, it updates at around 23:15 in the evening if I don't open the app manually.

@shoeper
Copy link

shoeper commented Aug 6, 2020

Last update was 31th Juli until I opened the app manually. This is a serious issue. Disabling battery optimizations which are enabled by default is no solution as millions of users won't do it.

@vaubaehn
Copy link
Contributor

vaubaehn commented Aug 6, 2020

@shoeper you are right, this is a very serious problem. Unfortunately, some device manufacturers messed it up. This thread testifies on how hard (or even impossible) it is for developers to regain the control over (scheduled) background tasks.
What I understand from different comments and pull requests in this repository, our developers and also Google are aware of the problem and working together with high effort to solve it. If I understand things right, Google recently implemented a feature in the Exposure Notification Framework (as a part of Google Mobile Services (as a part of Google Play Services)), that seems to be able to wake up the ENF-registered app (for us: CWA), if the device manufacturer's modified Android OS kills everything just to have a long battery running time... Looks like, one of the upcoming updates of CWA may support that new feature. and any battery optimization problems should be gone then...
Can anyone comfirm that I'm not talking nuts here? ;) Thank you...

@daimpi
Copy link

daimpi commented Aug 6, 2020

@vaubaehn I think you're spot on. The feature you're talking about (ENF waking CWA up) was mentioned here and this seems to be the PR implementing it: #947

@ghost ghost assigned thomasaugsten Sep 28, 2020
@svengabr svengabr moved this from Initial_OLD to Initial in [CM] cwa-app-android Nov 19, 2020
@dsarkar
Copy link
Member

dsarkar commented Dec 14, 2020

Hi @DannySchumann, and community,

Thanks for all the contributions. We think that this issue is resolved with release 1.5. We will close this issue now.

Best, DS


Corona-Warn-App Open Source Team

@dsarkar dsarkar closed this as completed Dec 14, 2020
@cwa-bot cwa-bot bot moved this from Initial to Done in [CM] cwa-app-android Dec 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working community Tag issues created by community members mirrored-to-jira This item is also tracked internally in JIRA UX Issue related to UX aspects
Development

No branches or pull requests