blob: 6b96dda6431f756a3fba94cd4cd5f43cf3943738 [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>
Jae Hoon Kim2f78c1c2019-07-25 13:20:43 -070019#include <base/strings/string_number_conversions.h>
20#include <brillo/key_value_store.h>
Christopher Wileycc8ce0e2015-10-01 16:48:47 -070021
Jae Hoon Kim2f78c1c2019-07-25 13:20:43 -070022using brillo::KeyValueStore;
23using std::string;
24using update_engine::UpdateEngineStatus;
Christopher Wileycc8ce0e2015-10-01 16:48:47 -070025using update_engine::UpdateStatus;
26
27namespace chromeos_update_engine {
28
Jae Hoon Kim916af852019-08-01 17:45:30 -070029namespace {
30
31// Note: Do not change these, autotest depends on these string variables being
32// exactly these matches.
33const char kCurrentOp[] = "CURRENT_OP";
34const char kIsInstall[] = "IS_INSTALL";
Amin Hassani9be122e2019-08-29 09:20:12 -070035const char kIsEnterpriseRollback[] = "IS_ENTERPRISE_ROLLBACK";
Jae Hoon Kim916af852019-08-01 17:45:30 -070036const char kLastCheckedTime[] = "LAST_CHECKED_TIME";
37const char kNewSize[] = "NEW_SIZE";
38const char kNewVersion[] = "NEW_VERSION";
39const char kProgress[] = "PROGRESS";
Miriam Polzer0cf1acb2020-04-29 17:39:51 +020040const char kWillPowerwashAfterReboot[] = "WILL_POWERWASH_AFTER_REBOOT";
Jae Hoon Kim916af852019-08-01 17:45:30 -070041
Kelvin Zhangc5803b72021-09-02 09:06:16 -070042namespace update_engine {
43const char kUpdateStatusIdle[] = "UPDATE_STATUS_IDLE";
44const char kUpdateStatusCheckingForUpdate[] =
45 "UPDATE_STATUS_CHECKING_FOR_UPDATE";
46const char kUpdateStatusUpdateAvailable[] = "UPDATE_STATUS_UPDATE_AVAILABLE";
47const char kUpdateStatusDownloading[] = "UPDATE_STATUS_DOWNLOADING";
48const char kUpdateStatusVerifying[] = "UPDATE_STATUS_VERIFYING";
49const char kUpdateStatusFinalizing[] = "UPDATE_STATUS_FINALIZING";
50const char kUpdateStatusUpdatedNeedReboot[] =
51 "UPDATE_STATUS_UPDATED_NEED_REBOOT";
52const char kUpdateStatusReportingErrorEvent[] =
53 "UPDATE_STATUS_REPORTING_ERROR_EVENT";
54const char kUpdateStatusAttemptingRollback[] =
55 "UPDATE_STATUS_ATTEMPTING_ROLLBACK";
56const char kUpdateStatusDisabled[] = "UPDATE_STATUS_DISABLED";
57const char kUpdateStatusNeedPermissionToUpdate[] =
58 "UPDATE_STATUS_NEED_PERMISSION_TO_UPDATE";
59const char kUpdateStatusCleanupPreviousUpdate[] =
60 "UPDATE_STATUS_CLEANUP_PREVIOUS_UPDATE";
61} // namespace update_engine
62
Jae Hoon Kim916af852019-08-01 17:45:30 -070063} // namespace
64
Christopher Wileycc8ce0e2015-10-01 16:48:47 -070065const char* UpdateStatusToString(const UpdateStatus& status) {
66 switch (status) {
67 case UpdateStatus::IDLE:
68 return update_engine::kUpdateStatusIdle;
69 case UpdateStatus::CHECKING_FOR_UPDATE:
70 return update_engine::kUpdateStatusCheckingForUpdate;
71 case UpdateStatus::UPDATE_AVAILABLE:
72 return update_engine::kUpdateStatusUpdateAvailable;
Weidong Guo421ff332017-04-17 10:08:38 -070073 case UpdateStatus::NEED_PERMISSION_TO_UPDATE:
74 return update_engine::kUpdateStatusNeedPermissionToUpdate;
Christopher Wileycc8ce0e2015-10-01 16:48:47 -070075 case UpdateStatus::DOWNLOADING:
76 return update_engine::kUpdateStatusDownloading;
77 case UpdateStatus::VERIFYING:
78 return update_engine::kUpdateStatusVerifying;
79 case UpdateStatus::FINALIZING:
80 return update_engine::kUpdateStatusFinalizing;
81 case UpdateStatus::UPDATED_NEED_REBOOT:
82 return update_engine::kUpdateStatusUpdatedNeedReboot;
83 case UpdateStatus::REPORTING_ERROR_EVENT:
84 return update_engine::kUpdateStatusReportingErrorEvent;
85 case UpdateStatus::ATTEMPTING_ROLLBACK:
86 return update_engine::kUpdateStatusAttemptingRollback;
87 case UpdateStatus::DISABLED:
88 return update_engine::kUpdateStatusDisabled;
Yifan Hong90965502020-02-19 15:22:47 -080089 case UpdateStatus::CLEANUP_PREVIOUS_UPDATE:
90 return update_engine::kUpdateStatusCleanupPreviousUpdate;
Christopher Wileycc8ce0e2015-10-01 16:48:47 -070091 }
92
93 NOTREACHED();
94 return nullptr;
95}
96
Jae Hoon Kim2f78c1c2019-07-25 13:20:43 -070097string UpdateEngineStatusToString(const UpdateEngineStatus& status) {
98 KeyValueStore key_value_store;
99
Jae Hoon Kim916af852019-08-01 17:45:30 -0700100 key_value_store.SetString(kLastCheckedTime,
Jae Hoon Kim2f78c1c2019-07-25 13:20:43 -0700101 base::NumberToString(status.last_checked_time));
Jae Hoon Kim916af852019-08-01 17:45:30 -0700102 key_value_store.SetString(kProgress, base::NumberToString(status.progress));
103 key_value_store.SetString(kNewSize,
Jae Hoon Kim2f78c1c2019-07-25 13:20:43 -0700104 base::NumberToString(status.new_size_bytes));
Jae Hoon Kim916af852019-08-01 17:45:30 -0700105 key_value_store.SetString(kCurrentOp, UpdateStatusToString(status.status));
106 key_value_store.SetString(kNewVersion, status.new_version);
Amin Hassani9be122e2019-08-29 09:20:12 -0700107 key_value_store.SetBoolean(kIsEnterpriseRollback,
108 status.is_enterprise_rollback);
Jae Hoon Kim916af852019-08-01 17:45:30 -0700109 key_value_store.SetBoolean(kIsInstall, status.is_install);
Miriam Polzer0cf1acb2020-04-29 17:39:51 +0200110 key_value_store.SetBoolean(kWillPowerwashAfterReboot,
111 status.will_powerwash_after_reboot);
Jae Hoon Kim2f78c1c2019-07-25 13:20:43 -0700112
113 return key_value_store.SaveToString();
Christopher Wiley3f97b5d2015-10-01 17:17:41 -0700114}
115
Christopher Wileycc8ce0e2015-10-01 16:48:47 -0700116} // namespace chromeos_update_engine