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

Search This thread

abusalimov

Senior Member
Mar 27, 2014
59
68
34
St. Petersburg
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
 
Last edited:

abusalimov

Senior Member
Mar 27, 2014
59
68
34
St. Petersburg
More on the issue

Two major issues with the Nexus 5 ambient light sensor (original module announcement)
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.

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?
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.
 

augoza

Senior Member
Feb 4, 2010
535
42
Do I need to disable the modules if I dirty flash a new Carbon nightly? Or is that not necessary
 
Last edited:

abusalimov

Senior Member
Mar 27, 2014
59
68
34
St. Petersburg
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://xdaforums.com/showthread.php?t=2616914). Probably there is some app/mod for tweaking these options.
 

abusalimov

Senior Member
Mar 27, 2014
59
68
34
St. Petersburg
Wonder if custom ROMs like Omni and CM already have the fix baked in?

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.
 

wantabe

Senior Member
Mar 8, 2011
454
191
Colorado Springs
Still coming up very bright compared to Lux. Battery drain WILL be an issue.
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!
 
Last edited:

Deeco7

Senior Member
Jul 12, 2010
1,816
421
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
 

zbloh

Member
Sep 25, 2013
11
8
10000 lux

My N5 reports 10000 lux instead of 30000, very annoying

Running CM11.0 m5
 

Top Liked Posts

  • There are no posts matching your filters.
  • 20
    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
    5
    How can I get back 0 lux? I often use phone in such low light and 1lux is brighter. Anyway thanks for such a good module!

    Inviato dal mio Nexus 5 utilizzando Tapatalk

    Yeah, I am coming to realize that this change was a mistake. I will consider to revert it back in the next version soon. I suggest you to use GravityBox to edit auto-brightness curve for now, or to downgrade to 1.1.

    Please update to v1.2.1
    4
    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)
    3
    More on the issue

    Two major issues with the Nexus 5 ambient light sensor (original module announcement)
    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.

    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?
    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.
    1
    How can I get back 0 lux? I often use phone in such low light and 1lux is brighter. Anyway thanks for such a good module!

    Inviato dal mio Nexus 5 utilizzando Tapatalk

    Yeah, I am coming to realize that this change was a mistake. I will consider to revert it back in the next version soon. I suggest you to use GravityBox to edit auto-brightness curve for now, or to downgrade to 1.1.