1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_WORK_SCHED_DATA_MANAGER_H 16 #define FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_WORK_SCHED_DATA_MANAGER_H 17 18 #include <map> 19 #include <mutex> 20 #include <set> 21 #include <string> 22 #include <list> 23 #include "singleton.h" 24 #include "ffrt.h" 25 26 namespace OHOS { 27 namespace WorkScheduler { 28 class DataManager { 29 DECLARE_DELAYED_SINGLETON(DataManager); 30 public: 31 // device sleep 32 void SetDeviceSleep(const bool isSleep); 33 bool GetDeviceSleep() const; 34 // deep idle 35 void SetDeepIdle(const bool isDeepIdle); 36 bool GetDeepIdle() const; 37 bool IsInDeviceStandyWhitelist(const std::string& bundleName); 38 void OnDeviceStandyWhitelistChanged(const std::string& bundleName, const bool add); 39 void AddDeviceStandyWhitelist(const std::list<std::string>& bundleNames); 40 void ClearDeviceStandyWhitelist(); 41 bool IsDeviceStandyWhitelistEmpty(); 42 43 bool IsInDeviceStandyRestrictlist(const std::string& bundleName); 44 void OnDeviceStandyRestrictlistChanged(const std::string& bundleName, const bool add); 45 void AddDeviceStandyRestrictlist(const std::list<std::string>& bundleNames); 46 void ClearDeviceStandyRestrictlist(); 47 // group 48 void AddGroup(const std::string& bundleName, const int32_t userId, const int32_t appGroup); 49 bool FindGroup(const std::string& bundleName, const int32_t userId, int32_t& appGroup); 50 void ClearGroup(const std::string& bundleName, const int32_t userId); 51 void ClearAllGroup(); 52 private: 53 std::atomic<bool> deviceSleep_ = false; 54 std::atomic<bool> deepIdle_ = false; 55 ffrt::mutex deviceStandySetMutex_; 56 // <bundle> 57 std::set<std::string> deviceStandySet {}; 58 ffrt::mutex deviceRestrictSetMutex_; 59 // <bundle> 60 std::set<std::string> deviceRestrictSet {}; 61 ffrt::mutex activeGroupMapMutex_; 62 // <bundle_userId, group> 63 std::unordered_map<std::string, int32_t> activeGroupMap_; 64 }; 65 } // namespace WorkScheduler 66 } // namespace OHOS 67 #endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_WORK_SCHED_DATA_MANAGER_H