Snap for 8857176 from b3666a84055a8a93d821584594e9de496f123bb5 to mainline-go-media-release

Change-Id: I8f81ebed0e5b057537310474211068662f052a37
diff --git a/build/sdk/Android.bp b/build/sdk/Android.bp
index a9ee675..9cafb8a 100644
--- a/build/sdk/Android.bp
+++ b/build/sdk/Android.bp
@@ -93,13 +93,10 @@
         },
 
         android: {
-            bootclasspath_fragments: [
-                // Adds the fragment and its contents to the sdk.
-                "art-bootclasspath-fragment",
-            ],
-
-            systemserverclasspath_fragments: [
-                "art-systemserverclasspath-fragment",
+            apexes: [
+                // Adds exportable dependencies of the API to the sdk,
+                // e.g. *classpath_fragments.
+                "com.android.art",
             ],
 
             compat_configs: [
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 149c8a9..2de3eb5 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -178,6 +178,7 @@
 #include "well_known_classes.h"
 
 #ifdef ART_TARGET_ANDROID
+#include <android/api-level.h>
 #include <android/set_abort_message.h>
 #include "com_android_apex.h"
 namespace apex = com::android::apex;
@@ -3358,13 +3359,21 @@
                                   const uint8_t* map_begin,
                                   const uint8_t* map_end,
                                   const std::string& file_name) {
+#ifdef ART_TARGET_ANDROID
   // Short-circuit the madvise optimization for background processes. This
   // avoids IO and memory contention with foreground processes, particularly
   // those involving app startup.
-  const Runtime* runtime = Runtime::Current();
-  if (runtime != nullptr && !runtime->InJankPerceptibleProcessState()) {
-    return;
+  // Note: We can only safely short-circuit the madvise on T+, as it requires
+  // the framework to always immediately notify ART of process states.
+  static const int kApiLevel = android_get_device_api_level();
+  const bool accurate_process_state_at_startup = kApiLevel >= __ANDROID_API_T__;
+  if (accurate_process_state_at_startup) {
+    const Runtime* runtime = Runtime::Current();
+    if (runtime != nullptr && !runtime->InJankPerceptibleProcessState()) {
+      return;
+    }
   }
+#endif  // ART_TARGET_ANDROID
 
   // Ideal blockTransferSize for madvising files (128KiB)
   static constexpr size_t kIdealIoTransferSizeBytes = 128*1024;
diff --git a/test/utils/regen-test-files b/test/utils/regen-test-files
index 237ec96..edf6dd1 100755
--- a/test/utils/regen-test-files
+++ b/test/utils/regen-test-files
@@ -736,18 +736,11 @@
 
     mts_test_shards = []
 
-    # ART test (gtest & run-test) shard(s).
-    # TODO: Also handle the case of gtests requiring root access to the device
-    # (`art_gtest_eng_only_module_names`).
+    # ART run-tests shard(s).
     art_run_test_module_names = [ART_RUN_TEST_MODULE_NAME_PREFIX + t for t in art_run_tests]
     art_run_test_shards = split_list(art_run_test_module_names, NUM_MTS_ART_RUN_TEST_SHARDS)
     for i in range(len(art_run_test_shards)):
       art_tests_shard_i_tests = art_run_test_shards[i]
-      # Append ART gtests to the last ART run-test shard for now.
-      # If needed, consider moving them to their own shard to increase
-      # the parallelization of code coverage runs.
-      if i + 1 == len(art_run_test_shards):
-        art_tests_shard_i_tests.extend(art_gtest_mts_user_module_names)
       art_tests_shard_i = self.create_mts_test_shard(
           "ART run-tests", art_tests_shard_i_tests, i, 2020,
           ["TODO(rpl): Find a way to express this list in a more concise fashion."])
@@ -775,6 +768,15 @@
         other_cts_libcore_tests_shard_num, 2021)
     mts_test_shards.append(other_cts_libcore_tests_shard)
 
+    # ART gtests shard.
+    # TODO: Also handle the case of gtests requiring root access to the device
+    # (`art_gtest_eng_only_module_names`).
+    art_gtests_shard_num = len(mts_test_shards)
+    art_gtests_shard_tests = art_gtest_mts_user_module_names
+    art_gtests_shard = self.create_mts_test_shard(
+        "ART gtests", art_gtests_shard_tests, art_gtests_shard_num, 2022)
+    mts_test_shards.append(art_gtests_shard)
+
     for s in mts_test_shards:
       s.regen_test_plan_file()
       s.regen_test_list_file()