Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 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 Arnold | a23e408 | 2014-07-17 11:40:43 -0700 | [diff] [blame] | 16 | |
Amin Hassani | 0468a76 | 2020-11-17 23:53:48 -0800 | [diff] [blame] | 17 | #include "update_engine/common/system_state.h" |
Gilad Arnold | a23e408 | 2014-07-17 11:40:43 -0700 | [diff] [blame] | 18 | #include "update_engine/update_manager/default_policy.h" |
| 19 | |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 20 | using chromeos_update_engine::ErrorCode; |
| 21 | using chromeos_update_engine::InstallPlan; |
Amin Hassani | 0468a76 | 2020-11-17 23:53:48 -0800 | [diff] [blame] | 22 | using chromeos_update_engine::SystemState; |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 23 | |
Gilad Arnold | a23e408 | 2014-07-17 11:40:43 -0700 | [diff] [blame] | 24 | namespace { |
| 25 | |
| 26 | // A fixed minimum interval between consecutive allowed update checks. This |
| 27 | // needs to be long enough to prevent busywork and/or DDoS attacks on Omaha, but |
| 28 | // at the same time short enough to allow the machine to update itself |
| 29 | // reasonably soon. |
| 30 | const int kCheckIntervalInSeconds = 15 * 60; |
| 31 | |
| 32 | } // namespace |
| 33 | |
| 34 | namespace chromeos_update_manager { |
| 35 | |
Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame] | 36 | EvalStatus DefaultPolicy::UpdateCheckAllowed(EvaluationContext* ec, |
| 37 | State* state, |
| 38 | std::string* error, |
| 39 | UpdateCheckParams* result) const { |
Gilad Arnold | a23e408 | 2014-07-17 11:40:43 -0700 | [diff] [blame] | 40 | result->updates_enabled = true; |
| 41 | result->target_channel.clear(); |
Amin Hassani | 37b6723 | 2020-08-13 09:29:48 -0700 | [diff] [blame] | 42 | result->lts_tag.clear(); |
Gilad Arnold | d4b3032 | 2014-07-21 15:35:27 -0700 | [diff] [blame] | 43 | result->target_version_prefix.clear(); |
Marton Hunyady | ba51c3f | 2018-04-25 15:18:10 +0200 | [diff] [blame] | 44 | result->rollback_allowed = false; |
Marton Hunyady | 0e0e354 | 2018-02-21 18:51:39 +0100 | [diff] [blame] | 45 | result->rollback_allowed_milestones = -1; // No version rolls should happen. |
Miriam Polzer | aff7200 | 2020-08-27 08:20:39 +0200 | [diff] [blame] | 46 | result->rollback_on_channel_downgrade = false; |
Amin Hassani | ed37d68 | 2018-04-06 13:22:00 -0700 | [diff] [blame] | 47 | result->interactive = false; |
Saurabh Nijhara | 43d7adc | 2020-11-06 16:13:02 +0100 | [diff] [blame] | 48 | result->quick_fix_build_token.clear(); |
Gilad Arnold | a23e408 | 2014-07-17 11:40:43 -0700 | [diff] [blame] | 49 | |
| 50 | // Ensure that the minimum interval is set. If there's no clock, this defaults |
| 51 | // to always allowing the update. |
| 52 | if (!aux_state_->IsLastCheckAllowedTimeSet() || |
| 53 | ec->IsMonotonicTimeGreaterThan( |
| 54 | aux_state_->last_check_allowed_time() + |
| 55 | base::TimeDelta::FromSeconds(kCheckIntervalInSeconds))) { |
Amin Hassani | 0468a76 | 2020-11-17 23:53:48 -0800 | [diff] [blame] | 56 | aux_state_->set_last_check_allowed_time( |
| 57 | SystemState::Get()->clock()->GetMonotonicTime()); |
Gilad Arnold | a23e408 | 2014-07-17 11:40:43 -0700 | [diff] [blame] | 58 | return EvalStatus::kSucceeded; |
| 59 | } |
| 60 | |
| 61 | return EvalStatus::kAskMeAgainLater; |
| 62 | } |
| 63 | |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 64 | EvalStatus DefaultPolicy::UpdateCanBeApplied(EvaluationContext* ec, |
| 65 | State* state, |
| 66 | std::string* error, |
| 67 | ErrorCode* result, |
| 68 | InstallPlan* install_plan) const { |
| 69 | *result = ErrorCode::kSuccess; |
| 70 | return EvalStatus::kSucceeded; |
| 71 | } |
| 72 | |
Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame] | 73 | EvalStatus DefaultPolicy::UpdateCanStart(EvaluationContext* ec, |
| 74 | State* state, |
| 75 | std::string* error, |
| 76 | UpdateDownloadParams* result, |
| 77 | const UpdateState update_state) const { |
Gilad Arnold | dc4bb26 | 2014-07-23 10:45:19 -0700 | [diff] [blame] | 78 | result->update_can_start = true; |
| 79 | result->cannot_start_reason = UpdateCannotStartReason::kUndefined; |
| 80 | result->download_url_idx = 0; |
Gilad Arnold | 14a9e70 | 2014-10-08 08:09:09 -0700 | [diff] [blame] | 81 | result->download_url_allowed = true; |
Gilad Arnold | dc4bb26 | 2014-07-23 10:45:19 -0700 | [diff] [blame] | 82 | result->download_url_num_errors = 0; |
Gilad Arnold | b2f9919 | 2014-10-07 13:01:52 -0700 | [diff] [blame] | 83 | result->p2p_downloading_allowed = false; |
| 84 | result->p2p_sharing_allowed = false; |
Gilad Arnold | dc4bb26 | 2014-07-23 10:45:19 -0700 | [diff] [blame] | 85 | result->do_increment_failures = false; |
| 86 | result->backoff_expiry = base::Time(); |
| 87 | result->scatter_wait_period = base::TimeDelta(); |
| 88 | result->scatter_check_threshold = 0; |
| 89 | return EvalStatus::kSucceeded; |
| 90 | } |
| 91 | |
Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame] | 92 | EvalStatus DefaultPolicy::P2PEnabled(EvaluationContext* ec, |
| 93 | State* state, |
| 94 | std::string* error, |
| 95 | bool* result) const { |
Gilad Arnold | 78ecbfc | 2014-10-22 14:38:25 -0700 | [diff] [blame] | 96 | *result = false; |
| 97 | return EvalStatus::kSucceeded; |
| 98 | } |
| 99 | |
Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame] | 100 | EvalStatus DefaultPolicy::P2PEnabledChanged(EvaluationContext* ec, |
| 101 | State* state, |
| 102 | std::string* error, |
| 103 | bool* result, |
| 104 | bool prev_result) const { |
Gilad Arnold | 78ecbfc | 2014-10-22 14:38:25 -0700 | [diff] [blame] | 105 | // This policy will always prohibit P2P, so this is signaling to the caller |
| 106 | // that the decision is final (because the current value is the same as the |
| 107 | // previous one) and there's no need to issue another call. |
| 108 | *result = false; |
| 109 | return EvalStatus::kSucceeded; |
| 110 | } |
| 111 | |
Gilad Arnold | a23e408 | 2014-07-17 11:40:43 -0700 | [diff] [blame] | 112 | } // namespace chromeos_update_manager |