• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!
Search This thread

Top Liked Posts

  • There are no posts matching your filters.
  • 70
    Battery Life Extender
    Code:
    ###### JayminSuthar @ xda-developers
    
    ###### Copyright (c) 2018 Jaymin Suthar. All rights reserved.
    
    ## Legal
    
    * This file is a part of "Battery Life Extender (blex)".
    
    * blex is released under the terms of GNU GPL v3 as published
      by the Free Software Foundation, and you hereby are allowed
      to use, modify or redistribute it, either pieces of it or
      entirely under v3 or any later version of the GPL.
    
    * blex is developed in a hope of being useful, but neither
      warranty nor support are promised with it, not even fitness
      for the particular purpose. See the GPLv3 for details.
    
    * A copy of GPLv3 (COPYING) is placed in the root folder of
      blex, see <https://www.gnu.org/licenses/> for more.
    
    ## Links
    
    * [Git Repository](https://github.com/Magisk-Modules-Repo/blex)
    * [Support Thread](https://forum.xda-developers.com/apps/magisk/mcs-charging-controller-t3739371)
    * [Telegram Group](https://t.me/joinchat/IiBDkxCpljv5TH994qtv6Q)
    
    ## Introduction
    
    * blex helps in extending/maintaining lithium batteries' life
      by controlling when charging is enabled or disabled.
    
    ## Details
    
    * blex is a tool that lets you enable or disable charging in
      programmatic manner so to extend/maintain batteries' life,
      it is reliable and also fully automated.
    
    * Automation provided includes two features which are 'Auto
      Switch' and 'Auto Power'. Auto Switch is a feature which
      disables charging when a disable threshold has been hit and
      enables charging back as soon as the battery level hits an
      enable threshold, whereas Auto Power is a feature which'll
      power the device OFF as soon as level has reached a power
      threshold.
    
    * The purpose behind Auto Switch is to make the battery lie
      inside our specified limits so that a constant charge cycle
      can be maintained that's a basic requirement when you wish
      to extend the batteries' life. It helps to increase maximum
      charge cycles the battery can have and that without losing
      anything.
    
    * And the purpose behind Auto Power is to never let the cells
      lose voltages too low that it might harm bring the battery
      back to the life. This helps to prevent some weirdities like
      unexpected battery levels shown.
    
    * blex also provides you to enable/disable charging manually
      on demand, and that introduces manual methods. You can use
      manual methods to fulfill the need based on either level or
      time, refer to the 'CUI' section for more.
    
    * The 'CUI' section provides details on each flag and option
      that you can use to setup Automation, configure blex, launch
      the daemon, reset battery statistics and more...
    
    ## Requirements
    
    * A modern arm-based chipset.
    * Basic terminal knowledge.
    * (if Magisk install...) Magisk 14.6+.
    * (...or else) Any root solution,
    * (...or else) Init.d support.
    
    ## Installation
    
    * blex supports both the Magisk systemless install and the
      standard /system modifying install, just make sure all the
      requirements are met for that specific install mode and do
      flash the zip from either custom recovery or Magisk Manager
      and blex will detect install mode and install accordingly.
    
    * NOTE: Modifying /system might make your device unbootable.
    * NOTE: If Magisk is detected, you can't do standard install.
    * NOTE: If Magisk is older than required, it'll automatically
      install in standard /system modifying mode.
    
    ## Setup
    
    * After installing, blex requires you to configure itself by
      running 'blex --configure', if you don't do that, blex will
      be of no use to you. This step is required only once after
      installing/upgrading.
    
    * I also recommend you to toggle ON/OFF Automation features
      and set their thresholds to your needs for a set-and-forget
      concept.
    
    * NOTE: Enforcing thresholds outside blex' recommended limits
      is against the purpose of extending batteries' life and thus
      is strongly discouraged. That flag is included just for some
      users who wish to use blex to control charging rather than
      to extend/maintain batteries' life.
    
    ## Usage
    
    * blex provides a nice, user-friendly and easy to use CUI to
      the user. This CUI can be used to configure or setup blex or
      to run a manual method, etc... All you need is a terminal
      emulator (like Termux). So, in steps...
    
    * ...launch the terminal,
    * write 'su' to have a root shell,
    * and call blex by running 'blex [flags] [options] args'.
    
    * NOTE: If you have multiple blex processes running, they may
      interfere with each other, please avoid such conditions.
    * NOTE: Most things in CUI are checked and defaulted to some
      action if an argument is not provided.
    
    ## CUI
    
    * Flags
    
        [--detach]
    
        Detach from the terminal and run as a background process.
    
        [--skip-logs]
    
        Skip dumping logs to the logfile (to improve performance).
    
        [--enforce]
    
        Enforce any value between 1-99 as a valid threshold and
        do not perform mathematics on arguments given.
    
        NOTE: Flags must be in order [--detach] > [--skip-logs] > [--enforce]
        or else blex will misinterpret them as options.
    
    * Options
    
        [--update] [switch/power] [disable/power] [enable]
    
        Update Automation thresholds. The feature that provides
        the thresholds is the first argument and new values of
        thresholds are arguments following that.
    
        If the feature is Auto Power, second argument is power
        threshold, and if the feature is Auto Switch, second and
        third arguments are disable and enable thresholds as in
        order.
    
        If enable threshold is not given, it will figure that out,
        and if no threshold is given, it'll revert thresholds of
        the feature to their defaults, and finally, if the feature
        is not given, it will revert every threshold.
    
        [--toggle] [switch/power] [ON/OFF]
    
        Toggle Automation feature ON or OFF. The feature to toggle
        is the first argument and the state to toggle to is the
        second.
    
        If state is not given, it'll invert the feature state like
        ON -> OFF and vice versa, and if the feature is not given,
        both features will be reverted to their default state.
    
        [--manual] [enable/disable/stop] [level/time]
    
        Enable or disable charging, or stop every manual method
        running. The action to perform is the first argument and
        the format string for the action (if not stop) is second
        argument.
    
        If the action is stop, it will stop every manual method
        currently running, and if enable or disable, then charging
        state will be {action}d based on the format specified by
        the format string.
    
        The format string will be '{level}%' if {action}ing until
        the 'level' is hit, or '{time}s', '{time}m' or '{time}h'
        to {action} charging until 'time' seconds, 'time' minutes
        or 'time' hours have passed respectively.
    
        [--mkdaemon] [start/stop]
    
        Start or stop the blex daemon manually. It will start or
        stop the daemon as per the first argument.
    
        If an argument is not given, it will start the daemon.
    
        [--configure]
    
        Configure blex' kernel communication interface.
    
        [--restat]
    
        Reset battery statistics on demand. Useful in recalibraing
        the battery, should only be used once a month.
    
        [--info]
    
        Print information about current battery state, settings of
        blex and whether the daemon is running or not.
    
        [--help]
    
        Print this HELP page and exit.
    
    ## Examples
    
    * blex --enforce --update switch 99
    * blex --detach --manual disable 1%
    * blex --skip-logs --configure
    
    * blex --update switch 80 60
    * blex --update switch 85
    * blex --update power 15
    * blex --update switch
    * blex --update
    * blex --toggle switch ON
    * blex --toggle power OFF
    * blex --toggle switch
    * blex --toggle
    * blex --manual enable 1h
    * blex --manual disable 30m
    * blex --manual enable 90%
    * blex --mkdaemon start
    * blex --mkdaemon stop
    * blex --mkdaemon
    * blex --configure
    * blex --restat
    * blex --info
    * blex --help
    
    ## Support
    
    * ISSUE: Device spontaneously reboots while configuring.
    * SOLUTION: Configure blex again after the device rebooted.
    
    * ISSUE: blex stops working after flashing some kernel.
    * SOLUTION: Reconfigure blex using 'blex --configure'.
    
    * NOTE: Resetting batterystats might not work for all devices.
    
    * If you experience any issue while installing, please share
      about that in either the 'Support Thread' (see 'Links') or
      'Telegram Group' (again, 'Links') and remember to attach
      the '/dev/blex_install.log' logfile.
    
    * If you experience any issue with the daemon or CUI, write
      about that in the thread or group and please attach logfiles
      placed in the folder '/sbin/.core/img/blex/log' if Magisk
      install, or in '/data/adb/blex/log' for standard install.
    
    * All the bug reports should be widely described and must have
      required (and relevant) logs.
    
    * If you're a developer willing to contribute, please do so
      by creating PRs at my personal GitHub fork of blex.
    
    * I'm a college first-year student who does it all as a hobby
      to help others, so if I helped you, kindly use the 'Thanks'
      button on the XDA Support Thread.
    
    ## Credits
    
    * @topjohnwu for Magisk.
    * @osm0sis for his BusyBox binary.
    * Every blex/mcc beta tester :)

    XDA:DevDB Information
    Battery Life Extender, Tool/Utility for the XDA Community Apps

    Contributors
    JayminSuthar
    Source Code: https://github.com/Magisk-Modules-Repo/blex


    Version Information
    Status: Stable
    Current Stable Version: 0.3
    Stable Release Date: 2018-10-16

    Created 2018-01-23
    Last Updated 2018-10-16
    16
    Changelog
    Code:
    #### 0.3
    
    * Fix default PATH for daemon startup.
    * Fix for kernels not responding node changes.
    * Limit checking for current to just once.
    * Minor UI change.
    * Documentations update.
    
    #### 0.2
    
    * Add examples for supported actions.
    * Symlink BusyBox applets instead of hardlinking.
    * Revert manual methods regardless of Auto Switch.
    * Check control file content before writing.
    * Filter out Changelog from [--help] output.
    * Update to osm0sis' BusyBox 1.29.3.
    * Update documentation.
    
    #### 0.1.4
    
    * Limit charging state changes to only two.
    * Fix unwanted output when checking for daemon.
    
    #### 0.1.3.3
    
    * Minor README fix.
    
    #### 0.1.3.2
    
    * Fix daemon not running issues.
    
    #### 0.1.3.1
    
    * Fix daemon detections.
    
    #### 0.1.2.1
    
    * Fix the daemon can not be launched.
    
    #### 0.1.2
    
    * Fix CLI not recognizing the daemon.
    * Fix [--mkdaemon] always starting daemon.
    * Update strings.
    
    #### 0.1.1
    
    * blex is no longer in beta stage!
    
    * Fix configuring for lazy kernel events.
    * Fix detecting running processes.
    * Fix daemon checking in [--mkdaemon].
    * Fix manual methods detection.
    * Fix stopping multiple methods.
    * Prevent running multiple daemons.
    * Minor UI update.
    
    #### 0.1.beta
    
    * Please remove any version of mcc before installing this.
    
    * Rework as 'Battery Life Extender (blex)'.
    
    #### Redefined 1.1.3
    
    * Fix [--help] page output.
    
    #### Redefined 1.1.2
    
    * Fix unzipping error.
    * Update strings.
    
    #### Redefined 1.1.1
    
    * I'm currently porting this project Shell -> native "C". No
       feature builds, will be released for the shell version of
       it. Only bugfixes! Keep reporting please.
    * In case you're interested, porting to "C" will allow it to
       function even without a root solution, though requiring a
       custom recovery. Also executions will be hell-lot-of fast
       and much less resource heavy (current: 7MB).
    
    * Fix the daemon incorrectly reverting the switch.
    * Fix boot script not launching the daemon.
    * Fix Install script aborting in recovery.
    * Fix A/B slot detection for some devices.
    * Fix permissions for generated files.
    * Fix read-only filesystem errors.
    * Fix lost BusyBox applet links.
    * Fix other bugs I discovered.
    * Automatically implement skip_root workaround.
    * Improvements (logging, daemon, algorithms).
    * Remove Magisk versionCode checking.
    * Remove separate error log_files.
    * Remove lock file feature.
    * Update BusyBox to 1.29.2.
    * Update documentation.
    * Update arguments.
    * Update UI.
    
    #### Redefined 1.1
    
    * Fix incorrect daemon status in [--info].
    * Fix control references identification.
    * Fix mounting issues for some devices.
    * Fix 'internal error' for system mode.
    * Fix racial condition with [--reset].
    * Fix boot scripts error logging.
    * Fix BusyBox aborting setup.
    * Fix other minor bugs.
    * Remove unnecessary x86 BusyBox.
    * Remove unnecessary img resizal.
    * Remove late_start boot script.
    * Remove the wrapper around su.
    * Install mcc to xbin for system mode.
    * Use BusyBox for mcc Install script.
    * Add logging to the Install script.
    * Update the behaviour of lock_file.
    * Update strings.
    * Update README.
    
    #### Redefined 1.0.2
    
    * Fix the daemon not writing control nodes.
    * Internal code improvements.
    * Update README.
    
    #### Redefined 1.0.1
    
    * Fix daemon not launching with beta Magisk.
    * Fix control reference nodes never identified.
    -> This should fix daemon not working and always reconfiguring.
    * Fix safe boundaries for [--switch/--power].
    * Fix some algotithmic flaws.
    * Update BusyBox to 1.29.1.
    * Update strings.
    
    ##### Redefined 1.0.MR
    
    * Fix a few bugs with BusyBox and UI.
    * Update README for public release.
    
    ##### Redefined 1.0
    
    * Initial redefined release.
    
    ##### 2.0.MR
    
    * Hello people, This build is a fix for when a [-s/--switch]
       call doesn't act like it should. Actually, the code while
       having the down threshold and the code for when not, were
       placed alternatively. So if you run... say 'mcc -s 85 70'
       it would run as the '70' was not given and as mcc I wrote
       to be intelligent, it would set 85 and ' 85 - 10 = 75'.
    
    ##### 2.0
    
    * This version is re-written from scratch, so please perform
      a CLEAN INSTALLATION.
    
    ##### 1.5.1.MR
    
    * Hi users,
    * This build is to fix two major bugs which I identified just
      now. First is the well-known, conflict of the mcc Installer
      and the mcc daemon, and the second is the daemon misbehaves
      if refs are not set or the lock file is created. Both of em
      have been fixed. While the first prevents mccs installtion,
      the second causes unwanted reboots for cases while the user
      has misused the lock file feature or have modified the conf
      file. After this fixations, I can proudly say that mcc does
      not have no bugs now...
    * Another thing is that mcc now patches the Main before Magic
      mounting has happened, so in theory, there will not be need
      to make any modifications if Magisk changes its mount point
      again, just enjoy!!! Regarding boot scripts, they log their
      errors now too as well as commands executed.
    * And also while some advanced users did directly run the mcc
      daemon, I have also prevented the daemon from running, only
      mcc internals can fork it, and that should be when required
      by mcc. This blocking also helps the initial daemon call on
      the boot a great algorithmic space, so is great.
    
    ##### 1.5
    
    * Hi users,
    * The final build by me is here, as I will be prepping for my
      college admissions. If someone is willing to develop it, PM
      me at XDA or open an issue at GitHub and I'd give you write
      access to the Repo.
    * This build is nothing other than previous build, but having
      fixed the Magisk mountpoint, BusyBox setup, and other minor
      issues.
    * A quick tip: If Magisk changes its mountpoint again, simply
      edit LINE 45 in /system/{x,}bin/mcc, NOTHING else.
    * Quick tip 2: All the core logic is documented, nothing else
      is there, I think logic builds program, not coding skills.
    * Wish me luck and Goodbye.....
    
    ##### 1.4.3
    
    * Hi users,
    * A small + sensitive release is here, which is aimed on some
      minor code errors, and a better way of eliminating failures
      due to interference with the daemon.
    * All the bugs fixed are reported by users at XDA, and I will
      not detail them here, but "Please toggle auto switch OFF if
      compatibility check fails upgrading".
    * What I am gonna detail is a new feature of the daemon. From
      this version on, mcc daemon can be paused with a lock file.
      Users, or anyone else, can create the file CACHE_DIR/lock_d
      and the daemon will go sleep until it exists. This is to be
      used by Installer, but not limited. So changelog reads...
    * ...Fix 'Permission denied' while running mcc
    * ...Fix daemon not launching for some devices
    * ...Fix bad compatibility check failures
    * ...Bring back initial 120 seconds delay
    * ...Add a lock file to pause the daemon
    
    ##### 1.4.2
    
    * Hi users,
    * This is another lil bug fix release, which is to fix a very
      serious bug, which makes auto switch non-functional, thanks
      to @pat357 for pointing the buggy thing out and providing a
      quick fix
    
    ##### 1.4.1.MR
    
    * Workaround Magisk bundled BusyBox missing poweroff applet
    
    ##### 1.4.1
    
    * Hi users,
    * This is a small bug fix release, which is aimed to fix some
      little, but very serious bugs, so changelog reads as
    * --> Fix mod_dir not being set by the service
      --> Fix unwanted reboots while installing
      --> Fix installations for Pixel 2 XL
      --> Fix switch not being written
    * And the last twos are thankfull contributions from @chuckr2
    
    ##### 1.4
    
    * Hi users,
    * As always it calls for an apology that you all had to manually
      set references even after succeeding the compatibility check from the
      mcc Installer, it was a misspelled variable in the Installer, which
      has now been fixed, for which I want to thank @pat357 for his pull
      request
    * Another critical bug was false positive compatibility successions, this
      bug appears when the device did not even have a recognized battery
      device / module, and so much funnier, the reason was just a single
      misplaced variable, that was used to detect if the check succeeded,
      this bug has also been fixed
    * @RSDamasceno at XDA reported having soft reboots and device warm-ups
      with mcc, which I suspect a bug with kernel not handling switch writes
      correctly, but as mcc is entirely written in Shell, I have added some
      code that will detect the current switch status and write to it only if
      the status is different, so the issue is supposed to be fixed
    * It fixes another issue when the user has given an invalid argument for
      manually enabling charging, issue appeared something like, mcc will
      first disable charging, then abort due to unrecognized argument, so
      charging will be disabled as opposed to be enabled, which has also
      been fixed
    * With any older mcc build, the first execution of command always took
      some seconds, some people reported 2, some 5 and some even 8 seconds,
      which happened due to mcc's Magisk mount point finding and BusyBox
      setup, which I implemented just to make sure mcc can work with all the
      present and possibly any future Magisk version, but the logic has now
      been shifted to service, which on boot, will do it all once for the
      entire boot session
    * The boot daemon launcher will now attempt 5 times to launch the daemon,
      which whether succeeded / failed will be logged in Magisk logs, so
      that users can check if the daemon was launched at boot time
    * And now as Android P DP1 is out, which removes make_ext4fs, I have put
      a fallback for that to mke2fs, just as same with Magisk
    * Also all the strings in the Installer and the Main have been re-written
      and some faulty code has been cleaned up and organized as always
    * So, the complete changelog is
      --> Fix the Installer not setting references by @pat357
      --> Fix false positives with compatibility check
      --> Fix a bug with with kernels not handling switch changes correctly
      --> Fix a bug with manually enabling charging
      --> Fix image creation for Android P DP1
      --> Fast as hell first time execution
      --> A better boot daemon launcher
      --> Re-write all the strings
      --> Cleanup some code
    
    ##### 1.3
    
    * Hi users,
    * Firstly, I'm sorry for the sucking 'No references set' bug,
      I forgot to split out the switch file which resulted in as an
      unrecognized switch by mcc, So, whenever mcc was ran, it did not
      detect switches and so the bug happened, this bug has been  fixed now
    * And now, so mcc provides manual run option, and which takes time as an
      argument, for which, mcc will fork a session which will keep sleeping
      for the given time, and mcc will check for that process every second,
      but it gave false positives when another shell process was also sleeping
      for the same time as mcc ( child ) did, that bug has also been fixed
    * I also recently intoduced a new feature said 'Revert Magic Mount'
      live from booted Android, but I realized that with A / B devices,
      it is completely different, which made it unusable for such devices,
      but now, the feature is working completely on A / B devices now, for which
      mcc requires Magisk >= 1410 from now ( would not matter for most users )
    * I have also put in a hell lot of efforts in making mcc rock stable,
      I started from the top of every single component and kept analyzing, and
      analyzing, and analyzing, and analyzing, and analyzing, and analyzing,
      and Finally, I'm glad to declare most unless all bugs are flushed out
    * I also have effingly strived harder to workaround many non-mcc flaws which I found
    * So, the complete changelog is
      --> Fix the 'No references set' bug
      --> Fix false positives for time-based run
      --> Fix 'Revert Magic Mount' for A / B devices
      --> Re-analyze and re-write the entire project
      --> Workaround many non-mcc flaws
      --> Require Magisk >= 1410
    
    ##### 1.2.4
    
    * Fix compatibility check ( Installer / mcc ) for some devices
      --> add support for some weird devices I saw ( mostly Honor )
    * Fix some faulty BusyBox setup code
    * Fix image sizes for resizing
      --> mcc never shrinks them, so expand only to needs
    * Fix regression opened by @pat357
    * Free Magisk daemon child after mcc daemon is launched
    * Abort installation for Magisk < 1400
    * Update README ( and indirectly [ --help ] )
    
    ##### 1.2.2
    
    * Fix daemon not being launched at boot ( was my bad )
    * Fix some faulty image resizing code in mcc Installer
    * Fix unwanted power-offs for when no references are set
    * Fix regression opened by @pat357
      --> show daemon status ( runnning or what ) in [ --info ]
    * Add perms handling for non Stock / near Stock kernels
    * Increase checking intervals from 10ms to 100ms
      --> which is likely to fix some compatibility check failures
    * Add double checking for uevent file
      --> which is likely to fix some compatibility issues
    * Flash again to uninstall feature now performs a complete uninstall
      --> 1) remove files 2) kill mcc processes and 3) revert Magic Mount
      --> it will revert Magic Mount live from booted Android!!!
      --> the last one is available only for Magisk >= 1410,
          as topjohnwu has changed the Magic Mount algorithms many times
    
    ##### 1.2.1
    
    * All previous versions are considered incompatible
    
    * Fix installations for Magisk Manager 5.6.0+
    * Fix some faulty busybox setup code
    * Correct some terminology ( see 'Arguments can be' )
    * Improve the [ --re-daemon ] option
    * Change defaults to 80 70 ( it be optimal )
    * Rewrite README ( which directly means [ --help ] )
    * Add messages to UI for some tasks
    * Reduce checking intervals to 10ms
    * Reduce max switches to two from four
    * Add error handling for new code
    * Port commit from Magisk to mcc Installer
      --> 'Round sizes to nearest integer', also repair image first if found
    * Put errors to a separate logfile
    * Rebase some tests on common observations
    * Remove and re-write some pieces of code
    * For developers
      --> Revert the source mcc feature, to keep the code clean
    11
    Announcement

    Hi my dear users,
    I'm happy to tell you all that I'm back in development. Although I may not have time at daytime, there is still some spare time for me in the night. I really like the fact that my work has been much appreciated, and really would not wish to disappoint mcc users. So, I thought I must be back in development, and here I come.
    MCMotherEffin'
    The been back developer
    8
    Development update!

    Hello guys,

    I am aware of some bugs like the 'internal error', etc... All bugs are fixed (huge thanks to @ToXiTe) in my local copy and also the beta branch of the GitHub Repo. It's just that, I am currently taking a little effort to redefine (again) it to have a modular designation, so that further updates to the project can be easily implemented without any refactor, redefine, etc... And yeah, I'm in the college 1st year, so currently running busy over excitement for the fresher's party :cowboy:. So, it might be late, but it surely will make to the official repo once I'm done all the testing (and @ToXiTe has been a great help for me). I recommend using an older version until the newer build is released, I hope y'all understand.

    Best regards,
    Jaymin.

    EDIT: I just rewrote a minor portion of blex (Name changed: Battery Life Extender (blex)). It was fun how I could implement a modular interface just to ease out the pain of merging. I'm really happy at what state is the project right now, and all because of your support! Thank you, guys :)