yashsingh1/xdaforums huggingface dataset:
[Nexus 5 Q&A, Help & Troubleshooting] Aria807:
I'm having the same issue too, but it appears to be under certain lightbulbs that I have this issue. For example in 2 different situations, one I was in a restaurant and another while I was in my bathroom, and my phone would constantly pick up either 0 lux or 30000 lux (depending on the angle of the phone under the light). This is under halogen lighting.

When I get out of the restaurant and under regular lighting and when I'm in my bedroom (LED/CCFL lights), the light sensor would behave normally.

Anyone else have these issues?
[Nexus 5 Q&A, Help & Troubleshooting] rabaker07:
Yes, and it's not really reproduceable for me but it's very annoying and sometimes painful. This screen can get very bright and it's blinded me in the dark when this happens.

Is it the light sensor? Is it LUX? Does this happen without lux installed?
[Nexus 5 Q&A, Help & Troubleshooting] coolguy949:
Can the sensor be calibrated or is it just bad hardware? This is a real annoyance. My S4 doesn't read 0 lux unless there is absolutely zero and it never jumps around. Even it's own screen reflecting on my face will cause it to read 1-10. That level of sensitivity is great for setting up lux to go subzero. Maybe the kernel is translating the sensor voltage output incorrectly?
[Nexus 5 Q&A, Help & Troubleshooting] Aerowinder:
Lux is a measurement of brightness.
[Nexus 5 Q&A, Help & Troubleshooting] Aria807:
I thought it was Lux causing it, but I have tried full wipe + reflashing a new rom, and my sensors still go a lil whack. This is flashing new rom + immediately downloading a sensor tool and checking the readings before installing Lux or any other apps.

However, Lux came out with a new version a week or so ago and it seems to have been waiving those spiked readings, so my phone atm isn't acting up super dim to super bright and back.
[Nexus 5 Q&A, Help & Troubleshooting] Kusie:
I still have this issue on 4.2.2.,very annoying. Is this a software issue or bad sensors?

Starts to piss me off so badly I think about sending my N5 back to google.

Happens both on stock auto brightness and yaab.

Help please?

Kusie
[Nexus 5 Q&A, Help & Troubleshooting] wolsty7:
Yeah same here, very annoying, have to use Manuel britness very often
[Nexus 5 Q&A, Help & Troubleshooting] exorz:
I have this same problem too. 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.

I feel like the sensor is too far recessed into the phone and causing a tunnel effect. If the phone is looking at a dark shirt or surface that's a foot away from it, it will register 0 even though there's plenty of ambient light. This seems like a design flaw or a flaw in android's API.

Using the full version of Lux app might be able to fix it since it allows you to use the camera for ambient light detection but I haven't purchased the full app yet so I don't know.

Really wish android would have a solution for this because it's quite irritating.
[Nexus 5 Q&A, Help & Troubleshooting] clocinnorcal:
Are you guys using the Lux app? I haven't had this problem with stock auto brightness.
[Nexus 5 Q&A, Help & Troubleshooting] exorz:
With the stock auto brightness it was too bright in most cases and also in some cases the brightness would spike. Downloaded the free version of lux app in order to try to fix the problem and while it can adjust the brightness to be lower, the problem is that the light sensor gives low readings straight from the api.
[Nexus 5 Q&A, Help & Troubleshooting] Xharos:
I just installed Lux and I can't reproduce it on my Nexus. Mine always behaves correctly in automatic brightness, so I guess it's a hardware problem that only affects some devices?
[Nexus 5 Q&A, Help & Troubleshooting] n3ocort3x:
I jump now in here as i have the same problem unfortunatley. I have no clue if its hardware related or software, but on my HTC One with kitkat running the same rom i dont have such issues s i guess its a HW fault. If anyone finds a solution or something that fixes this mess, would highly appreciate if wwe could keep this thread alive :)
[Nexus 5 Q&A, Help & Troubleshooting] coolguy949:
I hope it's just a kernel issue where it's not translating the sensor output to the OS granularly enough. On my S4, it has to be truly zero light for it to see 0lx. Even in low low light, it's registering a value between 1 and 100. It makes it very easy to distinguish between no light (laying in bed) and low light (driving in the car, movie theater, etc). I hope they fix it because it's rather annoying that we're having this issue.
[Nexus 5 Q&A, Help & Troubleshooting] n3ocort3x:
The next interesting thing is that it happens only in 1 out of 6 rooms at home. I hope I'm not totally crazy but could it be a bad combination between a sort of light bulb and the sensor?? I know this sounds totally stupid but I only can reproduce it with one light bulb. Or it is because that one light bulb is really low dimmed. I have to test that further tomorrow. Only have one dimmable light bulb atm to test so I will dim the others tomorrow that working atm.

noNeedforAsig
[Nexus 5 Q&A, Help & Troubleshooting] coolguy949:
I remember reading something weeks ago that the sensor doesn't work well with certain bulbs. I can't seem to locate the thread though.
[Nexus 5 Q&A, Help & Troubleshooting] n3ocort3x:
Tbh... I investigated this now with a few different light bulbs... Light daylight (really low) and the only light where I'm able to reproduce it is the dimmed one in my living room. Maybe it is the light temperature? This would be the most ridiculous bug I've ever seen. I will continue testing and keep u guys posted. Seems to work everywhere fine except in my living room so far.

Edit

No one will belive me that... I have to record a video about that. It's really only the light in my living room. Even with daylight + dimmed living room light I can reproduce it. The only thing I can imagine is that the color temp is responsible for that. And that the light sensor has a bug in combination with a lux error and a certain color temp.

noNeedforAsig
[Nexus 5 Q&A, Help & Troubleshooting] n3ocort3x:
So using Lux app and ditch out 0 value solves this issue (without setting the camera as calcultion source) just to inform u guys. Should make it easier to bring a fix for custom roms hopefully. Just played around with that app a bit
[Nexus 5 Q&A, Help & Troubleshooting] linqdesires:
Quite impressive noone is talking about this bad basic issue.

My light sensor give me a value of "zero" even in soft light condition. Well, light condition it's not really low, I can even read on paper and still read zero.

Now I'd want to understand whether the issue is hardware side, ROM or maybe kernel specific. Any hint?
[Nexus 5 Q&A, Help & Troubleshooting] AndrasLOHF:
I gave up on auto brightness a month after having the phone because of this issue. First phone I've ever had to turn it off.
[Nexus 5 Q&A, Help & Troubleshooting] linqdesires:
If this is an hardware issue I'm ready to send my N5 back. Hope we don't have another "working as intended".
[Nexus 5 Q&A, Help & Troubleshooting] aooga:
Yeah it's horrible. I turned it off after 2 minutes. Not a huge deal though, I just keep it on 25% brightness and thats fine for most situations.
[Nexus 5 Q&A, Help & Troubleshooting] wim69:
Same issue here. Before and after flashing Franco kernel. I use stock ROM and Lightmanager app.

It never happened in daylight, only inside my house.

Hopefully it is not hardware related.
[Nexus 5 Q&A, Help & Troubleshooting] n3ocort3x:
I solved this by lux lite app as mentioned above. It only happens on warm halogen light (at least for me) I have played around with kernel source but I can't ditch the values out. If it's a hw fault or not I have no clue but as it works with 3rd party apps I assume it's somewhere a fault in Rom sources.
[Nexus 5 Q&A, Help & Troubleshooting] linqdesires:
please use this thread to report any kernel/ROM which natively fix (one of) the issues, so we can stop using a background running application

thank you

---------- Post added at 11:21 AM ---------- Previous post was at 11:05 AM ----------

the light sensor should be an Avago APDS-9930

http://www.avagotech.com/pages/en/o...mbient_light_and_proximity_sensors/apds-9930/
[Nexus 5 Q&A, Help & Troubleshooting] ethoss:
I'm wondering if anyone of you have any screen protector that covers the light sensor like my case. (I have a spigen crystal).

Who does not have a screen protector has the same problem?
[Nexus 5 Q&A, Help & Troubleshooting] linqdesires:
I'm interested too. I'm in a hybrid situation so I hope someone else without screen protector at all, can report.

I use screen protector, but sensor is not covered by the screen protector which has a specific hole.

for reference, the hole on the right:

http://ecx.images-amazon.com/images/I/71fJ1UlmkaL._SL1500_.jpg
[Nexus 5 Q&A, Help & Troubleshooting] n3ocort3x:
i tried with nd without and its the same
[Nexus 5 Q&A, Help & Troubleshooting] Memnoch30:
I do not have a screen protector at all and I have the issue.
[Nexus 5 Q&A, Help & Troubleshooting] mattcoz:
I've resorted to using the camera sensor in Lux because of this, I really hope someone finds a fix for it.
[Nexus 5 Q&A, Help & Troubleshooting] coolguy949:
How does it affect battery life?
[Nexus 5 Q&A, Help & Troubleshooting] mattcoz:
I haven't done any detailed testing. I'm sure there is some effect, but because it only uses the camera on wake it's probably pretty minimal.
[Nexus 5 Q&A, Help & Troubleshooting] linqdesires:
This should be the sensor driver, even though I'm not 100% sure:

/kernel/lge/hammerhead/drivers/misc/apds993x.c

https://android.googlesource.com/ke...hammerhead-3.4-kk-fr2/drivers/misc/apds993x.c

https://github.com/android/kernel_m...erhead-3.4-kitkat-mr1/drivers/misc/apds993x.c

if (ch0data >= apds993x_als_res_tb[data->als_atime_index] ||
ch1data >= apds993x_als_res_tb[data->als_atime_index]) {
luxValue = 30*1000;
return luxValue;
}

30*1000 ==> 30k !

this issue is really bad.

The whole calculation method is this:

static int LuxCalculation(struct i2c_client *client, int ch0data, int ch1data)
{
struct apds993x_data *data = i2c_get_clientdata(client);
int luxValue=0;
int IAC1=0;
int IAC2=0;
int IAC=0;

if (ch0data >= apds993x_als_res_tb[data->als_atime_index] ||
ch1data >= apds993x_als_res_tb[data->als_atime_index]) {
luxValue = 30*1000;
return luxValue;
}

/* re-adjust COE_B to avoid 2 decimal point */
IAC1 = (ch0data - (apds993x_coe_b * ch1data) / 100);
/* re-adjust COE_C and COE_D to void 2 decimal point */
IAC2 = ((apds993x_coe_c * ch0data) / 100 -
(apds993x_coe_d * ch1data) / 100);

if (IAC1 > IAC2)
IAC = IAC1;
else if (IAC1 <= IAC2)
IAC = IAC2;
else
IAC = 0;

if (IAC1 < 0 && IAC2 < 0) {
IAC = 0;	/* cdata and irdata saturated */
return -1;	/* don't report first, change gain may help */
}

if (data->als_reduce) {
luxValue = ((IAC * apds993x_ga * APDS993X_DF) / 100) * 65 / 10 /
((apds993x_als_integration_tb[data->als_atime_index] /
100) * apds993x_als_again_tb[data->als_again_index]);
} else {
luxValue = ((IAC * apds993x_ga * APDS993X_DF) /100) /
((apds993x_als_integration_tb[data->als_atime_index] /
100) * apds993x_als_again_tb[data->als_again_index]);
}

return luxValue;
}

I hope some of the custom kernel dev should fix this bad behavior if not fixed by google.
[Nexus 5 Q&A, Help & Troubleshooting] linqdesires:
I wrote an email on friday last week pointing out the two issues as described on first post of this thread and I addressed the email to all those devs reported in the file history here https://android.googlesource.com/ke...hammerhead-3.4-kk-fr2/drivers/misc/apds993x.c

There are google and LGe devs involved, at least watching the commit history. No answer atm.

I believe they are the right owners of this issue and hope they can fix the only sensor bug we have on N5 (afaik).
[Nexus 5 Q&A, Help & Troubleshooting] linqdesires:
they're currently working to solve these issues... :good:
[Nexus 5 Q&A, Help & Troubleshooting] coolguy949:
Did they post something about it?
[Nexus 5 Q&A, Help & Troubleshooting] linqdesires:
one of the devs answered me in private.

should be good going public, maybe here: https://productforums.google.com/forum/#!categories/nexus ?

if google doesn't come to XDA, we go to google. :eek:
[Nexus 5 Q&A, Help & Troubleshooting] coolguy949:
Thanks. I'm on the Google forums a lot. It's actually quite discouraging to see how many issues are still open since I got my launch day N5.
[Nexus 5 Q&A, Help & Troubleshooting] linqdesires:
no news... sadly

anyway a rough test: while my old DesireS ambient light sensor reports 5 lux, my N5 is still at 0 lux (zero!)

again DesireS at 72 lux, at the same time N5 reports 5 lux!

It's a huge difference.

Should be nice a comparison with other phone model. You have the most interesting lighting scenario when N5 starts to report 1lux compared with value shown by the other phone model, N5 needs a lot of light to report a >0 value.

I call "lux" the value reported by the ambient light sensor, they're not lux really, at this point. :rolleyes:
[Nexus 5 Q&A, Help & Troubleshooting] drizek:
Just got my nexus 5 and this is really annoying. I haven't noticed the 30k lux problem yet but I constantly get readings of 0 lux in my lit apartment. I've fixed it by increasing the display brightness but it's going to blind me when I actually do turn the lights off and try to use it at night.
[Nexus 5 Q&A, Help & Troubleshooting] webwude:
Same issue as well... even in the darkest night jump to 30000 Lux and brightest level...

For now I will deactivate auto adjustments - first time on Android ever...
[Nexus 5 Q&A, Help & Troubleshooting] wim69:
Recently I installed Gravitybox and adjusted the brightness levels. Before that I experienced the jumps in brightness as well. Since the adjustments no more strange behavior.

Even my battery lasts longer due to lower brightness!
[Nexus 5 Q&A, Help & Troubleshooting] markdapimp:
Had an issue today the ambient light sensor froze up and reported that the light coming in was full sun light even when i was indoors in the dark as the result my Nexus 5 got super hot and it actually overheated and could not start till it cooled down..

I paid 450$ for this 16GB nexus 5 as the result of google play out of stock

The least i expected is a working ambient light sensor

Issues so far

-Mic Issues

-Ambient Light sensor issue

-GPS Issue

-Radio issue
[Nexus 5 Q&A, Help & Troubleshooting] linqdesires:
I can edit the brightness curve on my ROM but... the issue here is that a total darkness is 0lux on the N5 sensor... and a 50-70lux (real) is still 0lux on N5 light sensor! So you can change the brightness at 0lux, but this can't fix the brightness behavior because the light sensor doesn't change its value while the light vary from 0 to 50-70lux.

:eek:

anyone can compare the N5 lux reading values with other smartphone models?

for example:

DesireS 5lux <==> N5 0lux

or

DesireS 72lux <==> N5 5lux

It seems google is taking a lot of time to fix this issue.
[Nexus 5 Q&A, Help & Troubleshooting] bblzd:
For anyone who has Lux lite/pro can you confirm Enable Low Pass Filter solves the low light readings? Using that settings my phone is able to distinguish between 1-5 lux in low light situations where as otherwise it would just say 0 lux in any low light.
[Nexus 5 Q&A, Help & Troubleshooting] maardiweb:
Nice to see other are having the same issues (well.. it's nice that it is common ;) )

Noticed the problem twice now. Both times in dimmed light conditions, so that confirms what other have noted so far. It seemed to me that the 30k lux measurment was depending on the angle of the device. Not sure if that is just depending on how much light is noticed by the sensor, or that it is somehow correlated with the gyroscope?

Anyway, I'll keep track of this topic.
[Nexus 5 Q&A, Help & Troubleshooting] Kusie:
Seriously I don´t think that this bug will EVER be fixed by google or LG ... So I´m afraid if you have a nexus 5 you will have to live with it or switch off auto brightness (like I did...) ... sad but true.

Kusie
[Nexus 5 Q&A, Help & Troubleshooting] linqdesires:
I can say they are working on it... :angel: patiently wait
[Nexus 5 Q&A, Help & Troubleshooting] combatdeity:
Not saying you're wrong, but any evidence to back that up?
[Nexus 5 Q&A, Help & Troubleshooting] xb1z:
Any news?? Problem solved??
[Nexus 5 Q&A, Help & Troubleshooting] abusalimov:
Unfortunately it seems that this kernel driver was superseded by proprietary libraries in user space (probably sensors.qcom and friends from vendor_qcom_hammerhead) few month before release. I tried just to enable the driver in configs and device-tree, but then kernel simply refuses to start (reboots after few seconds after showing "google" splash). However I didn't try to revert rest of the kernel to the moment when the driver used to be enabled. Most likely one would have to revert HAL too in this case, so I'm rather pessimistic about this idea.

I also tried to attach to a running sensors.qcom (it is registered as a service in init.hammerhead.rc) using gdb (gdserver on the device + adb tcp forwarding), but with no success. For some reasons it always suspends on the same instruction and refuses to step over/out. In fact, I'm not sure that is the right binary at all, because all sensors remain working even when the process is suspended. The problem is that no source nor debug symbols are available for the binary. However, arm-eabi-strings reveals some plausible messages inside the binary (I2C communication, ALS lux conversion, proximity change events, etc.). Maybe I have some misunderstanding on how android services work.

Hope this will help to more lucky and experienced hackers. =)

P.S. I'm not allowed to post links, here is some related info.

Commits switching to qcom driver:

device/lge/hammerhead/+/4e858dde1463a7cbdb4e2489cfa9f7002cb73dc2 on android.googlesource dot com

android/kernel_msm/commit/50ee8cb3b8a29cf20514f8606439fa4e2893383d on github

Vendor binaries:

jamesonwilliams/vendor_qcom_hammerhead on github
[Nexus 5 Q&A, Help & Troubleshooting] abusalimov:
Further experiments revealed that this weird behavior can be a gdbserver issue. Actually, from time to time attaching gdb to sensors.qcom really suspends some sensors: sometimes it is on/off button, sometimes ALS/proximity sensor (I checked it using Lux lite dash debug mode).

After detaching the debugger (or just continuing the target), some error messages appear in logcat:

E/qcom_sensors_hal( 3039): hal_wait_for_response: pthread_cond_timedwait() rc=11
0 (cond: 0)
E/qcom_sensors_hal( 3039): hal_smgr_report_delete: ERROR: no response from reque
st
E/qcom_sensors_hal( 3039): hal_acquire_resources: Failed to deactivate sensor ha
ndle=1
E/libsensor1( 3039): sensor1_open: Sem wait timed-out for socket 237
E/qcom_sensors_hal( 3039): hal_acquire_resources: hal_sensor1_open failed 11
E/libsensor1( 3039): sensor1_open: Sem wait timed-out for socket 237
E/Sensors ( 222): sns_main.c(281):Error writing to ctl sock fd 97, err 32
E/Sensors ( 222): sns_main.c(281):Error writing to ctl sock fd 76, err 32
W/qcom_sensors_hal( 3039): hal_sensor1_data_cb: SENSOR1_MSG_TYPE_RETRY_OPEN
E/Sensors ( 222): sns_main.c(549):Error writing to ctl sock fd -1, err 9
E/Sensors ( 222): sns_main.c(549):Error writing to ctl sock fd -1, err 9
E/Sensors ( 222): sns_main.c(549):Error writing to ctl sock fd -1, err 9
E/Sensors ( 222): sns_main.c(549):Error writing to ctl sock fd -1, err 9
W/qcom_sensors_hal( 3039): hal_time_data_cb: Received unknown message type 251, id 50
E/Sensors ( 222): sns_main.c(549):Error writing to ctl sock fd -1, err 9
E/Sensors ( 222): sns_main.c(503):Error writing to ctl sock fd -1, err 9
...

Here 222 is /system/bin/sensors.qcom and 3039 is system_server

Another oddity is that gdb shows only a single thread, however there certainly should be more of them (pthread_xxx occurrences within constant strings of the binary and in the logcat output).

Is there anyone who has an experience of debugging native android services and reverse-engineering ARM binaries?
[Nexus 5 Q&A, Help & Troubleshooting] abusalimov:
I finally gave up trying to debug native code with no sources available and switched to a more high level workaround.

What I've basically done is a filter at a point where native HAL communicates to android framework. It intercepts all sensor readings and replaces abnormal 30k lux (and 0 lux following 30k) with an averaged value from a sliding window. This affects any process that use android sensors interface including system_process, so that default android auto-brightness now works fine too.

04-03 23:17:48.436: V/LightSensorFilter(871): fixup bogus high: 19.685715lux
04-03 23:17:49.036: V/LightSensorFilter(871): fixup bogus high: 24.08449lux
04-03 23:17:50.136: V/LightSensorFilter(871): fixup bogus low: 15.469254lux
04-03 23:17:57.286: V/LightSensorFilter(871): fixup bogus high: 28.414286lux

Working proof-of-concept is implemented using Xposed framework and available on my github: https://github.com/abusalimov/XposedHammerheadLightSensorFix.

I run stock Android with a custom kernel, so I didn't try to apply this fix directly to ROM, though some parts of code would be a bit more straight-forward in that case. In fact I got my very first android phone just few weeks ago, so I didn't research popular custom ROMs yet. Probably one day I'll choose one and switch to it so that I could pull my changes there and try them without using Xposed hacks.

http://xdaforums.com/showpost.php?p=51694977&postcount=8
[Nexus 5 Q&A, Help & Troubleshooting] n3ocort3x:
That's a pretty awesome thing u just done ☺ great work and interesting to read what u have done. I'm always interested in such things as I want to learn as much as possible. I really hope it finds someday the way in official Android source. Really cool man. Thanks for sharing
[Nexus 5 Q&A, Help & Troubleshooting] abusalimov:
I uploaded it into Xposed Module Repository. Please check it out here.

http://xdaforums.com/showpost.php?p=51619083&postcount=57
[Nexus 5 Q&A, Help & Troubleshooting] wantabe:
Thanks. Gave the module a try right after you uploaded v1.0 and it seems to me to now be more accurate indoors in low light situations. Too often I felt it was just too dim besides trying to blind you sometimes. I think the auto-brightness on every Nexus device I've owned has been extremely disappointing. You would think by now google would have figured it out. The auto-brightness on my One X is always spot on, all the time. Anyway... a little pain updating from v1.0 to v1.1 because of the signature change but it's all good. Also, I stumbled over here so I could make a donation and maybe buy you a beer so you might at some point want to fix that and maybe start a separate thread for your module. Thanks!
[Nexus 5 Q&A, Help & Troubleshooting] abusalimov:
Sorry, that's my fault. I used development signature for 1.0 by mistake and fixed it in 1.1, but Android forbids changing app signatures. I didn't realize that until your post, thank you!

The only way to perform an upgrade I can see is to manually remove an old 1.0 module and then install 1.1 as usual. I'm going to add such note to the module description and probably reupload version 1.0. If there is more right way to do it, please let me know.

Regarding donations and a separate post. I haven't received any donations before and I simply don't know how it is done (credit card? bitcoin? ...?). In fact, I'm quite glad to hear your "Thank you, guy!", so that's fine!

I'm not sure that a separate post is needed for such small and simple module addressing a certain bug of a certain phone. I still hope that google/lge/qcom will fix this bug eventually (in 4.2.3 maybe), or someone will add a similar workaround at ROM level, thus making my module no longer needed.