blob: 5da1520a13d9701646843ad47c4fb94d1530bb43 [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 Wood987ffc12017-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
37EvalStatus DefaultPolicy::UpdateCheckAllowed(
38 EvaluationContext* ec, State* state, std::string* error,
39 UpdateCheckParams* result) const {
40 result->updates_enabled = true;
41 result->target_channel.clear();
Gilad Arnoldd4b30322014-07-21 15:35:27 -070042 result->target_version_prefix.clear();
Gilad Arnold44dc3bf2014-07-18 23:39:38 -070043 result->is_interactive = false;
Gilad Arnolda23e4082014-07-17 11:40:43 -070044
45 // Ensure that the minimum interval is set. If there's no clock, this defaults
46 // to always allowing the update.
47 if (!aux_state_->IsLastCheckAllowedTimeSet() ||
48 ec->IsMonotonicTimeGreaterThan(
49 aux_state_->last_check_allowed_time() +
50 base::TimeDelta::FromSeconds(kCheckIntervalInSeconds))) {
51 if (clock_)
52 aux_state_->set_last_check_allowed_time(clock_->GetMonotonicTime());
53 return EvalStatus::kSucceeded;
54 }
55
56 return EvalStatus::kAskMeAgainLater;
57}
58
Aaron Wood987ffc12017-10-06 14:48:25 -070059EvalStatus DefaultPolicy::UpdateCanBeApplied(EvaluationContext* ec,
60 State* state,
61 std::string* error,
62 ErrorCode* result,
63 InstallPlan* install_plan) const {
64 *result = ErrorCode::kSuccess;
65 return EvalStatus::kSucceeded;
66}
67
Gilad Arnolddc4bb262014-07-23 10:45:19 -070068EvalStatus DefaultPolicy::UpdateCanStart(
69 EvaluationContext* ec,
70 State* state,
71 std::string* error,
72 UpdateDownloadParams* result,
Gilad Arnoldd78caf92014-09-24 09:28:14 -070073 const UpdateState update_state) const {
Gilad Arnolddc4bb262014-07-23 10:45:19 -070074 result->update_can_start = true;
75 result->cannot_start_reason = UpdateCannotStartReason::kUndefined;
76 result->download_url_idx = 0;
Gilad Arnold14a9e702014-10-08 08:09:09 -070077 result->download_url_allowed = true;
Gilad Arnolddc4bb262014-07-23 10:45:19 -070078 result->download_url_num_errors = 0;
Gilad Arnoldb2f99192014-10-07 13:01:52 -070079 result->p2p_downloading_allowed = false;
80 result->p2p_sharing_allowed = false;
Gilad Arnolddc4bb262014-07-23 10:45:19 -070081 result->do_increment_failures = false;
82 result->backoff_expiry = base::Time();
83 result->scatter_wait_period = base::TimeDelta();
84 result->scatter_check_threshold = 0;
85 return EvalStatus::kSucceeded;
86}
87
88EvalStatus DefaultPolicy::UpdateDownloadAllowed(
89 EvaluationContext* ec,
90 State* state,
91 std::string* error,
92 bool* result) const {
93 *result = true;
94 return EvalStatus::kSucceeded;
95}
96
Gilad Arnold78ecbfc2014-10-22 14:38:25 -070097EvalStatus DefaultPolicy::P2PEnabled(
98 EvaluationContext* ec,
99 State* state,
100 std::string* error,
101 bool* result) const {
102 *result = false;
103 return EvalStatus::kSucceeded;
104}
105
106EvalStatus DefaultPolicy::P2PEnabledChanged(
107 EvaluationContext* ec,
108 State* state,
109 std::string* error,
110 bool* result,
111 bool prev_result) const {
112 // This policy will always prohibit P2P, so this is signaling to the caller
113 // that the decision is final (because the current value is the same as the
114 // previous one) and there's no need to issue another call.
115 *result = false;
116 return EvalStatus::kSucceeded;
117}
118
Gilad Arnolda23e4082014-07-17 11:40:43 -0700119} // namespace chromeos_update_manager