1 // 2 // Copyright (C) 2018 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 #ifndef UPDATE_ENGINE_UPDATE_MANAGER_UPDATE_TIME_RESTRICTIONS_POLICY_IMPL_H_ 17 #define UPDATE_ENGINE_UPDATE_MANAGER_UPDATE_TIME_RESTRICTIONS_POLICY_IMPL_H_ 18 19 #include <string> 20 21 #include <base/time/time.h> 22 23 #include "update_engine/common/error_code.h" 24 #include "update_engine/payload_consumer/install_plan.h" 25 #include "update_engine/update_manager/policy_utils.h" 26 27 namespace chromeos_update_manager { 28 29 // Policy that allows administrators to set time intervals during which 30 // automatic update checks are disallowed. This implementation then checks if 31 // the current time falls in the range spanned by the time intervals. If the 32 // current time falls in one of the intervals then the update check is 33 // blocked by this policy. 34 class UpdateTimeRestrictionsPolicyImpl : public PolicyImplBase { 35 public: 36 UpdateTimeRestrictionsPolicyImpl() = default; 37 ~UpdateTimeRestrictionsPolicyImpl() override = default; 38 39 // When the current time is inside one of the intervals returns 40 // kSucceeded and sets |result| to kOmahaUpdateDeferredPerPolicy. If the 41 // current time is not inside any intervals returns kContinue. In case of 42 // errors, i.e. cannot access intervals or time, return kContinue. 43 EvalStatus UpdateCanBeApplied( 44 EvaluationContext* ec, 45 State* state, 46 std::string* error, 47 chromeos_update_engine::ErrorCode* result, 48 chromeos_update_engine::InstallPlan* install_plan) const override; 49 50 protected: PolicyName()51 std::string PolicyName() const override { 52 return "UpdateTimeRestrictionsPolicyImpl"; 53 } 54 55 private: 56 DISALLOW_COPY_AND_ASSIGN(UpdateTimeRestrictionsPolicyImpl); 57 }; 58 59 } // namespace chromeos_update_manager 60 61 #endif // UPDATE_ENGINE_UPDATE_MANAGER_UPDATE_TIME_RESTRICTIONS_POLICY_IMPL_H_ 62