[Moto G Original Android Development] elrod16:
If your are using LP or MM and having issues, please check out the detailed guide from [MENTION=6626737]the_poolee[/MENTION], right below the downloads

This is a native program for Android that addresses the wear done on Lithium-ion batteries by prolonged elevated voltage, high-resistance, and high heat charging. With lithium-ion batteries it is recommended to not quite charge to full capacity or keep the battery on the charger at an elevated voltage for lengths of time because making this a regular practice will rapidly degrade the battery.

Using apps that alert you that charging has completed or is 90% complete may be helpful but aren't always practical or convenient, such as over night charging, or as in my case a phone case with built in battery that charges itself and the phone at the same time, but it charges much more slowly and keeps the phones battery voltage elevated even after the phone has reached 100%.

I created MaxLife to make the handling of said situation convenient and entirely automatic. MaxLife runs as a background system service that interacts with the power_supply subsystem. Using a value chosen by you for the target battery percentage (or 90% default if not provided) monitors how far along your charge is until either you've disconnected the power source or your battery has charged to the target level you set. Upon reaching the target it stops the charging of the battery (even though the charger IS still connected) and suspends charging for a minimum of 15 minutes. After 15 minutes have passed however it still will not restart charging until the battery has fallen below your desired charge level.

This is perfect for trading a small amount of the battery's capacity for a longer and more reliable life of operation. Aside from keeping your battery's charge capped at the desired level it also beats the shortcomings of having to leave your phone unplugged overnight by assuring that it will be charged to the chosen percentage when you're ready to use it not leaving you with a potentially discharged battery due to overnight idle drain (whatever the cause may be e.g. wakelocks).

Prerequisites:

• init.d support

• custom recovery

• Qualcomm device

• A fairly complete busybox install. Toolbox and toybox won't cut it.

INSTALLATION:

Setting it up is simple. At the bottom of this post will be a recovery flashable zip. It installs two files onto your system partition: the MaxLife binary and an init.d script. To choose your target battery percentage first install the package, and use the settings editor described below (title of that section is in bold) (default is 85 in init script and tool is hard coded to 90 if no value or an invalid one is supplied).

New Feature:

Built in settings editor

Optional settings file

Live settings changes (no reboots)

Auto-BattStat Reset

Charge Rate Control

MaxLife now accepts a second argument to set the rate of charge (by changing the input current that is accepted). Valid values are slow, normal, and turbo. If no second argument is supplied in the init.d script or on the command line MaxLife defaults to "normal" (which means no change, system default). The default value in the installer zip is "slow".

slow- Will take somewhat longer to charge, but the battery will remain much cooler during charging and it places less stress on it, prolonging its operational life.

normal- Nothing is adjusted. Equivalent to leaving the option blank.

turbo- Fast charging for those scenarios where time is valuable and you need to get as much into your battery as fast as you can. Hotter charging temperature and more stress/risk to battery and charging components. Recommended to be used sparingly.

This parameter can be set in the init.d script just like the percentage setting.

NEW BUILT-IN SETTINGS EDITOR

There is also now a very straightforward and self-explanatory GUI with MaxLife for settings management now.

To change the settings override/live settings file from MaxLife itself from the command line, just use a terminal app and (as root/superuser) run:

maxlife set 70 slow

or

maxlife set slow 70

The options after set can be in either order and equally valid. If your settings are invalid you will get an error message saying so, otherwise it'll display an output of the newly applied settings. REMEMBER: It only takes options in lower case.

IMPORTANT:

If you do edit 91bms, please be sure your text editor is saving the file using UNIX text format. Other formats break the installation. I use the built in editor in ES File Explorer as my editor of choice because it let's you see what format you are saving text files in.

Uninstall:

Delete /system/etc/init.d/91bms and /system/bin/maxlife

This tool is very safe in its interactions with your device, but I am not liable for anything that happens to your device.

It is tested and confirmed working on the Moto G and ZTE Speed both running 4.4.4; however it was designed with the goal of Lollipop/Marshmallow compatibility as well as compatibility with any Qualcomm chip set, so if anyone wants to help test and confirm all and any aspects of compatibility feel free to lend a hand.

LICENSE:

By downloading and/or using MaxLife, you are showing that you accept the terms of this license.

This project is my own proud work, so please be respectful and do not redistribute, sell, modify, or reverse engineer the MaxLife binary and the data contained therein in any form or manner without first acquiring my permission and also giving due credit upon redistribution after receipt of my permission.

This software is being provided free of charge with no guaranteed nor implied warranty. I also hold no responsibility or liability for any damages direct or indirect that come to your person, property, or device from the use of MaxLife.

I also retain the right to modify the terms of this license at any time without having to give any notice of modification.

ENJOY!!!

MaxLife v1.0.9c Unified:

(UNINSTALL older GUI like normal app first)

https://drive.google.com/file/d/0B_hgNZE_j5sVVkJPM2hnWFVId1E/view?usp=drivesdk

If your are using LP or MM and having issues, please click below to open a detailed guide from [MENTION=6626737]the_poolee[/MENTION]

From the_poolee:

Well as our beloved [MENTION=6190802]elrod16[/MENTION] seems rather hesitant to upgrade to later android versions, he asked me to do a post regarding proper setting for Maxlife in LP/MM. I should clarify beforehand that I'm no dev nor do I have any coding knowledge. I just happened to find a solution for a persistent issue that most of us on LP/MM faced. And if it matters, I'm currently on CM13 (Android 6.0.1 Marshmallow), with Maxlife v1.0.7. I don't have Xposed or other addons, except for Greenify, working in Root mode. So here it goes....

The first and foremost thing to remember is that Maxlife doesn't have any front end UI with quick toggles [MENTION=6190802]elrod16[/MENTION] seems to be working on it). But it doesn't mean that the actual stuff that works behind screens is completely hidden from root level apps like Greenify and native Doze in MM. And therein lies the core problem.

Since CM13 got some issues with init.d(as per my understanding, it doesn't have it), I used the terminal commands. The charging rate setting and even charge level setting, all worked. My sole issue, then, was that under an unattended night-charge session, the charging went beyond the set values. Since everything was okay in the short-run trial, I assumed something was messing up in the extended session. I couldn't think of anything other than Greenify and Doze at that moment.

In Greenify for MM, there are Shallow Hibernation and Aggressive Doze options. And of course, Automatic Hibernation is also there. Like any other battery - life - caring - guy out there, I had all of these options turned ON. Talking about Doze, it is another factor that may mess with proper Maxlife working. But as per my understanding, doze mode doesn't kick in when connected to a charger. The extra Doze setting in Greenify is just an extension of the normal Android back-end doze,wherein Aggressive Doze puts the device into doze faster than usual, but again, not when charging. Besides, [MENTION=6190802]elrod16[/MENTION] had done some tweaks to ensure that Maxlife is not suspended unnecessarily in Doze(via wakelock). So doze cannot be the culprit. Even then, I tried turning each one off, and voila, guess what, as soon as I turned off Automatic Hibernation in Greenify, Maxlife settings persisted - charging never went beyond the set limits - even through full night charge sessions. I just solved the issue then and there. But I should add that for guys using Greenify in Xposed mode, the behaviour may be different.

In a nutshell, my observation is that apps like Greenify may interfere with Maxlife and hence, make sure that all of them are disabled, or at least, their automatic modes are disabled. Doze may not have been the problem child in my case, but even then, try turning off such Aggressive doze options or instant doze modifiers, if nothing else works.

NOTE: auto charge resume may not work with portable chargers because they often power down after the connection is dropped.

Also any relevant feature suggestions, bug reports, or other design suggestions are always welcome.

Changelog:

v1.0.9c- Split the engine and GUI into separate downloads until this issue with flashable updates and the GUI is resolved. The engine has also been tweaked so that resource hungry apps running in the forground are less likely to make MaxLife miss its target because it was forced to wait for its turn to run. It adjusts its niceness and I/O priority to accomplish this.

v1.0.9a- Now every 10 boots MaxLife forcea the battery guage to synchronize with the battery's internal reading to prevent drift in readings from not allowing full charge cycles.

v1.0.8a- Graphic user interface added with bug in mode setting in test version of UI fixed.

v1.0.7- Rolled the charge delay back to 15 minutes. Improved the wakelock code so that during the charge delay time if you disconnect your device from the charger it'll release the wakelock but continue counting the delay. Old versions the wakelock stayed on during the charge delay whether the device was connected or not.

v1.0.6- Lowered the charge waiting delay to 3 min. MaxLife now keeps the device from suspending while connected to a power source. This is experimental and aimed at fixing the issues with deep sleep. MaxLife has its own settings editor now for the live settings feature. Eliminates any possibility of the file being saved in DOS format.

V1.0.5a- Fixed a bug in a block of code shared between MaxLife and MaxOpt where data wasn't being thoroughly validated before being used.

v1.0.5- Now whenever the settings are changed using the new "on the fly" way, an update of the new settings is written out to logcat, just useful for individual debugging or troubleshooting. This message is at the Verbose priority/level/filter in logcat.

v1.0.4b- When launched from a terminal app (such as for testing) MaxLife now prints out the settings it initially detected and will use. There is also a new way of configuring the settings that also allows "live" changes, changes that will take effect without a reboot or restarting the tool.

v1.0.3- MaxLife now automatically resets your system battery usage stats when it hits the charging cutoff set point. The settings app battery page should no longer endlessly fill up.

v1.0.2- Added a kernel level suspend block (rather than app runtime PowerManagerService.Wakelocks) to fix issue of the tool missing the charge cutoff from deep sleep. Suspend block is released as soon as charging is stopped or charge cutoff is met. Changed default percentage in init.d script to 85.

v1.0.1b- Fixed a small mistake in the installer zip layout.

v1.0.1- Introduced charge speed setting. Details above in post in "New Feature" section.

---------------------------------------------------

Please thank if my software has helped you and please leave logs and descriptions of problems if my software did not work for you.