| 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 |  | 
|  | 17 | #include "update_engine/update_manager/default_policy.h" | 
|  | 18 |  | 
| Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 19 | using chromeos_update_engine::ErrorCode; | 
|  | 20 | using chromeos_update_engine::InstallPlan; | 
|  | 21 |  | 
| Gilad Arnold | a23e408 | 2014-07-17 11:40:43 -0700 | [diff] [blame] | 22 | namespace { | 
|  | 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. | 
|  | 28 | const int kCheckIntervalInSeconds = 15 * 60; | 
|  | 29 |  | 
|  | 30 | }  // namespace | 
|  | 31 |  | 
|  | 32 | namespace chromeos_update_manager { | 
|  | 33 |  | 
|  | 34 | DefaultPolicy::DefaultPolicy(chromeos_update_engine::ClockInterface* clock) | 
|  | 35 | : clock_(clock), aux_state_(new DefaultPolicyState()) {} | 
|  | 36 |  | 
|  | 37 | EvalStatus 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 Arnold | d4b3032 | 2014-07-21 15:35:27 -0700 | [diff] [blame] | 42 | result->target_version_prefix.clear(); | 
| Marton Hunyady | ba51c3f | 2018-04-25 15:18:10 +0200 | [diff] [blame] | 43 | result->rollback_allowed = false; | 
| Marton Hunyady | 0e0e354 | 2018-02-21 18:51:39 +0100 | [diff] [blame] | 44 | result->rollback_allowed_milestones = -1;  // No version rolls should happen. | 
| Amin Hassani | ed37d68 | 2018-04-06 13:22:00 -0700 | [diff] [blame] | 45 | result->interactive = false; | 
| Gilad Arnold | a23e408 | 2014-07-17 11:40:43 -0700 | [diff] [blame] | 46 |  | 
|  | 47 | // Ensure that the minimum interval is set. If there's no clock, this defaults | 
|  | 48 | // to always allowing the update. | 
|  | 49 | if (!aux_state_->IsLastCheckAllowedTimeSet() || | 
|  | 50 | ec->IsMonotonicTimeGreaterThan( | 
|  | 51 | aux_state_->last_check_allowed_time() + | 
|  | 52 | base::TimeDelta::FromSeconds(kCheckIntervalInSeconds))) { | 
|  | 53 | if (clock_) | 
|  | 54 | aux_state_->set_last_check_allowed_time(clock_->GetMonotonicTime()); | 
|  | 55 | return EvalStatus::kSucceeded; | 
|  | 56 | } | 
|  | 57 |  | 
|  | 58 | return EvalStatus::kAskMeAgainLater; | 
|  | 59 | } | 
|  | 60 |  | 
| Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 61 | EvalStatus DefaultPolicy::UpdateCanBeApplied(EvaluationContext* ec, | 
|  | 62 | State* state, | 
|  | 63 | std::string* error, | 
|  | 64 | ErrorCode* result, | 
|  | 65 | InstallPlan* install_plan) const { | 
|  | 66 | *result = ErrorCode::kSuccess; | 
|  | 67 | return EvalStatus::kSucceeded; | 
|  | 68 | } | 
|  | 69 |  | 
| Gilad Arnold | dc4bb26 | 2014-07-23 10:45:19 -0700 | [diff] [blame] | 70 | EvalStatus DefaultPolicy::UpdateCanStart( | 
|  | 71 | EvaluationContext* ec, | 
|  | 72 | State* state, | 
|  | 73 | std::string* error, | 
|  | 74 | UpdateDownloadParams* result, | 
| Gilad Arnold | d78caf9 | 2014-09-24 09:28:14 -0700 | [diff] [blame] | 75 | const UpdateState update_state) const { | 
| Gilad Arnold | dc4bb26 | 2014-07-23 10:45:19 -0700 | [diff] [blame] | 76 | result->update_can_start = true; | 
|  | 77 | result->cannot_start_reason = UpdateCannotStartReason::kUndefined; | 
|  | 78 | result->download_url_idx = 0; | 
| Gilad Arnold | 14a9e70 | 2014-10-08 08:09:09 -0700 | [diff] [blame] | 79 | result->download_url_allowed = true; | 
| Gilad Arnold | dc4bb26 | 2014-07-23 10:45:19 -0700 | [diff] [blame] | 80 | result->download_url_num_errors = 0; | 
| Gilad Arnold | b2f9919 | 2014-10-07 13:01:52 -0700 | [diff] [blame] | 81 | result->p2p_downloading_allowed = false; | 
|  | 82 | result->p2p_sharing_allowed = false; | 
| Gilad Arnold | dc4bb26 | 2014-07-23 10:45:19 -0700 | [diff] [blame] | 83 | result->do_increment_failures = false; | 
|  | 84 | result->backoff_expiry = base::Time(); | 
|  | 85 | result->scatter_wait_period = base::TimeDelta(); | 
|  | 86 | result->scatter_check_threshold = 0; | 
|  | 87 | return EvalStatus::kSucceeded; | 
|  | 88 | } | 
|  | 89 |  | 
|  | 90 | EvalStatus DefaultPolicy::UpdateDownloadAllowed( | 
|  | 91 | EvaluationContext* ec, | 
|  | 92 | State* state, | 
|  | 93 | std::string* error, | 
|  | 94 | bool* result) const { | 
|  | 95 | *result = true; | 
|  | 96 | return EvalStatus::kSucceeded; | 
|  | 97 | } | 
|  | 98 |  | 
| Gilad Arnold | 78ecbfc | 2014-10-22 14:38:25 -0700 | [diff] [blame] | 99 | EvalStatus DefaultPolicy::P2PEnabled( | 
|  | 100 | EvaluationContext* ec, | 
|  | 101 | State* state, | 
|  | 102 | std::string* error, | 
|  | 103 | bool* result) const { | 
|  | 104 | *result = false; | 
|  | 105 | return EvalStatus::kSucceeded; | 
|  | 106 | } | 
|  | 107 |  | 
|  | 108 | EvalStatus DefaultPolicy::P2PEnabledChanged( | 
|  | 109 | EvaluationContext* ec, | 
|  | 110 | State* state, | 
|  | 111 | std::string* error, | 
|  | 112 | bool* result, | 
|  | 113 | bool prev_result) const { | 
|  | 114 | // This policy will always prohibit P2P, so this is signaling to the caller | 
|  | 115 | // that the decision is final (because the current value is the same as the | 
|  | 116 | // previous one) and there's no need to issue another call. | 
|  | 117 | *result = false; | 
|  | 118 | return EvalStatus::kSucceeded; | 
|  | 119 | } | 
|  | 120 |  | 
| Gilad Arnold | a23e408 | 2014-07-17 11:40:43 -0700 | [diff] [blame] | 121 | }  // namespace chromeos_update_manager |