Nullptr check for getActiveConfig() in doDump()
HWComposer::getActiveConfig() returns nullptr when a bad
configuration is received from HWC. In this case a dumpsys
will cause a nullptr dereference and it'll crash SurfaceFlinger.
This CL adds a nullptr check to prevent this.
Bug: 165419673
Test: adb shell dumpsys SurfaceFlinger
Change-Id: I7da8d034a5a429412a73121d795e3adc4323db13
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index ca9f629..0821ca4 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -4794,12 +4794,21 @@
if (const auto displayId = getInternalDisplayIdLocked();
displayId && getHwComposer().isConnected(*displayId)) {
const auto activeConfig = getHwComposer().getActiveConfig(*displayId);
+ std::string fps, xDpi, yDpi;
+ if (activeConfig) {
+ fps = std::to_string(1e9 / getHwComposer().getDisplayVsyncPeriod(*displayId)) + " fps";
+ xDpi = activeConfig->getDpiX();
+ yDpi = activeConfig->getDpiY();
+ } else {
+ fps = "unknown";
+ xDpi = "unknown";
+ yDpi = "unknown";
+ }
StringAppendF(&result,
- " refresh-rate : %f fps\n"
- " x-dpi : %f\n"
- " y-dpi : %f\n",
- 1e9 / getHwComposer().getDisplayVsyncPeriod(*displayId),
- activeConfig->getDpiX(), activeConfig->getDpiY());
+ " refresh-rate : %s\n"
+ " x-dpi : %s\n"
+ " y-dpi : %s\n",
+ fps.c_str(), xDpi.c_str(), yDpi.c_str());
}
StringAppendF(&result, " transaction time: %f us\n", inTransactionDuration / 1000.0);