Snap tm-dev to android13-tests-dev

Bug:259849956

Merge ab/9299233

Merged-In: I347582df87e2bce0142d0210519f013d060a0180
Change-Id: I7276ba4aab3068af89c3f2a048fad58ae445407a
diff --git a/libnativebridge/tests/Android.bp b/libnativebridge/tests/Android.bp
index b787fba..57d26c0 100644
--- a/libnativebridge/tests/Android.bp
+++ b/libnativebridge/tests/Android.bp
@@ -110,6 +110,14 @@
     // unloading, so each test needs to be its own process.
     test_per_src: true,
 
+    // Disable pre-submit host unit-testing for this test module, as
+    // it is not compatible with TradeFed (because of the use of the
+    // `test_per_src` feature above) and meant to be executed with the
+    // `runtests.sh` script instead.
+    test_options: {
+        unit_test: false,
+    },
+
     srcs: [
         "NativeBridgeApi.c",
         "CodeCacheCreate_test.cpp",
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index c8dbc75..f6f98e6 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -10298,6 +10298,15 @@
   UNREACHABLE();
 }
 
+void ClassLinker::RemoveDexFromCaches(const DexFile& dex_file) {
+  ReaderMutexLock mu(Thread::Current(), *Locks::dex_lock_);
+
+  auto it = dex_caches_.find(&dex_file);
+  if (it != dex_caches_.end()) {
+      dex_caches_.erase(it);
+  }
+}
+
 // Instantiate ClassLinker::AllocClass.
 template ObjPtr<mirror::Class> ClassLinker::AllocClass</* kMovable= */ true>(
     Thread* self,
diff --git a/runtime/class_linker.h b/runtime/class_linker.h
index 3b20c75b..a3a1adf 100644
--- a/runtime/class_linker.h
+++ b/runtime/class_linker.h
@@ -837,6 +837,7 @@
   virtual bool DenyAccessBasedOnPublicSdk(const char* type_descriptor) const;
   // Enable or disable public sdk checks.
   virtual void SetEnablePublicSdkChecks(bool enabled);
+  void RemoveDexFromCaches(const DexFile& dex_file);
 
  protected:
   virtual bool InitializeClass(Thread* self,
diff --git a/runtime/native/dalvik_system_DexFile.cc b/runtime/native/dalvik_system_DexFile.cc
index d714206..ecb9010 100644
--- a/runtime/native/dalvik_system_DexFile.cc
+++ b/runtime/native/dalvik_system_DexFile.cc
@@ -377,6 +377,7 @@
         if (!class_linker->IsDexFileRegistered(soa.Self(), *dex_file)) {
           // Clear the element in the array so that we can call close again.
           long_dex_files->Set(i, 0);
+          class_linker->RemoveDexFromCaches(*dex_file);
           delete dex_file;
         } else {
           all_deleted = false;