• 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 <base/strings/string_number_conversions.h>
20 #include <brillo/key_value_store.h>
21 #include <update_engine/dbus-constants.h>
22 
23 using brillo::KeyValueStore;
24 using std::string;
25 using update_engine::UpdateEngineStatus;
26 using update_engine::UpdateStatus;
27 
28 namespace chromeos_update_engine {
29 
30 namespace {
31 
32 // Note: Do not change these, autotest depends on these string variables being
33 // exactly these matches.
34 const char kCurrentOp[] = "CURRENT_OP";
35 const char kIsInstall[] = "IS_INSTALL";
36 const char kIsEnterpriseRollback[] = "IS_ENTERPRISE_ROLLBACK";
37 const char kLastCheckedTime[] = "LAST_CHECKED_TIME";
38 const char kNewSize[] = "NEW_SIZE";
39 const char kNewVersion[] = "NEW_VERSION";
40 const char kProgress[] = "PROGRESS";
41 const char kWillPowerwashAfterReboot[] = "WILL_POWERWASH_AFTER_REBOOT";
42 
43 }  // namespace
44 
UpdateStatusToString(const UpdateStatus & status)45 const char* UpdateStatusToString(const UpdateStatus& status) {
46   switch (status) {
47     case UpdateStatus::IDLE:
48       return update_engine::kUpdateStatusIdle;
49     case UpdateStatus::CHECKING_FOR_UPDATE:
50       return update_engine::kUpdateStatusCheckingForUpdate;
51     case UpdateStatus::UPDATE_AVAILABLE:
52       return update_engine::kUpdateStatusUpdateAvailable;
53     case UpdateStatus::NEED_PERMISSION_TO_UPDATE:
54       return update_engine::kUpdateStatusNeedPermissionToUpdate;
55     case UpdateStatus::DOWNLOADING:
56       return update_engine::kUpdateStatusDownloading;
57     case UpdateStatus::VERIFYING:
58       return update_engine::kUpdateStatusVerifying;
59     case UpdateStatus::FINALIZING:
60       return update_engine::kUpdateStatusFinalizing;
61     case UpdateStatus::UPDATED_NEED_REBOOT:
62       return update_engine::kUpdateStatusUpdatedNeedReboot;
63     case UpdateStatus::REPORTING_ERROR_EVENT:
64       return update_engine::kUpdateStatusReportingErrorEvent;
65     case UpdateStatus::ATTEMPTING_ROLLBACK:
66       return update_engine::kUpdateStatusAttemptingRollback;
67     case UpdateStatus::DISABLED:
68       return update_engine::kUpdateStatusDisabled;
69     case UpdateStatus::CLEANUP_PREVIOUS_UPDATE:
70       return update_engine::kUpdateStatusCleanupPreviousUpdate;
71   }
72 
73   NOTREACHED();
74   return nullptr;
75 }
76 
UpdateEngineStatusToString(const UpdateEngineStatus & status)77 string UpdateEngineStatusToString(const UpdateEngineStatus& status) {
78   KeyValueStore key_value_store;
79 
80   key_value_store.SetString(kLastCheckedTime,
81                             base::NumberToString(status.last_checked_time));
82   key_value_store.SetString(kProgress, base::NumberToString(status.progress));
83   key_value_store.SetString(kNewSize,
84                             base::NumberToString(status.new_size_bytes));
85   key_value_store.SetString(kCurrentOp, UpdateStatusToString(status.status));
86   key_value_store.SetString(kNewVersion, status.new_version);
87   key_value_store.SetBoolean(kIsEnterpriseRollback,
88                              status.is_enterprise_rollback);
89   key_value_store.SetBoolean(kIsInstall, status.is_install);
90   key_value_store.SetBoolean(kWillPowerwashAfterReboot,
91                              status.will_powerwash_after_reboot);
92 
93   return key_value_store.SaveToString();
94 }
95 
96 }  // namespace chromeos_update_engine
97