From da7e23759660ebf76a184e4c4d981f11ef9e2653 Mon Sep 17 00:00:00 2001 From: Zhomart Mukhamejanov Date: Tue, 1 May 2018 12:50:55 -0700 Subject: updater_sample: Add streaming to PayloadSpec PayloadSpec - add streaming generator and tests - fix sample.json - fix tests - rename PackagePropertyFiles to PackageFiles, it has info not only about property files, and new name is shorter Bug: 77148467 Test: `mmma -j bootable/recovery/updater_sample` Change-Id: I9c1206c07c37183f13d3c25940f12981ca85b1b4 Signed-off-by: Zhomart Mukhamejanov --- .../systemupdatersample/util/PayloadSpecs.java | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'updater_sample/src/com/example/android/systemupdatersample/util/PayloadSpecs.java') diff --git a/updater_sample/src/com/example/android/systemupdatersample/util/PayloadSpecs.java b/updater_sample/src/com/example/android/systemupdatersample/util/PayloadSpecs.java index 43c8d75e2..4db448a31 100644 --- a/updater_sample/src/com/example/android/systemupdatersample/util/PayloadSpecs.java +++ b/updater_sample/src/com/example/android/systemupdatersample/util/PayloadSpecs.java @@ -16,9 +16,6 @@ package com.example.android.systemupdatersample.util; -import android.annotation.TargetApi; -import android.os.Build; - import com.example.android.systemupdatersample.PayloadSpec; import java.io.BufferedReader; @@ -26,6 +23,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; import java.util.Enumeration; @@ -34,7 +32,6 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; /** The helper class that creates {@link PayloadSpec}. */ -@TargetApi(Build.VERSION_CODES.N) public final class PayloadSpecs { /** @@ -68,14 +65,14 @@ public final class PayloadSpecs { } long length = entry.getCompressedSize(); - if (PackagePropertyFiles.PAYLOAD_BINARY_FILE_NAME.equals(name)) { + if (PackageFiles.PAYLOAD_BINARY_FILE_NAME.equals(name)) { if (entry.getMethod() != ZipEntry.STORED) { throw new IOException("Invalid compression method."); } payloadFound = true; payloadOffset = offset; payloadSize = length; - } else if (PackagePropertyFiles.PAYLOAD_PROPERTIES_FILE_NAME.equals(name)) { + } else if (PackageFiles.PAYLOAD_PROPERTIES_FILE_NAME.equals(name)) { InputStream inputStream = zip.getInputStream(entry); if (inputStream != null) { BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); @@ -100,6 +97,21 @@ public final class PayloadSpecs { .build(); } + /** + * Creates a {@link PayloadSpec} for streaming update. + */ + public static PayloadSpec forStreaming(String updateUrl, + long offset, + long size, + File propertiesFile) throws IOException { + return PayloadSpec.newBuilder() + .url(updateUrl) + .offset(offset) + .size(size) + .properties(Files.readAllLines(propertiesFile.toPath())) + .build(); + } + /** * Converts an {@link PayloadSpec} to a string. */ -- cgit v1.2.3