Donate to
e Foundation
|
Murena
handsets with /e/OS | Own a part of Murena!
Learn more
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
android_frameworks_base
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
e
os
android_frameworks_base
Commits
6348d1e9
Commit
6348d1e9
authored
5 years ago
by
Long Ling
Committed by
Android (Google) Code Review
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Responsiveness improvement for BrightnessObserver" into qt-r1-dev
parents
cd4208e0
c1ee0424
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
services/core/java/com/android/server/display/DisplayModeDirector.java
+68
-5
68 additions, 5 deletions
.../java/com/android/server/display/DisplayModeDirector.java
with
68 additions
and
5 deletions
services/core/java/com/android/server/display/DisplayModeDirector.java
+
68
−
5
View file @
6348d1e9
...
...
@@ -728,6 +728,7 @@ public class DisplayModeDirector {
private
SensorManager
mSensorManager
;
private
Sensor
mLightSensor
;
private
LightSensorEventListener
mLightSensorListener
=
new
LightSensorEventListener
();
// Take it as low brightness before valid sensor data comes
private
float
mAmbientLux
=
-
1.0f
;
private
AmbientFilter
mAmbientFilter
;
...
...
@@ -907,19 +908,40 @@ public class DisplayModeDirector {
mSensorManager
.
registerListener
(
mLightSensorListener
,
mLightSensor
,
LIGHT_SENSOR_RATE_MS
*
1000
,
mHandler
);
}
else
{
mLightSensorListener
.
removeCallbacks
();
mSensorManager
.
unregisterListener
(
mLightSensorListener
);
}
}
private
final
SensorEventListener
mLightSensorListener
=
new
SensorEventListener
()
{
private
final
class
LightSensorEventListener
implements
SensorEventListener
{
final
private
static
int
INJECT_EVENTS_INTERVAL_MS
=
LIGHT_SENSOR_RATE_MS
;
private
float
mLastSensorData
;
@Override
public
void
onSensorChanged
(
SensorEvent
event
)
{
mLastSensorData
=
event
.
values
[
0
];
if
(
DEBUG
)
{
Slog
.
d
(
TAG
,
"On sensor changed: "
+
mLastSensorData
);
}
boolean
zoneChanged
=
isDifferentZone
(
mLastSensorData
,
mAmbientLux
);
if
(
zoneChanged
&&
mLastSensorData
<
mAmbientLux
)
{
// Easier to see flicker at lower brightness environment. Forget the history to
// get immediate response.
mAmbientFilter
.
clear
();
}
long
now
=
SystemClock
.
uptimeMillis
();
mAmbientFilter
.
addValue
(
now
,
event
.
values
[
0
]);
mAmbientLux
=
mAmbientFilter
.
getEstimate
(
now
);
mAmbientFilter
.
addValue
(
now
,
mLastSensorData
);
synchronized
(
mLock
)
{
onBrightnessChangedLocked
();
mHandler
.
removeCallbacks
(
mInjectSensorEventRunnable
);
processSensorData
(
now
);
if
(
zoneChanged
&&
mLastSensorData
>
mAmbientLux
)
{
// Sensor may not report new event if there is no brightness change.
// Need to keep querying the temporal filter for the latest estimation,
// until enter in higher lux zone or is interrupted by a new sensor event.
mHandler
.
postDelayed
(
mInjectSensorEventRunnable
,
INJECT_EVENTS_INTERVAL_MS
);
}
}
...
...
@@ -927,6 +949,47 @@ public class DisplayModeDirector {
public
void
onAccuracyChanged
(
Sensor
sensor
,
int
accuracy
)
{
// Not used.
}
public
void
removeCallbacks
()
{
mHandler
.
removeCallbacks
(
mInjectSensorEventRunnable
);
}
private
void
processSensorData
(
long
now
)
{
mAmbientLux
=
mAmbientFilter
.
getEstimate
(
now
);
synchronized
(
mLock
)
{
onBrightnessChangedLocked
();
}
}
private
boolean
isDifferentZone
(
float
lux1
,
float
lux2
)
{
for
(
int
z
=
0
;
z
<
mAmbientBrightnessThresholds
.
length
;
z
++)
{
final
float
boundary
=
mAmbientBrightnessThresholds
[
z
];
// Test each boundary. See if the current value and the new value are at
// different sides.
if
((
lux1
<=
boundary
&&
lux2
>
boundary
)
||
(
lux1
>
boundary
&&
lux2
<=
boundary
))
{
return
true
;
}
}
return
false
;
}
private
Runnable
mInjectSensorEventRunnable
=
new
Runnable
()
{
@Override
public
void
run
()
{
long
now
=
SystemClock
.
uptimeMillis
();
// No need to really inject the last event into a temporal filter.
processSensorData
(
now
);
// Inject next event if there is a possible zone change.
if
(
isDifferentZone
(
mLastSensorData
,
mAmbientLux
))
{
mHandler
.
postDelayed
(
mInjectSensorEventRunnable
,
INJECT_EVENTS_INTERVAL_MS
);
}
}
};
};
private
final
class
ScreenStateReceiver
extends
BroadcastReceiver
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment