Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea86d713 authored by yangyankai1's avatar yangyankai1
Browse files

AutoBrightness: Remove handler's messages before send.



The contentprovider's callback 'onChange(...)' is asynchronous.
If one app set the 'screen_brightness' provider frequently over a period of time,
the contentprovider's 'onChange(...)' can't stop, just like 'Self-exciting oscillation'.
So, We need remove handler's messages before send.

Test: build pass, feature pass.
TestCase: set the 'screen_brightness' provider frequently, can use a
loop: for(i=0;i<1000;i++){put(...)}.

Signed-off-by: default avataryangyankai1 <yangyankai1@xiaomi.com>
Change-Id: I346696c69623829d4dda372edaf35b6e3f147780
parent 19189d88
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -259,10 +259,12 @@ public class BrightnessSynchronizer{
            }
            if (BRIGHTNESS_URI.equals(uri)) {
                int currentBrightness = getScreenBrightnessInt(mContext);
                mHandler.removeMessages(MSG_UPDATE_FLOAT);
                mHandler.obtainMessage(MSG_UPDATE_FLOAT, currentBrightness, 0).sendToTarget();
            } else if (BRIGHTNESS_FLOAT_URI.equals(uri)) {
                float currentFloat = getScreenBrightnessFloat(mContext);
                int toSend = Float.floatToIntBits(currentFloat);
                mHandler.removeMessages(MSG_UPDATE_INT);
                mHandler.obtainMessage(MSG_UPDATE_INT, toSend, 0).sendToTarget();
            }
        }