Open DavidPinilo opened 2 years ago
while debugging this issue, I found that the backlight service sends two backlight signals. one to /sys/class/leds/lcd-backlight/brightness and another to /sys/class/leds/lcd-backlight/brightness_clone. However, the data that gets sent to brightness_clone is the real backlight values that are supposed to be in brightness.
Here's a logcat snippet while sliding the brightness slider up:
05-17 05:06:54.949 1056 1056 D android.hardware.lights-service.mediatek: write 3436 to /sys/class/leds/lcd-backlight/brightness_clone, result: 0
05-17 05:06:54.950 1056 1056 D android.hardware.lights-service.mediatek: write 1717 to /sys/class/leds/lcd-backlight/brightness, result: 0
05-17 05:06:54.966 1056 1056 D android.hardware.lights-service.mediatek: write 3452 to /sys/class/leds/lcd-backlight/brightness_clone, result: 0
05-17 05:06:54.966 1056 1056 D android.hardware.lights-service.mediatek: write 1725 to /sys/class/leds/lcd-backlight/brightness, result: 0
05-17 05:06:54.983 1056 1056 D android.hardware.lights-service.mediatek: write 3468 to /sys/class/leds/lcd-backlight/brightness_clone, result: 0
05-17 05:06:54.984 1056 1056 D android.hardware.lights-service.mediatek: write 1733 to /sys/class/leds/lcd-backlight/brightness, result: 0
05-17 05:06:55.019 1056 1056 D android.hardware.lights-service.mediatek: write 3500 to /sys/class/leds/lcd-backlight/brightness_clone, result: 0
05-17 05:06:55.019 1056 1056 D android.hardware.lights-service.mediatek: write 1749 to /sys/class/leds/lcd-backlight/brightness, result: 0
05-17 05:06:55.035 1056 1056 D android.hardware.lights-service.mediatek: write 3516 to /sys/class/leds/lcd-backlight/brightness_clone, result: 0
05-17 05:06:55.035 1056 1056 D android.hardware.lights-service.mediatek: write 1757 to /sys/class/leds/lcd-backlight/brightness, result: 0
05-17 05:06:55.048 1056 1056 D android.hardware.lights-service.mediatek: write 3532 to /sys/class/leds/lcd-backlight/brightness_clone, result: 0
05-17 05:06:55.048 1056 1056 D android.hardware.lights-service.mediatek: write 1765 to /sys/class/leds/lcd-backlight/brightness, result: 0
05-17 05:06:55.067 1056 1056 D android.hardware.lights-service.mediatek: write 3549 to /sys/class/leds/lcd-backlight/brightness_clone, result: 0
05-17 05:06:55.067 1056 1056 D android.hardware.lights-service.mediatek: write 1774 to /sys/class/leds/lcd-backlight/brightness, result: 0
05-17 05:06:55.084 1056 1056 D android.hardware.lights-service.mediatek: write 3565 to /sys/class/leds/lcd-backlight/brightness_clone, result: 0
05-17 05:06:55.085 1056 1056 D android.hardware.lights-service.mediatek: write 1782 to /sys/class/leds/lcd-backlight/brightness, result: 0
05-17 05:06:55.118 1056 1056 D android.hardware.lights-service.mediatek: write 3597 to /sys/class/leds/lcd-backlight/brightness_clone, result: 0
05-17 05:06:55.118 1056 1056 D android.hardware.lights-service.mediatek: write 1798 to /sys/class/leds/lcd-backlight/brightness, result: 0
05-17 05:06:55.132 1056 1056 D android.hardware.lights-service.mediatek: write 3645 to /sys/class/leds/lcd-backlight/brightness_clone, result: 0
05-17 05:06:55.132 1056 1056 D android.hardware.lights-service.mediatek: write 1822 to /sys/class/leds/lcd-backlight/brightness, result: 0
05-17 05:06:55.149 1056 1056 D android.hardware.lights-service.mediatek: write 3709 to /sys/class/leds/lcd-backlight/brightness_clone, result: 0
05-17 05:06:55.149 1056 1056 D android.hardware.lights-service.mediatek: write 1854 to /sys/class/leds/lcd-backlight/brightness, result: 0
05-17 05:06:55.168 1056 1056 D android.hardware.lights-service.mediatek: write 3757 to /sys/class/leds/lcd-backlight/brightness_clone, result: 0
05-17 05:06:55.168 1056 1056 D android.hardware.lights-service.mediatek: write 1878 to /sys/class/leds/lcd-backlight/brightness, result: 0
05-17 05:06:55.202 1056 1056 D android.hardware.lights-service.mediatek: write 3789 to /sys/class/leds/lcd-backlight/brightness_clone, result: 0
05-17 05:06:55.202 1056 1056 D android.hardware.lights-service.mediatek: write 1894 to /sys/class/leds/lcd-backlight/brightness, result: 0
05-17 05:06:55.218 1056 1056 D android.hardware.lights-service.mediatek: write 3838 to /sys/class/leds/lcd-backlight/brightness_clone, result: 0
05-17 05:06:55.218 1056 1056 D android.hardware.lights-service.mediatek: write 1918 to /sys/class/leds/lcd-backlight/brightness, result: 0
05-17 05:06:55.233 1056 1056 D android.hardware.lights-service.mediatek: write 3902 to /sys/class/leds/lcd-backlight/brightness_clone, result: 0
05-17 05:06:55.233 1056 1056 D android.hardware.lights-service.mediatek: write 1950 to /sys/class/leds/lcd-backlight/brightness, result: 0
05-17 05:06:55.268 1056 1056 D android.hardware.lights-service.mediatek: write 3934 to /sys/class/leds/lcd-backlight/brightness_clone, result: 0
05-17 05:06:55.268 1056 1056 D android.hardware.lights-service.mediatek: write 1966 to /sys/class/leds/lcd-backlight/brightness, result: 0
05-17 05:06:55.288 1056 1056 D android.hardware.lights-service.mediatek: write 3998 to /sys/class/leds/lcd-backlight/brightness_clone, result: 0
05-17 05:06:55.288 1056 1056 D android.hardware.lights-service.mediatek: write 1998 to /sys/class/leds/lcd-backlight/brightness, result: 0
05-17 05:06:55.300 1056 1056 D android.hardware.lights-service.mediatek: write 4046 to /sys/class/leds/lcd-backlight/brightness_clone, result: 0
05-17 05:06:55.300 1056 1056 D android.hardware.lights-service.mediatek: write 2022 to /sys/class/leds/lcd-backlight/brightness, result: 0
05-17 05:06:55.316 1056 1056 D android.hardware.lights-service.mediatek: write 4095 to /sys/class/leds/lcd-backlight/brightness_clone, result: 0
05-17 05:06:55.316 1056 1056 D android.hardware.lights-service.mediatek: write 2047 to /sys/class/leds/lcd-backlight/brightness, result: 0
As you probably can tell, brightness_clone is more consistent and accurate than brightness, so i made a loop to take all brightness_clone values and send them to brightness and the brightness values are fixed.
while true; do cat /sys/class/leds/lcd-backlight/brightness_clone > /sys/class/leds/lcd-backlight/brightness_clone; done
With this running in the background I can use the whole slider and brightness go as low as 13 and as high as 4095 (max, after setting persist.sys.qcom-brightness to 4095).
I still don't know how to fix this but at least we now know the cause of it.
(and yeah this is the cause to 0 backlight issue after sleep)
Sorry for not updating the infos here, I actually debugged this issue few days ago...
What you said is right, though it doesn't explain the details. So:
So the first part (>=400) of the issue is fixed, but the under 400 sounds uh, extremely annoying. I can technically add a giant hack where Android's framework writes directly in /sys/class/leds/lcd-backlight/brightness, but this will most likely break various stuff (well, you have no AOD, so at least I can't break AOD...)
hello thanks for the code. It helps! Also i created temporary magisk module to run it on boot, it's working fine now ^^ you guys are awesome! magisk
FYI the while command eats 100% of one CPU, which will kill your battery life
- "Use alternate backlight scale" which changes lights called to call setLights with brightness rather than ARGB is required, but it assumes that the max is the content of /sys/class/leds/lcd-backlight/max_brightness. On this device, it's wrong, it's 4095, because the lights HAL does *=2 on the light value (probably because all Xiaomi devices use 4095 scale, and didn't bother to change for that one)
Makes sense. It's Xiaomi we're talking about.
- Both enabling that option and setting it in 4095 is done in phhusson/device_phh_treble@71f0000
At the time of writing, I didn't know that.
- Xiaomi's Android framework triggers DC diming when under 400, using Mediatek's setColorMatrix_3x3 (so instead of sending identity matrix [[1,0,0],[0,1,0],[0,0,1]] it sends [[0.8,0,0],[0,0.8,0],[0,0,0.8]])
Interesting.
- If Xiaomi switch to DC diming, it's probably because that real diming under 400 isn't nice with color artifacts
Well from what I tried there are no artifacts or anything wrong with the display under 400 using the loop I mentioned above, which as you mentioned eats battery and prevents the device from sleep.
So the first part (>=400) of the issue is fixed, but the under 400 sounds uh, extremely annoying. I can technically add a giant hack where Android's framework writes directly in /sys/class/leds/lcd-backlight/brightness, but this will most likely break various stuff (well, you have no AOD, so at least I can't break AOD...)
Well... I was about to try playing with the lights service in aosp and try to implement DC Dimming but instead I looked at android.hardware.lights-service.mediatek since it's the one writing to brightness_clone and did a string edit using HxD and... it worked! as silly as it is.
in offset 00001BB0, there's a single mention of brightness_clone. fill "_clone" with 00 and push it to /vendor/bin/hw. that's it. Brightness works perfectly.
I'll make a magisk module when I'm off work and send it here.
You can probably just do mount -o bind /sys/..../brightness_clone /sys/.../brightness
from rw-system.sh instead
You can probably just do
mount -o bind /sys/..../brightness_clone /sys/.../brightness
from rw-system.sh instead
Not sure why this hasn't came to mind when I was brainstorming a solution... but at least I came up with one, I guess...
meh, you already had a solution, i just improved yours a tiny bit But so can you try it, and PR the modified rw-system.sh if it works? it's always better to have the workaround in gsi rather than as a separate magisk module
meh, you already had a solution, i just improved yours a tiny bit But so can you try it, and PR the modified rw-system.sh if it works? it's always better to have the workaround in gsi rather than as a separate magisk module
Unfortunately it didn't work.
Here's the magisk module for now until we find another way to fix it.
Interesting... I used begonia's lightservice.mediatek file and it completely fixed brightness. no need for linear brightness either.
The mod I did kept writing two values to brightness
over 400 so it didn't give full brightness. While I tried different mods like removing the second "real" brightness line from camellia's lightservice file and some other stuff none of them worked.
As a last resort I looked online for similar devices and I tool begonia as a test, and it works flawlessly.
Even though it sets brightness to 2074, I tried manually changing it to 4095 with no difference at all.
I'll update the magisk module I made to use begonia's lightservice instead once I'm done with testing.
Screen won't wake for notifications. Also in low light conditions, screen brightness seems to fall to 0 and although the screen works, you can't see anything logcat_04-26-2022_09-03-04.txt g Device: POCO M3 Pro / Redmi Note 10 5G AOSP 12.1 v412