-
Notifications
You must be signed in to change notification settings - Fork 19
/
boxed_value.cc
264 lines (233 loc) · 7.9 KB
/
boxed_value.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
//
// Copyright (C) 2014 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "update_engine/update_manager/boxed_value.h"
#include <stdint.h>
#include <set>
#include <string>
#include <base/strings/string_number_conversions.h>
#include <base/time/time.h>
#include <base/version.h>
#include "update_engine/common/connection_utils.h"
#include "update_engine/common/utils.h"
#include "update_engine/update_manager/rollback_prefs.h"
#include "update_engine/update_manager/shill_provider.h"
#include "update_engine/update_manager/updater_provider.h"
#include "update_engine/update_manager/weekly_time.h"
using chromeos_update_engine::ConnectionTethering;
using chromeos_update_engine::ConnectionType;
using chromeos_update_engine::connection_utils::StringForConnectionType;
using std::set;
using std::string;
namespace chromeos_update_manager {
// Template instantiation for common types; used in BoxedValue::ToString().
// Keep in sync with boxed_value_unitttest.cc.
template <>
string BoxedValue::ValuePrinter<string>(const void* value) {
const string* val = reinterpret_cast<const string*>(value);
return *val;
}
template <>
string BoxedValue::ValuePrinter<int>(const void* value) {
const int* val = reinterpret_cast<const int*>(value);
return base::NumberToString(*val);
}
template <>
string BoxedValue::ValuePrinter<unsigned int>(const void* value) {
const unsigned int* val = reinterpret_cast<const unsigned int*>(value);
return base::NumberToString(*val);
}
template <>
string BoxedValue::ValuePrinter<int64_t>(const void* value) {
const int64_t* val = reinterpret_cast<const int64_t*>(value);
return base::NumberToString(*val);
}
template <>
string BoxedValue::ValuePrinter<uint64_t>(const void* value) {
const uint64_t* val = reinterpret_cast<const uint64_t*>(value);
return base::NumberToString(*val);
}
template <>
string BoxedValue::ValuePrinter<bool>(const void* value) {
const bool* val = reinterpret_cast<const bool*>(value);
return *val ? "true" : "false";
}
template <>
string BoxedValue::ValuePrinter<double>(const void* value) {
const double* val = reinterpret_cast<const double*>(value);
return base::NumberToString(*val);
}
template <>
string BoxedValue::ValuePrinter<base::Time>(const void* value) {
const base::Time* val = reinterpret_cast<const base::Time*>(value);
return chromeos_update_engine::utils::ToString(*val);
}
template <>
string BoxedValue::ValuePrinter<base::TimeDelta>(const void* value) {
const base::TimeDelta* val = reinterpret_cast<const base::TimeDelta*>(value);
return chromeos_update_engine::utils::FormatTimeDelta(*val);
}
template <>
string BoxedValue::ValuePrinter<ConnectionType>(const void* value) {
const ConnectionType* val = reinterpret_cast<const ConnectionType*>(value);
return StringForConnectionType(*val);
}
template <>
string BoxedValue::ValuePrinter<set<ConnectionType>>(const void* value) {
string ret = "";
const set<ConnectionType>* val =
reinterpret_cast<const set<ConnectionType>*>(value);
for (auto& it : *val) {
ConnectionType type = it;
if (ret.size() > 0)
ret += ",";
ret += StringForConnectionType(type);
}
return ret;
}
template <>
string BoxedValue::ValuePrinter<ConnectionTethering>(const void* value) {
const ConnectionTethering* val =
reinterpret_cast<const ConnectionTethering*>(value);
switch (*val) {
case ConnectionTethering::kNotDetected:
return "Not Detected";
case ConnectionTethering::kSuspected:
return "Suspected";
case ConnectionTethering::kConfirmed:
return "Confirmed";
case ConnectionTethering::kUnknown:
return "Unknown";
}
NOTREACHED();
return "Unknown";
}
template <>
string BoxedValue::ValuePrinter<RollbackToTargetVersion>(const void* value) {
const RollbackToTargetVersion* val =
reinterpret_cast<const RollbackToTargetVersion*>(value);
switch (*val) {
case RollbackToTargetVersion::kUnspecified:
return "Unspecified";
case RollbackToTargetVersion::kDisabled:
return "Disabled";
case RollbackToTargetVersion::kRollbackAndPowerwash:
return "Rollback and powerwash";
case RollbackToTargetVersion::kRollbackAndRestoreIfPossible:
return "Rollback and restore if possible";
case RollbackToTargetVersion::kMaxValue:
NOTREACHED();
return "Max value";
}
NOTREACHED();
return "Unknown";
}
template <>
string BoxedValue::ValuePrinter<Stage>(const void* value) {
const Stage* val = reinterpret_cast<const Stage*>(value);
switch (*val) {
case Stage::kIdle:
return "Idle";
case Stage::kCheckingForUpdate:
return "Checking For Update";
case Stage::kUpdateAvailable:
return "Update Available";
case Stage::kDownloading:
return "Downloading";
case Stage::kVerifying:
return "Verifying";
case Stage::kFinalizing:
return "Finalizing";
case Stage::kUpdatedNeedReboot:
return "Updated, Need Reboot";
case Stage::kReportingErrorEvent:
return "Reporting Error Event";
case Stage::kAttemptingRollback:
return "Attempting Rollback";
case Stage::kCleanupPreviousUpdate:
return "Cleanup Previous Update";
}
NOTREACHED();
return "Unknown";
}
template <>
string BoxedValue::ValuePrinter<UpdateRequestStatus>(const void* value) {
const UpdateRequestStatus* val =
reinterpret_cast<const UpdateRequestStatus*>(value);
switch (*val) {
case UpdateRequestStatus::kNone:
return "None";
case UpdateRequestStatus::kInteractive:
return "Interactive";
case UpdateRequestStatus::kPeriodic:
return "Periodic";
}
NOTREACHED();
return "Unknown";
}
template <>
string BoxedValue::ValuePrinter<UpdateRestrictions>(const void* value) {
const UpdateRestrictions* val =
reinterpret_cast<const UpdateRestrictions*>(value);
if (*val == UpdateRestrictions::kNone) {
return "None";
}
string retval = "Flags:";
if (*val & kRestrictDownloading) {
retval += " RestrictDownloading";
}
return retval;
}
template <>
string BoxedValue::ValuePrinter<WeeklyTimeInterval>(const void* value) {
const WeeklyTimeInterval* val =
reinterpret_cast<const WeeklyTimeInterval*>(value);
return val->ToString();
}
template <>
string BoxedValue::ValuePrinter<WeeklyTimeIntervalVector>(const void* value) {
const WeeklyTimeIntervalVector* val =
reinterpret_cast<const WeeklyTimeIntervalVector*>(value);
string retval = "Disallowed intervals:\n";
for (const auto& interval : *val) {
retval += interval.ToString() + "\n";
}
return retval;
}
template <>
string BoxedValue::ValuePrinter<ChannelDowngradeBehavior>(const void* value) {
const ChannelDowngradeBehavior* val =
reinterpret_cast<const ChannelDowngradeBehavior*>(value);
switch (*val) {
case ChannelDowngradeBehavior::kUnspecified:
return "Unspecified";
case ChannelDowngradeBehavior::kWaitForVersionToCatchUp:
return "Wait for the target channel to catch up";
case ChannelDowngradeBehavior::kRollback:
return "Roll back and powerwash on channel downgrade";
case ChannelDowngradeBehavior::kAllowUserToConfigure:
return "User decides on channel downgrade behavior";
}
NOTREACHED();
return "Unknown";
}
template <>
string BoxedValue::ValuePrinter<base::Version>(const void* value) {
const base::Version* val = reinterpret_cast<const base::Version*>(value);
if (val->IsValid())
return val->GetString();
return "Unknown";
}
} // namespace chromeos_update_manager