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 17 #ifndef UPDATE_ENGINE_UPDATE_MANAGER_STAGING_UTILS_H_ 18 #define UPDATE_ENGINE_UPDATE_MANAGER_STAGING_UTILS_H_ 19 20 #include <utility> 21 #include <vector> 22 23 #include <base/time/time.h> 24 #include <policy/device_policy.h> 25 26 #include "update_engine/common/prefs_interface.h" 27 28 namespace chromeos_update_manager { 29 30 using StagingSchedule = std::vector<policy::DevicePolicy::DayPercentagePair>; 31 32 // Possible cases that staging might run into based on the inputs. 33 enum class StagingCase { 34 // Staging is off, remove the persisted value. 35 kOff, 36 // Staging is enabled, but there is no valid persisted value, saved value or 37 // the value of the schedule has changed. 38 kNoSavedValue, 39 // Staging is enabled, and there is a valid persisted value. 40 kSetStagingFromPref, 41 // Staging is enabled, and there have been no changes to the schedule. 42 kNoAction 43 }; 44 45 // Calculate the bucket in which the device belongs based on a given staging 46 // schedule. |staging_schedule| is assumed to have already been validated. 47 int CalculateWaitTimeInDaysFromSchedule( 48 const StagingSchedule& staging_schedule); 49 50 // Verifies that |device_policy| contains a valid staging schedule. If 51 // |device_policy| contains a valid staging schedule, move it into 52 // |staging_schedule_out| and return the total number of days spanned by the 53 // schedule. Otherwise, don't modify |staging_schedule_out| and return 0 (which 54 // is an invalid value for the length of a schedule). 55 int GetStagingSchedule(const policy::DevicePolicy* device_policy, 56 StagingSchedule* staging_schedule_out); 57 58 // Uses the given arguments to check whether staging is on, and whether the 59 // state should be updated with a new waiting time or not. |staging_wait_time| 60 // should contain the old value of the wait time, it will be replaced with the 61 // new calculated wait time value if staging is on. |staging_schedule| should 62 // contain the previous staging schedule, if there is a new schedule found, its 63 // value will be replaced with the new one. 64 StagingCase CalculateStagingCase(const policy::DevicePolicy* device_policy, 65 chromeos_update_engine::PrefsInterface* prefs, 66 base::TimeDelta* staging_wait_time, 67 StagingSchedule* staging_schedule); 68 69 } // namespace chromeos_update_manager 70 71 #endif // UPDATE_ENGINE_UPDATE_MANAGER_STAGING_UTILS_H_ 72