-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp2p_enabled_policy.cc
93 lines (80 loc) · 3.55 KB
/
p2p_enabled_policy.cc
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
//
// Copyright 2021 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/p2p_enabled_policy.h"
#include <string>
using std::string;
namespace chromeos_update_manager {
const int kMaxP2PAttempts = 10;
const base::TimeDelta kMaxP2PAttemptsPeriod = base::Days(5);
EvalStatus P2PEnabledPolicy::Evaluate(EvaluationContext* ec,
State* state,
string* error,
PolicyDataInterface* data) const {
bool enabled = false;
// Determine whether use of P2P is allowed by policy. Even if P2P is not
// explicitly allowed, we allow it if the device is enterprise enrolled (that
// is, missing or empty owner string).
DevicePolicyProvider* const dp_provider = state->device_policy_provider();
const bool* device_policy_is_loaded_p =
ec->GetValue(dp_provider->var_device_policy_is_loaded());
if (device_policy_is_loaded_p && *device_policy_is_loaded_p) {
const bool* policy_au_p2p_enabled_p =
ec->GetValue(dp_provider->var_au_p2p_enabled());
if (policy_au_p2p_enabled_p) {
enabled = *policy_au_p2p_enabled_p;
}
}
// Enable P2P, if so mandated by the updater configuration. This is additive
// to whether or not P2P is enabled by device policy.
if (!enabled) {
const bool* updater_p2p_enabled_p =
ec->GetValue(state->updater_provider()->var_p2p_enabled());
enabled = updater_p2p_enabled_p && *updater_p2p_enabled_p;
}
static_cast<P2PEnabledPolicyData*>(data)->set_enabled(enabled);
return EvalStatus::kSucceeded;
}
EvalStatus P2PEnabledPolicy::EvaluateDefault(EvaluationContext* ec,
State* state,
std::string* error,
PolicyDataInterface* data) const {
static_cast<P2PEnabledPolicyData*>(data)->set_enabled(false);
return EvalStatus::kSucceeded;
}
EvalStatus P2PEnabledChangedPolicy::Evaluate(EvaluationContext* ec,
State* state,
string* error,
PolicyDataInterface* data) const {
P2PEnabledPolicy policy;
EvalStatus status = policy.Evaluate(ec, state, error, data);
auto p2p_data = static_cast<P2PEnabledPolicyData*>(data);
if (status == EvalStatus::kSucceeded &&
p2p_data->enabled() == p2p_data->prev_enabled())
return EvalStatus::kAskMeAgainLater;
return status;
}
EvalStatus P2PEnabledChangedPolicy::EvaluateDefault(
EvaluationContext* ec,
State* state,
std::string* error,
PolicyDataInterface* data) 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.
static_cast<P2PEnabledPolicyData*>(data)->set_enabled(false);
return EvalStatus::kSucceeded;
}
} // namespace chromeos_update_manager