Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,730,807 Members 43,629 Now Online
XDA Developers Android and Mobile Development Forum

[MOD][XPOSED][N5] Ambient Light Sensor fix for Nexus 5

Tip us?
 
abusalimov
Old
(Last edited by abusalimov; 16th May 2014 at 01:53 AM.)
#1  
Member - OP
Thanks Meter 62
Posts: 55
Join Date: Mar 2014
Location: St. Petersburg

 
DONATE TO ME
Default [MOD][XPOSED][N5] Ambient Light Sensor fix for Nexus 5

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
  1. Download and install Xposed framework
  2. Then install Nexus 5 Light Sensor fix module and activate it
  3. 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
The Following 19 Users Say Thank You to abusalimov For This Useful Post: [ Click to Expand ]
 
abusalimov
Old
#2  
Member - OP
Thanks Meter 62
Posts: 55
Join Date: Mar 2014
Location: St. Petersburg

 
DONATE TO ME
More on the issue

Two major issues with the Nexus 5 ambient light sensor (original module announcement)
Quote:
Originally Posted by Palmadores View Post
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.
Quote:
Originally Posted by exorz View Post
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.
Is the Auto-Brightness Functionality wonky on the Nexus5?
Quote:
Originally Posted by Aria807 View Post
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.
The Following 3 Users Say Thank You to abusalimov For This Useful Post: [ Click to Expand ]
 
wantabe
Old
(Last edited by wantabe; 14th April 2014 at 06:08 PM.)
#3  
Senior Member
Thanks Meter 135
Posts: 373
Join Date: Mar 2011
Location: Colorado Springs
Well done! Auto-brightness accuracy is much improved indoors! Appreciate your work on this!
"Don't confuse me with facts, I've already made up my mind!"

AT&T HTC One X - 4.2.2 CleanROM-odexed/Xposed/ElementalX
Nexus 5 32GB
Nexus 7 32GB (2013)
Nexus 4 8GB-Moved to Better Home!
Nexus 7 16GB-Moved to Better Home!.
Nexus 7 32GB-Moved to Better Home!
 
augoza
Old
(Last edited by augoza; 14th April 2014 at 07:26 PM.) Reason: words
#4  
augoza's Avatar
Senior Member
Thanks Meter 15
Posts: 341
Join Date: Feb 2010
Do I need to disable the modules if I dirty flash a new Carbon nightly? Or is that not necessary

current device..
Nexus 5 PA 4.4.4 ART Elementalx
previously..
HTC One m7 non-rooted Stock
iPhone 4s jailbroken
HTC Supersonic rooted

 
abusalimov
Old
#5  
Member - OP
Thanks Meter 62
Posts: 55
Join Date: Mar 2014
Location: St. Petersburg

 
DONATE TO ME
Quote:
Originally Posted by augoza View Post
Do I need to disable the modules if I dirty flash a new Carbon nightly? Or is that not necessary
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.
 
ddloco
Old
#6  
ddloco's Avatar
Senior Member
Thanks Meter 119
Posts: 486
Join Date: Jun 2010
Location: Rialto,Ca
1.1 update won't install on nexus 5 signature mismatch

Sent from my Nexus 5 using Tapatalk
 
abusalimov
Old
#7  
Member - OP
Thanks Meter 62
Posts: 55
Join Date: Mar 2014
Location: St. Petersburg

 
DONATE TO ME
Quote:
Originally Posted by ddloco View Post
1.1 update won't install on nexus 5 signature mismatch
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.
 
mcnob
Old
#8  
Senior Member
Thanks Meter 21
Posts: 429
Join Date: Aug 2010
Location: Suffolk
Still coming up very bright compared to Lux. Battery drain WILL be an issue.
Posted from either:

Nexus 5
Nexus 7 (2013)
Acer C720 Chromebook.....................(How much of a Google fanboy am I ?)
 
abusalimov
Old
#9  
Member - OP
Thanks Meter 62
Posts: 55
Join Date: Mar 2014
Location: St. Petersburg

 
DONATE TO ME
Quote:
Originally Posted by mcnob View Post
Still coming up very bright compared to Lux. Battery drain WILL be an issue.
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/show....php?t=2616914). Probably there is some app/mod for tweaking these options.
 
bland.life
Old
#10  
Senior Member
Thanks Meter 64
Posts: 361
Join Date: Oct 2010
Wonder if custom ROMs like Omni and CM already have the fix baked in?
Cyanogenmod on - LG Nexus 5 // Asus Nexus 7 (2013) // HTC Desire
OMNI on - Asus Nexus 7 (2012)
MIUI on - Samsung Galaxy SII

Tags
auto-brightness, hal, hammerhead, light sensor, nexus 5
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes