Christopher Wiley | cc8ce0e | 2015-10-01 16:48:47 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2015 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 | #include "update_engine/update_status_utils.h" |
| 17 | |
| 18 | #include <base/logging.h> |
Jae Hoon Kim | 2f78c1c | 2019-07-25 13:20:43 -0700 | [diff] [blame] | 19 | #include <base/strings/string_number_conversions.h> |
| 20 | #include <brillo/key_value_store.h> |
Christopher Wiley | cc8ce0e | 2015-10-01 16:48:47 -0700 | [diff] [blame] | 21 | #include <update_engine/dbus-constants.h> |
| 22 | |
Jae Hoon Kim | 2f78c1c | 2019-07-25 13:20:43 -0700 | [diff] [blame] | 23 | using brillo::KeyValueStore; |
| 24 | using std::string; |
| 25 | using update_engine::UpdateEngineStatus; |
Christopher Wiley | cc8ce0e | 2015-10-01 16:48:47 -0700 | [diff] [blame] | 26 | using update_engine::UpdateStatus; |
| 27 | |
| 28 | namespace chromeos_update_engine { |
| 29 | |
Jae Hoon Kim | 916af85 | 2019-08-01 17:45:30 -0700 | [diff] [blame] | 30 | namespace { |
| 31 | |
| 32 | // Note: Do not change these, autotest depends on these string variables being |
| 33 | // exactly these matches. |
| 34 | const char kCurrentOp[] = "CURRENT_OP"; |
| 35 | const char kIsInstall[] = "IS_INSTALL"; |
Amin Hassani | 9be122e | 2019-08-29 09:20:12 -0700 | [diff] [blame] | 36 | const char kIsEnterpriseRollback[] = "IS_ENTERPRISE_ROLLBACK"; |
Jae Hoon Kim | 916af85 | 2019-08-01 17:45:30 -0700 | [diff] [blame] | 37 | const char kLastCheckedTime[] = "LAST_CHECKED_TIME"; |
| 38 | const char kNewSize[] = "NEW_SIZE"; |
| 39 | const char kNewVersion[] = "NEW_VERSION"; |
| 40 | const char kProgress[] = "PROGRESS"; |
| 41 | |
| 42 | } // namespace |
| 43 | |
Christopher Wiley | cc8ce0e | 2015-10-01 16:48:47 -0700 | [diff] [blame] | 44 | const char* UpdateStatusToString(const UpdateStatus& status) { |
| 45 | switch (status) { |
| 46 | case UpdateStatus::IDLE: |
| 47 | return update_engine::kUpdateStatusIdle; |
| 48 | case UpdateStatus::CHECKING_FOR_UPDATE: |
| 49 | return update_engine::kUpdateStatusCheckingForUpdate; |
| 50 | case UpdateStatus::UPDATE_AVAILABLE: |
| 51 | return update_engine::kUpdateStatusUpdateAvailable; |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 52 | case UpdateStatus::NEED_PERMISSION_TO_UPDATE: |
| 53 | return update_engine::kUpdateStatusNeedPermissionToUpdate; |
Christopher Wiley | cc8ce0e | 2015-10-01 16:48:47 -0700 | [diff] [blame] | 54 | case UpdateStatus::DOWNLOADING: |
| 55 | return update_engine::kUpdateStatusDownloading; |
| 56 | case UpdateStatus::VERIFYING: |
| 57 | return update_engine::kUpdateStatusVerifying; |
| 58 | case UpdateStatus::FINALIZING: |
| 59 | return update_engine::kUpdateStatusFinalizing; |
| 60 | case UpdateStatus::UPDATED_NEED_REBOOT: |
| 61 | return update_engine::kUpdateStatusUpdatedNeedReboot; |
| 62 | case UpdateStatus::REPORTING_ERROR_EVENT: |
| 63 | return update_engine::kUpdateStatusReportingErrorEvent; |
| 64 | case UpdateStatus::ATTEMPTING_ROLLBACK: |
| 65 | return update_engine::kUpdateStatusAttemptingRollback; |
| 66 | case UpdateStatus::DISABLED: |
| 67 | return update_engine::kUpdateStatusDisabled; |
| 68 | } |
| 69 | |
| 70 | NOTREACHED(); |
| 71 | return nullptr; |
| 72 | } |
| 73 | |
Jae Hoon Kim | 2f78c1c | 2019-07-25 13:20:43 -0700 | [diff] [blame] | 74 | string UpdateEngineStatusToString(const UpdateEngineStatus& status) { |
| 75 | KeyValueStore key_value_store; |
| 76 | |
| 77 | #if BASE_VER < 576279 |
Jae Hoon Kim | 916af85 | 2019-08-01 17:45:30 -0700 | [diff] [blame] | 78 | key_value_store.SetString(kLastCheckedTime, |
Jae Hoon Kim | 2f78c1c | 2019-07-25 13:20:43 -0700 | [diff] [blame] | 79 | base::Int64ToString(status.last_checked_time)); |
Jae Hoon Kim | 916af85 | 2019-08-01 17:45:30 -0700 | [diff] [blame] | 80 | key_value_store.SetString(kProgress, base::DoubleToString(status.progress)); |
| 81 | key_value_store.SetString(kNewSize, |
Jae Hoon Kim | 2f78c1c | 2019-07-25 13:20:43 -0700 | [diff] [blame] | 82 | base::Uint64ToString(status.new_size_bytes)); |
| 83 | #else |
Jae Hoon Kim | 916af85 | 2019-08-01 17:45:30 -0700 | [diff] [blame] | 84 | key_value_store.SetString(kLastCheckedTime, |
Jae Hoon Kim | 2f78c1c | 2019-07-25 13:20:43 -0700 | [diff] [blame] | 85 | base::NumberToString(status.last_checked_time)); |
Jae Hoon Kim | 916af85 | 2019-08-01 17:45:30 -0700 | [diff] [blame] | 86 | key_value_store.SetString(kProgress, base::NumberToString(status.progress)); |
| 87 | key_value_store.SetString(kNewSize, |
Jae Hoon Kim | 2f78c1c | 2019-07-25 13:20:43 -0700 | [diff] [blame] | 88 | base::NumberToString(status.new_size_bytes)); |
| 89 | #endif |
Jae Hoon Kim | 916af85 | 2019-08-01 17:45:30 -0700 | [diff] [blame] | 90 | key_value_store.SetString(kCurrentOp, UpdateStatusToString(status.status)); |
| 91 | key_value_store.SetString(kNewVersion, status.new_version); |
Amin Hassani | 9be122e | 2019-08-29 09:20:12 -0700 | [diff] [blame] | 92 | key_value_store.SetBoolean(kIsEnterpriseRollback, |
| 93 | status.is_enterprise_rollback); |
Jae Hoon Kim | 916af85 | 2019-08-01 17:45:30 -0700 | [diff] [blame] | 94 | key_value_store.SetBoolean(kIsInstall, status.is_install); |
Jae Hoon Kim | 2f78c1c | 2019-07-25 13:20:43 -0700 | [diff] [blame] | 95 | |
| 96 | return key_value_store.SaveToString(); |
| 97 | } |
| 98 | |
Christopher Wiley | cc8ce0e | 2015-10-01 16:48:47 -0700 | [diff] [blame] | 99 | } // namespace chromeos_update_engine |