Snap for 11220357 from 33158ffcd4efdc90f142faf911f12918f20a4c75 to 24Q1-release

Change-Id: I529f00b2c92ec0f2d8d8f08137c767ad3486132e
diff --git a/javatests/com/android/tradefed/device/NativeDeviceTest.java b/javatests/com/android/tradefed/device/NativeDeviceTest.java
index 1c2d1b6..2269673 100644
--- a/javatests/com/android/tradefed/device/NativeDeviceTest.java
+++ b/javatests/com/android/tradefed/device/NativeDeviceTest.java
@@ -2800,7 +2800,8 @@
 
         verify(mMockIDevice)
                 .executeShellCommand(
-                        Mockito.eq(String.format("logcat -v threadtime -t '%s'", dateFormatted)),
+                        Mockito.eq(String.format(
+                            "logcat -b all -v threadtime -t '%s'", dateFormatted)),
                         Mockito.any());
     }
 
@@ -2818,7 +2819,8 @@
 
         verify(mMockIDevice)
                 .executeShellCommand(
-                        Mockito.eq("logcat -v threadtime,uid -t '1512990942.012'"), Mockito.any());
+                        Mockito.eq("logcat -b all -v threadtime,uid -t '1512990942.012'"),
+                        Mockito.any());
     }
 
     @Test
diff --git a/javatests/res/device/wifi_status_output_1.txt b/javatests/res/device/wifi_status_output_1.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/javatests/res/device/wifi_status_output_1.txt
diff --git a/src/com/android/tradefed/config/filter/OptionFetcher.java b/src/com/android/tradefed/config/filter/OptionFetcher.java
index 4750300..63ed71f 100644
--- a/src/com/android/tradefed/config/filter/OptionFetcher.java
+++ b/src/com/android/tradefed/config/filter/OptionFetcher.java
@@ -46,7 +46,8 @@
                     "enable-tracing",
                     "auto-collect",
                     "skip-retry-in-presubmit",
-                    "skip-retrying-list");
+                    "skip-retrying-list",
+                    "remote-dynamic-sharding");
 
     private TradefedFeatureClient mClient;
 
diff --git a/src/com/android/tradefed/device/LogcatReceiver.java b/src/com/android/tradefed/device/LogcatReceiver.java
index 96a3acf..442c6c4 100644
--- a/src/com/android/tradefed/device/LogcatReceiver.java
+++ b/src/com/android/tradefed/device/LogcatReceiver.java
@@ -95,7 +95,7 @@
 
     /** Get the default logcat command, only append uid format if api level > 24. */
     public static String getDefaultLogcatCmd(ITestDevice device) {
-        String logcatCmd = "logcat -v threadtime";
+        String logcatCmd = "logcat -b all -v threadtime";
         // Logcat format support UID started from api level 24.
         try {
             if (SystemUtil.isLocalMode() || device.getApiLevel() >= 24) {
diff --git a/src/com/android/tradefed/invoker/shard/DynamicShardHelper.java b/src/com/android/tradefed/invoker/shard/DynamicShardHelper.java
index 9a8527f..1ecbc23 100644
--- a/src/com/android/tradefed/invoker/shard/DynamicShardHelper.java
+++ b/src/com/android/tradefed/invoker/shard/DynamicShardHelper.java
@@ -90,6 +90,14 @@
             shouldDelegate = true;
         }
 
+        // Check if any of the tests are not ITestSuite instances
+        // If not, make sure that intra-module sharding is off and delegate
+        if (config.getTests().stream()
+                .anyMatch(x -> !ITestSuite.class.isAssignableFrom(x.getClass()))) {
+            CLog.d("Found non-ITestSuite tests, falling back to strict sharding");
+            shouldDelegate = true;
+        }
+
         if (shouldDelegate) {
             CLog.d(
                     "Setting option 'remote-dynamic-sharding' to false since precondition checks"
@@ -190,14 +198,20 @@
         List<ITestSuite> allTests = new ArrayList<>();
         for (IRemoteTest test : config.getTests()) {
             if (test instanceof ITestSuite) {
+                ITestSuite suite = (ITestSuite) test;
                 // Disable intra-module-sharding when requesting dynamic sharding
                 // as it's currently not supported together.
-                ((ITestSuite) test).setIntraModuleSharding(false);
+                if (suite.getIntraModuleSharding()) {
+                    CLog.w(
+                            "Disabling intra-module sharding because it is not supported with"
+                                    + "dynamic sharding.");
+                    suite.setIntraModuleSharding(false);
+                }
+
                 allTests.addAll(
-                        ((ITestSuite) test)
-                                .split(1000000, testInfo).stream()
-                                        .map(x -> (ITestSuite) x)
-                                        .collect(Collectors.toList()));
+                        suite.split(1000000, testInfo).stream()
+                                .map(x -> (ITestSuite) x)
+                                .collect(Collectors.toList()));
             } else {
                 throw new HarnessRuntimeException(
                         "Test not an instance of ITestSuite, cannot execute this using dynamic"
diff --git a/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java b/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java
index 9811439..4a07962 100644
--- a/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java
+++ b/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java
@@ -346,6 +346,9 @@
         // only set bootloader image if this build doesn't have one already
         // TODO: move this logic to the BuildProvider step
         if (bootloaderVersion != null && localBuild.getBootloaderImageFile() == null) {
+            CLog.v("Bootloader image was not included in the build artifacts (%s, %s), "
+                + "fetching from blob service instead.",
+                localBuild.getDeviceBuildId(), localBuild.getDeviceBuildFlavor());
             localBuild.setBootloaderImageFile(
                     getFlashingResourcesRetriever()
                             .retrieveFile(getBootloaderFilePrefix(device), bootloaderVersion),
@@ -354,6 +357,9 @@
         String basebandVersion = resourceParser.getRequiredBasebandVersion();
         // only set baseband image if this build doesn't have one already
         if (basebandVersion != null && localBuild.getBasebandImageFile() == null) {
+            CLog.v("Baseband image was not included in the build artifacts (%s, %s), "
+                + "fetching from blob service instead.",
+                localBuild.getDeviceBuildId(), localBuild.getDeviceBuildFlavor());
             localBuild.setBasebandImage(getFlashingResourcesRetriever().retrieveFile(
                     BASEBAND_IMAGE_NAME, basebandVersion), basebandVersion);
         }
diff --git a/src/com/android/tradefed/testtype/suite/ITestSuite.java b/src/com/android/tradefed/testtype/suite/ITestSuite.java
index 4808c3d..d363823 100644
--- a/src/com/android/tradefed/testtype/suite/ITestSuite.java
+++ b/src/com/android/tradefed/testtype/suite/ITestSuite.java
@@ -1697,4 +1697,8 @@
     public void setIntraModuleSharding(boolean intraModuleSharding) {
         mIntraModuleSharding = intraModuleSharding;
     }
+
+    public boolean getIntraModuleSharding() {
+        return mIntraModuleSharding;
+    }
 }