Fix AndroidJUnitTest sharding with empty runner

With the new default empty runner, default to sharding
and let the run logic decide later if it was the right
choice.

Test: unit tests
Bug: 130538116
Change-Id: I36c194e94b2919371bcd17863555b2b7ab109d88
Merged-In: I36c194e94b2919371bcd17863555b2b7ab109d88
(cherry picked from commit 3d4b7349b2e1616d7ca4b12107e26601017183ef)
diff --git a/src/com/android/tradefed/testtype/AndroidJUnitTest.java b/src/com/android/tradefed/testtype/AndroidJUnitTest.java
index db50108..8e8ce81 100644
--- a/src/com/android/tradefed/testtype/AndroidJUnitTest.java
+++ b/src/com/android/tradefed/testtype/AndroidJUnitTest.java
@@ -404,6 +404,11 @@
      * Helper to return if the runner is one that support sharding.
      */
     private boolean isShardable() {
+        // Edge toward shardable if no explicit runner specified. The runner will be determined
+        // later and if not shardable only the first shard will run.
+        if (getRunnerName() == null) {
+            return true;
+        }
         return ListInstrumentationParser.SHARDABLE_RUNNERS.contains(getRunnerName());
     }
 
diff --git a/tests/src/com/android/tradefed/testtype/AndroidJUnitTestTest.java b/tests/src/com/android/tradefed/testtype/AndroidJUnitTestTest.java
index aaefa60..c291318 100644
--- a/tests/src/com/android/tradefed/testtype/AndroidJUnitTestTest.java
+++ b/tests/src/com/android/tradefed/testtype/AndroidJUnitTestTest.java
@@ -31,6 +31,7 @@
 import org.easymock.EasyMock;
 
 import java.io.File;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
@@ -376,6 +377,16 @@
         assertNull(mAndroidJUnitTest.split());
     }
 
+    /** Test that {@link AndroidJUnitTest#split()} returns the split if no runner specified. */
+    public void testSplit_noRunner() {
+        AndroidJUnitTest test = new AndroidJUnitTest();
+        test.setRunnerName(null);
+        assertNull(test.getRunnerName());
+        Collection<IRemoteTest> listTests = test.split(4);
+        assertNotNull(listTests);
+        assertEquals(4, listTests.size());
+    }
+
     /** Test that {@link AndroidJUnitTest#split(int)} returns 3 shards when requested to do so. */
     public void testSplit_threeShards() throws Exception {
         mAndroidJUnitTest = new AndroidJUnitTest();