Open EmilEmilchen opened 4 months ago
Thanks Emil for your idea.
Somehow related to #61.
I think this does not only regard Xiaomi and Redmi phones, but all phones which do support flashlight dimming but do not implement the Android API I am using to change that.
I still don't have a rooted phone where I could develop this on and test it out.
An emulator wouldn't really help when playing with the flashlight.
Hi @EmilEmilchen again,
I finally have a rooted emulator up and running now and I can see the different LEDs at the mentioned path /sys/class/leds/
.
Your POC seems to work for my adapted path to one of the LEDs, even though I can not verify I the flashlight brightness would change because I still don't have a rooted physical device.
I plan on implementing some kind of fallback root access, but all development would be by imagining the outcome without being able to test it. Then I would need a user like you who can test it out on their rooted physical devices.
For now I have a question: What happens, if you write invalid values to the mentioned path? So writing a value from 1 to 16 in your case would obviously just change the flashlight brightness. But what happens if you write 0, -1, 99 and so on.
This information would be crucial to be able to properly implement this change.
Of course I'd love to help out with testing! From what I can recall I'm pretty confident that if any invalid value is written its just sort of ignored. As this file is part of sysfs it's sort of write-only and you e.g. can't read it's contents at all but writing invalid values definitely doesn't "break" anything. I'll double check the exact behavior in the next few days.
One more thing: I don't know whether the file path as well as the range of valid inputs is the same on every device where you need to use this method for brightness control but in assuming it is not perhaps some kind of advanced setting could at least be considered.
Of course I'd love to help out with testing! From what I can recall I'm pretty confident that if any invalid value is written its just sort of ignored. As this file is part of sysfs it's sort of write-only and you e.g. can't read it's contents at all but writing invalid values definitely doesn't "break" anything. I'll double check the exact behavior in the next few days.
That would be nice, you can check it with your "simpleFlashDimmer" and just set something like 50.
I don't think it's write-only as I can read these files with a file explorer.
One more thing: I don't know whether the file path as well as the range of valid inputs is the same on every device where you need to use this method for brightness control but in assuming it is not perhaps some kind of advanced setting could at least be considered.
As mentioned by rabaimor in #61 there are path differences. And of course different devices have different max levels, so we would need to be able to adjust that.
Sorry for my late response. I tried it out and I was partially right: The file isn't strictly speaking read only, it's just that reading it always reads 0
or 1
depending on if the torch is on or off, no matter the brightness:
rubypro:/sys/class/leds/torch-light0 # echo 10 > brightness //turned on
rubypro:/sys/class/leds/torch-light0 # cat brightness
1
rubypro:/sys/class/leds/torch-light0 # echo 15 > brightness // still on, brighter
rubypro:/sys/class/leds/torch-light0 # cat brightness
1
rubypro:/sys/class/leds/torch-light0 # echo 1 > brightness // dim but on
rubypro:/sys/class/leds/torch-light0 # cat brightness
1
rubypro:/sys/class/leds/torch-light0 # echo 0 > brightness // off
rubypro:/sys/class/leds/torch-light0 # cat brightness
0
rubypro:/sys/class/leds/torch-light0 # echo -1 > brightness // no change, note exit code at start of line, also no change if torch was on before
1|rubypro:/sys/class/leds/torch-light0 # cat brightness
0
rubypro:/sys/class/leds/torch-light0 # echo 100 > brightness // on but pretty dim, about equivalent to 4-5
rubypro:/sys/class/leds/torch-light0 # cat brightness
1
rubypro:/sys/class/leds/torch-light0 # echo 500 > brightness // on but pretty dim as well, about equivalent to 3-4, definitely dimmer then with 100
rubypro:/sys/class/leds/torch-light0 # cat brightness
1
I also checked with a photoresistor and the maximum brightness where there is a change compared to the next lower number is 15. I don't know why I wrote 16 in my initial post, I mean including 0 that would be 17 but anyway, its 0 - 15 for this device. Regarding invalid values see the comments in my code block. Hope that helped!
I really love this app but unfortunately it doesn't work with Xiaomi/Redmi devices, for example the Redmi Note 12 Pro Plus 5g. As far as I can tell it is impossible to get this feature working on this device without root permissions. Since I only have access to the Redmi device I mentioned I couldn't check on any other one but on the Note 12 Pro Plus the brightness is controlled by a 0-16 integer value in
/sys/class/leds/torch-light0/brightness
which is only accessible on a rooted device (as far as I can tell anyway). I haven't looked much into the inner workings of FlashDim but I'd love Xiaomi devices to be supported. I wrote a quick and dirty proof of concept (Github Repo) which just doesecho BRIGHTNESS_VALUE > /sys/class/leds/torch-light0/brightness
using theShell.cmd(command).exec()
method provided by the topjohnwu libsu API.