The branch linked minimizes the occurrence of this error since it only address scenario 1 above.
It may be possible to detect scenario 2 and 3 and address it by tearing down and recreating the compositor thread (similarly to what happens during hotplug on a display configuration change).
Scenario 2 is:
Submit list for both displays, unplug external display, HWC set returns -1, HWC reports display still connected (I assume this is a race in the HWC/kernel implementation). We could still throw an ExternalDisplayError.
Scenario 3:
Submit list for both displays, HWC returns 0 (i.e. success), unplug external display.
Submit list for primary display only, HWC returns -1, check if the last commit included external display, if it does, throw ExternalDisplayError
DisplayGroup could catch ExternalDisplayError and issue a display configuration change, which would tear restart the compositor thread.
The branch linked minimizes the occurrence of this error since it only address scenario 1 above.
It may be possible to detect scenario 2 and 3 and address it by tearing down and recreating the compositor thread (similarly to what happens during hotplug on a display configuration change).
Scenario 2 is:
Submit list for both displays, unplug external display, HWC set returns -1, HWC reports display still connected (I assume this is a race in the HWC/kernel implementation). We could still throw an ExternalDisplay Error.
Scenario 3:
Submit list for both displays, HWC returns 0 (i.e. success), unplug external display. Error
Submit list for primary display only, HWC returns -1, check if the last commit included external display, if it does, throw ExternalDisplay
DisplayGroup could catch ExternalDisplay Error and issue a display configuration change, which would tear restart the compositor thread.