Fix HWC2to1Adapter crashing dragon at startup
Some devices such a dragon(ryu) do not start with a valid active
configuration id (e.g: -1). This is unexpected from HWC2to1Adapter
and resulted in crash at startup when switching the device from HWC1
to HWC2 with adapter.
This patch detects this at startup and put the device in an expected
configutation using the first configuration index (0).
Test: Tested on ryu
Change-Id: If2bb258d12636f1b2ebe8c7b167708dbf572fbe8
diff --git a/services/surfaceflinger/DisplayHardware/HWC2On1Adapter.cpp b/services/surfaceflinger/DisplayHardware/HWC2On1Adapter.cpp
index b699b2c..1107c99 100644
--- a/services/surfaceflinger/DisplayHardware/HWC2On1Adapter.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWC2On1Adapter.cpp
@@ -1841,29 +1841,39 @@
auto activeConfig = mDevice.mHwc1Device->getActiveConfig(
mDevice.mHwc1Device, mHwc1Id);
- if (activeConfig >= 0) {
- for (const auto& config : mConfigs) {
- if (config->hasHwc1Id(activeConfig)) {
- ALOGV("Setting active config to %d for HWC1 config %u",
- config->getId(), activeConfig);
- mActiveConfig = config;
- if (config->getColorModeForHwc1Id(activeConfig, &mActiveColorMode) != Error::None) {
- // This should never happen since we checked for the config's presence before
- // setting it as active.
- ALOGE("Unable to find color mode for active HWC1 config %d",
- config->getId());
- mActiveColorMode = HAL_COLOR_MODE_NATIVE;
- }
- break;
+
+ // Some devices startup without an activeConfig:
+ // We need to set one ourselves.
+ if (activeConfig == HWC_ERROR) {
+ ALOGV("There is no active configuration: Picking the first one: 0.");
+ const int defaultIndex = 0;
+ mDevice.mHwc1Device->setActiveConfig(mDevice.mHwc1Device, mHwc1Id, defaultIndex);
+ activeConfig = defaultIndex;
+ }
+
+ for (const auto& config : mConfigs) {
+ if (config->hasHwc1Id(activeConfig)) {
+ ALOGE("Setting active config to %d for HWC1 config %u", config->getId(), activeConfig);
+ mActiveConfig = config;
+ if (config->getColorModeForHwc1Id(activeConfig, &mActiveColorMode) != Error::None) {
+ // This should never happen since we checked for the config's presence before
+ // setting it as active.
+ ALOGE("Unable to find color mode for active HWC1 config %d", config->getId());
+ mActiveColorMode = HAL_COLOR_MODE_NATIVE;
}
- }
- if (!mActiveConfig) {
- ALOGV("Unable to find active HWC1 config %u, defaulting to "
- "config 0", activeConfig);
- mActiveConfig = mConfigs[0];
- mActiveColorMode = HAL_COLOR_MODE_NATIVE;
+ break;
}
}
+ if (!mActiveConfig) {
+ ALOGV("Unable to find active HWC1 config %u, defaulting to "
+ "config 0", activeConfig);
+ mActiveConfig = mConfigs[0];
+ mActiveColorMode = HAL_COLOR_MODE_NATIVE;
+ }
+
+
+
+
}
void HWC2On1Adapter::Display::reallocateHwc1Contents()