Hotplug all physical displays to Android

Report all displays to surface flinger thru hotplug callback.

Bug: 142007329

Change-Id: If43754ec9dd706ca1451771023b7e4c1a5338178
diff --git a/system/hwc2/EmuHWC2.cpp b/system/hwc2/EmuHWC2.cpp
index bbf17ab..921d848 100644
--- a/system/hwc2/EmuHWC2.cpp
+++ b/system/hwc2/EmuHWC2.cpp
@@ -350,13 +350,8 @@
     if (descriptor == Callback::Hotplug) {
         lock.unlock();
         auto hotplug = reinterpret_cast<HWC2_PFN_VSYNC>(pointer);
-        hotplug(callbackData, 0, static_cast<int32_t>(Connection::Connected));
-
-        int ret = populateSecondaryDisplays();
-        if (ret < 0) {
-            ALOGE("Failed to populate secondary displays");
-        } else if (ret == 0) {
-            hotplug(callbackData, 1, static_cast<int32_t>(Connection::Connected));
+        for (const auto& iter : mDisplays) {
+            hotplug(callbackData, iter.first, static_cast<int32_t>(Connection::Connected));
         }
     }
 
@@ -1576,6 +1571,12 @@
         return ret;
     }
 
+    ret = ctx->populateSecondaryDisplays();
+    if (ret < 0) {
+        ALOGE("Failed to populate secondary displays");
+        return ret;
+    }
+
     ctx->common.module = const_cast<hw_module_t *>(module);
     *dev = &ctx->common;
     return 0;
diff --git a/system/hwc2/EmuHWC2.h b/system/hwc2/EmuHWC2.h
index 108dc51..d4615a7 100644
--- a/system/hwc2/EmuHWC2.h
+++ b/system/hwc2/EmuHWC2.h
@@ -476,7 +476,8 @@
     };
     std::unordered_map<HWC2::Callback, CallbackInfo> mCallbacks;
 
-    std::unordered_map<hwc2_display_t, std::shared_ptr<Display>> mDisplays;
+    // use map so displays can be pluged in by order of ID, 0, 1, 2, 3, etc.
+    std::map<hwc2_display_t, std::shared_ptr<Display>> mDisplays;
     std::unordered_map<hwc2_layer_t, std::shared_ptr<Layer>> mLayers;
 
 };