Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Commit 54fa919

Browse files
committed
When display is disconnected, return BadDisplay in DisplayHook
Without this checking, SF will try to invoke layerHook on disconnected display. Change-Id: I1f765dfee315bb1db46f816e1061d2dd2566ff50 Tracked-On: OAM-95793 Signed-off-by: Shaofeng Tang <shaofeng.tang@intel.com>
1 parent 19987a8 commit 54fa919

1 file changed

Lines changed: 33 additions & 7 deletions

File tree

os/android/iahwc2.h

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,17 @@ class IAHWC2 : public hwc2_device_t {
304304
return HWC2::Error::BadDisplay;
305305
}
306306

307+
bool IsValidDisplay(HwcDisplay *display) {
308+
if (!display) {
309+
return false;
310+
}
311+
hwcomposer::NativeDisplay *native_display = display->GetDisplay();
312+
if (!(native_display && native_display->IsConnected())) {
313+
return false;
314+
}
315+
return true;
316+
}
317+
307318
static IAHWC2 *toIAHWC2(hwc2_device_t *dev) {
308319
return static_cast<IAHWC2 *>(dev);
309320
}
@@ -346,12 +357,19 @@ class IAHWC2 : public hwc2_device_t {
346357

347358
if (display_handle == HWC_DISPLAY_EXTERNAL) {
348359
HwcDisplay *display = hwc->extended_displays_.at(0).get();
349-
return static_cast<int32_t>(
350-
(display->*func)(std::forward<Args>(args)...));
360+
if (!hwc->IsValidDisplay(display))
361+
return static_cast<int32_t>(hwc->BadDisplay());
362+
else
363+
return static_cast<int32_t>(
364+
(display->*func)(std::forward<Args>(args)...));
351365
}
352366

353367
HwcDisplay *display = hwc->extended_displays_.at(1).get();
354-
return static_cast<int32_t>((display->*func)(std::forward<Args>(args)...));
368+
if (!hwc->IsValidDisplay(display))
369+
return static_cast<int32_t>(hwc->BadDisplay());
370+
else
371+
return static_cast<int32_t>(
372+
(display->*func)(std::forward<Args>(args)...));
355373
}
356374

357375
template <typename HookType, HookType func, typename... Args>
@@ -376,13 +394,21 @@ class IAHWC2 : public hwc2_device_t {
376394

377395
if (display_handle == HWC_DISPLAY_EXTERNAL) {
378396
HwcDisplay *display = hwc->extended_displays_.at(0).get();
379-
Hwc2Layer &layer = display->get_layer(layer_handle);
380-
return static_cast<int32_t>((layer.*func)(std::forward<Args>(args)...));
397+
if (!hwc->IsValidDisplay(display)) {
398+
return static_cast<int32_t>(hwc->BadDisplay());
399+
} else {
400+
Hwc2Layer &layer = display->get_layer(layer_handle);
401+
return static_cast<int32_t>((layer.*func)(std::forward<Args>(args)...));
402+
}
381403
}
382404

383405
HwcDisplay *display = hwc->extended_displays_.at(1).get();
384-
Hwc2Layer &layer = display->get_layer(layer_handle);
385-
return static_cast<int32_t>((layer.*func)(std::forward<Args>(args)...));
406+
if (!hwc->IsValidDisplay(display)) {
407+
return static_cast<int32_t>(hwc->BadDisplay());
408+
} else {
409+
Hwc2Layer &layer = display->get_layer(layer_handle);
410+
return static_cast<int32_t>((layer.*func)(std::forward<Args>(args)...));
411+
}
386412
}
387413

388414
// hwc2_device_t hooks

0 commit comments

Comments
 (0)