Merge "Adjust ResolveRelativeEncodedDexLocation."
diff --git a/build/apex/Android.bp b/build/apex/Android.bp
index aa199d3..9bf6551 100644
--- a/build/apex/Android.bp
+++ b/build/apex/Android.bp
@@ -85,6 +85,15 @@
     "libopenjdk",
 ]
 
+// Java libraries
+libcore_target_java_libs = [
+    "core-oj",
+    "core-libart",
+    "okhttp",
+    "bouncycastle",
+    "apache-xml",
+]
+
 apex_key {
     name: "com.android.runtime.key",
     public_key: "com.android.runtime.avbpubkey",
@@ -108,6 +117,7 @@
     name: "com.android.runtime.release",
     compile_multilib: "both",
     manifest: "manifest.json",
+    java_libs: libcore_target_java_libs,
     native_shared_libs: art_runtime_base_native_shared_libs
         + bionic_native_shared_libs
         + libcore_native_shared_libs,
@@ -137,6 +147,7 @@
     name: "com.android.runtime.debug",
     compile_multilib: "both",
     manifest: "manifest.json",
+    java_libs: libcore_target_java_libs,
     native_shared_libs: art_runtime_base_native_shared_libs
         + art_runtime_debug_native_shared_libs
         + bionic_native_shared_libs
diff --git a/build/apex/ld.config.txt b/build/apex/ld.config.txt
index 9e02f9f..d5eb9fa 100644
--- a/build/apex/ld.config.txt
+++ b/build/apex/ld.config.txt
@@ -16,6 +16,7 @@
 # libart.
 namespace.default.visible = true
 namespace.default.search.paths = /apex/com.android.runtime/${LIB}
+namespace.default.asan.search.paths = /apex/com.android.runtime/${LIB}
 # odex files are in /system/framework. dalvikvm has to be able to dlopen the
 # files for CTS.
 namespace.default.permitted.paths = /system/framework
@@ -26,6 +27,7 @@
 # Keep in sync with the default namespace in /system/etc/ld.config.txt.
 namespace.platform.isolated = true
 namespace.platform.search.paths = /system/${LIB}
+namespace.platform.asan.search.paths = /data/asan/system/${LIB}
 namespace.platform.links = default
 namespace.platform.link.default.shared_libs  = libart.so:libartd.so
 namespace.platform.link.default.shared_libs += libnativebridge.so
@@ -47,6 +49,7 @@
 namespace.conscrypt.visible = true
 
 namespace.conscrypt.search.paths = /apex/com.android.conscrypt/${LIB}
+namespace.conscrypt.asan.search.paths = /apex/com.android.conscrypt/${LIB}
 namespace.conscrypt.links = platform
 namespace.conscrypt.link.platform.shared_libs  = libc.so
 namespace.conscrypt.link.platform.shared_libs += libm.so
diff --git a/build/apex/runtests.sh b/build/apex/runtests.sh
index 4c0e772..83c42bc 100755
--- a/build/apex/runtests.sh
+++ b/build/apex/runtests.sh
@@ -144,6 +144,10 @@
     || fail_check "Cannot find library '$1' in mounted image"
 }
 
+function check_java_library {
+  [[ -x "$mount_point/javalib/$1" ]] || fail_check "Cannot find java library '$1' in mounted image"
+}
+
 # Check contents of APEX payload located in `$mount_point`.
 function check_release_contents {
   # Check that the mounted image contains an APEX manifest.
@@ -189,6 +193,15 @@
   #   ...
   #
   # ?
+
+  # TODO: Enable for host
+  if [ $1 != "com.android.runtime.host" ]; then
+    check_java_library core-oj.jar
+    check_java_library core-libart.jar
+    check_java_library okhttp.jar
+    check_java_library bouncycastle.jar
+    check_java_library apache-xml.jar
+  fi
 }
 
 # Check debug contents of APEX payload located in `$mount_point`.
@@ -286,7 +299,7 @@
 
 # Run tests on APEX package.
 say "Checking APEX package $apex_module"
-check_release_contents
+check_release_contents "$apex_module"
 
 # Clean up.
 trap - EXIT
@@ -319,7 +332,7 @@
 
 # Run tests on APEX package.
 say "Checking APEX package $apex_module"
-check_release_contents
+check_release_contents "$apex_module"
 check_debug_contents
 # Check for files pulled in from debug target-only oatdump.
 check_binary oatdump
@@ -390,7 +403,7 @@
 
 # Run tests on APEX package.
 say "Checking APEX package $apex_module"
-check_release_contents
+check_release_contents "$apex_module"
 check_debug_contents
 
 # Clean up.
diff --git a/runtime/native/dalvik_system_DexFile.cc b/runtime/native/dalvik_system_DexFile.cc
index daf02fe..4f9cf70 100644
--- a/runtime/native/dalvik_system_DexFile.cc
+++ b/runtime/native/dalvik_system_DexFile.cc
@@ -244,7 +244,7 @@
   }
 
   size_t length = static_cast<size_t>(end - start);
-  memcpy(dex_mem_map.Begin(), base_address, length);
+  memcpy(dex_mem_map.Begin(), base_address + start, length);
   return CreateSingleDexFileCookie(env, std::move(dex_mem_map));
 }
 
diff --git a/tools/veridex/hidden_api.h b/tools/veridex/hidden_api.h
index 3c7f29a..e1b67a2 100644
--- a/tools/veridex/hidden_api.h
+++ b/tools/veridex/hidden_api.h
@@ -41,7 +41,7 @@
   }
 
   bool IsInAnyList(const std::string& name) const {
-    return GetApiList(name).IsEmpty();
+    return !GetApiList(name).IsEmpty();
   }
 
   static std::string GetApiMethodName(const DexFile& dex_file, uint32_t method_index);
diff --git a/tools/veridex/hidden_api_finder.cc b/tools/veridex/hidden_api_finder.cc
index 3cd7c95..fe6d88a 100644
--- a/tools/veridex/hidden_api_finder.cc
+++ b/tools/veridex/hidden_api_finder.cc
@@ -180,6 +180,7 @@
   for (const std::pair<const std::string,
                        std::vector<MethodReference>>& pair : method_locations_) {
     hiddenapi::ApiList api_list = hidden_api_.GetApiList(pair.first);
+    CHECK(api_list.IsValid());
     stats->api_counts[api_list.GetIntValue()]++;
     os << "#" << ++stats->count << ": Linking " << api_list << " " << pair.first << " use(s):";
     os << std::endl;
@@ -191,6 +192,7 @@
   for (const std::pair<const std::string,
                        std::vector<MethodReference>>& pair : field_locations_) {
     hiddenapi::ApiList api_list = hidden_api_.GetApiList(pair.first);
+    CHECK(api_list.IsValid());
     stats->api_counts[api_list.GetIntValue()]++;
     os << "#" << ++stats->count << ": Linking " << api_list << " " << pair.first << " use(s):";
     os << std::endl;