Android - How to prevent brightness from going to full when the battery low popup appears?
Automation is the preferred option, or rather only option in this case, since Android OS does not offer any settings for requirements quoted.
Many apps are available. I prefer using MacroDroid , since it is free (upto 5 macros) and easy to learn.
MacroDroid creates and runs Macros to automate
A macro consists of the following (elaborating on app help):
Trigger
Event(s) occurring on the device (e.g incoming SMS, headphones inserted). Multiple triggers are evaluated to logical (OR)- meaning, any of the trigger conditions met would fire macro
Actions
An action that the device can perform (e.g. set wallpaper, take picture)
Constraints
A constraint that must be satisfied for the trigger to fire (e.g. day of week, battery level). Multiple constraints are evaluated to logical (AND)- meaning, all the constraints must be satisfied to fire trigger
Notes on solution offered
Tested on KitKat. I don't visualise any issues with higher Android versions
This cannot "read" when the low battery level indication comes up, but for this macro assuming it to be 15 %. You can see the battery level in your tablet and accordingly tweak the macro
Doesn't require root
This solution does not address Android system explanation for high/low Brightness and how they are activated
System Settings
Do not Greenify MacroDroid and exclude it from task killers, if you use them.
Enable MacroDroid in "Auto Protect"(Huawei phones) or "Stamina Mode" (Sony phones or "Power Nap" (Stamina Mode Xposed module for non Sony devices). Also, if you update to Marshmallow in the future, exclude MacroDroid from Doze. Refer this: Is there a way to exclude an app from Doze?
These features prevent app(s) to be active when the device is not awake, conserving battery. May not be pertinent to your phone but adding this as a general precaution.
Enable MacroDroid in accessibility settings and also allow it as device administrator in security settings.
For Lollipop, enable notification access from notification settings
tl;dr: Your macro would look like this
Trigger:
Battery Level → decreases to → (choose percentage by sliding scale or 15 %)
Actions:
- Brightness →0 (Choose On sliding scale- doesn't require root)
- Wait before next action → set to 10 seconds (recommended to separate previous and next actions ensuring both happen)
- Dim Screen →Dimmer On → 10% (Choose On sliding scale- doesn't require root, if the earlier action is not good enough for you - this is akin to "screen filter" apps like Darker)
Constraints:
None (Macro always runs)
Testing Macro
Name and save the macro and from 3 button menu on right side
Test Actions: To see how macro behaves at each action without reference to trigger/constraint conditions
Test Macro: To see how macro behaves as expected ( with reference to trigger/action/constraints, that is, macro as a whole)
Trouble shooting
Macro doesn't run at all- In most cases, it is due to correct system settings not being applied. To verify this, from the 3 button help option on the main app interface select System Log and see if your macro had run when it was triggered. If your macro name doesn't figure, recheck system settings
Note: the solution below requires your Android to be rooted.
I believe that automation without root wouldn't straightly deal with the issue, since it is not changing or overriding anything, but doing its own stuff over the existing changes. I was about to post on similar lines until I realized that the key to the solution is a file named max_brightness
, a file under /sys
, hence a part of Linux kernel and directly managed by it. I found that setting the brightness limit in that file is the best way to go here. You may disagree with a better solution.
I noticed that once your custom maximum brightness is set, neither Android nor an app was able to set brightness beyond that custom level unless they changed the content of that file, which often an app has no reason to and none of them changed either. Besides, the file is owned by root and is part of group root, so any app or even system_server would require root privilege to make changes into that file.
Finding that file is bit tricky. In my MTK device with Android 4.2, that file appears to be under /sys/devices/platform/leds-mt65xx/leds/lcd-backlight/
.
In my Qualcomm device with Android 5.0.2 and above, the file appeared to be in /sys/devices/mdp.0/qcom,mdss_fb_primary.168/leds/lcd-backlight/
.
I assume that the best way to find that file is to run a search query (setup adb for that), such as:
(Requires busybox)
adb shell su -c 'find /sys/ -type f -iname "max_brightness"'
In my Qualcomm device, the output it gives is:
/sys/devices/f9924000.i2c/i2c-2/2-0068/leds/red/max_brightness /sys/devices/f9924000.i2c/i2c-2/2-0068/leds/blue/max_brightness /sys/devices/f9924000.i2c/i2c-2/2-0068/leds/green/max_brightness /sys/devices/mdp.0/qcom,mdss_fb_primary.168/leds/lcd-backlight/max_brightness /sys/devices/qcom,camera-led-flash.81/leds/torch-light/max_brightness /sys/devices/msm_sdcc.1/leds/mmc0::/max_brightness /sys/devices/msm_sdcc.2/leds/mmc1::/max_brightness /sys/devices/01-qcom,leds-d300/leds/led:flash_torch/max_brightness /sys/devices/01-qcom,leds-d300/leds/led:flash_0/max_brightness /sys/devices/01-qcom,leds-d300/leds/led:flash_1/max_brightness /sys/devices/01-qcom,leds-e200/leds/kpdbl-lut-2/max_brightness /sys/devices/01-qcom,leds-e200/leds/kpdbl-pwm-3/max_brightness /sys/devices/01-qcom,leds-e200/leds/kpdbl-pwm-4/max_brightness /sys/devices/01-qcom,leds-e200/leds/button-backlight/max_brightness
The location where lcd-backlight
is mentioned was the only one that made sense to me and this is how I found the file in my device. Don't you worry asking about others. I attempted changing the brightness of the screen and looked for the changes in the file named brightness
(also located under those said locations). None of them reflected the correct output other than the one at /sys/devices/mdp.0/qcom,mdss_fb_primary.168/leds/lcd-backlight
.
Only for demonstration, try setting a limit in max_brightness
adb shell su -c 'echo LIMIT > PATH_TO_MAX_BRIGHTNESS' # in my case PATH_TO_MAX_BRIGHTNESS is /sys/devices/mdp.0/qcom,mdss_fb_primary.168/leds/lcd-backlight/ and set LIMIT to a value less than 30 (not limited to).
Now try maxing the brightness by using brightness slider or a third party app and you would notice that the brightness of your screen doesn't exceed beyond a certain point even when slider or the app's configuration appears to be at maximum. The brightness for that "certain point" would certainly be less than the default one you are used to.
Note that the maximum value in max_brightness is often found to be 255 and the brightness ranges from 0-255. Often, not always true, that is. And fear not from setting the limit to 0. It would cause the screen not to lit until you revert the changes or restart the device.
Find a limit which would not disturb you in your sleep or drains the battery heavily when battery runs low on juice.
Automation
For automation, use any automation app that can run a command with root privilege and when the context of your preferred trigger is met. I recommend a time based trigger.
Some working examples:
In Tasker, setup a profile with your preferred context, create a task and use the action: Code → Run Shell:
- Command:
echo LIMIT > PATH_TO_MAX_BRIGHTNESS
- check Use Root
- Command:
In MacroDroid, setup your preferred trigger and for action install Secure Settings, choose it → Actions → Run Command:
- Command:
echo LIMIT > PATH_TO_MAX_BRIGHTNESS
- check Use Root
- Command:
In Automate, as part of your flow, when setting up an action for your trigger, select Shell command superuser under Apps and do:
- Command Line:
echo LIMIT > PATH_TO_MAX_BRIGHTNESS
Make sure to install all the permissions the flow require.- Command Line:
In DroidAutomation, setup your trigger and under task, select Root → Execute a command line and type:
echo LIMIT > PATH_TO_MAX_BRIGHTNESS
As you would've guessed, you would have to setup two profiles for every app. One to setup a limit and the other to set the maximum brightness to the default you're used to.
Explicit low battery triggers:
Tasker
- State → Battery Level → set the range
- Alternative: Event → System → Intent Received → leave everything untouched but set the Action to
android.intent.action.BATTERY_LOW
.
MacroDroid
Follow beeshayms' answer to setup the trigger
Automate
Go to Apps → Broadcast receive → leave everything untouched but select Battery low in Action
Droid Automation
Select Low battery from Add a trigger
I would like you to keep this under consideration that using a low battery or 100% battery trigger would defeat the purpose of this answer, which is to override the changes Android want to make. As an example, if you setup LIMIT to 0 whenever the battery reaches 100%, what would happen is your Android would lit the screen to maximum as usual and in few milliseconds (you read correctly) your automation app would run and set the limit. Your sleep may get interrupted in those milliseconds.
In an another situation, when low battery intent is broadcasted by system, Cool Guy's tablet may end up with a screen lit to maximum and in few milliseconds, the brightness would fall back to LIMIT.
The workaround is to set up the battery level to 16 or more for battery low trigger and 99 or less for full battery charge.
Try using an app called Screen filter. CAUTION: Do not set the brightness below 17 because you cant see anything. You can text at nighy n the person sitting next to you wont even see