diff options
author | Zhomart Mukhamejanov <zhomart@google.com> | 2018-12-17 23:19:25 +0100 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-12-17 23:19:25 +0100 |
commit | 2e33cbeb2035377691c8ea80e062bb4203aa2d06 (patch) | |
tree | 77198b8606c98d6e1aa3dbe74267d0a76c18039a /updater_sample/src/com/example/android/systemupdatersample/services | |
parent | Merge "use epoll_create1" (diff) | |
parent | Add PrepareUpdateService. (diff) | |
download | android_bootable_recovery-2e33cbeb2035377691c8ea80e062bb4203aa2d06.tar android_bootable_recovery-2e33cbeb2035377691c8ea80e062bb4203aa2d06.tar.gz android_bootable_recovery-2e33cbeb2035377691c8ea80e062bb4203aa2d06.tar.bz2 android_bootable_recovery-2e33cbeb2035377691c8ea80e062bb4203aa2d06.tar.lz android_bootable_recovery-2e33cbeb2035377691c8ea80e062bb4203aa2d06.tar.xz android_bootable_recovery-2e33cbeb2035377691c8ea80e062bb4203aa2d06.tar.zst android_bootable_recovery-2e33cbeb2035377691c8ea80e062bb4203aa2d06.zip |
Diffstat (limited to '')
-rw-r--r-- | updater_sample/src/com/example/android/systemupdatersample/services/PrepareUpdateService.java (renamed from updater_sample/src/com/example/android/systemupdatersample/services/PrepareStreamingService.java) | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/updater_sample/src/com/example/android/systemupdatersample/services/PrepareStreamingService.java b/updater_sample/src/com/example/android/systemupdatersample/services/PrepareUpdateService.java index 931404857..06581bee3 100644 --- a/updater_sample/src/com/example/android/systemupdatersample/services/PrepareStreamingService.java +++ b/updater_sample/src/com/example/android/systemupdatersample/services/PrepareUpdateService.java @@ -28,6 +28,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.RecoverySystem; import android.os.ResultReceiver; +import android.os.UpdateEngine; import android.util.Log; import com.example.android.systemupdatersample.PayloadSpec; @@ -49,10 +50,10 @@ import java.util.Optional; * without downloading the whole package. And it constructs {@link PayloadSpec}. * All this work required to install streaming A/B updates. * - * PrepareStreamingService runs on it's own thread. It will notify activity + * PrepareUpdateService runs on it's own thread. It will notify activity * using interface {@link UpdateResultCallback} when update is ready to install. */ -public class PrepareStreamingService extends IntentService { +public class PrepareUpdateService extends IntentService { /** * UpdateResultCallback result codes. @@ -61,62 +62,63 @@ public class PrepareStreamingService extends IntentService { public static final int RESULT_CODE_ERROR = 1; /** - * This interface is used to send results from {@link PrepareStreamingService} to + * Extra params that will be sent to IntentService. + */ + public static final String EXTRA_PARAM_CONFIG = "config"; + public static final String EXTRA_PARAM_RESULT_RECEIVER = "result-receiver"; + + /** + * This interface is used to send results from {@link PrepareUpdateService} to * {@code MainActivity}. */ public interface UpdateResultCallback { - /** * Invoked when files are downloaded and payload spec is constructed. * - * @param resultCode result code, values are defined in {@link PrepareStreamingService} + * @param resultCode result code, values are defined in {@link PrepareUpdateService} * @param payloadSpec prepared payload spec for streaming update */ void onReceiveResult(int resultCode, PayloadSpec payloadSpec); } /** - * Starts PrepareStreamingService. + * Starts PrepareUpdateService. * - * @param context application context - * @param config update config + * @param context application context + * @param config update config * @param resultCallback callback that will be called when the update is ready to be installed */ public static void startService(Context context, UpdateConfig config, + Handler handler, UpdateResultCallback resultCallback) { - Log.d(TAG, "Starting PrepareStreamingService"); - ResultReceiver receiver = new CallbackResultReceiver(new Handler(), resultCallback); - Intent intent = new Intent(context, PrepareStreamingService.class); + Log.d(TAG, "Starting PrepareUpdateService"); + ResultReceiver receiver = new CallbackResultReceiver(handler, resultCallback); + Intent intent = new Intent(context, PrepareUpdateService.class); intent.putExtra(EXTRA_PARAM_CONFIG, config); intent.putExtra(EXTRA_PARAM_RESULT_RECEIVER, receiver); context.startService(intent); } - public PrepareStreamingService() { + public PrepareUpdateService() { super(TAG); } - private static final String TAG = "PrepareStreamingService"; - - /** - * Extra params that will be sent from Activity to IntentService. - */ - private static final String EXTRA_PARAM_CONFIG = "config"; - private static final String EXTRA_PARAM_RESULT_RECEIVER = "result-receiver"; + private static final String TAG = "PrepareUpdateService"; /** * The files that should be downloaded before streaming. */ private static final ImmutableSet<String> PRE_STREAMING_FILES_SET = ImmutableSet.of( - PackageFiles.CARE_MAP_FILE_NAME, - PackageFiles.COMPATIBILITY_ZIP_FILE_NAME, - PackageFiles.METADATA_FILE_NAME, - PackageFiles.PAYLOAD_PROPERTIES_FILE_NAME + PackageFiles.CARE_MAP_FILE_NAME, + PackageFiles.COMPATIBILITY_ZIP_FILE_NAME, + PackageFiles.METADATA_FILE_NAME, + PackageFiles.PAYLOAD_PROPERTIES_FILE_NAME ); private final PayloadSpecs mPayloadSpecs = new PayloadSpecs(); + private final UpdateEngine mUpdateEngine = new UpdateEngine(); @Override protected void onHandleIntent(Intent intent) { @@ -142,6 +144,10 @@ public class PrepareStreamingService extends IntentService { private PayloadSpec execute(UpdateConfig config) throws IOException, PreparationFailedException { + if (config.getInstallType() == UpdateConfig.AB_INSTALL_TYPE_NON_STREAMING) { + return mPayloadSpecs.forNonStreaming(config.getUpdatePackageFile()); + } + downloadPreStreamingFiles(config, OTA_PACKAGE_DIR); Optional<UpdateConfig.PackageFile> payloadBinary = @@ -176,6 +182,7 @@ public class PrepareStreamingService extends IntentService { * Downloads files defined in {@link UpdateConfig#getAbConfig()} * and exists in {@code PRE_STREAMING_FILES_SET}, and put them * in directory {@code dir}. + * * @throws IOException when can't download a file */ private void downloadPreStreamingFiles(UpdateConfig config, String dir) @@ -212,7 +219,7 @@ public class PrepareStreamingService extends IntentService { } /** - * Used by {@link PrepareStreamingService} to pass {@link PayloadSpec} + * Used by {@link PrepareUpdateService} to pass {@link PayloadSpec} * to {@link UpdateResultCallback#onReceiveResult}. */ private static class CallbackResultReceiver extends ResultReceiver { |