greenaddress / abcore

ABCore - Android Bitcoin Core

Home Page:http://abco.re

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Battery optimization on Android 8.0 prevents ABCore from syncing

fedsten opened this issue · comments

Android 8.0 has introduced a battery optimization change that creates limits on how freely apps running in background can access to the device's resources. This prevents ABCore and other apps connected to the Bitcoin network from syncing the blocks when the app is running in background.

Luckily this can be solved by going to "Special app access" in the device's settings and deactivate the battery optimization feature for individual apps.

Since if not addressed this prevents the users from being able to use the app, I suggest to at least put a helper message somewhere to guide users in deactivating the battery optimization for ABCore.

As a reference: https://developer.android.com/about/versions/oreo/android-8.0-changes

I also reported the same issue to the Andorid Bitcoin-wallet devs and seems like their plan is to rewrite the background process to use WorkManager: bitcoin-wallet/bitcoin-wallet#557 (comment)

so while it looks like we could work around it https://developer.android.com/training/monitoring-device-state/doze-standby#support_for_other_use_cases it also seems google is a bit picky about which app can and can't do this.

Given we don't plan to rewrite entirely core but to just be a wrapper around it I doubt we can ever use a WorkManager for it.

Using a: ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS Intent, opens a simple dialog screen to turn off Optimizations, but can get your app banned, due to the necessity of asking for:

uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"

Instead you can use a: ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS Intent, which does not require any special permissions, only instead of directly asking the user if they want to ignore optimizations for your app, takes them to a overall list of all apps, and the user can toggle which apps they want to ignore battery optimizations. I use both a lot for my work, happy to implement either, the second would be the best best for not getting refused by the Play Store. ( as it's the manifest permission which is the red flag, and will result in refusal, even if you don't actually try and use it)

@gwicks56 Would love to get a PR for the second approach, agreed we don't want to get banned from Play Store.

If we wanted perhaps we could have a different version for f-droid that also uses the first approach but that seems a little more work.

@greenaddress, working on one now. Just to be clear, Doze mode is only an issue for devices that are running on battery power, if used for a IoT device, it should not be an issue, however across manufactures I have found it does not always work the way you think it should. So there are a couple of ways I could go about it.

  1. Just prompt the user with a Dialog Fragment to turn doze mode off after they have downloaded the core software, before they switch it on.
  2. Add another toggle below the "Switch ON / Switch OFF" toggle.

Either way, it will take a little bit of explanation of what they have to do. ( ie press accept on Dialog Fragment, get taken to settings, then they have to toggle "Show All" under the Battery Optimization menu, as by default it only shows the apps which are already turned off, then toggle ABCore. After that they will be returned to the app.)

Most of the code for checking if an f-droid version is pretty simple, unfortunately, it requires a permission, and I'm pretty sure you can't change them at run time. I could add all the code though, and we could put a simple message in the README explaining which permission to add. I'll explain more in my PR

closing as this has been addressed by #57.