Problem Background
Currently, we have facing "Excessive network usage (background)" from Android Vital report. Last 30 days is 0.04%, but we're only Better than 9%
- Last 30 days - 0.04%
- Benchmark - Better than 9%
Since only better than 9% looks like a scary thing. We decide to look into this issue seriously.
The app is a note taking app (https://play.google.com/store/apps/details?id=com.yocto.wenote), which provides an optional feature - sync to cloud in background after the app close.
This is how we perform sync to cloud in background.
- We use
WorkManager
. - In Application
onPause
, ScheduleOneTimeWorkRequest
, with constraintNetworkType.CONNECTED
. The worker is scheduled to start with delay 8 seconds. - In case failure, we retry using
BackoffPolicy.LINEAR
, with delay time 1.5 hours. - The maximum number of retry is 1 time. That's mean, after the app close till the app re-open again. The maximum number of execution, of sync to cloud process is 2.
- The size of data is vary, can be few KB till few hundred MB.
Additional information how we perform sync
- We are using Google Drive REST API.
- We are performing downloading of a zip file from Google Drive App Data folder, perform data merging in local, then zip, and re-upload the single zip file back to Google Drive App Data folder.
- The zip file size can ranged from few KB, to few hundred MB. This is because our note taking app supports image as attachment.
Analysis
The only information we have is https://developer.android.com/topic/performance/vitals/bg-network-usage .
When an app connects to the mobile network in the background, the app wakes up the CPU and turns on the radio. Doing so repeatedly can run down a device's battery. An app is considered to be running in the background if it is in the PROCESS_STATE_BACKGROUND or PROCESS_STATE_CACHED state. ... ... ... Android vitals considers background network usage excessive when an app is sending and receiving a combined total of 50 MB per hour while running in the background in 0.10% of battery sessions.
- We start the background sync job, 8 seconds after
Application
'sonPause
. During that period, will the app inside or outsidePROCESS_STATE_BACKGROUND
/PROCESS_STATE_CACHED
? How can we avoid running insidePROCESS_STATE_BACKGROUND
/PROCESS_STATE_CACHED
? - What does it mean by "running in the background in 0.10% of battery sessions."? How can we avoid such?
- Another assumption, is sync file is too large, and using too much data. Soon, we notice this assumption might not be true. We notice according to "Hourly mobile network usage (background)", the data size is from 0MB to 5MB.
Questions
My questions are
- What is the actual root cause for such "Excessive network usage (background)" warning? How can we accurately find out the root cause.
- How does other apps (Like Google Photo, Google Keep, Google Doc, ...) which perform background sync, tackle this problem?
"Excessive network usage (background)"
... you are probably transferring more data compared to the other applications/competition. Are you transferring any binary data like pictures, video, music, etc?How does other apps (Like Google Photo, Google Keep, Google Doc, ...)?
There are no magic tricks. If you have to transfer huge amounts of data they use compression. Did you try to compress your traffic e.g. gzip? (developers.google.com/drive/api/v3/performance) – Cammack