• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "update_engine/update_manager/update_time_restrictions_policy_impl.h"
17 
18 #include <memory>
19 
20 #include <base/time/time.h>
21 
22 #include "update_engine/update_manager/device_policy_provider.h"
23 #include "update_engine/update_manager/system_provider.h"
24 #include "update_engine/update_manager/weekly_time.h"
25 
26 using base::Time;
27 using base::TimeDelta;
28 
29 using chromeos_update_engine::ErrorCode;
30 using chromeos_update_engine::InstallPlan;
31 
32 namespace chromeos_update_manager {
33 
UpdateCanBeApplied(EvaluationContext * ec,State * state,std::string * error,ErrorCode * result,InstallPlan * install_plan) const34 EvalStatus UpdateTimeRestrictionsPolicyImpl::UpdateCanBeApplied(
35     EvaluationContext* ec,
36     State* state,
37     std::string* error,
38     ErrorCode* result,
39     InstallPlan* install_plan) const {
40   DevicePolicyProvider* const dp_provider = state->device_policy_provider();
41   TimeProvider* const time_provider = state->time_provider();
42 
43   // If kiosk mode is not enabled, don't restrict updates.
44   if (!ec->GetValue(dp_provider->var_auto_launched_kiosk_app_id()))
45     return EvalStatus::kContinue;
46 
47   const Time* curr_date = ec->GetValue(time_provider->var_curr_date());
48   const int* curr_hour = ec->GetValue(time_provider->var_curr_hour());
49   const int* curr_minute = ec->GetValue(time_provider->var_curr_minute());
50   if (!curr_date || !curr_hour || !curr_minute) {
51     LOG(WARNING) << "Unable to access local time.";
52     return EvalStatus::kContinue;
53   }
54 
55   WeeklyTime now = WeeklyTime::FromTime(*curr_date);
56   now.AddTime(TimeDelta::FromHours(*curr_hour) +
57               TimeDelta::FromMinutes(*curr_minute));
58 
59   const WeeklyTimeIntervalVector* intervals =
60       ec->GetValue(dp_provider->var_disallowed_time_intervals());
61   if (!intervals) {
62     return EvalStatus::kContinue;
63   }
64   for (const auto& interval : *intervals) {
65     if (interval.InRange(now)) {
66       *result = ErrorCode::kOmahaUpdateDeferredPerPolicy;
67       return EvalStatus::kSucceeded;
68     }
69   }
70 
71   return EvalStatus::kContinue;
72 }
73 
74 }  // namespace chromeos_update_manager
75