blob: 6b23d4fe0d5a6efbbce8107b9a9c399b354438f2 [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 <brillo/key_value_store.h>
Christopher Wileycc8ce0e2015-10-01 16:48:47 -070020
Jae Hoon Kim2f78c1c2019-07-25 13:20:43 -070021using brillo::KeyValueStore;
22using std::string;
23using update_engine::UpdateEngineStatus;
Christopher Wileycc8ce0e2015-10-01 16:48:47 -070024using update_engine::UpdateStatus;
25
26namespace chromeos_update_engine {
27
Jae Hoon Kim916af852019-08-01 17:45:30 -070028namespace {
29
30// Note: Do not change these, autotest depends on these string variables being
31// exactly these matches.
32const char kCurrentOp[] = "CURRENT_OP";
33const char kIsInstall[] = "IS_INSTALL";
Amin Hassani9be122e2019-08-29 09:20:12 -070034const char kIsEnterpriseRollback[] = "IS_ENTERPRISE_ROLLBACK";
Jae Hoon Kim916af852019-08-01 17:45:30 -070035const char kLastCheckedTime[] = "LAST_CHECKED_TIME";
36const char kNewSize[] = "NEW_SIZE";
37const char kNewVersion[] = "NEW_VERSION";
38const char kProgress[] = "PROGRESS";
Miriam Polzer0cf1acb2020-04-29 17:39:51 +020039const char kWillPowerwashAfterReboot[] = "WILL_POWERWASH_AFTER_REBOOT";
Jae Hoon Kim916af852019-08-01 17:45:30 -070040
Kelvin Zhangc5803b72021-09-02 09:06:16 -070041namespace update_engine {
42const char kUpdateStatusIdle[] = "UPDATE_STATUS_IDLE";
43const char kUpdateStatusCheckingForUpdate[] =
44 "UPDATE_STATUS_CHECKING_FOR_UPDATE";
45const char kUpdateStatusUpdateAvailable[] = "UPDATE_STATUS_UPDATE_AVAILABLE";
46const char kUpdateStatusDownloading[] = "UPDATE_STATUS_DOWNLOADING";
47const char kUpdateStatusVerifying[] = "UPDATE_STATUS_VERIFYING";
48const char kUpdateStatusFinalizing[] = "UPDATE_STATUS_FINALIZING";
49const char kUpdateStatusUpdatedNeedReboot[] =
50 "UPDATE_STATUS_UPDATED_NEED_REBOOT";
51const char kUpdateStatusReportingErrorEvent[] =
52 "UPDATE_STATUS_REPORTING_ERROR_EVENT";
53const char kUpdateStatusAttemptingRollback[] =
54 "UPDATE_STATUS_ATTEMPTING_ROLLBACK";
55const char kUpdateStatusDisabled[] = "UPDATE_STATUS_DISABLED";
56const char kUpdateStatusNeedPermissionToUpdate[] =
57 "UPDATE_STATUS_NEED_PERMISSION_TO_UPDATE";
58const char kUpdateStatusCleanupPreviousUpdate[] =
59 "UPDATE_STATUS_CLEANUP_PREVIOUS_UPDATE";
60} // namespace update_engine
61
Jae Hoon Kim916af852019-08-01 17:45:30 -070062} // namespace
63
Christopher Wileycc8ce0e2015-10-01 16:48:47 -070064const char* UpdateStatusToString(const UpdateStatus& status) {
65 switch (status) {
66 case UpdateStatus::IDLE:
67 return update_engine::kUpdateStatusIdle;
68 case UpdateStatus::CHECKING_FOR_UPDATE:
69 return update_engine::kUpdateStatusCheckingForUpdate;
70 case UpdateStatus::UPDATE_AVAILABLE:
71 return update_engine::kUpdateStatusUpdateAvailable;
Weidong Guo421ff332017-04-17 10:08:38 -070072 case UpdateStatus::NEED_PERMISSION_TO_UPDATE:
73 return update_engine::kUpdateStatusNeedPermissionToUpdate;
Christopher Wileycc8ce0e2015-10-01 16:48:47 -070074 case UpdateStatus::DOWNLOADING:
75 return update_engine::kUpdateStatusDownloading;
76 case UpdateStatus::VERIFYING:
77 return update_engine::kUpdateStatusVerifying;
78 case UpdateStatus::FINALIZING:
79 return update_engine::kUpdateStatusFinalizing;
80 case UpdateStatus::UPDATED_NEED_REBOOT:
81 return update_engine::kUpdateStatusUpdatedNeedReboot;
82 case UpdateStatus::REPORTING_ERROR_EVENT:
83 return update_engine::kUpdateStatusReportingErrorEvent;
84 case UpdateStatus::ATTEMPTING_ROLLBACK:
85 return update_engine::kUpdateStatusAttemptingRollback;
86 case UpdateStatus::DISABLED:
87 return update_engine::kUpdateStatusDisabled;
Yifan Hong90965502020-02-19 15:22:47 -080088 case UpdateStatus::CLEANUP_PREVIOUS_UPDATE:
89 return update_engine::kUpdateStatusCleanupPreviousUpdate;
Christopher Wileycc8ce0e2015-10-01 16:48:47 -070090 }
91
92 NOTREACHED();
93 return nullptr;
94}
95
Jae Hoon Kim2f78c1c2019-07-25 13:20:43 -070096string UpdateEngineStatusToString(const UpdateEngineStatus& status) {
97 KeyValueStore key_value_store;
98
Jae Hoon Kim916af852019-08-01 17:45:30 -070099 key_value_store.SetString(kLastCheckedTime,
Kokoa Matsuda1f46f5b2024-10-18 16:00:05 +0900100 std::format("{}", status.last_checked_time));
101 key_value_store.SetString(kProgress, std::format("{}", status.progress));
102 key_value_store.SetString(kNewSize, std::format("{}", status.new_size_bytes));
Jae Hoon Kim916af852019-08-01 17:45:30 -0700103 key_value_store.SetString(kCurrentOp, UpdateStatusToString(status.status));
104 key_value_store.SetString(kNewVersion, status.new_version);
Amin Hassani9be122e2019-08-29 09:20:12 -0700105 key_value_store.SetBoolean(kIsEnterpriseRollback,
106 status.is_enterprise_rollback);
Jae Hoon Kim916af852019-08-01 17:45:30 -0700107 key_value_store.SetBoolean(kIsInstall, status.is_install);
Miriam Polzer0cf1acb2020-04-29 17:39:51 +0200108 key_value_store.SetBoolean(kWillPowerwashAfterReboot,
109 status.will_powerwash_after_reboot);
Jae Hoon Kim2f78c1c2019-07-25 13:20:43 -0700110
111 return key_value_store.SaveToString();
Christopher Wiley3f97b5d2015-10-01 17:17:41 -0700112}
113
Christopher Wileycc8ce0e2015-10-01 16:48:47 -0700114} // namespace chromeos_update_engine