Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.example.android.systemupdatersample.updates; |
| 18 | |
| 19 | import android.os.UpdateEngine; |
| 20 | |
| 21 | import com.example.android.systemupdatersample.PayloadSpec; |
| 22 | import com.example.android.systemupdatersample.UpdateConfig; |
| 23 | import com.example.android.systemupdatersample.util.PayloadSpecs; |
| 24 | |
| 25 | /** |
| 26 | * Applies A/B (seamless) non-streaming update. |
| 27 | */ |
| 28 | public 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 | } |