Move sharding functions for reuse

Move shardPaths and shardTests to android.ShardPaths and
android.ShardStrings for reuse in other packages.

Test: m checkbuild
Change-Id: I868802872c73616b80f56cbf11f959c01a8b793a
diff --git a/java/robolectric.go b/java/robolectric.go
index dbf54c9..b7646eb 100644
--- a/java/robolectric.go
+++ b/java/robolectric.go
@@ -123,25 +123,6 @@
 	}
 }
 
-func shardTests(paths []string, shards int) [][]string {
-	if shards > len(paths) {
-		shards = len(paths)
-	}
-	if shards == 0 {
-		return nil
-	}
-	ret := make([][]string, 0, shards)
-	shardSize := (len(paths) + shards - 1) / shards
-	for len(paths) > shardSize {
-		ret = append(ret, paths[0:shardSize])
-		paths = paths[shardSize:]
-	}
-	if len(paths) > 0 {
-		ret = append(ret, paths)
-	}
-	return ret
-}
-
 func generateRoboTestConfig(ctx android.ModuleContext, outputFile android.WritablePath, instrumentedApp *AndroidApp) {
 	manifest := instrumentedApp.mergedManifestFile
 	resourceApk := instrumentedApp.outputFile
@@ -183,7 +164,9 @@
 	entries.ExtraFooters = []android.AndroidMkExtraFootersFunc{
 		func(w io.Writer, name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
 			if s := r.robolectricProperties.Test_options.Shards; s != nil && *s > 1 {
-				shards := shardTests(r.tests, int(*s))
+				numShards := int(*s)
+				shardSize := (len(r.tests) + numShards - 1) / numShards
+				shards := android.ShardStrings(r.tests, shardSize)
 				for i, shard := range shards {
 					r.writeTestRunner(w, name, "Run"+name+strconv.Itoa(i), shard)
 				}