blob: 11fd2995bcd9d9854f55483cd7f9524bda169a9d [file] [log] [blame]
Christopher Wileycc8ce0e2015-10-01 16:48:47 -07001//
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
21using update_engine::UpdateStatus;
22
23namespace chromeos_update_engine {
24
25const char* UpdateStatusToString(const UpdateStatus& status) {
26 switch (status) {
27 case UpdateStatus::IDLE:
28 return update_engine::kUpdateStatusIdle;
29 case UpdateStatus::CHECKING_FOR_UPDATE:
30 return update_engine::kUpdateStatusCheckingForUpdate;
31 case UpdateStatus::UPDATE_AVAILABLE:
32 return update_engine::kUpdateStatusUpdateAvailable;
Weidong Guo421ff332017-04-17 10:08:38 -070033 case UpdateStatus::NEED_PERMISSION_TO_UPDATE:
34 return update_engine::kUpdateStatusNeedPermissionToUpdate;
Christopher Wileycc8ce0e2015-10-01 16:48:47 -070035 case UpdateStatus::DOWNLOADING:
36 return update_engine::kUpdateStatusDownloading;
37 case UpdateStatus::VERIFYING:
38 return update_engine::kUpdateStatusVerifying;
39 case UpdateStatus::FINALIZING:
40 return update_engine::kUpdateStatusFinalizing;
41 case UpdateStatus::UPDATED_NEED_REBOOT:
42 return update_engine::kUpdateStatusUpdatedNeedReboot;
43 case UpdateStatus::REPORTING_ERROR_EVENT:
44 return update_engine::kUpdateStatusReportingErrorEvent;
45 case UpdateStatus::ATTEMPTING_ROLLBACK:
46 return update_engine::kUpdateStatusAttemptingRollback;
47 case UpdateStatus::DISABLED:
48 return update_engine::kUpdateStatusDisabled;
Yifan Hong1dcd1a62020-02-19 15:22:47 -080049 case UpdateStatus::CLEANUP_PREVIOUS_UPDATE:
50 return update_engine::kUpdateStatusCleanupPreviousUpdate;
Christopher Wileycc8ce0e2015-10-01 16:48:47 -070051 }
52
53 NOTREACHED();
54 return nullptr;
55}
56
Amin Hassani7cc8bb02019-01-14 16:29:47 -080057bool StringToUpdateStatus(const std::string& s, UpdateStatus* status) {
Christopher Wiley3f97b5d2015-10-01 17:17:41 -070058 if (s == update_engine::kUpdateStatusIdle) {
59 *status = UpdateStatus::IDLE;
60 return true;
61 } else if (s == update_engine::kUpdateStatusCheckingForUpdate) {
62 *status = UpdateStatus::CHECKING_FOR_UPDATE;
63 return true;
64 } else if (s == update_engine::kUpdateStatusUpdateAvailable) {
65 *status = UpdateStatus::UPDATE_AVAILABLE;
66 return true;
Weidong Guo421ff332017-04-17 10:08:38 -070067 } else if (s == update_engine::kUpdateStatusNeedPermissionToUpdate) {
68 *status = UpdateStatus::NEED_PERMISSION_TO_UPDATE;
69 return true;
Christopher Wiley3f97b5d2015-10-01 17:17:41 -070070 } else if (s == update_engine::kUpdateStatusDownloading) {
71 *status = UpdateStatus::DOWNLOADING;
72 return true;
73 } else if (s == update_engine::kUpdateStatusVerifying) {
74 *status = UpdateStatus::VERIFYING;
75 return true;
76 } else if (s == update_engine::kUpdateStatusFinalizing) {
77 *status = UpdateStatus::FINALIZING;
78 return true;
79 } else if (s == update_engine::kUpdateStatusUpdatedNeedReboot) {
80 *status = UpdateStatus::UPDATED_NEED_REBOOT;
81 return true;
82 } else if (s == update_engine::kUpdateStatusReportingErrorEvent) {
83 *status = UpdateStatus::REPORTING_ERROR_EVENT;
84 return true;
85 } else if (s == update_engine::kUpdateStatusAttemptingRollback) {
86 *status = UpdateStatus::ATTEMPTING_ROLLBACK;
87 return true;
88 } else if (s == update_engine::kUpdateStatusDisabled) {
89 *status = UpdateStatus::DISABLED;
90 return true;
Yifan Hong1dcd1a62020-02-19 15:22:47 -080091 } else if (s == update_engine::kUpdateStatusCleanupPreviousUpdate) {
92 *status = UpdateStatus::CLEANUP_PREVIOUS_UPDATE;
93 return true;
Christopher Wiley3f97b5d2015-10-01 17:17:41 -070094 }
95 return false;
96}
97
Christopher Wileycc8ce0e2015-10-01 16:48:47 -070098} // namespace chromeos_update_engine