1 //
2 // Copyright (C) 2020 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/minimum_version_policy_impl.h"
18
19 #include <base/version.h>
20
21 using chromeos_update_engine::ErrorCode;
22 using chromeos_update_engine::InstallPlan;
23
24 namespace chromeos_update_manager {
25
UpdateCanBeApplied(EvaluationContext * ec,State * state,std::string * error,ErrorCode * result,InstallPlan * install_plan) const26 EvalStatus MinimumVersionPolicyImpl::UpdateCanBeApplied(
27 EvaluationContext* ec,
28 State* state,
29 std::string* error,
30 ErrorCode* result,
31 InstallPlan* install_plan) const {
32 const base::Version* current_version(
33 ec->GetValue(state->system_provider()->var_chromeos_version()));
34 if (current_version == nullptr || !current_version->IsValid()) {
35 LOG(WARNING) << "Unable to access current version";
36 return EvalStatus::kContinue;
37 }
38
39 const base::Version* minimum_version = ec->GetValue(
40 state->device_policy_provider()->var_device_minimum_version());
41 if (minimum_version == nullptr || !minimum_version->IsValid()) {
42 LOG(WARNING) << "Unable to access minimum version";
43 return EvalStatus::kContinue;
44 }
45
46 if (*current_version < *minimum_version) {
47 LOG(INFO) << "Updating from version less than minimum required"
48 ", allowing update to be applied.";
49 *result = ErrorCode::kSuccess;
50 return EvalStatus::kSucceeded;
51 }
52
53 return EvalStatus::kContinue;
54 }
55
56 } // namespace chromeos_update_manager
57