Zimuzo | 9cc0be4 | 2019-01-09 11:37:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | #define LOG_TAG "apexd" |
| 18 | |
| 19 | #include "apexd_prop.h" |
| 20 | |
| 21 | #include <android-base/logging.h> |
| 22 | #include <android-base/properties.h> |
| 23 | |
Nikita Ioffe | 31dc34d | 2019-02-23 15:59:04 +0000 | [diff] [blame] | 24 | #include "apexd_utils.h" |
| 25 | |
Zimuzo | 9cc0be4 | 2019-01-09 11:37:34 +0000 | [diff] [blame] | 26 | namespace android { |
| 27 | namespace apex { |
Jooyung Han | f707829 | 2019-04-19 01:40:38 +0900 | [diff] [blame] | 28 | void waitForBootStatus(Status (&rollback_fn)(), void (&complete_fn)()) { |
Zimuzo | 9cc0be4 | 2019-01-09 11:37:34 +0000 | [diff] [blame] | 29 | while (true) { |
| 30 | // Check for change in either crashing property or sys.boot_completed |
| 31 | // Wait for updatable_crashing property change for most of the time |
| 32 | // (arbitrary 30s), briefly check if boot has completed successfully, |
| 33 | // if not continue waiting for updatable_crashing. |
| 34 | // We use this strategy so that we can quickly detect if an updatable |
| 35 | // process is crashing. |
| 36 | if (android::base::WaitForProperty("ro.init.updatable_crashing", "1", |
| 37 | std::chrono::seconds(30))) { |
| 38 | LOG(INFO) << "Updatable crashing, attempting rollback"; |
Nikita Ioffe | 9ae986a | 2019-02-18 22:39:27 +0000 | [diff] [blame] | 39 | auto status = rollback_fn(); |
| 40 | if (!status.Ok()) { |
| 41 | LOG(ERROR) << "Rollback failed : " << status.ErrorMessage(); |
Nikita Ioffe | 31dc34d | 2019-02-23 15:59:04 +0000 | [diff] [blame] | 42 | } else { |
| 43 | LOG(INFO) << "Successfuly rolled back. Rebooting device"; |
| 44 | Reboot(); |
Nikita Ioffe | 9ae986a | 2019-02-18 22:39:27 +0000 | [diff] [blame] | 45 | } |
Zimuzo | 9cc0be4 | 2019-01-09 11:37:34 +0000 | [diff] [blame] | 46 | return; |
| 47 | } |
| 48 | if (android::base::GetProperty("sys.boot_completed", "") == "1") { |
| 49 | // Boot completed we can return |
Jooyung Han | f707829 | 2019-04-19 01:40:38 +0900 | [diff] [blame] | 50 | complete_fn(); |
Zimuzo | 9cc0be4 | 2019-01-09 11:37:34 +0000 | [diff] [blame] | 51 | return; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | } // namespace apex |
| 56 | } // namespace android |