相关文件:
release/frameworks/base/services/core/java/com/android/server/hdmi/HdmiControlService.java
Android设备亮屏熄屏时会发送相关广播,亮屏广播:“android.intent.action.SCREEN_ON”,熄屏广播:“android.intent.action.SCREEN_OFF”。HdmiControlService.java接收到亮屏熄屏广播时会调用相关方法去控制CEC设备断电上电,相关代码如下:
private class HdmiControlBroadcastReceiver extends BroadcastReceiver {
@ServiceThreadOnly
@Override
public void onReceive(Context context, Intent intent) {
assertRunOnServiceThread();
boolean isReboot = SystemProperties.get(SHUTDOWN_ACTION_PROPERTY).contains("1");
Slog.d(TAG, "HdmiControlBroadcastReceiver intent.getAction(): " + intent.getAction());
switch (intent.getAction()) {
case Intent.ACTION_SCREEN_OFF:
if (isPowerOnOrTransient() && !isReboot) {
onStandby(STANDBY_SCREEN_OFF);
}
break;
case Intent.ACTION_SCREEN_ON:
Slog.d(TAG, " Intent.ACTION_SCREEN_ON isPowerStandbyOrTransient: " + isPowerStandbyOrTransient());
if (isPowerStandbyOrTransient()) {
onWakeUp(WAKE_UP_SCREEN_ON);
}
break;
case Intent.ACTION_CONFIGURATION_CHANGED:
String language = HdmiControlService.localeToMenuLanguage(Locale.getDefault());
if (!mMenuLanguage.equals(language)) {
onLanguageChanged(language);
}
break;
case Intent.ACTION_SHUTDOWN:
if (isPowerOnOrTransient() && !isReboot) {
onStandby(STANDBY_SHUTDOWN);
}
break;
}
}
如上代码块当接收到Intent.ACTION_SCREEN_OFF熄屏广播时会调用onStandby(STANDBY_SCREEN_OFF)方法控制CEC设备断电,当接收到 Intent.ACTION_SCREEN_ON广播时会调用 onWakeUp(WAKE_UP_SCREEN_ON)方法控制CEC设备上电。
Android设备亮屏熄屏流程,以及CEC相关流程可以参考以下文章,文章描述的比较详细可以认真阅读一下:
Android设备亮屏流程链接
Android设备熄屏流程链接