blob: f8ef84f2e8fd835aedf314aab1bc8cb0cbc2395f [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//
Alex Deymoc705cc82014-02-19 11:15:00 -080016
Alex Deymo63784a52014-05-28 10:46:14 -070017#include "update_engine/update_manager/chromeos_policy.h"
Alex Deymo0d11c602014-04-23 20:12:20 -070018
Gilad Arnolde1218812014-05-07 12:21:36 -070019#include <algorithm>
Gilad Arnold0adbc942014-05-12 10:35:43 -070020#include <set>
Alex Deymoc705cc82014-02-19 11:15:00 -080021#include <string>
Amin Hassani186ff6a2018-02-27 11:06:03 -080022#include <vector>
Alex Deymoc705cc82014-02-19 11:15:00 -080023
Gilad Arnoldf62a4b82014-05-01 07:41:07 -070024#include <base/logging.h>
Gilad Arnoldb3b05442014-05-30 14:25:05 -070025#include <base/strings/string_util.h>
Gilad Arnoldf62a4b82014-05-01 07:41:07 -070026#include <base/time/time.h>
27
Alex Deymo39910dc2015-11-09 17:04:30 -080028#include "update_engine/common/error_code.h"
Alex Deymoe88e9fe2016-02-03 16:38:00 -080029#include "update_engine/common/error_code_utils.h"
Alex Deymo39910dc2015-11-09 17:04:30 -080030#include "update_engine/common/utils.h"
Alex Deymo63784a52014-05-28 10:46:14 -070031#include "update_engine/update_manager/device_policy_provider.h"
Amin Hassani186ff6a2018-02-27 11:06:03 -080032#include "update_engine/update_manager/enough_slots_ab_updates_policy_impl.h"
33#include "update_engine/update_manager/enterprise_device_policy_impl.h"
34#include "update_engine/update_manager/interactive_update_policy_impl.h"
35#include "update_engine/update_manager/official_build_check_policy_impl.h"
36#include "update_engine/update_manager/out_of_box_experience_policy_impl.h"
Alex Deymo63784a52014-05-28 10:46:14 -070037#include "update_engine/update_manager/policy_utils.h"
38#include "update_engine/update_manager/shill_provider.h"
Adolfo Victoria94ffe132018-06-28 16:14:56 -070039#include "update_engine/update_manager/update_time_restrictions_policy_impl.h"
Gilad Arnoldf62a4b82014-05-01 07:41:07 -070040
Alex Deymo0d11c602014-04-23 20:12:20 -070041using base::Time;
42using base::TimeDelta;
Sen Jiang255e22b2016-05-20 16:15:29 -070043using chromeos_update_engine::ConnectionTethering;
44using chromeos_update_engine::ConnectionType;
Gilad Arnoldb3b05442014-05-30 14:25:05 -070045using chromeos_update_engine::ErrorCode;
Aaron Wood23bd3392017-10-06 14:48:25 -070046using chromeos_update_engine::InstallPlan;
Gilad Arnolddc4bb262014-07-23 10:45:19 -070047using std::get;
Gilad Arnoldf62a4b82014-05-01 07:41:07 -070048using std::min;
Gilad Arnold0adbc942014-05-12 10:35:43 -070049using std::set;
Alex Deymoc705cc82014-02-19 11:15:00 -080050using std::string;
Amin Hassani186ff6a2018-02-27 11:06:03 -080051using std::vector;
Alex Deymoc705cc82014-02-19 11:15:00 -080052
Gilad Arnoldb3b05442014-05-30 14:25:05 -070053namespace {
54
Gilad Arnolddc4bb262014-07-23 10:45:19 -070055// Examines |err_code| and decides whether the URL index needs to be advanced,
56// the error count for the URL incremented, or none of the above. In the first
57// case, returns true; in the second case, increments |*url_num_error_p| and
58// returns false; otherwise just returns false.
Gilad Arnoldb3b05442014-05-30 14:25:05 -070059//
60// TODO(garnold) Adapted from PayloadState::UpdateFailed() (to be retired).
Gilad Arnolddc4bb262014-07-23 10:45:19 -070061bool HandleErrorCode(ErrorCode err_code, int* url_num_error_p) {
Gilad Arnoldb3b05442014-05-30 14:25:05 -070062 err_code = chromeos_update_engine::utils::GetBaseErrorCode(err_code);
63 switch (err_code) {
64 // Errors which are good indicators of a problem with a particular URL or
65 // the protocol used in the URL or entities in the communication channel
66 // (e.g. proxies). We should try the next available URL in the next update
67 // check to quickly recover from these errors.
68 case ErrorCode::kPayloadHashMismatchError:
69 case ErrorCode::kPayloadSizeMismatchError:
70 case ErrorCode::kDownloadPayloadVerificationError:
71 case ErrorCode::kDownloadPayloadPubKeyVerificationError:
72 case ErrorCode::kSignedDeltaPayloadExpectedError:
73 case ErrorCode::kDownloadInvalidMetadataMagicString:
74 case ErrorCode::kDownloadSignatureMissingInManifest:
75 case ErrorCode::kDownloadManifestParseError:
76 case ErrorCode::kDownloadMetadataSignatureError:
77 case ErrorCode::kDownloadMetadataSignatureVerificationError:
78 case ErrorCode::kDownloadMetadataSignatureMismatch:
79 case ErrorCode::kDownloadOperationHashVerificationError:
80 case ErrorCode::kDownloadOperationExecutionError:
81 case ErrorCode::kDownloadOperationHashMismatch:
82 case ErrorCode::kDownloadInvalidMetadataSize:
83 case ErrorCode::kDownloadInvalidMetadataSignature:
84 case ErrorCode::kDownloadOperationHashMissingError:
85 case ErrorCode::kDownloadMetadataSignatureMissingError:
86 case ErrorCode::kPayloadMismatchedType:
87 case ErrorCode::kUnsupportedMajorPayloadVersion:
88 case ErrorCode::kUnsupportedMinorPayloadVersion:
89 LOG(INFO) << "Advancing download URL due to error "
Alex Deymoe88e9fe2016-02-03 16:38:00 -080090 << chromeos_update_engine::utils::ErrorCodeToString(err_code)
Gilad Arnoldb3b05442014-05-30 14:25:05 -070091 << " (" << static_cast<int>(err_code) << ")";
Gilad Arnoldb3b05442014-05-30 14:25:05 -070092 return true;
93
94 // Errors which seem to be just transient network/communication related
95 // failures and do not indicate any inherent problem with the URL itself.
96 // So, we should keep the current URL but just increment the
97 // failure count to give it more chances. This way, while we maximize our
98 // chances of downloading from the URLs that appear earlier in the response
99 // (because download from a local server URL that appears earlier in a
100 // response is preferable than downloading from the next URL which could be
Alex Vakulenko072359c2014-07-18 11:41:07 -0700101 // an Internet URL and thus could be more expensive).
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700102 case ErrorCode::kError:
103 case ErrorCode::kDownloadTransferError:
104 case ErrorCode::kDownloadWriteError:
105 case ErrorCode::kDownloadStateInitializationError:
Gilad Arnold684219d2014-07-07 14:54:57 -0700106 case ErrorCode::kOmahaErrorInHTTPResponse: // Aggregate for HTTP errors.
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700107 LOG(INFO) << "Incrementing URL failure count due to error "
Alex Deymoe88e9fe2016-02-03 16:38:00 -0800108 << chromeos_update_engine::utils::ErrorCodeToString(err_code)
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700109 << " (" << static_cast<int>(err_code) << ")";
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700110 *url_num_error_p += 1;
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700111 return false;
112
113 // Errors which are not specific to a URL and hence shouldn't result in
114 // the URL being penalized. This can happen in two cases:
115 // 1. We haven't started downloading anything: These errors don't cost us
116 // anything in terms of actual payload bytes, so we should just do the
117 // regular retries at the next update check.
118 // 2. We have successfully downloaded the payload: In this case, the
119 // payload attempt number would have been incremented and would take care
Alex Vakulenko072359c2014-07-18 11:41:07 -0700120 // of the back-off at the next update check.
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700121 // In either case, there's no need to update URL index or failure count.
122 case ErrorCode::kOmahaRequestError:
123 case ErrorCode::kOmahaResponseHandlerError:
124 case ErrorCode::kPostinstallRunnerError:
125 case ErrorCode::kFilesystemCopierError:
126 case ErrorCode::kInstallDeviceOpenError:
127 case ErrorCode::kKernelDeviceOpenError:
128 case ErrorCode::kDownloadNewPartitionInfoError:
129 case ErrorCode::kNewRootfsVerificationError:
130 case ErrorCode::kNewKernelVerificationError:
131 case ErrorCode::kPostinstallBootedFromFirmwareB:
132 case ErrorCode::kPostinstallFirmwareRONotUpdatable:
133 case ErrorCode::kOmahaRequestEmptyResponseError:
134 case ErrorCode::kOmahaRequestXMLParseError:
135 case ErrorCode::kOmahaResponseInvalid:
136 case ErrorCode::kOmahaUpdateIgnoredPerPolicy:
137 case ErrorCode::kOmahaUpdateDeferredPerPolicy:
Kevin Cernekee2494e282016-03-29 18:03:53 -0700138 case ErrorCode::kNonCriticalUpdateInOOBE:
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700139 case ErrorCode::kOmahaUpdateDeferredForBackoff:
140 case ErrorCode::kPostinstallPowerwashError:
141 case ErrorCode::kUpdateCanceledByChannelChange:
David Zeuthenf3e28012014-08-26 18:23:52 -0400142 case ErrorCode::kOmahaRequestXMLHasEntityDecl:
Allie Woodeb9e6d82015-04-17 13:55:30 -0700143 case ErrorCode::kFilesystemVerifierError:
Alex Deymo1f19dcc2016-02-03 09:22:17 -0800144 case ErrorCode::kUserCanceled:
Weidong Guo421ff332017-04-17 10:08:38 -0700145 case ErrorCode::kOmahaUpdateIgnoredOverCellular:
Sen Jiang02c49422017-10-31 15:14:11 -0700146 case ErrorCode::kUpdatedButNotActive:
Sen Jiang3978ddd2018-03-22 18:05:44 -0700147 case ErrorCode::kNoUpdate:
Marton Hunyady199152d2018-05-07 19:08:48 +0200148 case ErrorCode::kRollbackNotPossible:
Amin Hassani80f4d4c2018-05-16 13:34:00 -0700149 case ErrorCode::kFirstActiveOmahaPingSentPersistenceError:
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700150 LOG(INFO) << "Not changing URL index or failure count due to error "
Alex Deymoe88e9fe2016-02-03 16:38:00 -0800151 << chromeos_update_engine::utils::ErrorCodeToString(err_code)
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700152 << " (" << static_cast<int>(err_code) << ")";
153 return false;
154
155 case ErrorCode::kSuccess: // success code
156 case ErrorCode::kUmaReportedMax: // not an error code
157 case ErrorCode::kOmahaRequestHTTPResponseBase: // aggregated already
Alex Deymo1f19dcc2016-02-03 09:22:17 -0800158 case ErrorCode::kDevModeFlag: // not an error code
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700159 case ErrorCode::kResumedFlag: // not an error code
160 case ErrorCode::kTestImageFlag: // not an error code
161 case ErrorCode::kTestOmahaUrlFlag: // not an error code
162 case ErrorCode::kSpecialFlags: // not an error code
163 // These shouldn't happen. Enumerating these explicitly here so that we
164 // can let the compiler warn about new error codes that are added to
165 // action_processor.h but not added here.
166 LOG(WARNING) << "Unexpected error "
Alex Deymoe88e9fe2016-02-03 16:38:00 -0800167 << chromeos_update_engine::utils::ErrorCodeToString(err_code)
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700168 << " (" << static_cast<int>(err_code) << ")";
169 // Note: Not adding a default here so as to let the compiler warn us of
170 // any new enums that were added in the .h but not listed in this switch.
171 }
172 return false;
173}
174
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700175// Checks whether |url| can be used under given download restrictions.
176bool IsUrlUsable(const string& url, bool http_allowed) {
Alex Vakulenko0103c362016-01-20 07:56:15 -0800177 return http_allowed ||
178 !base::StartsWith(url, "http://",
179 base::CompareCase::INSENSITIVE_ASCII);
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700180}
181
182} // namespace
183
Alex Deymo63784a52014-05-28 10:46:14 -0700184namespace chromeos_update_manager {
Alex Deymoc705cc82014-02-19 11:15:00 -0800185
Amin Hassani186ff6a2018-02-27 11:06:03 -0800186const NextUpdateCheckPolicyConstants
187 ChromeOSPolicy::kNextUpdateCheckPolicyConstants = {
188 .timeout_initial_interval = 7 * 60,
189 .timeout_periodic_interval = 45 * 60,
190 .timeout_max_backoff_interval = 4 * 60 * 60,
191 .timeout_regular_fuzz = 10 * 60,
192 .attempt_backoff_max_interval_in_days = 16,
193 .attempt_backoff_fuzz_in_hours = 12,
194};
Alex Deymo14e7dde2015-10-20 14:46:33 -0700195
Gilad Arnold349ac832014-10-06 14:20:28 -0700196const int ChromeOSPolicy::kMaxP2PAttempts = 10;
197const int ChromeOSPolicy::kMaxP2PAttemptsPeriodInSeconds = 5 * 24 * 60 * 60;
Gilad Arnolda2e8eaa2014-09-24 13:12:33 -0700198
Alex Deymo0d11c602014-04-23 20:12:20 -0700199EvalStatus ChromeOSPolicy::UpdateCheckAllowed(
200 EvaluationContext* ec, State* state, string* error,
201 UpdateCheckParams* result) const {
Gilad Arnold42f253b2014-06-25 12:39:17 -0700202 // Set the default return values.
203 result->updates_enabled = true;
204 result->target_channel.clear();
Gilad Arnoldd4b30322014-07-21 15:35:27 -0700205 result->target_version_prefix.clear();
Marton Hunyadyba51c3f2018-04-25 15:18:10 +0200206 result->rollback_allowed = false;
Marton Hunyady0e0e3542018-02-21 18:51:39 +0100207 result->rollback_allowed_milestones = -1;
Amin Hassanied37d682018-04-06 13:22:00 -0700208 result->interactive = false;
Gilad Arnold42f253b2014-06-25 12:39:17 -0700209
Amin Hassani186ff6a2018-02-27 11:06:03 -0800210 EnoughSlotsAbUpdatesPolicyImpl enough_slots_ab_updates_policy;
211 EnterpriseDevicePolicyImpl enterprise_device_policy;
212 OnlyUpdateOfficialBuildsPolicyImpl only_update_official_builds_policy;
213 InteractiveUpdatePolicyImpl interactive_update_policy;
214 OobePolicyImpl oobe_policy;
215 NextUpdateCheckTimePolicyImpl next_update_check_time_policy(
216 kNextUpdateCheckPolicyConstants);
Adolfo Victoria94ffe132018-06-28 16:14:56 -0700217 UpdateTimeRestrictionsPolicyImpl update_time_restrictions_policy;
Gilad Arnolda1eabcd2014-07-09 15:42:40 -0700218
Amin Hassani186ff6a2018-02-27 11:06:03 -0800219 vector<Policy const*> policies_to_consult = {
220 // Do not perform any updates if there are not enough slots to do A/B
221 // updates.
222 &enough_slots_ab_updates_policy,
223
224 // Check to see if Enterprise-managed (has DevicePolicy) and/or
225 // Kiosk-mode. If so, then defer to those settings.
226 &enterprise_device_policy,
227
228 // Check to see if an interactive update was requested.
229 &interactive_update_policy,
230
231 // Unofficial builds should not perform periodic update checks.
232 &only_update_official_builds_policy,
233
234 // If OOBE is enabled, wait until it is completed.
235 &oobe_policy,
236
Adolfo Victoria94ffe132018-06-28 16:14:56 -0700237 // Ensure that updates are checked only in allowed times.
238 &update_time_restrictions_policy,
239
Amin Hassani186ff6a2018-02-27 11:06:03 -0800240 // Ensure that periodic update checks are timed properly.
241 &next_update_check_time_policy,
242 };
243
244 // Now that the list of policy implementations, and the order to consult them,
245 // has been setup, consult the policies. If none of the policies make a
246 // definitive decisions about whether or not to check for updates, then allow
247 // the update check to happen.
248 EvalStatus status = ConsultPolicies(policies_to_consult,
249 &Policy::UpdateCheckAllowed,
250 ec,
251 state,
252 error,
253 result);
254 if (EvalStatus::kContinue != status) {
255 return status;
256 } else {
257 // It is time to check for an update.
258 LOG(INFO) << "Allowing update check.";
Gilad Arnoldbfc44f72014-07-09 14:41:39 -0700259 return EvalStatus::kSucceeded;
260 }
Alex Deymoc705cc82014-02-19 11:15:00 -0800261}
262
Aaron Wood23bd3392017-10-06 14:48:25 -0700263EvalStatus ChromeOSPolicy::UpdateCanBeApplied(EvaluationContext* ec,
264 State* state,
265 std::string* error,
266 ErrorCode* result,
267 InstallPlan* install_plan) const {
268 *result = ErrorCode::kSuccess;
269 return EvalStatus::kSucceeded;
270}
271
Gilad Arnoldf62a4b82014-05-01 07:41:07 -0700272EvalStatus ChromeOSPolicy::UpdateCanStart(
273 EvaluationContext* ec,
274 State* state,
275 string* error,
Gilad Arnold42f253b2014-06-25 12:39:17 -0700276 UpdateDownloadParams* result,
Gilad Arnoldd78caf92014-09-24 09:28:14 -0700277 const UpdateState update_state) const {
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700278 // Set the default return values. Note that we set persisted values (backoff,
279 // scattering) to the same values presented in the update state. The reason is
280 // that preemptive returns, such as the case where an update check is due,
281 // should not clear off the said values; rather, it is the deliberate
282 // inference of new values that should cause them to be reset.
Gilad Arnold14a9e702014-10-08 08:09:09 -0700283 result->update_can_start = false;
Gilad Arnoldf62a4b82014-05-01 07:41:07 -0700284 result->cannot_start_reason = UpdateCannotStartReason::kUndefined;
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700285 result->download_url_idx = -1;
Gilad Arnold14a9e702014-10-08 08:09:09 -0700286 result->download_url_allowed = true;
287 result->download_url_num_errors = 0;
Gilad Arnoldb2f99192014-10-07 13:01:52 -0700288 result->p2p_downloading_allowed = false;
289 result->p2p_sharing_allowed = false;
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700290 result->do_increment_failures = false;
291 result->backoff_expiry = update_state.backoff_expiry;
292 result->scatter_wait_period = update_state.scatter_wait_period;
293 result->scatter_check_threshold = update_state.scatter_check_threshold;
Gilad Arnoldf62a4b82014-05-01 07:41:07 -0700294
295 // Make sure that we're not due for an update check.
296 UpdateCheckParams check_result;
297 EvalStatus check_status = UpdateCheckAllowed(ec, state, error, &check_result);
298 if (check_status == EvalStatus::kFailed)
299 return EvalStatus::kFailed;
Gilad Arnold14a9e702014-10-08 08:09:09 -0700300 bool is_check_due = (check_status == EvalStatus::kSucceeded &&
301 check_result.updates_enabled == true);
Gilad Arnoldf62a4b82014-05-01 07:41:07 -0700302
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700303 // Check whether backoff applies, and if not then which URL can be used for
304 // downloading. These require scanning the download error log, and so they are
305 // done together.
306 UpdateBackoffAndDownloadUrlResult backoff_url_result;
307 EvalStatus backoff_url_status = UpdateBackoffAndDownloadUrl(
308 ec, state, error, &backoff_url_result, update_state);
Gilad Arnold14a9e702014-10-08 08:09:09 -0700309 if (backoff_url_status == EvalStatus::kFailed)
310 return EvalStatus::kFailed;
311 result->download_url_idx = backoff_url_result.url_idx;
312 result->download_url_num_errors = backoff_url_result.url_num_errors;
313 result->do_increment_failures = backoff_url_result.do_increment_failures;
314 result->backoff_expiry = backoff_url_result.backoff_expiry;
315 bool is_backoff_active =
316 (backoff_url_status == EvalStatus::kAskMeAgainLater) ||
317 !backoff_url_result.backoff_expiry.is_null();
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700318
Gilad Arnoldf62a4b82014-05-01 07:41:07 -0700319 DevicePolicyProvider* const dp_provider = state->device_policy_provider();
Gilad Arnold14a9e702014-10-08 08:09:09 -0700320 bool is_scattering_active = false;
321 EvalStatus scattering_status = EvalStatus::kSucceeded;
Gilad Arnoldf62a4b82014-05-01 07:41:07 -0700322
323 const bool* device_policy_is_loaded_p = ec->GetValue(
324 dp_provider->var_device_policy_is_loaded());
325 if (device_policy_is_loaded_p && *device_policy_is_loaded_p) {
Gilad Arnold76a11f62014-05-20 09:02:12 -0700326 // Check whether scattering applies to this update attempt. We should not be
327 // scattering if this is an interactive update check, or if OOBE is enabled
328 // but not completed.
329 //
330 // Note: current code further suppresses scattering if a "deadline"
Gilad Arnoldf62a4b82014-05-01 07:41:07 -0700331 // attribute is found in the Omaha response. However, it appears that the
Gilad Arnold76a11f62014-05-20 09:02:12 -0700332 // presence of this attribute is merely indicative of an OOBE update, during
333 // which we suppress scattering anyway.
Gilad Arnold14a9e702014-10-08 08:09:09 -0700334 bool is_scattering_applicable = false;
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700335 result->scatter_wait_period = kZeroInterval;
336 result->scatter_check_threshold = 0;
Amin Hassanied37d682018-04-06 13:22:00 -0700337 if (!update_state.interactive) {
Gilad Arnold76a11f62014-05-20 09:02:12 -0700338 const bool* is_oobe_enabled_p = ec->GetValue(
339 state->config_provider()->var_is_oobe_enabled());
340 if (is_oobe_enabled_p && !(*is_oobe_enabled_p)) {
Gilad Arnold14a9e702014-10-08 08:09:09 -0700341 is_scattering_applicable = true;
Gilad Arnold76a11f62014-05-20 09:02:12 -0700342 } else {
343 const bool* is_oobe_complete_p = ec->GetValue(
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700344 state->system_provider()->var_is_oobe_complete());
Gilad Arnold14a9e702014-10-08 08:09:09 -0700345 is_scattering_applicable = (is_oobe_complete_p && *is_oobe_complete_p);
Gilad Arnold76a11f62014-05-20 09:02:12 -0700346 }
347 }
348
349 // Compute scattering values.
Gilad Arnold14a9e702014-10-08 08:09:09 -0700350 if (is_scattering_applicable) {
Gilad Arnoldf62a4b82014-05-01 07:41:07 -0700351 UpdateScatteringResult scatter_result;
Gilad Arnold14a9e702014-10-08 08:09:09 -0700352 scattering_status = UpdateScattering(ec, state, error, &scatter_result,
353 update_state);
354 if (scattering_status == EvalStatus::kFailed) {
355 return EvalStatus::kFailed;
356 } else {
357 result->scatter_wait_period = scatter_result.wait_period;
358 result->scatter_check_threshold = scatter_result.check_threshold;
359 if (scattering_status == EvalStatus::kAskMeAgainLater ||
360 scatter_result.is_scattering)
361 is_scattering_active = true;
Gilad Arnoldf62a4b82014-05-01 07:41:07 -0700362 }
363 }
Gilad Arnold78ecbfc2014-10-22 14:38:25 -0700364 }
Gilad Arnoldf62a4b82014-05-01 07:41:07 -0700365
Gilad Arnold78ecbfc2014-10-22 14:38:25 -0700366 // Find out whether P2P is globally enabled.
367 bool p2p_enabled;
368 EvalStatus p2p_enabled_status = P2PEnabled(ec, state, error, &p2p_enabled);
369 if (p2p_enabled_status != EvalStatus::kSucceeded)
370 return EvalStatus::kFailed;
371
372 // Is P2P is enabled, consider allowing it for downloading and/or sharing.
373 if (p2p_enabled) {
374 // Sharing via P2P is allowed if not disabled by Omaha.
375 if (update_state.p2p_sharing_disabled) {
376 LOG(INFO) << "Blocked P2P sharing because it is disabled by Omaha.";
Gilad Arnoldb2f99192014-10-07 13:01:52 -0700377 } else {
Gilad Arnold78ecbfc2014-10-22 14:38:25 -0700378 result->p2p_sharing_allowed = true;
Gilad Arnoldef8d0872014-10-03 14:14:06 -0700379 }
Gilad Arnoldf62a4b82014-05-01 07:41:07 -0700380
Gilad Arnold78ecbfc2014-10-22 14:38:25 -0700381 // Downloading via P2P is allowed if not disabled by Omaha, an update is not
382 // interactive, and other limits haven't been reached.
383 if (update_state.p2p_downloading_disabled) {
384 LOG(INFO) << "Blocked P2P downloading because it is disabled by Omaha.";
Amin Hassanied37d682018-04-06 13:22:00 -0700385 } else if (update_state.interactive) {
Gilad Arnold78ecbfc2014-10-22 14:38:25 -0700386 LOG(INFO) << "Blocked P2P downloading because update is interactive.";
Gilad Arnoldb2f99192014-10-07 13:01:52 -0700387 } else if (update_state.p2p_num_attempts >= kMaxP2PAttempts) {
Gilad Arnold78ecbfc2014-10-22 14:38:25 -0700388 LOG(INFO) << "Blocked P2P downloading as it was attempted too many "
389 "times.";
Gilad Arnoldb2f99192014-10-07 13:01:52 -0700390 } else if (!update_state.p2p_first_attempted.is_null() &&
391 ec->IsWallclockTimeGreaterThan(
392 update_state.p2p_first_attempted +
393 TimeDelta::FromSeconds(kMaxP2PAttemptsPeriodInSeconds))) {
Gilad Arnold78ecbfc2014-10-22 14:38:25 -0700394 LOG(INFO) << "Blocked P2P downloading as its usage timespan exceeds "
395 "limit.";
Gilad Arnoldb2f99192014-10-07 13:01:52 -0700396 } else {
Gilad Arnold14a9e702014-10-08 08:09:09 -0700397 // P2P download is allowed; if backoff or scattering are active, be sure
398 // to suppress them, yet prevent any download URL from being used.
Gilad Arnoldb2f99192014-10-07 13:01:52 -0700399 result->p2p_downloading_allowed = true;
Gilad Arnold14a9e702014-10-08 08:09:09 -0700400 if (is_backoff_active || is_scattering_active) {
401 is_backoff_active = is_scattering_active = false;
402 result->download_url_allowed = false;
403 }
Gilad Arnoldb2f99192014-10-07 13:01:52 -0700404 }
Gilad Arnoldf62a4b82014-05-01 07:41:07 -0700405 }
406
Gilad Arnold14a9e702014-10-08 08:09:09 -0700407 // Check for various deterrents.
408 if (is_check_due) {
409 result->cannot_start_reason = UpdateCannotStartReason::kCheckDue;
410 return EvalStatus::kSucceeded;
411 }
412 if (is_backoff_active) {
413 result->cannot_start_reason = UpdateCannotStartReason::kBackoff;
414 return backoff_url_status;
415 }
416 if (is_scattering_active) {
417 result->cannot_start_reason = UpdateCannotStartReason::kScattering;
418 return scattering_status;
419 }
Gilad Arnoldb2f99192014-10-07 13:01:52 -0700420 if (result->download_url_idx < 0 && !result->p2p_downloading_allowed) {
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700421 result->cannot_start_reason = UpdateCannotStartReason::kCannotDownload;
Gilad Arnold14a9e702014-10-08 08:09:09 -0700422 return EvalStatus::kSucceeded;
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700423 }
424
Gilad Arnold14a9e702014-10-08 08:09:09 -0700425 // Update is good to go.
426 result->update_can_start = true;
Gilad Arnoldaf2f6ae2014-04-28 14:14:52 -0700427 return EvalStatus::kSucceeded;
428}
429
Gilad Arnolda8262e22014-06-02 13:54:27 -0700430// TODO(garnold) Logic in this method is based on
431// ConnectionManager::IsUpdateAllowedOver(); be sure to deprecate the latter.
432//
433// TODO(garnold) The current logic generally treats the list of allowed
434// connections coming from the device policy as a whitelist, meaning that it
435// can only be used for enabling connections, but not disable them. Further,
436// certain connection types (like Bluetooth) cannot be enabled even by policy.
437// In effect, the only thing that device policy can change is to enable
438// updates over a cellular network (disabled by default). We may want to
439// revisit this semantics, allowing greater flexibility in defining specific
440// permissions over all types of networks.
Gilad Arnold684219d2014-07-07 14:54:57 -0700441EvalStatus ChromeOSPolicy::UpdateDownloadAllowed(
Gilad Arnolda8262e22014-06-02 13:54:27 -0700442 EvaluationContext* ec,
443 State* state,
444 string* error,
445 bool* result) const {
446 // Get the current connection type.
447 ShillProvider* const shill_provider = state->shill_provider();
448 const ConnectionType* conn_type_p = ec->GetValue(
449 shill_provider->var_conn_type());
450 POLICY_CHECK_VALUE_AND_FAIL(conn_type_p, error);
451 ConnectionType conn_type = *conn_type_p;
452
453 // If we're tethering, treat it as a cellular connection.
454 if (conn_type != ConnectionType::kCellular) {
455 const ConnectionTethering* conn_tethering_p = ec->GetValue(
456 shill_provider->var_conn_tethering());
457 POLICY_CHECK_VALUE_AND_FAIL(conn_tethering_p, error);
458 if (*conn_tethering_p == ConnectionTethering::kConfirmed)
459 conn_type = ConnectionType::kCellular;
460 }
461
462 // By default, we allow updates for all connection types, with exceptions as
463 // noted below. This also determines whether a device policy can override the
464 // default.
465 *result = true;
466 bool device_policy_can_override = false;
467 switch (conn_type) {
468 case ConnectionType::kBluetooth:
469 *result = false;
470 break;
471
472 case ConnectionType::kCellular:
473 *result = false;
474 device_policy_can_override = true;
475 break;
476
477 case ConnectionType::kUnknown:
478 if (error)
479 *error = "Unknown connection type";
480 return EvalStatus::kFailed;
481
482 default:
483 break; // Nothing to do.
484 }
485
486 // If update is allowed, we're done.
487 if (*result)
488 return EvalStatus::kSucceeded;
489
490 // Check whether the device policy specifically allows this connection.
Gilad Arnolda8262e22014-06-02 13:54:27 -0700491 if (device_policy_can_override) {
492 DevicePolicyProvider* const dp_provider = state->device_policy_provider();
493 const bool* device_policy_is_loaded_p = ec->GetValue(
494 dp_provider->var_device_policy_is_loaded());
495 if (device_policy_is_loaded_p && *device_policy_is_loaded_p) {
496 const set<ConnectionType>* allowed_conn_types_p = ec->GetValue(
497 dp_provider->var_allowed_connection_types_for_update());
498 if (allowed_conn_types_p) {
499 if (allowed_conn_types_p->count(conn_type)) {
500 *result = true;
501 return EvalStatus::kSucceeded;
502 }
Gilad Arnold28d6be62014-06-30 14:04:04 -0700503 } else if (conn_type == ConnectionType::kCellular) {
504 // Local user settings can allow updates over cellular iff a policy was
505 // loaded but no allowed connections were specified in it.
506 const bool* update_over_cellular_allowed_p = ec->GetValue(
507 state->updater_provider()->var_cellular_enabled());
508 if (update_over_cellular_allowed_p && *update_over_cellular_allowed_p)
509 *result = true;
Gilad Arnolda8262e22014-06-02 13:54:27 -0700510 }
511 }
512 }
513
Gilad Arnold28d6be62014-06-30 14:04:04 -0700514 return (*result ? EvalStatus::kSucceeded : EvalStatus::kAskMeAgainLater);
Gilad Arnolda8262e22014-06-02 13:54:27 -0700515}
516
Gilad Arnold78ecbfc2014-10-22 14:38:25 -0700517EvalStatus ChromeOSPolicy::P2PEnabled(EvaluationContext* ec,
518 State* state,
Alex Deymo39910dc2015-11-09 17:04:30 -0800519 string* error,
Gilad Arnold78ecbfc2014-10-22 14:38:25 -0700520 bool* result) const {
521 bool enabled = false;
522
523 // Determine whether use of P2P is allowed by policy. Even if P2P is not
524 // explicitly allowed, we allow it if the device is enterprise enrolled (that
525 // is, missing or empty owner string).
526 DevicePolicyProvider* const dp_provider = state->device_policy_provider();
527 const bool* device_policy_is_loaded_p = ec->GetValue(
528 dp_provider->var_device_policy_is_loaded());
529 if (device_policy_is_loaded_p && *device_policy_is_loaded_p) {
530 const bool* policy_au_p2p_enabled_p = ec->GetValue(
531 dp_provider->var_au_p2p_enabled());
532 if (policy_au_p2p_enabled_p) {
533 enabled = *policy_au_p2p_enabled_p;
534 } else {
535 const string* policy_owner_p = ec->GetValue(dp_provider->var_owner());
536 if (!policy_owner_p || policy_owner_p->empty())
537 enabled = true;
538 }
539 }
540
541 // Enable P2P, if so mandated by the updater configuration. This is additive
542 // to whether or not P2P is enabled by device policy.
543 if (!enabled) {
544 const bool* updater_p2p_enabled_p = ec->GetValue(
545 state->updater_provider()->var_p2p_enabled());
546 enabled = updater_p2p_enabled_p && *updater_p2p_enabled_p;
547 }
548
549 *result = enabled;
550 return EvalStatus::kSucceeded;
551}
552
553EvalStatus ChromeOSPolicy::P2PEnabledChanged(EvaluationContext* ec,
554 State* state,
Alex Deymo39910dc2015-11-09 17:04:30 -0800555 string* error,
Gilad Arnold78ecbfc2014-10-22 14:38:25 -0700556 bool* result,
557 bool prev_result) const {
558 EvalStatus status = P2PEnabled(ec, state, error, result);
559 if (status == EvalStatus::kSucceeded && *result == prev_result)
560 return EvalStatus::kAskMeAgainLater;
561 return status;
562}
563
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700564EvalStatus ChromeOSPolicy::UpdateBackoffAndDownloadUrl(
Alex Deymof329b932014-10-30 01:37:48 -0700565 EvaluationContext* ec, State* state, string* error,
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700566 UpdateBackoffAndDownloadUrlResult* result,
567 const UpdateState& update_state) const {
568 // Sanity checks.
569 DCHECK_GE(update_state.download_errors_max, 0);
570
571 // Set default result values.
572 result->do_increment_failures = false;
573 result->backoff_expiry = update_state.backoff_expiry;
574 result->url_idx = -1;
575 result->url_num_errors = 0;
576
577 const bool* is_official_build_p = ec->GetValue(
578 state->system_provider()->var_is_official_build());
579 bool is_official_build = (is_official_build_p ? *is_official_build_p : true);
580
581 // Check whether backoff is enabled.
582 bool may_backoff = false;
583 if (update_state.is_backoff_disabled) {
584 LOG(INFO) << "Backoff disabled by Omaha.";
Amin Hassanied37d682018-04-06 13:22:00 -0700585 } else if (update_state.interactive) {
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700586 LOG(INFO) << "No backoff for interactive updates.";
587 } else if (update_state.is_delta_payload) {
588 LOG(INFO) << "No backoff for delta payloads.";
589 } else if (!is_official_build) {
590 LOG(INFO) << "No backoff for unofficial builds.";
591 } else {
592 may_backoff = true;
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700593 }
594
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700595 // If previous backoff still in effect, block.
596 if (may_backoff && !update_state.backoff_expiry.is_null() &&
597 !ec->IsWallclockTimeGreaterThan(update_state.backoff_expiry)) {
598 LOG(INFO) << "Previous backoff has not expired, waiting.";
599 return EvalStatus::kAskMeAgainLater;
600 }
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700601
602 // Determine whether HTTP downloads are forbidden by policy. This only
603 // applies to official system builds; otherwise, HTTP is always enabled.
604 bool http_allowed = true;
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700605 if (is_official_build) {
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700606 DevicePolicyProvider* const dp_provider = state->device_policy_provider();
607 const bool* device_policy_is_loaded_p = ec->GetValue(
608 dp_provider->var_device_policy_is_loaded());
609 if (device_policy_is_loaded_p && *device_policy_is_loaded_p) {
610 const bool* policy_http_downloads_enabled_p = ec->GetValue(
611 dp_provider->var_http_downloads_enabled());
612 http_allowed = (!policy_http_downloads_enabled_p ||
613 *policy_http_downloads_enabled_p);
614 }
615 }
616
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700617 int url_idx = update_state.last_download_url_idx;
618 if (url_idx < 0)
619 url_idx = -1;
620 bool do_advance_url = false;
621 bool is_failure_occurred = false;
622 Time err_time;
623
624 // Scan the relevant part of the download error log, tracking which URLs are
625 // being used, and accounting the number of errors for each URL. Note that
626 // this process may not traverse all errors provided, as it may decide to bail
627 // out midway depending on the particular errors exhibited, the number of
628 // failures allowed, etc. When this ends, |url_idx| will point to the last URL
629 // used (-1 if starting fresh), |do_advance_url| will determine whether the
630 // URL needs to be advanced, and |err_time| the point in time when the last
631 // reported error occurred. Additionally, if the error log indicates that an
632 // update attempt has failed (abnormal), then |is_failure_occurred| will be
633 // set to true.
634 const int num_urls = update_state.download_urls.size();
635 int prev_url_idx = -1;
636 int url_num_errors = update_state.last_download_url_num_errors;
637 Time prev_err_time;
638 bool is_first = true;
639 for (const auto& err_tuple : update_state.download_errors) {
640 // Do some sanity checks.
641 int used_url_idx = get<0>(err_tuple);
642 if (is_first && url_idx >= 0 && used_url_idx != url_idx) {
643 LOG(WARNING) << "First URL in error log (" << used_url_idx
644 << ") not as expected (" << url_idx << ")";
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700645 }
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700646 is_first = false;
647 url_idx = used_url_idx;
648 if (url_idx < 0 || url_idx >= num_urls) {
649 LOG(ERROR) << "Download error log contains an invalid URL index ("
650 << url_idx << ")";
651 return EvalStatus::kFailed;
652 }
653 err_time = get<2>(err_tuple);
654 if (!(prev_err_time.is_null() || err_time >= prev_err_time)) {
655 // TODO(garnold) Monotonicity cannot really be assumed when dealing with
656 // wallclock-based timestamps. However, we're making a simplifying
657 // assumption so as to keep the policy implementation straightforward, for
658 // now. In general, we should convert all timestamp handling in the
659 // UpdateManager to use monotonic time (instead of wallclock), including
660 // the computation of various expiration times (backoff, scattering, etc).
661 // The client will do whatever conversions necessary when
662 // persisting/retrieving these values across reboots. See chromium:408794.
663 LOG(ERROR) << "Download error timestamps not monotonically increasing.";
664 return EvalStatus::kFailed;
665 }
666 prev_err_time = err_time;
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700667
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700668 // Ignore errors that happened before the last known failed attempt.
669 if (!update_state.failures_last_updated.is_null() &&
670 err_time <= update_state.failures_last_updated)
671 continue;
672
673 if (prev_url_idx >= 0) {
674 if (url_idx < prev_url_idx) {
675 LOG(ERROR) << "The URLs in the download error log have wrapped around ("
676 << prev_url_idx << "->" << url_idx
677 << "). This should not have happened and means that there's "
678 "a bug. To be conservative, we record a failed attempt "
679 "(invalidating the rest of the error log) and resume "
680 "download from the first usable URL.";
681 url_idx = -1;
682 is_failure_occurred = true;
683 break;
684 }
685
686 if (url_idx > prev_url_idx) {
687 url_num_errors = 0;
688 do_advance_url = false;
689 }
690 }
691
692 if (HandleErrorCode(get<1>(err_tuple), &url_num_errors) ||
693 url_num_errors > update_state.download_errors_max)
694 do_advance_url = true;
695
696 prev_url_idx = url_idx;
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700697 }
698
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700699 // If required, advance to the next usable URL. If the URLs wraparound, we
700 // mark an update attempt failure. Also be sure to set the download error
701 // count to zero.
702 if (url_idx < 0 || do_advance_url) {
703 url_num_errors = 0;
704 int start_url_idx = -1;
705 do {
706 if (++url_idx == num_urls) {
707 url_idx = 0;
708 // We only mark failure if an actual advancing of a URL was required.
709 if (do_advance_url)
710 is_failure_occurred = true;
711 }
712
713 if (start_url_idx < 0)
714 start_url_idx = url_idx;
715 else if (url_idx == start_url_idx)
716 url_idx = -1; // No usable URL.
717 } while (url_idx >= 0 &&
718 !IsUrlUsable(update_state.download_urls[url_idx], http_allowed));
719 }
720
721 // If we have a download URL but a failure was observed, compute a new backoff
722 // expiry (if allowed). The backoff period is generally 2 ^ (num_failures - 1)
723 // days, bounded by the size of int and kAttemptBackoffMaxIntervalInDays, and
724 // fuzzed by kAttemptBackoffFuzzInHours hours. Backoff expiry is computed from
725 // the latest recorded time of error.
726 Time backoff_expiry;
727 if (url_idx >= 0 && is_failure_occurred && may_backoff) {
728 CHECK(!err_time.is_null())
729 << "We must have an error timestamp if a failure occurred!";
730 const uint64_t* seed = ec->GetValue(state->random_provider()->var_seed());
731 POLICY_CHECK_VALUE_AND_FAIL(seed, error);
732 PRNG prng(*seed);
Alex Deymof329b932014-10-30 01:37:48 -0700733 int exp = min(update_state.num_failures,
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700734 static_cast<int>(sizeof(int)) * 8 - 2);
Amin Hassani186ff6a2018-02-27 11:06:03 -0800735 TimeDelta backoff_interval = TimeDelta::FromDays(min(
736 1 << exp,
737 kNextUpdateCheckPolicyConstants.attempt_backoff_max_interval_in_days));
738 TimeDelta backoff_fuzz = TimeDelta::FromHours(
739 kNextUpdateCheckPolicyConstants.attempt_backoff_fuzz_in_hours);
740 TimeDelta wait_period = NextUpdateCheckTimePolicyImpl::FuzzedInterval(
741 &prng, backoff_interval.InSeconds(), backoff_fuzz.InSeconds());
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700742 backoff_expiry = err_time + wait_period;
743
744 // If the newly computed backoff already expired, nullify it.
745 if (ec->IsWallclockTimeGreaterThan(backoff_expiry))
746 backoff_expiry = Time();
747 }
748
749 result->do_increment_failures = is_failure_occurred;
750 result->backoff_expiry = backoff_expiry;
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700751 result->url_idx = url_idx;
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700752 result->url_num_errors = url_num_errors;
Gilad Arnoldb3b05442014-05-30 14:25:05 -0700753 return EvalStatus::kSucceeded;
754}
755
Gilad Arnoldf62a4b82014-05-01 07:41:07 -0700756EvalStatus ChromeOSPolicy::UpdateScattering(
757 EvaluationContext* ec,
758 State* state,
759 string* error,
760 UpdateScatteringResult* result,
761 const UpdateState& update_state) const {
762 // Preconditions. These stem from the postconditions and usage contract.
763 DCHECK(update_state.scatter_wait_period >= kZeroInterval);
764 DCHECK_GE(update_state.scatter_check_threshold, 0);
765
766 // Set default result values.
767 result->is_scattering = false;
768 result->wait_period = kZeroInterval;
769 result->check_threshold = 0;
770
771 DevicePolicyProvider* const dp_provider = state->device_policy_provider();
772
773 // Ensure that a device policy is loaded.
774 const bool* device_policy_is_loaded_p = ec->GetValue(
775 dp_provider->var_device_policy_is_loaded());
776 if (!(device_policy_is_loaded_p && *device_policy_is_loaded_p))
777 return EvalStatus::kSucceeded;
778
779 // Is scattering enabled by policy?
780 const TimeDelta* scatter_factor_p = ec->GetValue(
781 dp_provider->var_scatter_factor());
782 if (!scatter_factor_p || *scatter_factor_p == kZeroInterval)
783 return EvalStatus::kSucceeded;
784
785 // Obtain a pseudo-random number generator.
786 const uint64_t* seed = ec->GetValue(state->random_provider()->var_seed());
787 POLICY_CHECK_VALUE_AND_FAIL(seed, error);
788 PRNG prng(*seed);
789
790 // Step 1: Maintain the scattering wait period.
791 //
792 // If no wait period was previously determined, or it no longer fits in the
793 // scatter factor, then generate a new one. Otherwise, keep the one we have.
Gilad Arnoldf62a4b82014-05-01 07:41:07 -0700794 TimeDelta wait_period = update_state.scatter_wait_period;
795 if (wait_period == kZeroInterval || wait_period > *scatter_factor_p) {
796 wait_period = TimeDelta::FromSeconds(
797 prng.RandMinMax(1, scatter_factor_p->InSeconds()));
798 }
799
Gilad Arnolddc4bb262014-07-23 10:45:19 -0700800 // If we surpassed the wait period or the max scatter period associated with
Gilad Arnoldf62a4b82014-05-01 07:41:07 -0700801 // the update, then no wait is needed.
802 Time wait_expires = (update_state.first_seen +
803 min(wait_period, update_state.scatter_wait_period_max));
Gilad Arnolda65fced2014-07-23 09:01:31 -0700804 if (ec->IsWallclockTimeGreaterThan(wait_expires))
Gilad Arnoldf62a4b82014-05-01 07:41:07 -0700805 wait_period = kZeroInterval;
806
807 // Step 2: Maintain the update check threshold count.
808 //
809 // If an update check threshold is not specified then generate a new
810 // one.
811 int check_threshold = update_state.scatter_check_threshold;
812 if (check_threshold == 0) {
813 check_threshold = prng.RandMinMax(
814 update_state.scatter_check_threshold_min,
815 update_state.scatter_check_threshold_max);
816 }
817
818 // If the update check threshold is not within allowed range then nullify it.
819 // TODO(garnold) This is compliant with current logic found in
820 // OmahaRequestAction::IsUpdateCheckCountBasedWaitingSatisfied(). We may want
821 // to change it so that it behaves similarly to the wait period case, namely
822 // if the current value exceeds the maximum, we set a new one within range.
823 if (check_threshold > update_state.scatter_check_threshold_max)
824 check_threshold = 0;
825
826 // If the update check threshold is non-zero and satisfied, then nullify it.
827 if (check_threshold > 0 && update_state.num_checks >= check_threshold)
828 check_threshold = 0;
829
830 bool is_scattering = (wait_period != kZeroInterval || check_threshold);
831 EvalStatus ret = EvalStatus::kSucceeded;
832 if (is_scattering && wait_period == update_state.scatter_wait_period &&
833 check_threshold == update_state.scatter_check_threshold)
834 ret = EvalStatus::kAskMeAgainLater;
835 result->is_scattering = is_scattering;
836 result->wait_period = wait_period;
837 result->check_threshold = check_threshold;
838 return ret;
839}
840
Alex Deymo63784a52014-05-28 10:46:14 -0700841} // namespace chromeos_update_manager