lin
2025-08-14 dae8bad597b6607a449b32bf76c523423f7720ed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// Copyright (C) 2014 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
 
#include "update_engine/update_manager/default_policy.h"
 
using chromeos_update_engine::ErrorCode;
using chromeos_update_engine::InstallPlan;
 
namespace {
 
// A fixed minimum interval between consecutive allowed update checks. This
// needs to be long enough to prevent busywork and/or DDoS attacks on Omaha, but
// at the same time short enough to allow the machine to update itself
// reasonably soon.
const int kCheckIntervalInSeconds = 15 * 60;
 
}  // namespace
 
namespace chromeos_update_manager {
 
DefaultPolicy::DefaultPolicy(chromeos_update_engine::ClockInterface* clock)
    : clock_(clock), aux_state_(new DefaultPolicyState()) {}
 
EvalStatus DefaultPolicy::UpdateCheckAllowed(EvaluationContext* ec,
                                             State* state,
                                             std::string* error,
                                             UpdateCheckParams* result) const {
  result->updates_enabled = true;
  result->target_channel.clear();
  result->target_version_prefix.clear();
  result->rollback_allowed = false;
  result->rollback_allowed_milestones = -1;  // No version rolls should happen.
  result->interactive = false;
 
  // Ensure that the minimum interval is set. If there's no clock, this defaults
  // to always allowing the update.
  if (!aux_state_->IsLastCheckAllowedTimeSet() ||
      ec->IsMonotonicTimeGreaterThan(
          aux_state_->last_check_allowed_time() +
          base::TimeDelta::FromSeconds(kCheckIntervalInSeconds))) {
    if (clock_)
      aux_state_->set_last_check_allowed_time(clock_->GetMonotonicTime());
    return EvalStatus::kSucceeded;
  }
 
  return EvalStatus::kAskMeAgainLater;
}
 
EvalStatus DefaultPolicy::UpdateCanBeApplied(EvaluationContext* ec,
                                             State* state,
                                             std::string* error,
                                             ErrorCode* result,
                                             InstallPlan* install_plan) const {
  *result = ErrorCode::kSuccess;
  return EvalStatus::kSucceeded;
}
 
EvalStatus DefaultPolicy::UpdateCanStart(EvaluationContext* ec,
                                         State* state,
                                         std::string* error,
                                         UpdateDownloadParams* result,
                                         const UpdateState update_state) const {
  result->update_can_start = true;
  result->cannot_start_reason = UpdateCannotStartReason::kUndefined;
  result->download_url_idx = 0;
  result->download_url_allowed = true;
  result->download_url_num_errors = 0;
  result->p2p_downloading_allowed = false;
  result->p2p_sharing_allowed = false;
  result->do_increment_failures = false;
  result->backoff_expiry = base::Time();
  result->scatter_wait_period = base::TimeDelta();
  result->scatter_check_threshold = 0;
  return EvalStatus::kSucceeded;
}
 
EvalStatus DefaultPolicy::UpdateDownloadAllowed(EvaluationContext* ec,
                                                State* state,
                                                std::string* error,
                                                bool* result) const {
  *result = true;
  return EvalStatus::kSucceeded;
}
 
EvalStatus DefaultPolicy::P2PEnabled(EvaluationContext* ec,
                                     State* state,
                                     std::string* error,
                                     bool* result) const {
  *result = false;
  return EvalStatus::kSucceeded;
}
 
EvalStatus DefaultPolicy::P2PEnabledChanged(EvaluationContext* ec,
                                            State* state,
                                            std::string* error,
                                            bool* result,
                                            bool prev_result) const {
  // This policy will always prohibit P2P, so this is signaling to the caller
  // that the decision is final (because the current value is the same as the
  // previous one) and there's no need to issue another call.
  *result = false;
  return EvalStatus::kSucceeded;
}
 
}  // namespace chromeos_update_manager