Merge "Fix virtual touchpad scroll events." into oc-dr1-dev
diff --git a/cmds/installd/dexopt.cpp b/cmds/installd/dexopt.cpp
index 4ecbf92..baa05d0 100644
--- a/cmds/installd/dexopt.cpp
+++ b/cmds/installd/dexopt.cpp
@@ -863,6 +863,8 @@
         return false;
     }
 
+    // As a security measure we want to write the profile information with the reduced capabilities
+    // of the package user id. So we fork and drop capabilities in the child.
     pid_t pid = fork();
     if (pid == 0) {
         /* child -- drop privileges before continuing */
@@ -900,7 +902,9 @@
         if (flock(out_fd.get(), LOCK_UN) != 0) {
             PLOG(WARNING) << "Error unlocking profile " << data_profile_location;
         }
-        exit(0);
+        // Use _exit since we don't want to run the global destructors in the child.
+        // b/62597429
+        _exit(0);
     }
     /* parent */
     int return_code = wait_child(pid);
diff --git a/libs/vr/libvrflinger/hardware_composer.cpp b/libs/vr/libvrflinger/hardware_composer.cpp
index 00172a1..d937c88 100644
--- a/libs/vr/libvrflinger/hardware_composer.cpp
+++ b/libs/vr/libvrflinger/hardware_composer.cpp
@@ -210,9 +210,6 @@
 }
 
 void HardwareComposer::OnPostThreadResumed() {
-  if (request_display_callback_)
-    request_display_callback_(true);
-
   hwc2_hidl_->resetCommands();
 
   // HIDL HWC seems to have an internal race condition. If we submit a frame too
@@ -249,9 +246,6 @@
 
   // Trigger target-specific performance mode change.
   property_set(kDvrPerformanceProperty, "idle");
-
-  if (request_display_callback_)
-    request_display_callback_(false);
 }
 
 HWC::Error HardwareComposer::Validate(hwc2_display_t display) {
@@ -479,6 +473,9 @@
     pending_surfaces_ = std::move(surfaces);
   }
 
+  if (request_display_callback_)
+    request_display_callback_(!display_idle);
+
   // Set idle state based on whether there are any surfaces to handle.
   UpdatePostThreadState(PostThreadState::Idle, display_idle);
 }
diff --git a/services/surfaceflinger/DisplayHardware/HWC2.h b/services/surfaceflinger/DisplayHardware/HWC2.h
index 15a43df..b7376d0 100644
--- a/services/surfaceflinger/DisplayHardware/HWC2.h
+++ b/services/surfaceflinger/DisplayHardware/HWC2.h
@@ -35,6 +35,7 @@
 #include <unordered_map>
 #include <unordered_set>
 #include <vector>
+#include <map>
 
 namespace android {
     class Fence;
@@ -283,7 +284,9 @@
     bool mIsConnected;
     DisplayType mType;
     std::unordered_map<hwc2_layer_t, std::weak_ptr<Layer>> mLayers;
-    std::unordered_map<hwc2_config_t, std::shared_ptr<const Config>> mConfigs;
+    // The ordering in this map matters, for getConfigs(), when it is
+    // converted to a vector
+    std::map<hwc2_config_t, std::shared_ptr<const Config>> mConfigs;
 };
 
 // Convenience C++ class to access hwc2_device_t Layer functions directly.
diff --git a/services/vr/hardware_composer/impl/vr_hwc.cpp b/services/vr/hardware_composer/impl/vr_hwc.cpp
index 565e5d3..9bbb7f3 100644
--- a/services/vr/hardware_composer/impl/vr_hwc.cpp
+++ b/services/vr/hardware_composer/impl/vr_hwc.cpp
@@ -336,7 +336,19 @@
       *outValue = display_ptr->height();
       break;
     case IComposerClient::Attribute::VSYNC_PERIOD:
-      *outValue = 1000 * 1000 * 1000 / 30;  // 30fps
+      {
+        int error = 0;
+        auto display_client = display::DisplayClient::Create(&error);
+        if (!display_client) {
+          ALOGE("Could not connect to display service : %s(%d)",
+                strerror(error), error);
+          // Return a default value of 30 fps
+          *outValue = 1000 * 1000 * 1000 / 30;
+        } else {
+          auto metrics = display_client->GetDisplayMetrics();
+          *outValue = metrics.get().vsync_period_ns;
+        }
+      }
       break;
     case IComposerClient::Attribute::DPI_X:
     case IComposerClient::Attribute::DPI_Y: