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/ui/MainActivity.java | 2 +- .../systemupdatersample/util/PackageFiles.java | 59 ++++++++++++++++++++++ .../util/PackagePropertyFiles.java | 42 --------------- .../systemupdatersample/util/PayloadSpecs.java | 24 ++++++--- .../util/UpdateEngineErrorCodes.java | 1 + .../util/UpdateEngineStatuses.java | 2 +- 6 files changed, 80 insertions(+), 50 deletions(-) create mode 100644 updater_sample/src/com/example/android/systemupdatersample/util/PackageFiles.java delete mode 100644 updater_sample/src/com/example/android/systemupdatersample/util/PackagePropertyFiles.java (limited to 'updater_sample/src') diff --git a/updater_sample/src/com/example/android/systemupdatersample/ui/MainActivity.java b/updater_sample/src/com/example/android/systemupdatersample/ui/MainActivity.java index 8507a9e84..9f1e5d170 100644 --- a/updater_sample/src/com/example/android/systemupdatersample/ui/MainActivity.java +++ b/updater_sample/src/com/example/android/systemupdatersample/ui/MainActivity.java @@ -297,7 +297,7 @@ public class MainActivity extends Activity { } /** - * Helper class to delegate UpdateEngine callbacks to MainActivity + * Helper class to delegate {@code update_engine} callbacks to MainActivity */ class UpdateEngineCallbackImpl extends UpdateEngineCallback { @Override diff --git a/updater_sample/src/com/example/android/systemupdatersample/util/PackageFiles.java b/updater_sample/src/com/example/android/systemupdatersample/util/PackageFiles.java new file mode 100644 index 000000000..b485234ea --- /dev/null +++ b/updater_sample/src/com/example/android/systemupdatersample/util/PackageFiles.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.systemupdatersample.util; + +/** Utility class for an OTA package. */ +public final class PackageFiles { + + /** + * Directory used to perform updates. + */ + public static final String OTA_PACKAGE_DIR = "/data/ota_package"; + + /** + * update payload, it will be passed to {@code UpdateEngine#applyPayload}. + */ + public static final String PAYLOAD_BINARY_FILE_NAME = "payload.bin"; + + /** + * Currently, when calling {@code UpdateEngine#applyPayload} to perform actions + * that don't require network access (e.g. change slot), update_engine still + * talks to the server to download/verify file. + * {@code update_engine} might throw error when rebooting if {@code UpdateEngine#applyPayload} + * is not supplied right headers and tokens. + * This behavior might change in future android versions. + * + * To avoid extra network request in {@code update_engine}, this file has to be + * downloaded and put in {@code OTA_PACKAGE_DIR}. + */ + public static final String PAYLOAD_METADATA_FILE_NAME = "payload_metadata.bin"; + + public static final String PAYLOAD_PROPERTIES_FILE_NAME = "payload_properties.txt"; + + /** The zip entry in an A/B OTA package, which will be used by update_verifier. */ + public static final String CARE_MAP_FILE_NAME = "care_map.txt"; + + public static final String METADATA_FILE_NAME = "metadata"; + + /** + * The zip file that claims the compatibility of the update package to check against the Android + * framework to ensure that the package can be installed on the device. + */ + public static final String COMPATIBILITY_ZIP_FILE_NAME = "compatibility.zip"; + + private PackageFiles() {} +} diff --git a/updater_sample/src/com/example/android/systemupdatersample/util/PackagePropertyFiles.java b/updater_sample/src/com/example/android/systemupdatersample/util/PackagePropertyFiles.java deleted file mode 100644 index 3988b5928..000000000 --- a/updater_sample/src/com/example/android/systemupdatersample/util/PackagePropertyFiles.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.android.systemupdatersample.util; - -/** Utility class for property files in a package. */ -public final class PackagePropertyFiles { - - public static final String PAYLOAD_BINARY_FILE_NAME = "payload.bin"; - - public static final String PAYLOAD_HEADER_FILE_NAME = "payload_header.bin"; - - public static final String PAYLOAD_METADATA_FILE_NAME = "payload_metadata.bin"; - - public static final String PAYLOAD_PROPERTIES_FILE_NAME = "payload_properties.txt"; - - /** The zip entry in an A/B OTA package, which will be used by update_verifier. */ - public static final String CARE_MAP_FILE_NAME = "care_map.txt"; - - public static final String METADATA_FILE_NAME = "metadata"; - - /** - * The zip file that claims the compatibility of the update package to check against the Android - * framework to ensure that the package can be installed on the device. - */ - public static final String COMPATIBILITY_ZIP_FILE_NAME = "compatibility.zip"; - - private PackagePropertyFiles() {} -} 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. */ diff --git a/updater_sample/src/com/example/android/systemupdatersample/util/UpdateEngineErrorCodes.java b/updater_sample/src/com/example/android/systemupdatersample/util/UpdateEngineErrorCodes.java index e63da6298..6d319c5af 100644 --- a/updater_sample/src/com/example/android/systemupdatersample/util/UpdateEngineErrorCodes.java +++ b/updater_sample/src/com/example/android/systemupdatersample/util/UpdateEngineErrorCodes.java @@ -50,6 +50,7 @@ public final class UpdateEngineErrorCodes { CODE_TO_NAME_MAP.put(10, "PAYLOAD_HASH_MISMATCH_ERROR"); CODE_TO_NAME_MAP.put(11, "PAYLOAD_SIZE_MISMATCH_ERROR"); CODE_TO_NAME_MAP.put(12, "DOWNLOAD_PAYLOAD_VERIFICATION_ERROR"); + CODE_TO_NAME_MAP.put(15, "NEW_ROOTFS_VERIFICATION_ERROR"); CODE_TO_NAME_MAP.put(20, "DOWNLOAD_STATE_INITIALIZATION_ERROR"); CODE_TO_NAME_MAP.put(48, "USER_CANCELLED"); CODE_TO_NAME_MAP.put(52, "UPDATED_BUT_NOT_ACTIVE"); diff --git a/updater_sample/src/com/example/android/systemupdatersample/util/UpdateEngineStatuses.java b/updater_sample/src/com/example/android/systemupdatersample/util/UpdateEngineStatuses.java index 6203b201a..a96f19d84 100644 --- a/updater_sample/src/com/example/android/systemupdatersample/util/UpdateEngineStatuses.java +++ b/updater_sample/src/com/example/android/systemupdatersample/util/UpdateEngineStatuses.java @@ -20,7 +20,7 @@ import android.util.SparseArray; /** * Helper class to work with update_engine's error codes. - * Many error codes are defined in {@link UpdateEngine.UpdateStatusConstants}, + * Many error codes are defined in {@code UpdateEngine.UpdateStatusConstants}, * but you can find more in system/update_engine/common/error_code.h. */ public final class UpdateEngineStatuses { -- cgit v1.2.3