Android background services stop responding after ~1 day - android

I'm building an app that has two background/foreground services:
Sync with API on FCM data notification - high priority
Physical activity monitoring using Activity Transition API
This app is also ignoring battery optimization(on the exemption list).
If app is terminated and devices put to sleep, these services function properly for about 24 hours. After then they both just stop.
Devices has no battery saver mode enabled, it's unpluged from charging and the battery is at 90%. The device is Samsung with Android 11. App is not on the sleep/deepsleep list.
I can't get my head around why these services just drop out after those ~24 hours. Based on Android documentation, app with ignored battery optimization shouldn't Doze. And FCM message with high priority should wake the app from Standby. When this happens nothing really helps, I have tried manually disabling standby using adb and put the device on charger. The only thing that helps is relaunching the app.
Any help would be greatly appriciated.

Related

Android BLE Scan Stops after a couple of minutes in background

I faced the Android scan stopping issue in background when I am developing my COVID contact tracing app for my company. Here is what I have tried:
Add foreground service
Disable all the battery related optimization options in the phones
Enable the application running in background
Tesging devices:Galaxy S20 and Xperia with Android 10, Huawei with Android 8.
The scan stops immediately when going to background if you don't disable those battery optimization settings and application background update. After you disabled those settings, the scan can run about a couple of minutes(~5 minutes), then still stops. From the blog of David:http://www.davidgyoungtech.com/2017/08/07/beacon-detection-with-android-8, it seems that it is impossible to scan continuesly in background, because the JobScheduler will restart every 15 minutes while each scan lasts ~10 minutes at most. Is this the reality, or this is the best solution that I can scan 10 minutes at every 15 mins cycle?
Background beacon detections are tricky to implement because many small issues can trip you up, and the specific issues vary by Android version, Android manufacturer and sometimes model. While Android 8+ restricts background ranging to every 15 mins using the Job Scheduler, if you add a Foreground Service, you can unlock unlimited background ranging.
A few tips:
Focus first on the Galaxy S20 as Samsung behaviors are better documented and closer to vanilla Android. (Ideally you would test on a Pixel device first.) Only once it works on Samsung, move on to the others.
Using the Android Beacon Library reference app configured with the built-in foreground service, I have seen detections of a standard iBeacon or AltBeacon continue on a Galaxy S10 indefinitely in the background, even with a 1.1 second scan period. See if you can reproduce the same.
Be careful of Doze mode. If the CPU is put to sleep due to the phone being motionless with the screen off and not charging, your detections will stop. You can defeat Doze mode with wake locks, but it has a punishing impact on battery usage. You are better off accepting its limitations and keeping your phone in motion periodically during testing. If you want to get logs to see what is happening, use ADB commands to disable charging when connected via USB or learn to use ADB over WiFi.

Wake up android app via push notification while in doze without FCM

Greatings!
We are developing an android app with Xamarin that has to meet the following restrictions:
wifi yes, but no internet connection
no FCM/google play services (app should also work in China)
push messages from a Manager-SW (uses rabbitmq) need to arrive quickly after being send (< 1min) AND also when the device is in doze mode
no pulling mechanism
At the moment we are having a wifilock and a wakelock. The battery optimization for this app is turned off. This way messages always arrive even when the device goes to doze mode.. with some exceptions.
There are devices like the HUAWEI P20 that have their own battery save solution (App launch) --> app is not running although we have all the stuff above
Also this solution is not ideal considering battery usage.
I have looked into alternatvies like Pushy, but for me it seems they have problems with doze mode too.
Do you know any alternatives to FCM?
Is there any easy way to go around the Huawei stuff without the user having to change the settings manually?
Many thanks to all of you in advance!

"Unable to resolve host" error with Google Drive API

I am using Google Drive REST API to download 1.5 GB backup file using a foreground service. I found that after the file is downloaded partially, the following exception is generated by code:
Unable to resolve host "www.googleapis.com": No address associated with hostname
I am testing my application on Android 6.0 device. I have set the targetSdkVersion to 27.
I have following questions:
Is the device WIFI automatically tuned off when the device is kept idle for sometime? As I am using a foreground service, is it possible to have this problem?
If no, what can be the other causes for this issue?
I would appreciate any suggestions and thoughts on this topic. Thank you.
Starting from Android 6.0 (API level 23), App Standby defers background network activity for apps with which the user has not recently interacted. You can read the documentation about Optimize Doze and App Stanby of Android app.
If a user leaves a device unplugged and stationary for a period of time, with the screen off, the device enters Doze mode. In Doze mode, the system attempts to conserve battery by restricting apps' access to network and CPU-intensive services. Doze mode restricts to perform a Wi-Fi scans.
You can prevent the doze mode or standby mode of Android apps using foreground service by GcmTaskService.

Android BLE disconnected when screen off (without charger)

It's working well on most Android devices.
Other device's screen gets locked after 1 minutes BLE device gets disconnected,if device without charger.
Thanks for any suggestions!
this might come from the Keep Wi-Fi on during sleep option (which might affect all radios) - as it seems this only exists in 8.0 but not in 8.1 (at least on the Pixel 2 XL, according to this article).
You might be having this problem because your app is not properly configured to handle Doze mode.
While there do not seem to be any restrictions on using BLE itself, doze mode might be messing with the control mechanism for your bluetooth connection (ex: a background service).
To see if this is the issue, you can whitelist your app manually via Settings > Battery > Battery Optimization and disabling optimization for your app.
Furthermore, as of Android 8.0, there are restrictions on background services when your app is not in the foreground. So, you may need to create a foreground service to handle the connection.

Can an application on Android phone be updated in sleep mode?

There are 3 states an Android phone can be in: Awake, Asleep and Off. See: Android: Sleep stages/levels on an Android device?
In sleep mode screen goes off, CPU shuts down along with Wi-Fi and GPS radios. See: http://developer.android.com/reference/android/os/PowerManager.html and Android Sleep/Standby Mode
But GSM or CDMA radio still works and the device can receive incoming calls, SMSes, and IP packets. Also, Google introduced new Google Cloud Messaging service that sends data to devices and can, as I understood, wake the device if necessary. See: http://developer.android.com/guide/google/gcm/index.html
So, my question is: can application on Android device be updated via Google Play if the device is in sleep mode? I mean is Google Play allowed to receive some kind of messages from the cloud, wake the device and update applications? I assume that the application is allowed to be updated automatically and can be updated through mobile network (3G/4G).
Thank you.
UPDATE: I did some research and it happens that Nippey's answer and comments are correct. I did not see any updates to wake my device but as soon as the device is awake updating mechanism starts to work normally. So, theoretically, Google Play Store can start updating your applications right after the device wake up.
The device is able to process push-messages while in sleep mode.
As soon as you trigger an update via the play.google.com, this will issue a push request, which, as a consequence will wake up your device. The update will be installed immediately.
So, it doesn't work in sleep mode, but if the device gets a trigger to wake up, it will do what has to be done.

Categories

Resources