blob: b2505ee23b65b1adebb9a3b8b0abd7076a3b9874 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2014 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//
David Zeuthenfe225c12014-04-29 10:37:35 -070016
Alex Deymoaab50e32014-11-10 19:55:35 -080017#include "update_engine/update_manager/boxed_value.h"
18
Ben Chandcf5a1d2014-08-07 09:34:12 -070019#include <stdint.h>
20
David Zeuthenfe225c12014-04-29 10:37:35 -070021#include <set>
22#include <string>
23
24#include <base/strings/string_number_conversions.h>
25#include <base/time/time.h>
26
Alex Deymo39910dc2015-11-09 17:04:30 -080027#include "update_engine/common/utils.h"
Sen Jiang255e22b2016-05-20 16:15:29 -070028#include "update_engine/connection_utils.h"
Marton Hunyady0e0e3542018-02-21 18:51:39 +010029#include "update_engine/update_manager/rollback_prefs.h"
Alex Deymo63784a52014-05-28 10:46:14 -070030#include "update_engine/update_manager/shill_provider.h"
31#include "update_engine/update_manager/updater_provider.h"
David Zeuthenfe225c12014-04-29 10:37:35 -070032
Sen Jiang255e22b2016-05-20 16:15:29 -070033using chromeos_update_engine::ConnectionTethering;
34using chromeos_update_engine::ConnectionType;
35using chromeos_update_engine::connection_utils::StringForConnectionType;
David Zeuthenfe225c12014-04-29 10:37:35 -070036using std::set;
37using std::string;
38
Alex Deymo63784a52014-05-28 10:46:14 -070039namespace chromeos_update_manager {
David Zeuthenfe225c12014-04-29 10:37:35 -070040
41// Template instantiation for common types; used in BoxedValue::ToString().
42// Keep in sync with boxed_value_unitttest.cc.
43
44template<>
Gilad Arnoldec7f9162014-07-15 13:24:46 -070045string BoxedValue::ValuePrinter<string>(const void* value) {
David Zeuthenfe225c12014-04-29 10:37:35 -070046 const string* val = reinterpret_cast<const string*>(value);
47 return *val;
48}
49
50template<>
Gilad Arnoldec7f9162014-07-15 13:24:46 -070051string BoxedValue::ValuePrinter<int>(const void* value) {
Alex Deymof967ebe2014-05-05 14:46:17 -070052 const int* val = reinterpret_cast<const int*>(value);
53 return base::IntToString(*val);
54}
55
56template<>
Gilad Arnoldec7f9162014-07-15 13:24:46 -070057string BoxedValue::ValuePrinter<unsigned int>(const void* value) {
David Zeuthenfe225c12014-04-29 10:37:35 -070058 const unsigned int* val = reinterpret_cast<const unsigned int*>(value);
59 return base::UintToString(*val);
60}
61
62template<>
Gilad Arnoldec7f9162014-07-15 13:24:46 -070063string BoxedValue::ValuePrinter<int64_t>(const void* value) {
Alex Deymof967ebe2014-05-05 14:46:17 -070064 const int64_t* val = reinterpret_cast<const int64_t*>(value);
65 return base::Int64ToString(*val);
David Zeuthenfe225c12014-04-29 10:37:35 -070066}
67
68template<>
Gilad Arnoldec7f9162014-07-15 13:24:46 -070069string BoxedValue::ValuePrinter<uint64_t>(const void* value) {
Alex Deymof967ebe2014-05-05 14:46:17 -070070 const uint64_t* val =
71 reinterpret_cast<const uint64_t*>(value);
Ben Chandcf5a1d2014-08-07 09:34:12 -070072 return base::Uint64ToString(static_cast<uint64_t>(*val));
David Zeuthenfe225c12014-04-29 10:37:35 -070073}
74
75template<>
Gilad Arnoldec7f9162014-07-15 13:24:46 -070076string BoxedValue::ValuePrinter<bool>(const void* value) {
David Zeuthenfe225c12014-04-29 10:37:35 -070077 const bool* val = reinterpret_cast<const bool*>(value);
78 return *val ? "true" : "false";
79}
80
81template<>
Gilad Arnoldec7f9162014-07-15 13:24:46 -070082string BoxedValue::ValuePrinter<double>(const void* value) {
David Zeuthenfe225c12014-04-29 10:37:35 -070083 const double* val = reinterpret_cast<const double*>(value);
84 return base::DoubleToString(*val);
85}
86
87template<>
Gilad Arnoldec7f9162014-07-15 13:24:46 -070088string BoxedValue::ValuePrinter<base::Time>(const void* value) {
David Zeuthenfe225c12014-04-29 10:37:35 -070089 const base::Time* val = reinterpret_cast<const base::Time*>(value);
90 return chromeos_update_engine::utils::ToString(*val);
91}
92
93template<>
Gilad Arnoldec7f9162014-07-15 13:24:46 -070094string BoxedValue::ValuePrinter<base::TimeDelta>(const void* value) {
David Zeuthenfe225c12014-04-29 10:37:35 -070095 const base::TimeDelta* val = reinterpret_cast<const base::TimeDelta*>(value);
96 return chromeos_update_engine::utils::FormatTimeDelta(*val);
97}
98
David Zeuthenfe225c12014-04-29 10:37:35 -070099template<>
Gilad Arnoldec7f9162014-07-15 13:24:46 -0700100string BoxedValue::ValuePrinter<ConnectionType>(const void* value) {
David Zeuthenfe225c12014-04-29 10:37:35 -0700101 const ConnectionType* val = reinterpret_cast<const ConnectionType*>(value);
Sen Jiang255e22b2016-05-20 16:15:29 -0700102 return StringForConnectionType(*val);
David Zeuthenfe225c12014-04-29 10:37:35 -0700103}
104
105template<>
Gilad Arnoldec7f9162014-07-15 13:24:46 -0700106string BoxedValue::ValuePrinter<set<ConnectionType>>(const void* value) {
David Zeuthenfe225c12014-04-29 10:37:35 -0700107 string ret = "";
108 const set<ConnectionType>* val =
109 reinterpret_cast<const set<ConnectionType>*>(value);
110 for (auto& it : *val) {
111 ConnectionType type = it;
112 if (ret.size() > 0)
113 ret += ",";
Sen Jiang255e22b2016-05-20 16:15:29 -0700114 ret += StringForConnectionType(type);
David Zeuthenfe225c12014-04-29 10:37:35 -0700115 }
116 return ret;
117}
118
119template<>
Gilad Arnoldec7f9162014-07-15 13:24:46 -0700120string BoxedValue::ValuePrinter<ConnectionTethering>(const void* value) {
David Zeuthenfe225c12014-04-29 10:37:35 -0700121 const ConnectionTethering* val =
122 reinterpret_cast<const ConnectionTethering*>(value);
123 switch (*val) {
124 case ConnectionTethering::kNotDetected:
125 return "Not Detected";
126 case ConnectionTethering::kSuspected:
127 return "Suspected";
128 case ConnectionTethering::kConfirmed:
129 return "Confirmed";
130 case ConnectionTethering::kUnknown:
131 return "Unknown";
132 }
133 NOTREACHED();
134 return "Unknown";
135}
136
Marton Hunyady0e0e3542018-02-21 18:51:39 +0100137template <>
138string BoxedValue::ValuePrinter<RollbackToTargetVersion>(const void* value) {
139 const RollbackToTargetVersion* val =
140 reinterpret_cast<const RollbackToTargetVersion*>(value);
141 switch (*val) {
142 case RollbackToTargetVersion::kUnspecified:
143 return "Unspecified";
144 case RollbackToTargetVersion::kDisabled:
145 return "Disabled";
146 case RollbackToTargetVersion::kRollbackWithFullPowerwash:
147 return "Rollback with full powerwash";
148 case RollbackToTargetVersion::kMaxValue:
149 NOTREACHED();
150 return "Max value";
151 }
152 NOTREACHED();
153 return "Unknown";
154}
155
David Zeuthenfe225c12014-04-29 10:37:35 -0700156template<>
Gilad Arnoldec7f9162014-07-15 13:24:46 -0700157string BoxedValue::ValuePrinter<Stage>(const void* value) {
David Zeuthenfe225c12014-04-29 10:37:35 -0700158 const Stage* val = reinterpret_cast<const Stage*>(value);
159 switch (*val) {
Alex Vakulenko072359c2014-07-18 11:41:07 -0700160 case Stage::kIdle:
David Zeuthenfe225c12014-04-29 10:37:35 -0700161 return "Idle";
162 case Stage::kCheckingForUpdate:
163 return "Checking For Update";
164 case Stage::kUpdateAvailable:
165 return "Update Available";
166 case Stage::kDownloading:
167 return "Downloading";
168 case Stage::kVerifying:
169 return "Verifying";
170 case Stage::kFinalizing:
171 return "Finalizing";
172 case Stage::kUpdatedNeedReboot:
173 return "Updated, Need Reboot";
174 case Stage::kReportingErrorEvent:
175 return "Reporting Error Event";
176 case Stage::kAttemptingRollback:
177 return "Attempting Rollback";
178 }
179 NOTREACHED();
180 return "Unknown";
181}
182
Gilad Arnoldec7f9162014-07-15 13:24:46 -0700183template<>
184string BoxedValue::ValuePrinter<UpdateRequestStatus>(const void* value) {
185 const UpdateRequestStatus* val =
186 reinterpret_cast<const UpdateRequestStatus*>(value);
187 switch (*val) {
188 case UpdateRequestStatus::kNone:
189 return "None";
190 case UpdateRequestStatus::kInteractive:
191 return "Interactive";
192 case UpdateRequestStatus::kPeriodic:
193 return "Periodic";
194 }
195 NOTREACHED();
196 return "Unknown";
197}
198
Aaron Woodbf5a2522017-10-04 10:58:36 -0700199template <>
200string BoxedValue::ValuePrinter<UpdateRestrictions>(const void* value) {
201 const UpdateRestrictions* val =
202 reinterpret_cast<const UpdateRestrictions*>(value);
203
204 if (*val == UpdateRestrictions::kNone) {
205 return "None";
206 }
207 string retval = "Flags:";
208 if (*val & kRestrictDownloading) {
209 retval += " RestrictDownloading";
210 }
211 return retval;
212}
213
Alex Deymo63784a52014-05-28 10:46:14 -0700214} // namespace chromeos_update_manager