blob: b56d94a1de776c760fbc54bbe25f7decde209823 [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#include <update_engine/dbus-constants.h>
22
Jae Hoon Kim2f78c1c2019-07-25 13:20:43 -070023using brillo::KeyValueStore;
24using std::string;
25using update_engine::UpdateEngineStatus;
Christopher Wileycc8ce0e2015-10-01 16:48:47 -070026using update_engine::UpdateStatus;
27
28namespace chromeos_update_engine {
29
30const char* UpdateStatusToString(const UpdateStatus& status) {
31 switch (status) {
32 case UpdateStatus::IDLE:
33 return update_engine::kUpdateStatusIdle;
34 case UpdateStatus::CHECKING_FOR_UPDATE:
35 return update_engine::kUpdateStatusCheckingForUpdate;
36 case UpdateStatus::UPDATE_AVAILABLE:
37 return update_engine::kUpdateStatusUpdateAvailable;
Weidong Guo421ff332017-04-17 10:08:38 -070038 case UpdateStatus::NEED_PERMISSION_TO_UPDATE:
39 return update_engine::kUpdateStatusNeedPermissionToUpdate;
Christopher Wileycc8ce0e2015-10-01 16:48:47 -070040 case UpdateStatus::DOWNLOADING:
41 return update_engine::kUpdateStatusDownloading;
42 case UpdateStatus::VERIFYING:
43 return update_engine::kUpdateStatusVerifying;
44 case UpdateStatus::FINALIZING:
45 return update_engine::kUpdateStatusFinalizing;
46 case UpdateStatus::UPDATED_NEED_REBOOT:
47 return update_engine::kUpdateStatusUpdatedNeedReboot;
48 case UpdateStatus::REPORTING_ERROR_EVENT:
49 return update_engine::kUpdateStatusReportingErrorEvent;
50 case UpdateStatus::ATTEMPTING_ROLLBACK:
51 return update_engine::kUpdateStatusAttemptingRollback;
52 case UpdateStatus::DISABLED:
53 return update_engine::kUpdateStatusDisabled;
54 }
55
56 NOTREACHED();
57 return nullptr;
58}
59
Jae Hoon Kim2f78c1c2019-07-25 13:20:43 -070060string UpdateEngineStatusToString(const UpdateEngineStatus& status) {
61 KeyValueStore key_value_store;
62
63#if BASE_VER < 576279
64 key_value_store.SetString("LAST_CHECKED_TIME",
65 base::Int64ToString(status.last_checked_time));
66 key_value_store.SetString("PROGRESS", base::DoubleToString(status.progress));
67 key_value_store.SetString("NEW_SIZE",
68 base::Uint64ToString(status.new_size_bytes));
69#else
70 key_value_store.SetString("LAST_CHECKED_TIME",
71 base::NumberToString(status.last_checked_time));
72 key_value_store.SetString("PROGRESS", base::NumberToString(status.progress));
73 key_value_store.SetString("NEW_SIZE",
74 base::NumberToString(status.new_size_bytes));
75#endif
76 key_value_store.SetString("CURRENT_OPERATION",
77 UpdateStatusToString(status.status));
78 key_value_store.SetString("NEW_VERSION", status.new_version);
79 key_value_store.SetBoolean("IS_INSTALL", status.is_install);
80
81 return key_value_store.SaveToString();
82}
83
Christopher Wileycc8ce0e2015-10-01 16:48:47 -070084} // namespace chromeos_update_engine