2

I made the device which monitors person's health in sleep time and it connects to a smartphone via BLE.

It's working great with the iOS app. But since Doze mode came on Android world. It's really hard to deal with it because my device is working in his sleep time.

The main feature is that it detects particular danger and notify to the user while he is sleeping with the device. I need a network connection when it occurs.

Many articles tell me that I can use a network even in the doze mode if my app is in the whitelist. But it does not seem true after I tested Doze mode. Am I right?

I can ensure that I can find my app in the lists, when I fire

adb shell dumpsys deviceidle

What is the best approach that I can take to make my app working correctly?

  • foreground services
  • alarm manager with SetExactAndAllowWhileIdle.
  • GCM (it means push, right?)
  • anything else

Any tips will help me. Thanks.

Edit

Unfortunately, I tested with using GCM but it only wakes my app in short time. It means I have to send GCM as many as I want to keep it awake. I don't think I can use it.

Bright Lee
  • 2,306
  • 2
  • 27
  • 55

1 Answers1

0

Many articles tell me that I can use a network even in the doze mode if my app is in the whitelist. But it does not seem true after I tested Doze mode. Am I right?

You are not right. One of the restrictions of doze that are lifted when your app is on the whitelist, is the ability to use the network when doze is active.

An app that is whitelisted can use the network and hold partial wake locks during Doze and App Standby. However, other restrictions still apply to the whitelisted app, just as they do to other apps. For example, the whitelisted app’s jobs and syncs are deferred (on API level 23 and below), and its regular AlarmManager alarms do not fire.

From here.

In other words: you should be able to use the network in doze if you are on the whitelist.

What is the best approach that I can take to make my app working correctly?

Considering your app is a health monitor and thus should be able to do its work constantly or at least very regularly, you could put the functionality in a foreground service. Foreground services are not effected by doze.

You should be aware that you should have a good reason to use a foreground service since the user is aware of them, but I think you have one with the health monitoring etc.

Note: You should only use a foreground service for tasks the user expects the system to execute immediately or without interruption. Such cases include uploading a photo to social media, or playing music even while the music-player app is not in the foreground. You should not start a foreground service simply to prevent the system from determining that your app is idle.

From here.

Tim
  • 41,901
  • 18
  • 127
  • 145
  • Hi Tim. Thanks for your very kind answer. I really appreciate your help. I will try again as you said and will share the result. Thanks! – Bright Lee May 23 '17 at 17:15
  • A foreground service will only prevent the app standby mode from freezing/killing your app https://stackoverflow.com/questions/35811042/doze-and-app-standby-mode-in-android-6-0?rq=1 – behelit Feb 08 '18 at 04:48
  • @behelit sorry, what? – Tim Feb 08 '18 at 08:48
  • @TimCastelijns you mentioned "Foreground services are not effected by doze." but it only relates to the 'App Standby' part of doze not the deep sleep doze, from what I understand – behelit Feb 12 '18 at 03:18
  • 1
    @behelit there is no "'App Standby' part of doze" or "deep sleep doze". App standy and doze are 2 different things – Tim Feb 12 '18 at 09:23
  • "Foreground services are not effected by doze." it is not true if the app does not have permission to "ignore battery optimizations" and in some cases it must also be on the white list of the manufacturer's proprietary optimization system. – Paolo Mastrangelo Feb 11 '19 at 14:03
  • @PaoloMastrangelo please back up your statements with some credible sources – Tim Feb 11 '19 at 14:15
  • I did a test creating a Foreground Service that writes every 3 seconds the writing "Check - " in a file and this sometimes skips writing for 3-4 minutes before resuming. The foreground service remains active, but its activities are deferred according to the Doze. I redid the test by putting my app in list on both Android and the huawei battery manager and the foreground service has never skipped a cycle. – Paolo Mastrangelo Feb 11 '19 at 15:21
  • Sorry for the two comments, but I had no more space. I have tested on different devices (huawei / samsung) and the result has always been the same. If you look at your second reference "from here" in your answer, the section is called "Understanding App Standby" which is different from the 'Doze'. You could link me a credible source to the fact that the foreground service are always and in any case not affected by the optimization of the doze. As @behelit said, the foreground service prevents the app idle, they have no automatic and certain optimization for the Doze. – Paolo Mastrangelo Feb 11 '19 at 15:35
  • @PaoloMastrangelo yes, my answer here was based on the comment by Dianne (android framework team manager) that is referenced here https://stackoverflow.com/a/33077301/1843331 but it's been a while since that was said – Tim Feb 11 '19 at 15:36
  • 1
    I would not want to be overbearing, but Dianne can say what he wants, but I say what I see. In the Android documentation there is no relationship between Foreground Service and Doze, while there is for Foreground Service and App Standby. I've done some tests and the Foreground service does not guarantee the continuity of an operation if you are not on a white list. This for me wants to understand that the Doze sees the Foreground Service as a process that can differ as it pleases. ->Sorry, but I do not see the part of the comment you're talking about. – Paolo Mastrangelo Feb 11 '19 at 15:45