David Anderson | 89d2d05 | 2019-10-15 13:22:20 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright (C) 2019 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <android-base/properties.h> |
| 19 | #include <libsnapshot/snapshot.h> |
| 20 | |
| 21 | #include "recovery_ui/device.h" |
| 22 | #include "recovery_ui/ui.h" |
| 23 | #include "recovery_utils/roots.h" |
| 24 | |
| 25 | using android::snapshot::SnapshotManager; |
| 26 | |
| 27 | bool FinishPendingSnapshotMerges(Device* device) { |
| 28 | if (!android::base::GetBoolProperty("ro.virtual_ab.enabled", false)) { |
| 29 | return true; |
| 30 | } |
| 31 | |
| 32 | RecoveryUI* ui = device->GetUI(); |
| 33 | auto sm = SnapshotManager::NewForFirstStageMount(); |
| 34 | if (!sm) { |
| 35 | ui->Print("Could not create SnapshotManager.\n"); |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | auto callback = [&]() -> void { |
| 40 | double progress; |
| 41 | sm->GetUpdateState(&progress); |
| 42 | ui->Print("Waiting for merge to complete: %.2f\n", progress); |
| 43 | }; |
| 44 | if (!sm->HandleImminentDataWipe(callback)) { |
| 45 | ui->Print("Unable to check merge status and/or complete update merge.\n"); |
| 46 | return false; |
| 47 | } |
| 48 | return true; |
| 49 | } |