MuntashirAkon / BatteryChargeLimiter

Limit battery charging on Android
GNU General Public License v3.0
159 stars 15 forks source link

Battery Limit Service only enables by manual launch #11

Closed AzzyC closed 1 month ago

AzzyC commented 2 years ago

ROM: ArrowOS Device: Poco F3 / alioth Control File: input_suspend

Problem: Battery Limit service only enables after manually launching the app, not detecting when power is connected. Though the app may have not been launched in a while, the service would still enable upon charge detection in the older versions of this app

Expect to happen: App should detect when power is connected and start the Limit service itself

Anything else: Maybe the app isn't taking advantage of having the privilege of 'Unrestricted' Battery usage (?)

MuntashirAkon commented 2 years ago

I haven't looked at that part yet. So, you could be right.

AzzyC commented 2 years ago

Just for further context:

https://user-images.githubusercontent.com/36119634/180644191-9c94768a-4ea4-4c51-a867-18d85a04e7ce.mp4

You will notice the notification icon didn't appear as the service didn't start until I launched the app

I will verify if this aspect worked in F-Droid Battery Charge Limit, and edit this comment accordingly

MuntashirAkon commented 2 years ago

I will verify if this aspect worked in F-Droid Battery Charge Limit, and edit this comment accordingly

I have made the latest fork from the repository (updated in 2020) which isn't the same as the F-Droid version (which was updated in 2018).

AzzyC commented 2 years ago

Oh okay never mind so much for that then,

But just as an N.B, the F-Droid variant does auto-start Limit service upon charge, so maybe something got written out or not addressed in the 2020 repo update.

Nonetheless, it is not too much of a biggy. I always launch the app anyways to always be sure of the service being on

MuntashirAkon commented 2 years ago

I've taken a look at it. Apparently, the charging on/off only works if a foreground service is active or if a job schedular is in place. So, the option is to use a job schedular to trigger the service.

Fred-Vatin commented 1 year ago

I confirm this bug on Android 11 even if app is not battery optimized and installed as system.

The battery charge limit from 2018 is triggered as soon the charger is plugged.

MuntashirAkon commented 1 year ago

The battery charge limit from 2018 is triggered as soon the charger is plugged.

Yes, it's because the 2018 version targets an older SDK. So, it runs on compatibility mode. I have already outlined the solutions above, but I do not have enough time to work on it right now.

MuntashirAkon commented 1 month ago

If an app targets Android 8 onwards, ACTION_POWER_CONNECTED is no longer sent to the app. So, there's no way to detect if power is connected.