一、powermanager最终会调用如下线程
frameworks/base/services/core/java/com/android/server/display/LocalDisplayAdapter.java :
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, "setDisplayState("
+ "id=" + displayId
+ ", state=" + Display.stateToString(state) + ")");
}
Trace.traceBegin(Trace.TRACE_TAG_POWER, "setDisplayState("
+ "id=" + displayId
+ ", state=" + Display.stateToString(state) + ")");
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, "setDisplayBrightness("
+ "id=" + displayId + ", brightness=" + brightness + ")");
}
Trace.traceBegin(Trace.TRACE_TAG_POWER, "setDisplayBrightness("
+ "id=" + displayId + ", brightness=" + brightness + ")");
try {
mBacklight.setBrightness(brightness);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_POWER);
}
}
};
}
return null;
}
二、mBacklight.setBrightness(brightness);直接调用lightservice中接口
三、电源管理模式的设置
final int mode = getPowerModeForState(state);
SurfaceControl.setDisplayPowerMode(token, mode);
1、 getPowerModeForState()
static int getPowerModeForState(int state) {
switch (state) {
case Display.STATE_OFF:
return SurfaceControl.POWER_MODE_OFF;
case Display.STATE_DOZE:
return SurfaceControl.POWER_MODE_DOZE;
case Display.STATE_DOZE_SUSPEND:
return SurfaceControl.POWER_MODE_DOZE_SUSPEND;
default:
return SurfaceControl.POWER_MODE_NORMAL;
}
}
2、SurfaceControl.setDisplayPowerMode(token, mode);
(1)setDisplayPowerMode()
framework/base/core/java/android/view/SurfaceControl.java
public static void setDisplayPowerMode(IBinder displayToken, int mode) {
if (displayToken == null) {
throw new IllegalArgumentException("displayToken must not be null");
}
nativeSetDisplayPowerMode(displayToken, mode);
}
(2)nativeSetDisplayPowerMode()
framework/base/core/jni/android_view_SurfaceControl.cpp
static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
if (token == NULL) return;
ALOGD_IF_SLOW(100, "Excessive delay in setPowerMode()");
SurfaceComposerClient::setDisplayPowerMode(token, mode);
}
(3)framework/native/libs/gui/SurfaceComposerClient.cpp
void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
int mode) {
ComposerService::getComposerService()->setPowerMode(token, mode);
}
(4)setPowerMode()
frameworks/native/services/surfaceflinger/DisplayHardware/HWComposer.cpp
status_t HWComposer::setPowerMode(int disp, int mode) {
LOG_FATAL_IF(disp >= VIRTUAL_DISPLAY_ID_BASE);
if (mHwc) {
if (mode == HWC_POWER_MODE_OFF) {
eventControl(disp, HWC_EVENT_VSYNC, 0);
}
if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_4)) {
return (status_t)mHwc->setPowerMode(mHwc, disp, mode);
} else {
return (status_t)mHwc->blank(mHwc, disp,
mode == HWC_POWER_MODE_OFF ? 1 : 0);
}
}
return NO_ERROR;
}
接着往下调用HWC中接口,最终调用到驱动中