1 //
2 // Copyright (C) 2017 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 //
16
17 #include "update_engine/update_manager/interactive_update_policy_impl.h"
18
19 using chromeos_update_engine::ErrorCode;
20 using chromeos_update_engine::InstallPlan;
21
22 namespace chromeos_update_manager {
23
24 // Check to see if an interactive update was requested.
UpdateCheckAllowed(EvaluationContext * ec,State * state,std::string * error,UpdateCheckParams * result) const25 EvalStatus InteractiveUpdatePolicyImpl::UpdateCheckAllowed(
26 EvaluationContext* ec,
27 State* state,
28 std::string* error,
29 UpdateCheckParams* result) const {
30 bool interactive;
31 if (CheckInteractiveUpdateRequested(
32 ec, state->updater_provider(), &interactive)) {
33 result->interactive = interactive;
34 LOG(INFO) << "Forced update signaled ("
35 << (interactive ? "interactive" : "periodic")
36 << "), allowing update check.";
37 return EvalStatus::kSucceeded;
38 }
39 return EvalStatus::kContinue;
40 }
41
UpdateCanBeApplied(EvaluationContext * ec,State * state,std::string * error,ErrorCode * result,InstallPlan * install_plan) const42 EvalStatus InteractiveUpdatePolicyImpl::UpdateCanBeApplied(
43 EvaluationContext* ec,
44 State* state,
45 std::string* error,
46 ErrorCode* result,
47 InstallPlan* install_plan) const {
48 bool interactive;
49 if (CheckInteractiveUpdateRequested(
50 ec, state->updater_provider(), &interactive)) {
51 LOG(INFO) << "Forced update signaled ("
52 << (interactive ? "interactive" : "periodic")
53 << "), allowing update to be applied.";
54 *result = ErrorCode::kSuccess;
55 return EvalStatus::kSucceeded;
56 }
57 return EvalStatus::kContinue;
58 }
59
CheckInteractiveUpdateRequested(EvaluationContext * ec,UpdaterProvider * const updater_provider,bool * interactive_out) const60 bool InteractiveUpdatePolicyImpl::CheckInteractiveUpdateRequested(
61 EvaluationContext* ec,
62 UpdaterProvider* const updater_provider,
63 bool* interactive_out) const {
64 // First, check to see if an interactive update was requested.
65 const UpdateRequestStatus* forced_update_requested_p =
66 ec->GetValue(updater_provider->var_forced_update_requested());
67 if (forced_update_requested_p != nullptr &&
68 *forced_update_requested_p != UpdateRequestStatus::kNone) {
69 if (interactive_out)
70 *interactive_out =
71 (*forced_update_requested_p == UpdateRequestStatus::kInteractive);
72 return true;
73 }
74 return false;
75 }
76
77 } // namespace chromeos_update_manager
78