updater_sample: add streaming support

- UpdateConfigs: add helper methods for streaming
- add PrepareStreamingService intent service

Test: manually and junit4
Bug: 77148143
Change-Id: I61711eb9abe051987e725fbd94f8cd029ff21dd3
diff --git a/updater_sample/src/com/example/android/systemupdatersample/util/UpdateConfigs.java b/updater_sample/src/com/example/android/systemupdatersample/util/UpdateConfigs.java
index 71d4df8..5080cb6 100644
--- a/updater_sample/src/com/example/android/systemupdatersample/util/UpdateConfigs.java
+++ b/updater_sample/src/com/example/android/systemupdatersample/util/UpdateConfigs.java
@@ -26,14 +26,16 @@
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.Optional;
 
 /**
  * Utility class for working with json update configurations.
  */
 public final class UpdateConfigs {
 
-    private static final String UPDATE_CONFIGS_ROOT = "configs/";
+    public static final String UPDATE_CONFIGS_ROOT = "configs/";
 
     /**
      * @param configs update configs
@@ -48,13 +50,12 @@
      * @return configs root directory
      */
     public static String getConfigsRoot(Context context) {
-        return Paths.get(context.getFilesDir().toString(),
-                UPDATE_CONFIGS_ROOT).toString();
+        return Paths
+                .get(context.getFilesDir().toString(), UPDATE_CONFIGS_ROOT)
+                .toString();
     }
 
     /**
-     * It parses only {@code .json} files.
-     *
      * @param context application context
      * @return list of configs from directory {@link UpdateConfigs#getConfigsRoot}
      */
@@ -80,5 +81,20 @@
         return configs;
     }
 
+    /**
+     * @param filename searches by given filename
+     * @param config searches in {@link UpdateConfig#getStreamingMetadata()}
+     * @return offset and size of {@code filename} in the package zip file
+     *         stored as {@link UpdateConfig.PackageFile}.
+     */
+    public static Optional<UpdateConfig.PackageFile> getPropertyFile(
+            final String filename,
+            UpdateConfig config) {
+        return Arrays
+                .stream(config.getStreamingMetadata().getPropertyFiles())
+                .filter(file -> filename.equals(file.getFilename()))
+                .findFirst();
+    }
+
     private UpdateConfigs() {}
 }