[Redmi Note 2 Android Development] jajk:
Firstly I credit Urix2003 on 4pda forum for the explanation of what is wrong and how to fix it.

The problem may not be universal to all MIUI releases but the majority suffer from the same issue. I have personally proven the fix to work on 7550, 8030 and 61110.

The error is in services.jar whereby the light sensor values for autobrightness control are inadvertently reduced to just three values: 0 lux, 120 lux, 2000 lux hence, the lack of Auto Brightness Adjustment.

DEFINITELY NOT FOR NOOBS............ This thread is to provide the knowledge to

skilled

people to help themselves and maybe to then help others by providing their fixed files to others:fingers-crossed:

I ask that anyone providing edited files clearly states the

exact

version of MIUI (both date code and variant - SU, MR, EU, Stock, Global, China etc) and also provide the table values as code in their post.

To fix: Decompile Services.jar with something like TickleMyAndroid:good:

Edit services\com\android\server\display\AutomaticBrightnessController$1.smali to fix the restriction of light sensor values as follows:

find text:

iget-object v1, p1, Landroid/hardware/SensorEvent;->values:[F
const/4 v4, 0x0
aget v0, v1, v4

Add this line below the text:

goto :goto_0

Note: Label: goto_0 should lead a few lines down to: const-string v1, "AutomaticBrightnessController"

To fix the slow response time:

Edit services\com\android\server\display\AutomaticBrightnessController.smali to halve the response time to changes in brightness

find text 0xfa0, replaced by 0xfa0 (example reduces 4sec to 4sec)

iget v5, p0, Lcom/android/server/display/AutomaticBrightnessController;->mBrighteningLuxThreshold:F

cmpg-float v4, v4, v5

if-gtz v4, :cond_1

:cond_0

const-wide/16 v4, 0xfa0

find text 0x1f40, replaced by 0xfa0 (example reduces 8sec to 4sec)

iget v5, p0, Lcom/android/server/display/AutomaticBrightnessController;->mDarkeningLuxThreshold:F

cmpl-float v4, v4, v5

if-ltz v4, :cond_1

:cond_0

const-wide/16 v4, 0xfao

You can also play around with these settings with caution:

You can also mess around with these settings with caution:

# static fields

.field private static final BRIGHTENING_LIGHT_DEBOUNCE:J = 0xfa0L

.field private static final BRIGHTENING_LIGHT_HYSTERESIS:F = 0.1f

.field private static final DARKENING_LIGHT_DEBOUNCE:J = 0x1f40L (reduce to 0xfa0L 8sec --> 4sec)

.field private static final DARKENING_LIGHT_HYSTERESIS:F = 0.2f (reduce to 0.12f)

.field private static final LIGHT_SENSOR_RATE_MILLIS:I = 0xc8 (increase to 3f8 200ms --> 1sec)

To fix the brightness response to ambient light changes:

Decompile framework-res.apk then edit framework-res\res\values\arrays.xml

Edit the table to values below for a good starting point:

<integer-array name="config_autoBrightnessLevels">
<item>1</item>
<item>11</item>
<item>31</item>
<item>81</item>
<item>121</item>
<item>226</item>
<item>321</item>
<item>551</item>
<item>801</item>
<item>1251</item>
<item>2001</item>
<item>3001</item>
<item>5001</item>
<item>7501</item>
<item>13000</item>
</integer-array>
<integer-array name="config_autoBrightnessLcdBacklightValues">
<item>25</item>
<item>28</item>
<item>34</item>
<item>40</item>
<item>42</item>
<item>43</item>
<item>44</item>
<item>46</item>
<item>48</item>
<item>51</item>
<item>55</item>
<item>60</item>
<item>69</item>
<item>88</item>
<item>137</item>
<item>255</item>
</integer-array>
<integer name="config_screenBrightnessSettingMinimum">15</integer>
<integer name="config_screenBrightnessSettingDefault">50</integer>

Valid autoBrightnessLevels are: (add 1 for the transition to above the value)

0, 5, 10, 30, 80, 120, 225, 320, 550, 800, 1250, 2000, 3000, 5000, 5500, 7500, 13000, 24000

autoBrightnessLevels can be probed here (in hex): /sys/bus/platform/drivers/als_ps/als but it is much better to use an app that displays value in lux;)

LcdBacklightValues can be probed here: /sys/class/leds/lcd-backlight/brightness

WARNING: The 2 altered files are absolutely

unique

to every release version of MIUI so a single fix package cannot be offered.

Also, there are 3 different LCD panels used in the RN2 (but only 1 ALSPS sensor - the LTR559) which may have different brightness characteristics so values that work for 1 display, may not be ideal for another.

Thank me by all means but don't ask for help on how to decompile / recompile;)