mDisplayPowerController = new DisplayPowerController(
mContext, callbacks, handler, sensorManager, blanker); } }
我们再来看看requestGlobalDisplayStateInternal函数:
[cpp] view plain copy 在CODE上查看代码片派生到我的代码片
private void requestGlobalDisplayStateInternal(int state, int brightness) { if (state == Display.STATE_UNKNOWN) { state = Display.STATE_ON; }
if (state == Display.STATE_OFF) {
brightness = PowerManager.BRIGHTNESS_OFF; } else if (brightness < 0) {
brightness = PowerManager.BRIGHTNESS_DEFAULT; } else if (brightness > PowerManager.BRIGHTNESS_ON) { brightness = PowerManager.BRIGHTNESS_ON; }
synchronized (mTempDisplayStateWorkQueue) { try {
// Update the display state within the lock.
// Note that we do not need to schedule traversals here although it // may happen as a side-effect of displays changing state. synchronized (mSyncRoot) {
if (mGlobalDisplayState == state
&& mGlobalDisplayBrightness == brightness) { return; // no change }
Trace.traceBegin(Trace.TRACE_TAG_POWER, \
+ Display.stateToString(state)
+ \ mGlobalDisplayState = state;
mGlobalDisplayBrightness = brightness;
applyGlobalDisplayStateLocked(mTempDisplayStateWorkQueue); }
// Setting the display power state can take hundreds of milliseconds // to complete so we defer the most expensive part of the work until // after we have exited the critical section to avoid blocking other // threads for a long time.
for (int i = 0; i < mTempDisplayStateWorkQueue.size(); i++) { mTempDisplayStateWorkQueue.get(i).run();
}
Trace.traceEnd(Trace.TRACE_TAG_POWER); } finally {
mTempDisplayStateWorkQueue.clear(); } } }
再看看applyGlobalDisplayStateLocked函数,最后遍历device调用updateDisplayStateLocked函数
[cpp] view plain copy 在CODE上查看代码片派生到我的代码片
private void applyGlobalDisplayStateLocked(List
DisplayDevice device = mDisplayDevices.get(i);
Runnable runnable = updateDisplayStateLocked(device); if (runnable != null) {
workQueue.add(runnable); } } }
updateDisplayStateLocked函数调用device的requestDisplayStateLocked返回是Runnable,最后放在workQueue队列中
[cpp] view plain copy 在CODE上查看代码片派生到我的代码片 private Runnable updateDisplayStateLocked(DisplayDevice device) {
// Blank or unblank the display immediately to match the state requested // by the display power controller (if known).
DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
if ((info.flags & DisplayDeviceInfo.FLAG_NEVER_BLANK) == 0) { return device.requestDisplayStateLocked(mGlobalDisplayState, mGlobalDisplayBrightness); }
return null; }
我们再来看看LocalDisplayDevice的requestDisplayStateLocked函数 [cpp] view plain copy 在CODE上查看代码片派生到我的代码片
public Runnable requestDisplayStateLocked(final int state, final int brightness) { // Assume that the brightness is off if the display is being turned off.
assert state != Display.STATE_OFF || brightness == PowerManager.BRIGHTNESS_OFF;
final boolean stateChanged = (mState != state);
final boolean brightnessChanged = (mBrightness != brightness) && mBacklight != null; if (stateChanged || brightnessChanged) { final int displayId = mBuiltInDisplayId;
final IBinder token = getDisplayTokenLocked();
final int oldState = mState;
if (stateChanged) {
mState = state;// 状态
updateDeviceInfoLocked(); }
if (brightnessChanged) {
mBrightness = brightness;//保存亮度 }
// Defer actually setting the display state until after we have exited // the critical section since it can take hundreds of milliseconds // to complete.
return new Runnable() { @Override
public void run() {
// Exit a suspended state before making any changes. int currentState = oldState;
if (Display.isSuspendedState(oldState)
|| oldState == Display.STATE_UNKNOWN) { if (!Display.isSuspendedState(state)) { setDisplayState(state); currentState = state;
} else if (state == Display.STATE_DOZE_SUSPEND
|| oldState == Display.STATE_DOZE_SUSPEND) { setDisplayState(Display.STATE_DOZE); currentState = Display.STATE_DOZE; } else {
return; // old state and new state is off } }
// Apply brightness changes given that we are in a non-suspended state. if (brightnessChanged) {
setDisplayBrightness(brightness);//设置亮度 }
// Enter the final desired state, possibly suspended. if (state != currentState) { setDisplayState(state); } }
private void setDisplayState(int state) { if (DEBUG) {
Slog.d(TAG, \ + \
+ \ }
Trace.traceBegin(Trace.TRACE_TAG_POWER, \ + \
+ \ try {
final int mode = getPowerModeForState(state);
SurfaceControl.setDisplayPowerMode(token, mode); } finally {
Trace.traceEnd(Trace.TRACE_TAG_POWER); } }
private void setDisplayBrightness(int brightness) { if (DEBUG) {
Slog.d(TAG, \
+ \ }
Trace.traceBegin(Trace.TRACE_TAG_POWER, \ + \ try {
mBacklight.setBrightness(brightness);//真正的设置背光 } finally {
Trace.traceEnd(Trace.TRACE_TAG_POWER); } } }; }
return null; }
上面函数返回一个Runnable放在workQueue,在Runnable 中会调用mBacklight.setBrightness设置背光。
之前是将Runnable接口都放在了mTempDisplayStateWorkQueue中,然后遍历调用了run函数。最后就调用到了LocalDisplayDevice的Runnable接口中设置背光了。 [cpp] view plain copy 在CODE上查看代码片派生到我的代码片 synchronized (mSyncRoot) {
if (mGlobalDisplayState == state
&& mGlobalDisplayBrightness == brightness) {
return; // no change }
Trace.traceBegin(Trace.TRACE_TAG_POWER, \ + Display.stateToString(state)
+ \ mGlobalDisplayState = state;
mGlobalDisplayBrightness = brightness;
applyGlobalDisplayStateLocked(mTempDisplayStateWorkQueue); }
// Setting the display power state can take hundreds of milliseconds // to complete so we defer the most expensive part of the work until // after we have exited the critical section to avoid blocking other // threads for a long time.
for (int i = 0; i < mTempDisplayStateWorkQueue.size(); i++) { mTempDisplayStateWorkQueue.get(i).run(); }
四、背光hal层
我们先来看看LightsService
[cpp] view plain copy 在CODE上查看代码片派生到我的代码片 public class LightsService extends SystemService { static final String TAG = \ static final boolean DEBUG = false;
final LightImpl mLights[] = new LightImpl[LightsManager.LIGHT_ID_COUNT];
private final class LightImpl extends Light {
private LightImpl(int id) { mId = id; }
@Override
public void setBrightness(int brightness) {
setBrightness(brightness, BRIGHTNESS_MODE_USER); }
@Override
public void setBrightness(int brightness, int brightnessMode) { synchronized (thwww.sm136.comis) { int color = brightness & 0x000000ff;
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库android6.0 power显示(亮度等)深入分析(二)DisplayManagerServic(2)在线全文阅读。
相关推荐: