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 | |
| 30 | const char* UpdateStatusToString(const UpdateStatus& status) { |
| 31 | switch (status) { |
| 32 | case UpdateStatus::IDLE: |
| 33 | return update_engine::kUpdateStatusIdle; |
| 34 | case UpdateStatus::CHECKING_FOR_UPDATE: |
| 35 | return update_engine::kUpdateStatusCheckingForUpdate; |
| 36 | case UpdateStatus::UPDATE_AVAILABLE: |
| 37 | return update_engine::kUpdateStatusUpdateAvailable; |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 38 | case UpdateStatus::NEED_PERMISSION_TO_UPDATE: |
| 39 | return update_engine::kUpdateStatusNeedPermissionToUpdate; |
Christopher Wiley | cc8ce0e | 2015-10-01 16:48:47 -0700 | [diff] [blame] | 40 | case UpdateStatus::DOWNLOADING: |
| 41 | return update_engine::kUpdateStatusDownloading; |
| 42 | case UpdateStatus::VERIFYING: |
| 43 | return update_engine::kUpdateStatusVerifying; |
| 44 | case UpdateStatus::FINALIZING: |
| 45 | return update_engine::kUpdateStatusFinalizing; |
| 46 | case UpdateStatus::UPDATED_NEED_REBOOT: |
| 47 | return update_engine::kUpdateStatusUpdatedNeedReboot; |
| 48 | case UpdateStatus::REPORTING_ERROR_EVENT: |
| 49 | return update_engine::kUpdateStatusReportingErrorEvent; |
| 50 | case UpdateStatus::ATTEMPTING_ROLLBACK: |
| 51 | return update_engine::kUpdateStatusAttemptingRollback; |
| 52 | case UpdateStatus::DISABLED: |
| 53 | return update_engine::kUpdateStatusDisabled; |
| 54 | } |
| 55 | |
| 56 | NOTREACHED(); |
| 57 | return nullptr; |
| 58 | } |
| 59 | |
Jae Hoon Kim | 2f78c1c | 2019-07-25 13:20:43 -0700 | [diff] [blame^] | 60 | string UpdateEngineStatusToString(const UpdateEngineStatus& status) { |
| 61 | KeyValueStore key_value_store; |
| 62 | |
| 63 | #if BASE_VER < 576279 |
| 64 | key_value_store.SetString("LAST_CHECKED_TIME", |
| 65 | base::Int64ToString(status.last_checked_time)); |
| 66 | key_value_store.SetString("PROGRESS", base::DoubleToString(status.progress)); |
| 67 | key_value_store.SetString("NEW_SIZE", |
| 68 | base::Uint64ToString(status.new_size_bytes)); |
| 69 | #else |
| 70 | key_value_store.SetString("LAST_CHECKED_TIME", |
| 71 | base::NumberToString(status.last_checked_time)); |
| 72 | key_value_store.SetString("PROGRESS", base::NumberToString(status.progress)); |
| 73 | key_value_store.SetString("NEW_SIZE", |
| 74 | base::NumberToString(status.new_size_bytes)); |
| 75 | #endif |
| 76 | key_value_store.SetString("CURRENT_OPERATION", |
| 77 | UpdateStatusToString(status.status)); |
| 78 | key_value_store.SetString("NEW_VERSION", status.new_version); |
| 79 | key_value_store.SetBoolean("IS_INSTALL", status.is_install); |
| 80 | |
| 81 | return key_value_store.SaveToString(); |
| 82 | } |
| 83 | |
Christopher Wiley | cc8ce0e | 2015-10-01 16:48:47 -0700 | [diff] [blame] | 84 | } // namespace chromeos_update_engine |