Led Notification


baofrankit

Members
Jan 3, 2020
29
15
How to turn on led lights? Please help to enable led.
c15379e4c906096cd03a42ce0fbc388c.jpg


Gửi từ Redmi K30 của tôi bằng cách sử dụng Tapatalk
 
  • Like
Reactions: Nagarlay
How to turn on led lights? Please help to enable led.
c15379e4c906096cd03a42ce0fbc388c.jpg


Gửi từ Redmi K30 của tôi bằng cách sử dụng Tapatalk
I can't turn on notification light too. Even when I do the full check of the phone, there is no "LED Notification Light" option, as it is shown in some video reviews.
Is it a ROM related problem? If so, will it be fixed?Notification light is very important.
 
Technically LED exists and it has standard interface. You can see it in action with command `echo 1 > /sys/class/leds/white/breath`
But it is disabled in the firmware (also in stock fw).

Maybe it only requires to change `support_led_light` to true in /vendor/etc/device_features/picasso.xml
Maybe something more.

For now I have no success to test that because did not find a way to modify `vendor`.
I think Magisk module is not enough because that file is read earlier than Magisk starts.
And as I understand system, product, vendor can not be easily modified (filesystem is created with dedup activated or something, so it is read-only and can not be re-mounted).
I tried to rebuild vendor using mkuserimg_mke2fs.py from AOSP (+ mke2fs, e2fsdroid also from AOSP), but I have bootloop, maybe I do something wrong.


@ingbrzy , could you share scripts to build images like vendor.new.dat.br+vendor.patch.dat+vendor.transfer.list?
 
I still be glad to see scripts to build images, but already find a way to modify existing images and maybe after some experiments can find a way to build them from the scratch.

In any case I tested the system with modified xml in `vendor` and notification light did not work. But I found a way to make it works.

After setting support_led_light = true in /vendor/etc/device_features/picasso.xml we have Notification Light settings and in logcat we can see that the system tries to work with notification light. In particular there are records from the method "realSetLightLocked". But there is no light.

I followed all calls in Java code and found that finally it calls setLight_native which is implemented in native code (in android_servers.so). I did not de-compile native code, but instead add another method which writes to /sys/class/leds/white/* instead of setLight_native call. And it works fine.
So, looks like something is wrong in native code, but Xiaomi did not fix that, but just disabled notification light.
I think that a call to FileWriter.write is not heavier than a call of native method, so this patch is a good solution.

What are the changes to make it works (it should works for both K30 4G and 5G versions):

1. /vendor/etc/device_features/picasso.xml (phoenix.xml):
Set true in <bool name="support_led_light">true</bool>

2. Add SELinux rule:
allow system_server sysfs_white_led file *

3. Add a new method in services.jar/smali/com/android/server/lights/LightsService.smali:
Code:
.method static public setLight_native_patched(IIIIII)V
    .registers 15

    const/4 v0, 0x3

    if-eq p0, v0, :check_color_mode_write

    const/4 v0, 0x4

    if-eq p0, v0, :check_color_mode_write

    goto :call_native

    :check_color_mode_write

    if-nez p1, :color_is_not_0_check_mode

    :write_0_0

    new-instance v0, Ljava/io/FileWriter;

    const-string v1, "/sys/class/leds/white/breath"

    invoke-direct {v0, v1}, Ljava/io/FileWriter;-><init>(Ljava/lang/String;)V

    const-string v1, "0"

    invoke-virtual {v0, v1}, Ljava/io/FileWriter;->write(Ljava/lang/String;)V

    invoke-virtual {v0}, Ljava/io/FileWriter;->close()V

    new-instance v0, Ljava/io/FileWriter;

    const-string v1, "/sys/class/leds/white/brightness"

    invoke-direct {v0, v1}, Ljava/io/FileWriter;-><init>(Ljava/lang/String;)V

    const-string v1, "0"

    invoke-virtual {v0, v1}, Ljava/io/FileWriter;->write(Ljava/lang/String;)V

    invoke-virtual {v0}, Ljava/io/FileWriter;->close()V

    :write_0_0_end

    .catch Ljava/lang/Exception; {:write_0_0 .. :write_0_0_end} :catch_write_0_0

    goto :return

    :color_is_not_0_check_mode

    if-nez p2, :mode_is_not_0

    :write___4

    new-instance v0, Ljava/io/FileWriter;

    const-string v1, "/sys/class/leds/white/brightness"

    invoke-direct {v0, v1}, Ljava/io/FileWriter;-><init>(Ljava/lang/String;)V

    const-string v1, "4"

    invoke-virtual {v0, v1}, Ljava/io/FileWriter;->write(Ljava/lang/String;)V

    invoke-virtual {v0}, Ljava/io/FileWriter;->close()V

    :write___4_end

    .catch Ljava/lang/Exception; {:write___4 .. :write___4_end} :catch_write___4

    goto :return

    :mode_is_not_0

    new-instance v0, Ljava/io/FileWriter;

    const-string v1, "/sys/class/leds/white/breath"

    invoke-direct {v0, v1}, Ljava/io/FileWriter;-><init>(Ljava/lang/String;)V

    const-string v1, "1"

    invoke-virtual {v0, v1}, Ljava/io/FileWriter;->write(Ljava/lang/String;)V

    invoke-virtual {v0}, Ljava/io/FileWriter;->close()V

    :mode_is_not_0_end

    .catch Ljava/lang/Exception; {:mode_is_not_0 .. :mode_is_not_0_end} :catch_mode_is_not_0

    goto :return

    :catch_write_0_0

    :catch_write___4

    :catch_mode_is_not_0

    move-exception v0

    const-string v1, "LightsService"

    const-string v2, "setLight_native_patched exception"

    invoke-static {v1, v2, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :return

    :call_native

    move v0, p0

    move v1, p1

    move v2, p2

    move v3, p3

    move v4, p4

    move v5, p5

    invoke-static/range {v0 .. v5}, Lcom/android/server/lights/LightsService;->setLight_native(IIIIII)V

    :return

    return-void
.end method
In Java it looks like:
Java:
public static void setLight_native_patched(int i, int i2, int i3, int i4, int i5, int i6) {
    if (i != 3 && i != 4) {
        setLight_native(i, i2, i3, i4, i5, i6);
    } else if (i2 == 0) {
        FileWriter fileWriter = new FileWriter("/sys/class/leds/white/breath");
        fileWriter.write("0");
        fileWriter.close();
        FileWriter fileWriter2 = new FileWriter("/sys/class/leds/white/brightness");
        fileWriter2.write("0");
        fileWriter2.close();
    } else if (i3 == 0) {
        FileWriter fileWriter3 = new FileWriter("/sys/class/leds/white/brightness");
        fileWriter3.write("4");
        fileWriter3.close();
    } else {
        FileWriter fileWriter4 = new FileWriter("/sys/class/leds/white/breath");
        fileWriter4.write(SplitScreenReporter.ACTION_ENTER_SPLIT);
        fileWriter4.close();
    }
}
First argument is notification light Id. We should process only 3 and 4 - battery and notification lights. setLight_native should be used for other types (for example 0 is screen backlight level and so on).

Second argument is color. We only compare it with 0. 0 means disable led, other value means enable led.

Third argument is mode. 0 means permanent light (we write 4 in /sys/class/leds/white/brightness for that) and 1 means blink light (we write 1 in /sys/class/leds/white/breath for that).

Basically the logic can be more complex, for example /sys/class/leds/white/brightness accept values from 1 to 4, but there is no big difference on the practice and even with 4 it is not very bright (but it is quite bright in blink mode).

4th and 5th arguments and on_ms and off_ms. We can write them in `delay_on` and `delay_off`, but `breath` looks more beautiful :) So we just ignore them.

6th argument (BrightnessMode) looks like unused in our case.

4. Change calls from `setLight_native` to `setLight_native_patched` in:
services.jar/smali/com/android/server/lights/LightsService$LightImpl.smali
services.jar/smali/com/android/server/lights/MiuiLightsService$LightImpl.smali

#3 and #4 as patch-file are attached.

All changes are described for Xiaomi.eu firmware 20.4.30
 

Attachments

  • services_notif_lights.patch.txt
    4.6 KB · Views: 899
Last edited:
I hope that this change can be integrated in xiaomi.eu firmware.
@Igor Eisberg @ingbrzy is that possible?


In any case, I also implemented it as Magisk module for 5G version. It is based on xiaomi.eu firmware 20.4.30 and I'm not sure about using of it on other versions. If you want to try it on another firmware then be ready to manually delete it from TWRP-mode in case of bootloops.
 
In any case I tested the system with modified xml in `vendor` and notification light did not work. But I found a way to make it works.

After setting support_led_light = true in /vendor/etc/device_features/picasso.xml we have Notification Light settings and in logcat we can see that the system tries to work with notification light. In particular there are records from the method "realSetLightLocked". But there is no light.
Can you explain why hacking the setLight_native method is necessary? This guy seem to be able to get it to work with just support_led_light=true
To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.
 
just support_led_light=true
After setting support_led_light = true in /vendor/etc/device_features/picasso.xml we have Notification Light settings and in logcat we can see that the system tries to work with notification light. In particular there are records from the method "realSetLightLocked". But there is no light.

Maybe something is different on Poco X2.

I tried exactly on K30 5G. I tried many times. Also I tried not only through Magisk, but also through modification of `vendor` image.

Also I saw reports of users of K30 4G version which installed that Poco X2 patch and also they had only settings, but no real light.
 
Rumor has it that the first sold batches of K30/K30 5G had LED light as shown in the picture. However, later the vendor decided LED be removed and LED control was disabled in firmware, though there was a way to turn it on in early ROMs on the first batches of phones sold. That's why many users claimed their phone didn't have a LED light while others say they can turn it on on their phones in early ROMs.

Anyways, the Xiaomi.cn support has already announced in official forum that the K30 series don't have LED lights, after thousands of users asking about it and proposed to enable LED light in future ROMs.
 
first sold batches of K30/K30 5G had LED light
I bought the phone less than 40 days ago (on Ali, with EU Express delivery), so I think I'm not from first batches.
Basically I never heard about K30 4G/5G (and Poco X2) without LED. But of course not so much people make tests.
Now, it is in xiaomi.eu firmware and we will have more reviews.
 
I bought the phone less than 40 days ago (on Ali, with EU Express delivery), so I think I'm not from first batches.
Basically I never heard about K30 4G/5G (and Poco X2) without LED. But of course not so much people make tests.
Now, it is in xiaomi.eu firmware and we will have more reviews.
Well I donno what you mean by "make tests". I myself, like so many others in Xiaomi.cn forum, tested by dialling "*#*#7664#*#*" and entering the QMMI test. There are usually three options about LED tests, red blue and green, among others. I entered all three and didn't see any LED light, not when I was using China ROM or EU ROM now. Many users reported same results as mine. I am not sure QMMI is the proper tool to test.
 
what you mean by "make tests"
The most reliable test is executing of command `echo 1 > /sys/class/leds/white/breath` (in TWRP or in the system with root)

There are at least two test apps - CIT (com.miui.cit) and QMMI (com.qualcomm.qti.qmmi).
*#*#7664#*#* allows to run QMMI
*#*#6484#*#* allows to run CIT
Not always both codes work, it depends on firmware.
But as I see all firmwares have both apps, it is possible to run any of them using Activity Launcher or something.

From my tests I see that QMMI can enable LED, but CIT can not.


So, when you use QMMI you do NOT see light? I see it with QMMI for all of red/green/blue tests (of course it is white in all cases).
Which phone do you have? My is K30 5G.
Which model it is? Settings - My device - All specs. My model is "M2001G7AE".
Also maybe you could run CIT and check hardware version in "check version info". My is "MP".


In any case I think it is good to have this patch in the firmware. Those who have LED will be able to use it. Those who have not will not lose anything.
 
The most reliable test is executing of command `echo 1 > /sys/class/leds/white/breath` (in TWRP or in the system with root)

There are at least two test apps - CIT (com.miui.cit) and QMMI (com.qualcomm.qti.qmmi).
*#*#7664#*#* allows to run QMMI
*#*#6484#*#* allows to run CIT
Not always both codes work, it depends on firmware.
But as I see all firmwares have both apps, it is possible to run any of them using Activity Launcher or something.

From my tests I see that QMMI can enable LED, but CIT can not.


So, when you use QMMI you do NOT see light? I see it with QMMI for all of red/green/blue tests (of course it is white in all cases).
Which phone do you have? My is K30 5G.
Which model it is? Settings - My device - All specs. My model is "M2001G7AE".
Also maybe you could run CIT and check hardware version in "check version info". My is "MP".


In any case I think it is good to have this patch in the firmware. Those who have LED will be able to use it. Those who have not will not lose anything.

Tried all 3 methods you mentioned, didn't see any LED lights.

My phone is K30 5G, model and hardware version same as yours.

Yes, I agree it'll be great to have this patch in EU ROM. I am simply pointing out that maybe Xiaomi company did remove LED light in some K30 phones if not all anyway. And that's why it's not enabled by default in official China ROM and they'll never do it either in the future versions of firmware. Just post it here in case someone like me is looking into this.
 
The most reliable test is executing of command `echo 1 > /sys/class/leds/white/breath` (in TWRP or in the system with root)

There are at least two test apps - CIT (com.miui.cit) and QMMI (com.qualcomm.qti.qmmi).
*#*#7664#*#* allows to run QMMI
*#*#6484#*#* allows to run CIT
Not always both codes work, it depends on firmware.
But as I see all firmwares have both apps, it is possible to run any of them using Activity Launcher or something.

From my tests I see that QMMI can enable LED, but CIT can not.


So, when you use QMMI you do NOT see light? I see it with QMMI for all of red/green/blue tests (of course it is white in all cases).
Which phone do you have? My is K30 5G.
Which model it is? Settings - My device - All specs. My model is "M2001G7AE".
Also maybe you could run CIT and check hardware version in "check version info". My is "MP".


In any case I think it is good to have this patch in the firmware. Those who have LED will be able to use it. Those who have not will not lose anything.

That are very good news. I also got the same Model "M2001G7AE" and i did the Test. On QMMI the LED is working, but not on CIT. So at least a few of us got the LED, strange is that Xiaomi got different Versionen on this "new" Phone
 
Really thanks to all who make this happen, the LED Notifaction works like a charm on my K30 5G. Thanks thanks thanks
 
Thank you for implementing this! I do have the LED notification on a Redmi K30 4G purchased 06/16/2020, and it works when charging and when checking in QMMI. CIT does not show any notification LED test. However, I do not get any notification light for anything else besides charging, despite it being enabled in each app permission and in the additional settings in MIUI 12 @Igor Eisberg Is there anything I'm missing out on?
 
Thank you for implementing this! I do have the LED notification on a Redmi K30 4G purchased 06/16/2020, and it works when charging and when checking in QMMI. CIT does not show any notification LED test. However, I do not get any notification light for anything else besides charging, despite it being enabled in each app permission and in the additional settings in MIUI 12 @Igor Eisberg Is there anything I'm missing out on?

On my 5g, go to Setting, Addational Setting, LED Notifications. There you can activate or deactivate it
 
  • Like
Reactions: Poney70
On my 5g, go to Setting, Addational Setting, LED Notifications. There you can activate or deactivate it
I've done so already, LED notifications on, along with app permissions for it, but no light pulses.

The light itself works - it works while charging and on QMMI, but notifications do not trigger it.

This is on latest stable MIUI 12 - 12.0.3.0.QGHCNXM
 

Attachments

  • Screenshot_2020-07-07-19-37-05-145_com.android.settings.jpg
    Screenshot_2020-07-07-19-37-05-145_com.android.settings.jpg
    127 KB · Views: 662
  • Screenshot_2020-07-07-19-38-02-690_com.android.settings.jpg
    Screenshot_2020-07-07-19-38-02-690_com.android.settings.jpg
    232.6 KB · Views: 564
Greetings! Is it possible to make the notification LED to work without rooting the device? I'm currently using a K30 5G with the xiaomi.eu 12.0.5 stable ROM. Thanks in advance!
 
Greetings! Is it possible to make the notification LED to work without rooting the device? I'm currently using a K30 5G with the xiaomi.eu 12.0.5 stable ROM. Thanks in advance!
I'm interested on this as well.

I can't do the QMMI test, it doesn't open. I'm still don't know if my K30 5G has the LED.
 
Last edited:
I'm interested on this as well.

I can't do the QMMI test, it doesn't open. I'm still don't know if my K30 5G has the LED.
I really didn't want to root my device because I don't like to mess with the Magisk Hide settings to make both Pokémon Go and my banking app work under such circumstances. Nonetheless I made a full TWRP backup and rooted my device, after that I installed an app available into the Play Store that enables the notification LED for both the Redmi K30 4G/5G and the POCO X2 but as soon as I gave SU permissions and ran it then was when I realised my unit doesn't came with the LED installed... It's a shame because it's a deal breaker for me and I'm even considering selling the device :(

So, if you can root your phone to double check the presence and functionality of the notification LED then I highly suggest you to do so.

Best regards.
 
Last edited: