[MOD][XPOSED][N5] Ambient Light Sensor fix for Nexus 5 - Xposed Framework Modules

This module aims to fix Nexus 5 ambient light sensor issues leading to random auto-brightness spikes under certain lighting.
The issue
Sometimes the light sensor goes crazy and reports 30000 lux even in a dim light because of what auto-brightness attempts to blind you in a moment. These random spikes happen when you hold a phone at certain angles and depend on light bulbs used in a room.
The solution
The fix is implemented as an Xposed module.
Basically, it is a filter inserted near a point where native HAL communicates to Android framework. It intercepts all sensor readings and replaces abnormal 30000 lux (and 0 lux following 30000) with an averaged value from a sliding window. This affects any process that use Android sensors API including system_process, so that default Android auto-brightness works fine too (no need to use apps like Lux Dash to workaround the issue).
Installation
Download and install Xposed framework
Then install Nexus 5 Light Sensor fix module and activate it
Reboot
Usage
The module provides no user interface, nor it runs any services in a background. It only injects a proxy method to the implementation of Android sensors API. You won't be able to notice it in the main menu or in a task manager. Think of it as a patch that can be turned on and off through Xposed installer.
Source
The mod is open source (with permissive MIT licence), the source code is available on my GitHub.
Thanks
@rovo89 for his Xposed framework
@n3ocort3x and @wantabe for the initial attention and for kicking me up to finally create a new thread
and you (the community) for your feedback

More on the issue
Two major issues with the Nexus 5 ambient light sensor (original module announcement)
Palmadores said:
1. The sensor reading often jumps to 30000lx momentarily, (measured using Lux Dash in Debug mode), and so the phone blinds you for while. This happens in a repeatable fashion when you hold the phone at certain angles. Try it yourself.
2. The N5 reads zero lux even in moderate/dim light, while my old N4 still reads around 10 lux.
Click to expand...
Click to collapse
exorz said:
Using the Lux app debug mode I rotated the phone while in a room lit with incandescent bulbs and one lit with daylight. When rotating the phone I sometimes see a spike of 30000 lx but more importantly the sensor drops to 0 even though there is plenty of ambient light. During daylight I don't see the 30000 lx spikes but I still see the sensor dropping to 0 when there's plenty of ambient light.
Click to expand...
Click to collapse
Is the Auto-Brightness Functionality wonky on the Nexus5?
Aria807 said:
I think it may be bugged with Halogen lighting (correct me if I'm wrong). My home is ~ 18 years old, and we have some bulbs that have not been changed yet (yellow). Sometimes when I use my N5 under those lighting, the sensors go whack and don't register properly picking up 0lx, then spike up to 30000lx. Once I move to areas in the house with newer bulbs, the sensors work normal, picking up the right readings.
Click to expand...
Click to collapse

Well done! Auto-brightness accuracy is much improved indoors! Appreciate your work on this!

Do I need to disable the modules if I dirty flash a new Carbon nightly? Or is that not necessary

augoza said:
Do I need to disable the modules if I dirty flash a new Carbon nightly? Or is that not necessary
Click to expand...
Click to collapse
I'm not sure, cause I use stock ROM, but I guess there is no need to disable it. As I can see from Carbon sources, related parts of code was not modified at all. To be sure, please ask ROM developers or other Xposed guys.

1.1 update won't install on nexus 5 signature mismatch
Sent from my Nexus 5 using Tapatalk

ddloco said:
1.1 update won't install on nexus 5 signature mismatch
Click to expand...
Click to collapse
I know, this is my fault and this is actually stated in the module description. Please remove version 1.0 and install 1.1 from scratch.

Still coming up very bright compared to Lux. Battery drain WILL be an issue.

mcnob said:
Still coming up very bright compared to Lux. Battery drain WILL be an issue.
Click to expand...
Click to collapse
The mod only removes random spikes reported by sensors. It does not affect an algo used by stock auto-brightness (any auto-broghtness is basically a function that maps a given input value from the sensors to the screen brightness; the mod just removes some trash from the input).
AFAIK the stock auto-brightness is configured through framework-res (google: config_autoBrightnessLcdBacklightValues, e.g. http://forum.xda-developers.com/showthread.php?t=2616914). Probably there is some app/mod for tweaking these options.

Wonder if custom ROMs like Omni and CM already have the fix baked in?

Anyone tries this on something other than an N5?
Motorola perhaps?
Sent from my DROID RAZR M using Tapatalk

FirePsych said:
Anyone tries this on something other than an N5?
Motorola perhaps?
Click to expand...
Click to collapse
I'm pretty sure this wouldn't make any sense, at least with current implementation, which compares each input value against hardcoded 30000 lux.

bland.life said:
Wonder if custom ROMs like Omni and CM already have the fix baked in?
Click to expand...
Click to collapse
The problem is that a code to be patched is located in a device-independent part of Android, but only Nexus 5 build should be modified. However, I didn't research well whether there is a way to build some piece of base framework only for a particular device. Probably Omni/CM guys know better.

mcnob said:
Still coming up very bright compared to Lux. Battery drain WILL be an issue.
Click to expand...
Click to collapse
Must be a variance between different devices because on my N5 auto-brightness indoors at night looks just a little on the dim side. In brighter light it looks good to me but I can't tell you what percentages it's using. I would probably like it 2 or 3 percentage points higher indoors but I'm fine with the way it is now. At least on my device I haven't seen any noticeable effect on battery life with auto-brightness on most of the time. Still getting 5-9 hrs of screen on time with my use. I made a comment in a previous post about auto-brightness being more accurate, I was referring to the way it would constantly adjust the brightness level and the changes would be big ones. Personally I think auto-brightness is much better with the module installed and in my case useable now. No, it's not as accurate as the auto-brightness is on my One X, which is amazingly accurate, for that kind of accuracy I would use something like Lux, maybe in conjunction with the module. I would give it a shot myself but I've purchased enough apps to modify the display brightness as it is. Running stock 4.4.2.
Edit:
Forgot to mention I'm using the dimmer backlight setting in the config file for the ElementalX kernel. I don't think that makes much of a difference in accuracy, if any, just how dark the display can potentially go. I also completely forgot that the dimmer backlight and auto-brightness levels are options available in the GravityBox module. As effing long as I've used GB I've never used those two options!

abusalimov said:
I'm pretty sure this wouldn't make any sense, at least with current implementation, which compares each input value against hardcoded 30000 lux.
Click to expand...
Click to collapse
Yup. Didn't work on my Razr M.
Sent from my DROID RAZR M using Tapatalk

I don't know what the issue is lol, but I have Franco kernel so I assume I'm immune to this right?
Sent from my Nexus 5 using Tapatalk

Deeco7 said:
I don't know what the issue is lol, but I have Franco kernel so I assume I'm immune to this right?
Click to expand...
Click to collapse
It doesn't matter, which kernel do you run, ALS is a user space driver. BTW I use franco kernel too.

10000 lux
My N5 reports 10000 lux instead of 30000, very annoying
Running CM11.0 m5

zbloh said:
My N5 reports 10000 lux instead of 30000, very annoying
Running CM11.0 m5
Click to expand...
Click to collapse
Thanks for reporting. Is it reproduced on CM11.0 M5 only, did you try other ROMs? Does it show exactly 10000.0 lux? If so, I could catch this value as well.

New version 1.2 is available now:
- Always replace 0 lux with 1 lux to prevent auto-brightness changing hither and thither in a very low light environment
- Do not feed replaced values back to EMA filter (makes it more responsive to newly coming proper readings)
- Filter out 10000 lux as well (reported by zbloh)

Related

[Q] Temperature sensor using Z-Device Test.

I just Download Z-Device test and everything is ticked apart from NFC (obviously) and Temperature sensor?
I was wondering why my Temperature Sensor had an X instead of a tick. Does this mean it's not working?
Can somebody else who uses this app confirm if they get the same results.
Thanks.
Maybe the software is not reading the hardware correctly.
Tinderbox (UK) said:
Maybe the software is not reading the hardware correctly.
Click to expand...
Click to collapse
That's why I wanted to know other peoples results to see if it was the app or my phone?
I just installed Z-Device myself and the temperature sensor test is crossed out for my to, I must just be a fault in the software, maybe you should report it, As i have seen the temperature sensor working fine in all the cpu apps i have downloaded.
Tinderbox (UK) said:
I just installed Z-Device myself and the temperature sensor test is crossed out for my to, I must just be a fault in the software, maybe you should report it, As i have seen the temperature sensor working fine in all the cpu apps i have downloaded.
Click to expand...
Click to collapse
Thankyou for checking, much appreciated.
What other apps are there that are similar?
Z-Device could be looking for an external temperature sensor that measures the temperature of the environment.
I use an app called elexir to chek all my sensors and 2 sensors are shown as not installed which is pressure and temperature sensors. so i assume those sensors are for ambient temp & pressure.
Sent from my GT-I9100 using Tapatalk
simacca said:
I just Download Z-Device test and everything is ticked apart from NFC (obviously) and Temperature sensor?
I was wondering why my Temperature Sensor had an X instead of a tick. Does this mean it's not working?
Can somebody else who uses this app confirm if they get the same results.
Thanks.
Click to expand...
Click to collapse
Hi simacca,
I'm part of the developers team of Z-DeviceTest .
Answering your question:
All models ussually comes with a temperature sensor for battery, due that a very high temperature (>80º Celsius) could provoque a battery degradation, even explosion in rare cases.
The sensor is used to minimice sensor & CPU usage in order to get the battery colder or even, automatic turn off the phone in overheat events.
Z-DeviceTest controlls this sensor that you could find in battery screen test as "Temperature:".
The temperature sensor showed on main screen, is an extra sensor always included on digital compass sensor, due that the physical principle used to measure magnetic fields (Hall effect) is higly temperature dependant.
Depending on the ROM you have instaled, the access to this temperature sensor is granted or not, and if the O.S., could access and read the sensor, we detect it and show the measure, or not.
I hope to have helped you with this issue.
Best Regards.
zausan said:
Hi simacca,
I'm part of the developers team of Z-DeviceTest .
Answering your question:
All models ussually comes with a temperature sensor for battery, due that a very high temperature (>80º Celsius) could provoque a battery degradation, even explosion in rare cases.
The sensor is used to minimice sensor & CPU usage in order to get the battery colder or even, automatic turn off the phone in overheat events.
Z-DeviceTest controlls this sensor that you could find in battery screen test as "Temperature:".
The temperature sensor showed on main screen, is an extra sensor always included on digital compass sensor, due that the physical principle used to measure magnetic fields (Hall effect) is higly temperature dependant.
Depending on the ROM you have instaled, the access to this temperature sensor is granted or not, and if the O.S., could access and read the sensor, we detect it and show the measure, or not.
I hope to have helped you with this issue.
Best Regards.
Click to expand...
Click to collapse
Thanks for the reply.
I am using the stock unbranded KE7 XEU rom.
Maybe when I get the new update that's due out any time it will fix the problem.
You are wellcome.
¿Could you please confirm back if you can read battery temperature trough the battery screen test of Z-DeviceTest?
Thanks in advanced.
Best regards.
zausan said:
You are wellcome.
¿Could you please confirm back if you can read battery temperature trough the battery screen test of Z-DeviceTest?
Thanks in advanced.
Best regards.
Click to expand...
Click to collapse
Yes I can see the battery temperature
Thank you again !
Is there an apk of z-test, I have no wifi or data access (so can't get it from the market) but need to check my wifi status as trying to turn it on just returns "error".
Thanks
Matt
zausan said:
You are wellcome.
¿Could you please confirm back if you can read battery temperature trough the battery screen test of Z-DeviceTest?
Thanks in advanced.
Best regards.
Click to expand...
Click to collapse
Works for me too , using Cognition 1.07 Rom.
msiviter said:
Is there an apk of z-test, I have no wifi or data access (so can't get it from the market) but need to check my wifi status as trying to turn it on just returns "error".
Thanks
Matt
Click to expand...
Click to collapse
im not allowed to post links so...
www[dot]4shared[dot]com/file/7y7UXjvt/Z-Device_Test_v167.html
I'm using Andro Sensor app (market) for temp reading, works very well.

Best brightness app?

If you have an Amaze then you know that the secret to long battery life is minimizing screen brightness. Problem is the default auto-brightness levels are brighter than needed and there is no way to adjust.
I recently installed Lux which allows you to customize the auto brightness curve. This should theoretically extend battery life. I'll report what I find here on this thread.
Meanwhile one thing I noticed.... In Lux you can monitor the level reported by the phones built in light sensor. On my Amaze I get really strange readings. There are four levels: 90, 320, 640, 11000. Really? With careful shading of the sensor I was able to get a reading of 2400 once. 11000 was reported even in shade on a cloudy day.
But it seems like the sensor doesn't read light levels well at all. There isn't enough granularity and the calibration is way off.
Anyway if we can fix it or address it, that should make a real difference in the battery life of the device.
Sent from my HTC Ruby using Tapatalk 2
I use elixir 2 and the personal add on.. I set my icon/widget to whatever percentages I want.. Then tap it till its right for my environment
e-Sex.. All of the carpral none of the tunnel
Use screen filter from play.. works great..
Sent from my Amaze using xda app-developers app
This one is pretty awesome.. "Display Brightness".. https://play.google.com/store/apps/details?id=rubberbigpepper.DisplayBrightness&hl=en
You can put a 'slider' anywhere you want and simply slide it up and down to change the brightness to the exact levels you want.
Works great an you can customize it quite a bit. :good:
It's shown in on the top in the screenshots at the link, but I always put it on the right hand side, a little higher than mid-way, and I make it translucent grey so you cant even really see it unless you're looking for it.
That's the free version, I have the Pro version and it's worth it. lol

[q] custom light level suggestions?

now that aosp is pretty stable and soon to be for jb I was wondering if anyone polished up on what works nicely for the custom light levels for auto brightness settings. I found what I used on the original inc but doesn't seem right to me based on the compatible levels of the rez. any ideas?
I assume you are referring to recommended settings in the built in auto brightness correct? I just start at 30 and raise each level by 20. By the time it gets to the highest setting, it's brought enough for direct sunlight
Sent from my ADR6425LVW using Tapatalk 2
Evocm7 said:
I assume you are referring to recommended settings in the built in auto brightness correct? I just start at 30 and raise each level by 20. By the time it gets to the highest setting, it's brought enough for direct sunlight
Sent from my ADR6425LVW using Tapatalk 2
Click to expand...
Click to collapse
you using the default amount of levels which is 10? I think there's 1-3 more it can recognize but I haven't loaded a sensor app to detect them all

TIP. how to get 12h SOT

After 1 week of use and compare of some settings -->
1. Don't use dark mode in OS or app settings.
Reason: it will not save any power on LCD display but you will have to increase the Backpanel light to be able to read everything.
2. Disable 120Hz setting for now.
Reason: I am not sure if it is a bug but my display stays at 120Hz...all the time (except running YouTube with 60Hz). Even if I don't touch the screen at all.
You can check the actual fps in Developer options - power monitor.
Results: 2h game playing, whatsapp, spotify and browser usage...I have 6h SOT and still more then 50% battery left.
I wasn't able to get 6h SOT on my OnePlus 6 at all
Info: I didn't use plane mode over night. Wifi was active all the time.
Bloatware is removed and using AD blocker.
I have that sot with 120hz, I don't think it makes much of a difference . I use 60 only when traveling
Same settings ofc. Wifi all the time. But I use videoconference software
One more: use samsung browser which is known to use less battery
Also use nightmode slider to set brightness correctly (maximum here) otherwise you might end using more brightness on low light because nightmode brightness is too low
+1 on the other things
You can get rid of most of miui bloatware apps.
It will probably help with battery
whats the point of buying a 120hz display if you have to disable it?
bazzanaja said:
whats the point of buying a 120hz display if you have to disable it?
Click to expand...
Click to collapse
Prisoner without USB cable?
Kidding. Everything is fine meanwhile. All kind of features are enabled. Also 120hz. The battery is banana. Positively surprised from this midrange mobile after using flagships for years.
bazzanaja said:
whats the point of buying a 120hz display if you have to disable it?
Click to expand...
Click to collapse
The phone is BBB regardless of the display, at least here when it was at launch
BBB= best for the price xP
bacitoto said:
You can get rid of most of miui bloatware apps.
It will probably help with battery
Click to expand...
Click to collapse
can u tell me how to do it plz, tkz

Question Automatic brightness

Anyone else having problems with automatic brightness changes?
Every evening when it gets dark the brightness level goes to the lowest level, which is much to dark to read anything. Every evening I have to adjust the ''automatic'' level to halfway the level-slider, multiple times.
Do you have night mode enabled ?
I have this feature enabled from 9pm to 7am and indeed the auto brightness goes lower than normal value during this time slot .
Pouic said:
Do you have night mode enabled ?
I have this feature enabled from 9pm to 7am and indeed the auto brightness goes lower than normal value during this time slot .
Click to expand...
Click to collapse
No eye comfort modus
No Adaptive sleep modus
Only 'dark modus' enabled day and night
The same is happening to me. The brightness of the screen in darker lights is too low. Every time I move the slider to upper brightness but next time I open the screen is lower again.
marselcj said:
The same is happening to me. The brightness of the screen in darker lights is too low. Every time I move the slider to upper brightness but next time I open the screen is lower again.
Click to expand...
Click to collapse
I tried to wipe the system settings but the problem persists. I hope they can fix this in an update
BartKey said:
I tried to wipe the system settings but the problem persists. I hope they can fix this in an update
Click to expand...
Click to collapse
I might state the obvious, but the sensor is a bit high up on the device and it might be covered by your phone case, u sure it's not just a goof with an off brand cover?
The sensor is not covered. I use an original OnePlus cover.
Strange thing ... Everybody or at least majority of Oneplus Nord 2 owners had complained about automatic brightness . It's true in my case as well but now problem is solved with a 3-d party apk . Velis Auto Brightness from G.Play . Calibrating autobrightness is very accurate but the app remain active in background all the time and I didn't know how this affect battery drain . I read all OnePlus latest phones have this annoying bug and it's pitty none of latest updates solved it , worst here on XDA or OnePlus forum no one offer any solutions to calibrate automatic brightness .
Some smart guys said there is not "automatic brightness" but "adaptive brightness" so we had to learn phone AI how to adjust brightness a few days and then restart the phone . This are childish thoughts of those which are nothing to do else .
So , what do you think about this ? There are solutions to calibrate or fix this issue ?
I noticed that when the phone is on below 15% or lower and the battery saver is on ( for me it's 10%) the phone brightness goes to automatic mode and it becomes even less bright. I think it has to be a certain feature which is connected to battery saving IMO.
I'm using Velis for 3 months as well. This solves the problem. But OnePlus definitely should solve this.
Even latest update v11.3 EU, doesn't solve it. I even did a factory reset. 3 hours work to reset everything back as is was, for nothing...
Look at a possible solution (for me didn't work) :
"
stevendumond​Cupcake​​
stevendumond , Sep 25, 2021 :​
stevendumond said: ↑
FYI: I did this a few minutes ago. I think that may be it. Before I did this, the screen brightness did not work at all. I could slide that slider up and down and nothing ever changed on screen brightness, auto or manual. Now it works! On auto and manual!
Hopefully this is the "fix"! But disabling a feature is NOT a fix, it's a workaround. Luckily I don't need that feature
Click to expand...
Click to collapse
So far the screen brightness has not faded into darkness. Phone is working fine now. This is a workaround that works.
Settings> Battery> Battery Optimization> Advanced Optimization (3 dots in upper right)> Sleep Standby Optimization: OFF
Click to expand...
Click to collapse
Since A.14 OTA , Adaptive Brightness is better but not entirely satisfying . It seems they solve bugs by little steps ... which is quite annoying !
muppetz said:
Since A.14 OTA , Adaptive Brightness is better but not entirely satisfying . It seems they solve bugs by little steps ... which quite annoying !
Click to expand...
Click to collapse
Not better here with a.14. Same problem as before... Indeed very annoying
BartKey said:
Not better here with a.14. Same problem as before... Indeed very annoying
Click to expand...
Click to collapse
Minimum level (especially in low light) is a little bit higher , sensitivity is more accurate and transition between levels is also a little bit faster . I'm pretty sure there are some improvements , that's a fact not a feeling .
muppetz said:
Minimum level (especially in low light) is a little bit higher , sensitivity is more accurate and transition between levels is also a little bit faster . I'm pretty sure there are some improvements , that's a fact not a feeling .
Click to expand...
Click to collapse
Let's hope it improves a lot more. My previous devices, Moto g, Moto G5 plus, never had such problem, even on any custom ROM...
BartKey said:
Let's hope it improves a lot more. My previous devices, Moto g, Moto G5 plus, never had such problem, even on any custom ROM...
Click to expand...
Click to collapse
Oh , yes I still have Motorola One Vision and automatic brightness is flawless ...

Categories

Resources