blob: 53c5bba6dc1cef4a55fb22a63297a3fb0d2fff89 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2013 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//
Jay Srinivasan1c0fe792013-03-28 16:45:25 -070016
Alex Deymo39910dc2015-11-09 17:04:30 -080017#ifndef UPDATE_ENGINE_COMMON_CONSTANTS_H_
18#define UPDATE_ENGINE_COMMON_CONSTANTS_H_
Jay Srinivasan1c0fe792013-03-28 16:45:25 -070019
Kelvin Zhangec205cf2020-09-28 13:23:40 -040020#include <cstdint>
21
Jay Srinivasan1c0fe792013-03-28 16:45:25 -070022namespace chromeos_update_engine {
Jae Hoon Kim38de3b12020-04-29 19:41:23 -070023// The root path of all exclusion prefs.
Kelvin Zhang575b8f82021-05-13 11:14:44 -040024static constexpr const auto& kExclusionPrefsSubDir = "exclusion";
Jae Hoon Kim38de3b12020-04-29 19:41:23 -070025
Andrew065d78d2020-04-07 15:43:07 -070026// The root path of all DLC metadata.
Kelvin Zhang575b8f82021-05-13 11:14:44 -040027static constexpr const auto& kDlcPrefsSubDir = "dlc";
Andrewe045aef2020-01-08 16:29:22 -080028
Chris Sosaaa18e162013-06-20 13:20:30 -070029// Directory for AU prefs that are preserved across powerwash.
Kelvin Zhang575b8f82021-05-13 11:14:44 -040030static constexpr const auto& kPowerwashSafePrefsSubDirectory =
31 "update_engine/prefs";
Chris Sosaaa18e162013-06-20 13:20:30 -070032
33// The location where we store the AU preferences (state etc).
Kelvin Zhang575b8f82021-05-13 11:14:44 -040034static constexpr const auto& kPrefsSubDirectory = "prefs";
Alex Deymo390efed2016-02-18 11:00:40 -080035
Chris Sosabe45bef2013-04-09 18:25:12 -070036// Path to the stateful partition on the root filesystem.
Kelvin Zhang575b8f82021-05-13 11:14:44 -040037static constexpr const auto& kStatefulPartition = "/mnt/stateful_partition";
38
39// Path to the post install command, relative to the partition.
40static constexpr const auto& kPostinstallDefaultScript = "postinst";
Chris Sosabe45bef2013-04-09 18:25:12 -070041
Jay Srinivasand29695d2013-04-08 15:08:05 -070042// Constants related to preferences.
Kelvin Zhang575b8f82021-05-13 11:14:44 -040043// Constants defining keys for the persisted state of update engine.
44static constexpr const auto& kPrefsAttemptInProgress = "attempt-in-progress";
45static constexpr const auto& kPrefsBackoffExpiryTime = "backoff-expiry-time";
46static constexpr const auto& kPrefsBootId = "boot-id";
47static constexpr const auto& kPrefsCurrentBytesDownloaded =
48 "current-bytes-downloaded";
49static constexpr const auto& kPrefsCurrentResponseSignature =
50 "current-response-signature";
51static constexpr const auto& kPrefsCurrentUrlFailureCount =
52 "current-url-failure-count";
53static constexpr const auto& kPrefsCurrentUrlIndex = "current-url-index";
54static constexpr const auto& kPrefsDailyMetricsLastReportedAt =
55 "daily-metrics-last-reported-at";
56static constexpr const auto& kPrefsDeltaUpdateFailures =
57 "delta-update-failures";
58static constexpr const auto& kPrefsDynamicPartitionMetadataUpdated =
59 "dynamic-partition-metadata-updated";
60static constexpr const auto& kPrefsFullPayloadAttemptNumber =
61 "full-payload-attempt-number";
62static constexpr const auto& kPrefsInstallDateDays = "install-date-days";
63static constexpr const auto& kPrefsLastActivePingDay = "last-active-ping-day";
64static constexpr const auto& kPrefsLastRollCallPingDay =
65 "last-roll-call-ping-day";
66static constexpr const auto& kPrefsManifestMetadataSize =
67 "manifest-metadata-size";
68static constexpr const auto& kPrefsManifestSignatureSize =
69 "manifest-signature-size";
70static constexpr const auto& kPrefsMetricsAttemptLastReportingTime =
71 "metrics-attempt-last-reporting-time";
72static constexpr const auto& kPrefsMetricsCheckLastReportingTime =
73 "metrics-check-last-reporting-time";
74static constexpr const auto& kPrefsNoIgnoreBackoff = "no-ignore-backoff";
75static constexpr const auto& kPrefsNumReboots = "num-reboots";
76static constexpr const auto& kPrefsNumResponsesSeen = "num-responses-seen";
77static constexpr const auto& kPrefsOmahaCohort = "omaha-cohort";
78static constexpr const auto& kPrefsOmahaCohortHint = "omaha-cohort-hint";
79static constexpr const auto& kPrefsOmahaCohortName = "omaha-cohort-name";
80static constexpr const auto& kPrefsOmahaEolDate = "omaha-eol-date";
81static constexpr const auto& kPrefsP2PEnabled = "p2p-enabled";
82static constexpr const auto& kPrefsP2PFirstAttemptTimestamp =
83 "p2p-first-attempt-timestamp";
84static constexpr const auto& kPrefsP2PNumAttempts = "p2p-num-attempts";
85static constexpr const auto& kPrefsPayloadAttemptNumber =
86 "payload-attempt-number";
87static constexpr const auto& kPrefsTestUpdateCheckIntervalTimeout =
88 "test-update-check-interval-timeout";
89// Keep |kPrefsPingActive| in sync with |kDlcMetadataFilePingActive| in
90// dlcservice.
91static constexpr const auto& kPrefsPingActive = "active";
92static constexpr const auto& kPrefsPingLastActive = "date_last_active";
93static constexpr const auto& kPrefsPingLastRollcall = "date_last_rollcall";
94static constexpr const auto& kPrefsLastFp = "last-fp";
95static constexpr const auto& kPrefsPostInstallSucceeded =
96 "post-install-succeeded";
97static constexpr const auto& kPrefsPreviousVersion = "previous-version";
98static constexpr const auto& kPrefsResumedUpdateFailures =
99 "resumed-update-failures";
100static constexpr const auto& kPrefsRollbackHappened = "rollback-happened";
101static constexpr const auto& kPrefsRollbackVersion = "rollback-version";
102static constexpr const auto& kPrefsChannelOnSlotPrefix = "channel-on-slot-";
103static constexpr const auto& kPrefsSystemUpdatedMarker =
104 "system-updated-marker";
105static constexpr const auto& kPrefsTargetVersionAttempt =
106 "target-version-attempt";
107static constexpr const auto& kPrefsTargetVersionInstalledFrom =
108 "target-version-installed-from";
109static constexpr const auto& kPrefsTargetVersionUniqueId =
110 "target-version-unique-id";
111static constexpr const auto& kPrefsTotalBytesDownloaded =
112 "total-bytes-downloaded";
113static constexpr const auto& kPrefsUpdateCheckCount = "update-check-count";
114static constexpr const auto& kPrefsUpdateCheckResponseHash =
115 "update-check-response-hash";
116static constexpr const auto& kPrefsUpdateCompletedBootTime =
117 "update-completed-boot-time";
118static constexpr const auto& kPrefsUpdateCompletedOnBootId =
119 "update-completed-on-boot-id";
120static constexpr const auto& kPrefsUpdateDurationUptime =
121 "update-duration-uptime";
122static constexpr const auto& kPrefsUpdateFirstSeenAt = "update-first-seen-at";
123static constexpr const auto& kPrefsUpdateOverCellularPermission =
124 "update-over-cellular-permission";
125static constexpr const auto& kPrefsUpdateOverCellularTargetVersion =
126 "update-over-cellular-target-version";
127static constexpr const auto& kPrefsUpdateOverCellularTargetSize =
128 "update-over-cellular-target-size";
129static constexpr const auto& kPrefsUpdateServerCertificate =
130 "update-server-cert";
131static constexpr const auto& kPrefsUpdateStateNextDataLength =
132 "update-state-next-data-length";
133static constexpr const auto& kPrefsUpdateStateNextDataOffset =
134 "update-state-next-data-offset";
135static constexpr const auto& kPrefsUpdateStateNextOperation =
136 "update-state-next-operation";
137static constexpr const auto& kPrefsUpdateStatePayloadIndex =
138 "update-state-payload-index";
139static constexpr const auto& kPrefsUpdateStateSHA256Context =
140 "update-state-sha-256-context";
141static constexpr const auto& kPrefsUpdateStateSignatureBlob =
142 "update-state-signature-blob";
143static constexpr const auto& kPrefsUpdateStateSignedSHA256Context =
144 "update-state-signed-sha-256-context";
145static constexpr const auto& kPrefsUpdateBootTimestampStart =
146 "update-boot-timestamp-start";
147static constexpr const auto& kPrefsUpdateTimestampStart =
148 "update-timestamp-start";
149static constexpr const auto& kPrefsUrlSwitchCount = "url-switch-count";
150static constexpr const auto& kPrefsVerityWritten = "verity-written";
151static constexpr const auto& kPrefsWallClockScatteringWaitPeriod =
152 "wall-clock-wait-period";
153static constexpr const auto& kPrefsWallClockStagingWaitPeriod =
154 "wall-clock-staging-wait-period";
155static constexpr const auto& kPrefsManifestBytes = "manifest-bytes";
156static constexpr const auto& kPrefsPreviousSlot = "previous-slot";
Jay Srinivasand29695d2013-04-08 15:08:05 -0700157
Alex Deymo98e691c2016-02-04 21:05:45 -0800158// Keys used when storing and loading payload properties.
Kelvin Zhang575b8f82021-05-13 11:14:44 -0400159// These four fields are generated by scripts/brillo_update_payload.
160static constexpr const auto& kPayloadPropertyFileSize = "FILE_SIZE";
161static constexpr const auto& kPayloadPropertyFileHash = "FILE_HASH";
162static constexpr const auto& kPayloadPropertyMetadataSize = "METADATA_SIZE";
163static constexpr const auto& kPayloadPropertyMetadataHash = "METADATA_HASH";
164// The Authorization: HTTP header to be sent when downloading the payload.
165static constexpr const auto& kPayloadPropertyAuthorization = "AUTHORIZATION";
166// The User-Agent HTTP header to be sent when downloading the payload.
167static constexpr const auto& kPayloadPropertyUserAgent = "USER_AGENT";
168// Set "POWERWASH=1" to powerwash (factory data reset) the device after
169// applying the update.
170static constexpr const auto& kPayloadPropertyPowerwash = "POWERWASH";
171// The network id to pass to android_setprocnetwork before downloading.
172// This can be used to zero-rate OTA traffic by sending it over the correct
173// network.
174static constexpr const auto& kPayloadPropertyNetworkId = "NETWORK_ID";
175// Set "SWITCH_SLOT_ON_REBOOT=0" to skip marking the updated partitions active.
176// The default is 1 (always switch slot if update succeeded).
177static constexpr const auto& kPayloadPropertySwitchSlotOnReboot =
178 "SWITCH_SLOT_ON_REBOOT";
179// Set "RUN_POST_INSTALL=0" to skip running optional post install.
180// The default is 1 (always run post install).
181static constexpr const auto& kPayloadPropertyRunPostInstall =
182 "RUN_POST_INSTALL";
Alex Deymo98e691c2016-02-04 21:05:45 -0800183
Kelvin Zhang575b8f82021-05-13 11:14:44 -0400184static constexpr const auto& kOmahaUpdaterVersion = "0.1.0.0";
Amin Hassani7fca2862019-03-28 16:09:22 -0700185
Jae Hoon Kim0ae8fe12019-06-26 14:32:50 -0700186// X-Goog-Update headers.
Kelvin Zhang575b8f82021-05-13 11:14:44 -0400187// X-Goog-Update headers.
188static constexpr const auto& kXGoogleUpdateInteractivity =
189 "X-Goog-Update-Interactivity";
190static constexpr const auto& kXGoogleUpdateAppId = "X-Goog-Update-AppId";
191static constexpr const auto& kXGoogleUpdateUpdater = "X-Goog-Update-Updater";
192static constexpr const auto& kXGoogleUpdateSessionId = "X-Goog-SessionId";
Jae Hoon Kim0ae8fe12019-06-26 14:32:50 -0700193
Kelvin Zhangc7a1d1f2022-07-29 13:36:29 -0700194// Proxy URL for direction connection
195static constexpr const auto& kNoProxy = "direct://";
196
Jay Srinivasan19409b72013-04-12 19:23:36 -0700197// A download source is any combination of protocol and server (that's of
198// interest to us when looking at UMA metrics) using which we may download
199// the payload.
200typedef enum {
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700201 kDownloadSourceHttpsServer, // UMA Binary representation: 0001
202 kDownloadSourceHttpServer, // UMA Binary representation: 0010
203 kDownloadSourceHttpPeer, // UMA Binary representation: 0100
Jay Srinivasan19409b72013-04-12 19:23:36 -0700204
205 // Note: Add new sources only above this line.
206 kNumDownloadSources
207} DownloadSource;
208
Alex Deymo1c656c42013-06-28 11:02:14 -0700209// A payload can be a Full or Delta payload. In some cases, a Full payload is
210// used even when a Delta payload was available for the update, called here
211// ForcedFull. The PayloadType enum is only used to send UMA metrics about the
212// successfully applied payload.
213typedef enum {
214 kPayloadTypeFull,
215 kPayloadTypeDelta,
216 kPayloadTypeForcedFull,
217
218 // Note: Add new payload types only above this line.
219 kNumPayloadTypes
220} PayloadType;
221
David Zeuthen8f191b22013-08-06 12:27:50 -0700222// Maximum number of times we'll allow using p2p for the same update payload.
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400223constexpr int kMaxP2PAttempts = 10;
David Zeuthendcba8092013-08-06 12:16:35 -0700224
David Zeuthen8f191b22013-08-06 12:27:50 -0700225// Maximum wallclock time we allow attempting to update using p2p for
David Zeuthen472b2052014-02-25 16:27:04 -0800226// the same update payload - five days.
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400227constexpr int kMaxP2PAttemptTimeSeconds = 5 * 24 * 60 * 60;
David Zeuthen8f191b22013-08-06 12:27:50 -0700228
229// The maximum amount of time to spend waiting for p2p-client(1) to
230// return while waiting in line to use the LAN - six hours.
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400231constexpr int kMaxP2PNetworkWaitTimeSeconds = 6 * 60 * 60;
David Zeuthendcba8092013-08-06 12:16:35 -0700232
David Zeuthen526cb582013-08-06 12:26:18 -0700233// The maximum number of payload files to keep in /var/cache/p2p.
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400234constexpr int kMaxP2PFilesToKeep = 3;
David Zeuthen526cb582013-08-06 12:26:18 -0700235
David Zeuthen41f2cf52014-11-05 12:29:45 -0500236// The maximum number of days to keep a p2p file;
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400237constexpr int kMaxP2PFileAgeDays = 5;
David Zeuthen41f2cf52014-11-05 12:29:45 -0500238
Jay Srinivasan19409b72013-04-12 19:23:36 -0700239// The default number of UMA buckets for metrics.
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400240constexpr int kNumDefaultUmaBuckets = 50;
Jay Srinivasan19409b72013-04-12 19:23:36 -0700241
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400242// General constexprants
243constexpr int kNumBytesInOneMiB = 1024 * 1024;
Jay Srinivasan19409b72013-04-12 19:23:36 -0700244
David Zeuthen34135a92013-08-06 11:16:16 -0700245// Number of redirects allowed when downloading.
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400246constexpr int kDownloadMaxRedirects = 10;
David Zeuthen34135a92013-08-06 11:16:16 -0700247
David Zeuthena641be52013-09-12 10:59:57 -0700248// The minimum average speed that downloads must sustain...
David Zeuthen34135a92013-08-06 11:16:16 -0700249//
250// This is set low because some devices may have very poor
Alex Vakulenko072359c2014-07-18 11:41:07 -0700251// connectivity and we want to make as much forward progress as
David Zeuthena641be52013-09-12 10:59:57 -0700252// possible. For p2p this is high (25 kB/second) since we can assume
David Zeuthen34135a92013-08-06 11:16:16 -0700253// high bandwidth (same LAN) and we want to fail fast.
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400254constexpr int kDownloadLowSpeedLimitBps = 1;
255constexpr int kDownloadP2PLowSpeedLimitBps = 25 * 1000;
David Zeuthen34135a92013-08-06 11:16:16 -0700256
257// ... measured over this period.
258//
259// For non-official builds (e.g. typically built on a developer's
260// workstation and served via devserver) bump this since it takes time
Aaron Wood22290592018-03-09 09:19:15 -0800261// for the workstation to generate the payload. For normal operation
262// and p2p, make this relatively low since we want to fail fast in
263// those cases.
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400264constexpr int kDownloadLowSpeedTimeSeconds = 30;
265constexpr int kDownloadDevModeLowSpeedTimeSeconds = 180;
266constexpr int kDownloadP2PLowSpeedTimeSeconds = 60;
David Zeuthen34135a92013-08-06 11:16:16 -0700267
268// The maximum amount of HTTP server reconnect attempts.
269//
270// This is set high in order to maximize the attempt's chance of
271// succeeding. When using p2p, this is low in order to fail fast.
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400272constexpr int kDownloadMaxRetryCount = 20;
273constexpr int kDownloadMaxRetryCountOobeNotComplete = 3;
274constexpr int kDownloadMaxRetryCountInteractive = 3;
275constexpr int kDownloadP2PMaxRetryCount = 5;
David Zeuthen34135a92013-08-06 11:16:16 -0700276
277// The connect timeout, in seconds.
278//
279// This is set high because some devices may have very poor
280// connectivity and we may be using HTTPS which involves complicated
281// multi-roundtrip setup. For p2p, this is set low because we can
282// the server is on the same LAN and we want to fail fast.
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400283constexpr int kDownloadConnectTimeoutSeconds = 30;
284constexpr int kDownloadP2PConnectTimeoutSeconds = 5;
David Zeuthen34135a92013-08-06 11:16:16 -0700285
xunchangcda3c032019-03-26 15:41:14 -0700286// Size in bytes of SHA256 hash.
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400287constexpr int kSHA256Size = 32;
288
289// A hardcoded label to mark end of all InstallOps
290// This number must be greater than number of install ops.
291// Number of install ops is bounded by number of blocks on any partition.
292// Currently, the block size is 4096. Using |kEndOfInstallLabel| of 2^48 will
293// allow partitions with 2^48 * 4096 = 2^60 bytes. That's 1024PB? Partitions on
294// android aren't getting that big any time soon.
295constexpr uint64_t kEndOfInstallLabel = (1ULL << 48);
xunchangcda3c032019-03-26 15:41:14 -0700296
Jay Srinivasan1c0fe792013-03-28 16:45:25 -0700297} // namespace chromeos_update_engine
298
Alex Deymo39910dc2015-11-09 17:04:30 -0800299#endif // UPDATE_ENGINE_COMMON_CONSTANTS_H_