composer: Guard layer buffer access around hotplug disconnect

Drop commands to a Display if it is not found in the DisplayData map.

Restore lines from Change-Id Ibd5b2b03150b34f2613fc93ec0241ca2787938b6
overwritten by Change-Id I9a0fc80413a01da9bb32e07e995b5365a924d5ca.

CRs-Fixed: 2605239
Change-Id: I2d04a312f3df12edcc5772ab1586cc900305d2ae
diff --git a/composer/QtiComposerClient.cpp b/composer/QtiComposerClient.cpp
index 2519ea7..4ff4db5 100644
--- a/composer/QtiComposerClient.cpp
+++ b/composer/QtiComposerClient.cpp
@@ -1117,6 +1117,11 @@
   // Commands from ::android::hardware::graphics::composer::V2_1::IComposerClient follow.
   case IComposerClient::Command::SELECT_DISPLAY:
     parsed = parseSelectDisplay(length);
+    // Displays will not be removed while processing the command queue.
+    if (parsed && mClient.mDisplayData.find(mDisplay) == mClient.mDisplayData.end()) {
+      ALOGW("Command::SELECT_DISPLAY: Display %lu not found. Dropping commands.", mDisplay);
+      mDisplay = sdm::HWCCallbacks::kNumDisplays;
+    }
     break;
   case IComposerClient::Command::SELECT_LAYER:
     parsed = parseSelectLayer(length);