blob: 1b2dfbcbc8b0f4314a4aadbba2b7fea622d3fb6a [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
Alex Deymof7ead812015-10-23 17:37:27 -070023namespace {
24
25const char kWeaveStatusIdle[] = "idle";
26const char kWeaveStatusCheckingForUpdate[] = "checkingForUpdate";
27const char kWeaveStatusUpdateAvailable[] = "updateAvailable";
Weidong Guo70063d92017-04-17 10:08:38 -070028const char kWeaveStatusNeedPermissionToUpdate[] = "needPermissionToUpdate";
Alex Deymof7ead812015-10-23 17:37:27 -070029const char kWeaveStatusDownloading[] = "downloading";
30const char kWeaveStatusVerifying[] = "verifying";
31const char kWeaveStatusFinalizing[] = "finalizing";
32const char kWeaveStatusUpdatedNeedReboot[] = "updatedNeedReboot";
33const char kWeaveStatusReportingErrorEvent[] = "reportingErrorEvent";
34const char kWeaveStatusAttemptingRollback[] = "attemptingRollback";
35const char kWeaveStatusDisabled[] = "disabled";
36
37} // namespace
38
Christopher Wileycc8ce0e2015-10-01 16:48:47 -070039namespace chromeos_update_engine {
40
41const 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 Guo70063d92017-04-17 10:08:38 -070049 case UpdateStatus::NEED_PERMISSION_TO_UPDATE:
50 return update_engine::kUpdateStatusNeedPermissionToUpdate;
Christopher Wileycc8ce0e2015-10-01 16:48:47 -070051 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 Deymof7ead812015-10-23 17:37:27 -070071const 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 Guo70063d92017-04-17 10:08:38 -070079 case UpdateStatus::NEED_PERMISSION_TO_UPDATE:
80 return kWeaveStatusNeedPermissionToUpdate;
Alex Deymof7ead812015-10-23 17:37:27 -070081 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 Wiley3f97b5d2015-10-01 17:17:41 -0700101bool 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 Guo70063d92017-04-17 10:08:38 -0700112 } else if (s == update_engine::kUpdateStatusNeedPermissionToUpdate) {
113 *status = UpdateStatus::NEED_PERMISSION_TO_UPDATE;
114 return true;
Christopher Wiley3f97b5d2015-10-01 17:17:41 -0700115 } 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 Wileycc8ce0e2015-10-01 16:48:47 -0700140} // namespace chromeos_update_engine