blob: 1b91a1ac3badaebdb10c0063e78223531cf167d6 [file] [log] [blame]
Zhomart Mukhamejanovf4d280c2018-04-17 13:20:22 -07001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.example.android.systemupdatersample.updates;
18
19import android.os.UpdateEngine;
20
21import com.example.android.systemupdatersample.PayloadSpec;
22import com.example.android.systemupdatersample.UpdateConfig;
23import com.example.android.systemupdatersample.util.PayloadSpecs;
24
25/**
26 * Applies A/B (seamless) non-streaming update.
27 */
28public class AbNonStreamingUpdate {
29
30 private final UpdateEngine mUpdateEngine;
31 private final UpdateConfig mUpdateConfig;
32
33 public AbNonStreamingUpdate(UpdateEngine updateEngine, UpdateConfig config) {
34 this.mUpdateEngine = updateEngine;
35 this.mUpdateConfig = config;
36 }
37
38 /**
39 * Start applying the update. This method doesn't wait until end of the update.
40 * {@code update_engine} works asynchronously.
41 */
42 public void execute() throws Exception {
43 PayloadSpec payload = PayloadSpecs.forNonStreaming(mUpdateConfig.getUpdatePackageFile());
44
45 mUpdateEngine.applyPayload(
46 payload.getUrl(),
47 payload.getOffset(),
48 payload.getSize(),
49 payload.getProperties().toArray(new String[0]));
50 }
51
52}