blob: cb9977f7982e01a33e9fa744f2018e9a3d109bf3 [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//
Gilad Arnolda23e4082014-07-17 11:40:43 -070016
17#include "update_engine/update_manager/default_policy.h"
18
Aaron Wood23bd3392017-10-06 14:48:25 -070019using chromeos_update_engine::ErrorCode;
20using chromeos_update_engine::InstallPlan;
21
Gilad Arnolda23e4082014-07-17 11:40:43 -070022namespace {
23
24// A fixed minimum interval between consecutive allowed update checks. This
25// needs to be long enough to prevent busywork and/or DDoS attacks on Omaha, but
26// at the same time short enough to allow the machine to update itself
27// reasonably soon.
28const int kCheckIntervalInSeconds = 15 * 60;
29
30} // namespace
31
32namespace chromeos_update_manager {
33
34DefaultPolicy::DefaultPolicy(chromeos_update_engine::ClockInterface* clock)
35 : clock_(clock), aux_state_(new DefaultPolicyState()) {}
36
Amin Hassani4b717432019-01-14 16:24:20 -080037EvalStatus DefaultPolicy::UpdateCheckAllowed(EvaluationContext* ec,
38 State* state,
39 std::string* error,
40 UpdateCheckParams* result) const {
Gilad Arnolda23e4082014-07-17 11:40:43 -070041 result->updates_enabled = true;
42 result->target_channel.clear();
Amin Hassani37b67232020-08-13 09:29:48 -070043 result->lts_tag.clear();
Gilad Arnoldd4b30322014-07-21 15:35:27 -070044 result->target_version_prefix.clear();
Marton Hunyadyba51c3f2018-04-25 15:18:10 +020045 result->rollback_allowed = false;
Marton Hunyady0e0e3542018-02-21 18:51:39 +010046 result->rollback_allowed_milestones = -1; // No version rolls should happen.
Miriam Polzeraff72002020-08-27 08:20:39 +020047 result->rollback_on_channel_downgrade = false;
Amin Hassanied37d682018-04-06 13:22:00 -070048 result->interactive = false;
Saurabh Nijhara43d7adc2020-11-06 16:13:02 +010049 result->quick_fix_build_token.clear();
Gilad Arnolda23e4082014-07-17 11:40:43 -070050
51 // Ensure that the minimum interval is set. If there's no clock, this defaults
52 // to always allowing the update.
53 if (!aux_state_->IsLastCheckAllowedTimeSet() ||
54 ec->IsMonotonicTimeGreaterThan(
55 aux_state_->last_check_allowed_time() +
56 base::TimeDelta::FromSeconds(kCheckIntervalInSeconds))) {
57 if (clock_)
58 aux_state_->set_last_check_allowed_time(clock_->GetMonotonicTime());
59 return EvalStatus::kSucceeded;
60 }
61
62 return EvalStatus::kAskMeAgainLater;
63}
64
Aaron Wood23bd3392017-10-06 14:48:25 -070065EvalStatus DefaultPolicy::UpdateCanBeApplied(EvaluationContext* ec,
66 State* state,
67 std::string* error,
68 ErrorCode* result,
69 InstallPlan* install_plan) const {
70 *result = ErrorCode::kSuccess;
71 return EvalStatus::kSucceeded;
72}
73
Amin Hassani4b717432019-01-14 16:24:20 -080074EvalStatus DefaultPolicy::UpdateCanStart(EvaluationContext* ec,
75 State* state,
76 std::string* error,
77 UpdateDownloadParams* result,
78 const UpdateState update_state) const {
Gilad Arnolddc4bb262014-07-23 10:45:19 -070079 result->update_can_start = true;
80 result->cannot_start_reason = UpdateCannotStartReason::kUndefined;
81 result->download_url_idx = 0;
Gilad Arnold14a9e702014-10-08 08:09:09 -070082 result->download_url_allowed = true;
Gilad Arnolddc4bb262014-07-23 10:45:19 -070083 result->download_url_num_errors = 0;
Gilad Arnoldb2f99192014-10-07 13:01:52 -070084 result->p2p_downloading_allowed = false;
85 result->p2p_sharing_allowed = false;
Gilad Arnolddc4bb262014-07-23 10:45:19 -070086 result->do_increment_failures = false;
87 result->backoff_expiry = base::Time();
88 result->scatter_wait_period = base::TimeDelta();
89 result->scatter_check_threshold = 0;
90 return EvalStatus::kSucceeded;
91}
92
Amin Hassani4b717432019-01-14 16:24:20 -080093EvalStatus DefaultPolicy::P2PEnabled(EvaluationContext* ec,
94 State* state,
95 std::string* error,
96 bool* result) const {
Gilad Arnold78ecbfc2014-10-22 14:38:25 -070097 *result = false;
98 return EvalStatus::kSucceeded;
99}
100
Amin Hassani4b717432019-01-14 16:24:20 -0800101EvalStatus DefaultPolicy::P2PEnabledChanged(EvaluationContext* ec,
102 State* state,
103 std::string* error,
104 bool* result,
105 bool prev_result) const {
Gilad Arnold78ecbfc2014-10-22 14:38:25 -0700106 // This policy will always prohibit P2P, so this is signaling to the caller
107 // that the decision is final (because the current value is the same as the
108 // previous one) and there's no need to issue another call.
109 *result = false;
110 return EvalStatus::kSucceeded;
111}
112
Gilad Arnolda23e4082014-07-17 11:40:43 -0700113} // namespace chromeos_update_manager