GithubHelp home page GithubHelp logo

muisit / rechargereset Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 353 KB

Special app for rooted devices to reset the 'charging_enabled' value while plugged in

License: Apache License 2.0

Kotlin 100.00%

rechargereset's Introduction

RechargeReset

This is a privately developed Android application to reset the /sys/class/power_supply/battery/charging_enabled setting when the power cable is connected.

Problem Description

My Moto X Play device developed an issue after a few years where the battery temperature sensor broke down and reported invalid temperatures. This causes the device to disable the charge cycle while powered on. If the device is powered off, it will charge up to about 80%. More people are running into this issue and some of it is documented here, for example:

Lenovo Forum

Solution

The solution seems to be to reset the charging_enabled setting, which overrides the process that disabled charging due to the temperature. Unfortunately, the temperature is checked periodically, so you need to reset this setting periodically as well. The only way to do that is by having the device root-ed. Yes, no other way around this: you need to fool with device settings that are exclusively accessed by the original system code and should not be touchable by applications. Rooting does not damage your device. There are a ton of manuals about how to root your device and in some cases it takes only a few minutes. In my case, I needed an access code from Motorola to unlock the bootloader, but that was sent to me quickly.

After rooting the device and installing SuperSU, you have the option of running a script to reset the value. In order to run this script, you need a script manager. Unfortunately, it is rather a pain to have this script run at boot time automatically.

Android App

This RechargeReset android app replaces the script on rooted phones. You can open the project in Android Studio and build the application. Then 'Run' the project with your phone connected over the USB cable (make sure USB debugging is allowed). This will install the application on your phone and start it. Upon start it opens the battery optimization screen. Select all applications, find the RechargeReset application and mark it as not available for battery optimization. This will make sure it can run with a low battery as well (which we need if the battery is low and needs to be recharged). Once the application has run, it will register itself at boot time and when the power cable is connected. The first time that happens, it will request superSU powers, which you must manually grant once. Because the power cable is connected when uploading the application through USB, you will get this question immediately.

The project requires the libsuperuser library by Jorrit Chainfire Jongma. Download that project and include it in your development environment using File->New->Import Project. There is probably a better way, but this is my first Android application. I am open to suggestions.

Breakdown

The application consists of a simple Activity to display a text, register the BroadcastReceiver and allow you to select the application for battery-optimization-whitelisting. It has a BroadcastReceiver that receives the BOOT and LOCKED_BOOT Intents as well as the POWER_CONNECTED Intent. Because POWER_CONNECTED cannot be registered in the manifest since Android 8.0, that intent is registered at BOOT as well. On POWER_CONNECTED, the application instantiates the background service RechargeReset to monitor the battery status while power is connected. If the battery status is FULL, the application will recheck in another 10 minutes to avoid overcharging. Otherwise the /sys/class/power_supply/battery/charging_enabled setting is set to 1 and the application will recheck in 10 seconds. This continues while the power cable is connected. When the power cable is disconnected, the service dies naturally.

Issues may arise if the battery is full and you repeatedly connect and disconnect the power cable. Each time it is connected, a service is created that will wait for 10 minutes to recheck again. There is no code to check whether the service is already running, which I could have added, but did not. Deal with it.

rechargereset's People

Contributors

muisit avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.