• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
23 namespace chromeos_update_engine {
24 
UpdateStatusToString(const UpdateStatus & status)25 const 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;
33     case UpdateStatus::NEED_PERMISSION_TO_UPDATE:
34       return update_engine::kUpdateStatusNeedPermissionToUpdate;
35     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;
49   }
50 
51   NOTREACHED();
52   return nullptr;
53 }
54 
StringToUpdateStatus(const std::string & s,UpdateStatus * status)55 bool StringToUpdateStatus(const std::string& s, UpdateStatus* status) {
56   if (s == update_engine::kUpdateStatusIdle) {
57     *status = UpdateStatus::IDLE;
58     return true;
59   } else if (s == update_engine::kUpdateStatusCheckingForUpdate) {
60     *status = UpdateStatus::CHECKING_FOR_UPDATE;
61     return true;
62   } else if (s == update_engine::kUpdateStatusUpdateAvailable) {
63     *status = UpdateStatus::UPDATE_AVAILABLE;
64     return true;
65   } else if (s == update_engine::kUpdateStatusNeedPermissionToUpdate) {
66     *status = UpdateStatus::NEED_PERMISSION_TO_UPDATE;
67     return true;
68   } else if (s == update_engine::kUpdateStatusDownloading) {
69     *status = UpdateStatus::DOWNLOADING;
70     return true;
71   } else if (s == update_engine::kUpdateStatusVerifying) {
72     *status = UpdateStatus::VERIFYING;
73     return true;
74   } else if (s == update_engine::kUpdateStatusFinalizing) {
75     *status = UpdateStatus::FINALIZING;
76     return true;
77   } else if (s == update_engine::kUpdateStatusUpdatedNeedReboot) {
78     *status = UpdateStatus::UPDATED_NEED_REBOOT;
79     return true;
80   } else if (s == update_engine::kUpdateStatusReportingErrorEvent) {
81     *status = UpdateStatus::REPORTING_ERROR_EVENT;
82     return true;
83   } else if (s == update_engine::kUpdateStatusAttemptingRollback) {
84     *status = UpdateStatus::ATTEMPTING_ROLLBACK;
85     return true;
86   } else if (s == update_engine::kUpdateStatusDisabled) {
87     *status = UpdateStatus::DISABLED;
88     return true;
89   }
90   return false;
91 }
92 
93 }  // namespace chromeos_update_engine
94