Merge "Surface: Use async lock/unlock in copyBlt"
diff --git a/cmds/installd/dexopt.cpp b/cmds/installd/dexopt.cpp
index a2bce41..5025fde 100644
--- a/cmds/installd/dexopt.cpp
+++ b/cmds/installd/dexopt.cpp
@@ -1150,7 +1150,13 @@
             ALOGE("installd cannot compute input vdex location for '%s'\n", path);
             return -1;
         }
-        in_vdex_fd.reset(open(in_vdex_path_str.c_str(), O_RDONLY, 0));
+        if (dexopt_action == DEX2OAT_FOR_BOOT_IMAGE) {
+            // When we dex2oat because iof boot image change, we are going to update
+            // in-place the vdex file.
+            in_vdex_fd.reset(open(in_vdex_path_str.c_str(), O_RDWR, 0));
+        } else {
+            in_vdex_fd.reset(open(in_vdex_path_str.c_str(), O_RDONLY, 0));
+        }
     }
 
     // Infer the name of the output VDEX and create it.
@@ -1158,14 +1164,26 @@
     if (out_vdex_path_str.empty()) {
         return -1;
     }
-    Dex2oatFileWrapper<std::function<void ()>> out_vdex_fd(
-            open_output_file(out_vdex_path_str.c_str(), /*recreate*/true, /*permissions*/0644),
-            [out_vdex_path_str]() { unlink(out_vdex_path_str.c_str()); });
-    if (out_vdex_fd.get() < 0) {
-        ALOGE("installd cannot open '%s' for output during dexopt\n", out_vdex_path_str.c_str());
-        return -1;
+    Dex2oatFileWrapper<std::function<void ()>> out_vdex_wrapper_fd;
+    int out_vdex_fd = -1;
+
+    // If we are compiling because the boot image is out of date, we do not
+    // need to recreate a vdex, and can use the same existing one.
+    if (dexopt_action == DEX2OAT_FOR_BOOT_IMAGE &&
+            in_vdex_fd != -1 &&
+            in_vdex_path_str == out_vdex_path_str) {
+        out_vdex_fd = in_vdex_fd;
+    } else {
+        out_vdex_wrapper_fd.reset(
+              open_output_file(out_vdex_path_str.c_str(), /*recreate*/true, /*permissions*/0644),
+              [out_vdex_path_str]() { unlink(out_vdex_path_str.c_str()); });
+        out_vdex_fd = out_vdex_wrapper_fd.get();
+        if (out_vdex_fd < 0) {
+            ALOGE("installd cannot open '%s' for output during dexopt\n", out_vdex_path_str.c_str());
+            return -1;
+        }
     }
-    if (!set_permissions_and_ownership(out_vdex_fd.get(), is_public,
+    if (!set_permissions_and_ownership(out_vdex_fd, is_public,
                 uid, out_vdex_path_str.c_str())) {
         return -1;
     }
@@ -1248,7 +1266,7 @@
             run_patchoat(input_fd.get(),
                          in_vdex_fd.get(),
                          out_oat_fd.get(),
-                         out_vdex_fd.get(),
+                         out_vdex_fd,
                          input_file,
                          in_vdex_path_str.c_str(),
                          out_oat_path,
@@ -1261,7 +1279,7 @@
             run_dex2oat(input_fd.get(),
                         out_oat_fd.get(),
                         in_vdex_fd.get(),
-                        out_vdex_fd.get(),
+                        out_vdex_fd,
                         image_fd.get(),
                         input_file_name,
                         out_oat_path,
@@ -1292,7 +1310,7 @@
 
     // We've been successful, don't delete output.
     out_oat_fd.SetCleanup(false);
-    out_vdex_fd.SetCleanup(false);
+    out_vdex_wrapper_fd.SetCleanup(false);
     image_fd.SetCleanup(false);
     reference_profile_fd.SetCleanup(false);
 
diff --git a/include/ui/Rect.h b/include/ui/Rect.h
index a8513a9..b0dccfd 100644
--- a/include/ui/Rect.h
+++ b/include/ui/Rect.h
@@ -22,6 +22,7 @@
 #include <utils/TypeHelpers.h>
 #include <ui/Point.h>
 
+#include <android/log.h>
 #include <android/rect.h>
 
 namespace android {
diff --git a/opengl/libagl/egl.cpp b/opengl/libagl/egl.cpp
index bb20409..4e9cb5b 100644
--- a/opengl/libagl/egl.cpp
+++ b/opengl/libagl/egl.cpp
@@ -1459,6 +1459,9 @@
     if (egl_display_t::is_valid(dpy) == EGL_FALSE)
         return setError(EGL_BAD_DISPLAY, EGL_FALSE);
 
+    if (ggl_unlikely(num_config==NULL))
+        return setError(EGL_BAD_PARAMETER, EGL_FALSE);
+
     GLint numConfigs = NELEM(gConfigs);
     if (!configs) {
         *num_config = numConfigs;
@@ -1478,8 +1481,8 @@
 {
     if (egl_display_t::is_valid(dpy) == EGL_FALSE)
         return setError(EGL_BAD_DISPLAY, EGL_FALSE);
-    
-    if (ggl_unlikely(num_config==0)) {
+
+    if (ggl_unlikely(num_config==NULL)) {
         return setError(EGL_BAD_PARAMETER, EGL_FALSE);
     }
 
diff --git a/opengl/libs/Android.bp b/opengl/libs/Android.bp
index cbdd502..60c4b36 100644
--- a/opengl/libs/Android.bp
+++ b/opengl/libs/Android.bp
@@ -26,27 +26,28 @@
     name: "libEGL.ndk",
     symbol_file: "libEGL.map.txt",
     first_version: "9",
+    unversioned_until: "current",
 }
 
 ndk_library {
     name: "libGLESv1_CM.ndk",
     symbol_file: "libGLESv1_CM.map.txt",
     first_version: "9",
+    unversioned_until: "current",
 }
 
 ndk_library {
     name: "libGLESv2.ndk",
     symbol_file: "libGLESv2.map.txt",
     first_version: "9",
+    unversioned_until: "current",
 }
 
 ndk_library {
     name: "libGLESv3.ndk",
     symbol_file: "libGLESv3.map.txt",
     first_version: "18",
-
-    // https://github.com/android-ndk/ndk/issues/265
-    unversioned_until: "24",
+    unversioned_until: "current",
 }
 
 cc_defaults {
diff --git a/vulkan/libvulkan/Android.bp b/vulkan/libvulkan/Android.bp
index 34697d1..147cc56 100644
--- a/vulkan/libvulkan/Android.bp
+++ b/vulkan/libvulkan/Android.bp
@@ -17,6 +17,7 @@
     name: "libvulkan.ndk",
     symbol_file: "libvulkan.map.txt",
     first_version: "24",
+    unversioned_until: "current",
 }
 
 cc_library_shared {