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> |
| 19 | #include <update_engine/dbus-constants.h> |
| 20 | |
| 21 | using update_engine::UpdateStatus; |
| 22 | |
Alex Deymo | f7ead81 | 2015-10-23 17:37:27 -0700 | [diff] [blame] | 23 | namespace { |
| 24 | |
| 25 | const char kWeaveStatusIdle[] = "idle"; |
| 26 | const char kWeaveStatusCheckingForUpdate[] = "checkingForUpdate"; |
| 27 | const char kWeaveStatusUpdateAvailable[] = "updateAvailable"; |
Weidong Guo | 70063d9 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 28 | const char kWeaveStatusNeedPermissionToUpdate[] = "needPermissionToUpdate"; |
Alex Deymo | f7ead81 | 2015-10-23 17:37:27 -0700 | [diff] [blame] | 29 | const char kWeaveStatusDownloading[] = "downloading"; |
| 30 | const char kWeaveStatusVerifying[] = "verifying"; |
| 31 | const char kWeaveStatusFinalizing[] = "finalizing"; |
| 32 | const char kWeaveStatusUpdatedNeedReboot[] = "updatedNeedReboot"; |
| 33 | const char kWeaveStatusReportingErrorEvent[] = "reportingErrorEvent"; |
| 34 | const char kWeaveStatusAttemptingRollback[] = "attemptingRollback"; |
| 35 | const char kWeaveStatusDisabled[] = "disabled"; |
| 36 | |
| 37 | } // namespace |
| 38 | |
Christopher Wiley | cc8ce0e | 2015-10-01 16:48:47 -0700 | [diff] [blame] | 39 | namespace chromeos_update_engine { |
| 40 | |
| 41 | const char* UpdateStatusToString(const UpdateStatus& status) { |
| 42 | switch (status) { |
| 43 | case UpdateStatus::IDLE: |
| 44 | return update_engine::kUpdateStatusIdle; |
| 45 | case UpdateStatus::CHECKING_FOR_UPDATE: |
| 46 | return update_engine::kUpdateStatusCheckingForUpdate; |
| 47 | case UpdateStatus::UPDATE_AVAILABLE: |
| 48 | return update_engine::kUpdateStatusUpdateAvailable; |
Weidong Guo | 70063d9 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 49 | case UpdateStatus::NEED_PERMISSION_TO_UPDATE: |
| 50 | return update_engine::kUpdateStatusNeedPermissionToUpdate; |
Christopher Wiley | cc8ce0e | 2015-10-01 16:48:47 -0700 | [diff] [blame] | 51 | case UpdateStatus::DOWNLOADING: |
| 52 | return update_engine::kUpdateStatusDownloading; |
| 53 | case UpdateStatus::VERIFYING: |
| 54 | return update_engine::kUpdateStatusVerifying; |
| 55 | case UpdateStatus::FINALIZING: |
| 56 | return update_engine::kUpdateStatusFinalizing; |
| 57 | case UpdateStatus::UPDATED_NEED_REBOOT: |
| 58 | return update_engine::kUpdateStatusUpdatedNeedReboot; |
| 59 | case UpdateStatus::REPORTING_ERROR_EVENT: |
| 60 | return update_engine::kUpdateStatusReportingErrorEvent; |
| 61 | case UpdateStatus::ATTEMPTING_ROLLBACK: |
| 62 | return update_engine::kUpdateStatusAttemptingRollback; |
| 63 | case UpdateStatus::DISABLED: |
| 64 | return update_engine::kUpdateStatusDisabled; |
| 65 | } |
| 66 | |
| 67 | NOTREACHED(); |
| 68 | return nullptr; |
| 69 | } |
| 70 | |
Alex Deymo | f7ead81 | 2015-10-23 17:37:27 -0700 | [diff] [blame] | 71 | const char* UpdateStatusToWeaveStatus(const UpdateStatus& status) { |
| 72 | switch (status) { |
| 73 | case UpdateStatus::IDLE: |
| 74 | return kWeaveStatusIdle; |
| 75 | case UpdateStatus::CHECKING_FOR_UPDATE: |
| 76 | return kWeaveStatusCheckingForUpdate; |
| 77 | case UpdateStatus::UPDATE_AVAILABLE: |
| 78 | return kWeaveStatusUpdateAvailable; |
Weidong Guo | 70063d9 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 79 | case UpdateStatus::NEED_PERMISSION_TO_UPDATE: |
| 80 | return kWeaveStatusNeedPermissionToUpdate; |
Alex Deymo | f7ead81 | 2015-10-23 17:37:27 -0700 | [diff] [blame] | 81 | case UpdateStatus::DOWNLOADING: |
| 82 | return kWeaveStatusDownloading; |
| 83 | case UpdateStatus::VERIFYING: |
| 84 | return kWeaveStatusVerifying; |
| 85 | case UpdateStatus::FINALIZING: |
| 86 | return kWeaveStatusFinalizing; |
| 87 | case UpdateStatus::UPDATED_NEED_REBOOT: |
| 88 | return kWeaveStatusUpdatedNeedReboot; |
| 89 | case UpdateStatus::REPORTING_ERROR_EVENT: |
| 90 | return kWeaveStatusReportingErrorEvent; |
| 91 | case UpdateStatus::ATTEMPTING_ROLLBACK: |
| 92 | return kWeaveStatusAttemptingRollback; |
| 93 | case UpdateStatus::DISABLED: |
| 94 | return kWeaveStatusDisabled; |
| 95 | } |
| 96 | |
| 97 | NOTREACHED(); |
| 98 | return nullptr; |
| 99 | } |
| 100 | |
Christopher Wiley | 3f97b5d | 2015-10-01 17:17:41 -0700 | [diff] [blame] | 101 | bool StringToUpdateStatus(const std::string& s, |
| 102 | UpdateStatus* status) { |
| 103 | if (s == update_engine::kUpdateStatusIdle) { |
| 104 | *status = UpdateStatus::IDLE; |
| 105 | return true; |
| 106 | } else if (s == update_engine::kUpdateStatusCheckingForUpdate) { |
| 107 | *status = UpdateStatus::CHECKING_FOR_UPDATE; |
| 108 | return true; |
| 109 | } else if (s == update_engine::kUpdateStatusUpdateAvailable) { |
| 110 | *status = UpdateStatus::UPDATE_AVAILABLE; |
| 111 | return true; |
Weidong Guo | 70063d9 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 112 | } else if (s == update_engine::kUpdateStatusNeedPermissionToUpdate) { |
| 113 | *status = UpdateStatus::NEED_PERMISSION_TO_UPDATE; |
| 114 | return true; |
Christopher Wiley | 3f97b5d | 2015-10-01 17:17:41 -0700 | [diff] [blame] | 115 | } else if (s == update_engine::kUpdateStatusDownloading) { |
| 116 | *status = UpdateStatus::DOWNLOADING; |
| 117 | return true; |
| 118 | } else if (s == update_engine::kUpdateStatusVerifying) { |
| 119 | *status = UpdateStatus::VERIFYING; |
| 120 | return true; |
| 121 | } else if (s == update_engine::kUpdateStatusFinalizing) { |
| 122 | *status = UpdateStatus::FINALIZING; |
| 123 | return true; |
| 124 | } else if (s == update_engine::kUpdateStatusUpdatedNeedReboot) { |
| 125 | *status = UpdateStatus::UPDATED_NEED_REBOOT; |
| 126 | return true; |
| 127 | } else if (s == update_engine::kUpdateStatusReportingErrorEvent) { |
| 128 | *status = UpdateStatus::REPORTING_ERROR_EVENT; |
| 129 | return true; |
| 130 | } else if (s == update_engine::kUpdateStatusAttemptingRollback) { |
| 131 | *status = UpdateStatus::ATTEMPTING_ROLLBACK; |
| 132 | return true; |
| 133 | } else if (s == update_engine::kUpdateStatusDisabled) { |
| 134 | *status = UpdateStatus::DISABLED; |
| 135 | return true; |
| 136 | } |
| 137 | return false; |
| 138 | } |
| 139 | |
Christopher Wiley | cc8ce0e | 2015-10-01 16:48:47 -0700 | [diff] [blame] | 140 | } // namespace chromeos_update_engine |