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 bool IsInDeviceStandyWhitelist(const std::string& bundleName); 35 void OnDeviceStandyWhitelistChanged(const std::string& bundleName, const bool add); 36 void AddDeviceStandyWhitelist(const std::list<std::string>& bundleNames); 37 void ClearDeviceStandyWhitelist(); 38 bool IsDeviceStandyWhitelistEmpty(); 39 40 bool IsInDeviceStandyRestrictlist(const std::string& bundleName); 41 void OnDeviceStandyRestrictlistChanged(const std::string& bundleName, const bool add); 42 void AddDeviceStandyRestrictlist(const std::list<std::string>& bundleNames); 43 void ClearDeviceStandyRestrictlist(); 44 // group 45 void AddGroup(const std::string& bundleName, const int32_t userId, const int32_t appGroup); 46 bool FindGroup(const std::string& bundleName, const int32_t userId, int32_t& appGroup); 47 void ClearGroup(const std::string& bundleName, const int32_t userId); 48 void ClearAllGroup(); 49 private: 50 std::atomic<bool> deviceSleep_ = false; 51 ffrt::mutex deviceStandySetMutex_; 52 // <bundle> 53 std::set<std::string> deviceStandySet {}; 54 ffrt::mutex deviceRestrictSetMutex_; 55 // <bundle> 56 std::set<std::string> deviceRestrictSet {}; 57 ffrt::mutex activeGroupMapMutex_; 58 // <bundle_userId, group> 59 std::unordered_map<std::string, int32_t> activeGroupMap_; 60 }; 61 } // namespace WorkScheduler 62 } // namespace OHOS 63 #endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_WORK_SCHED_DATA_MANAGER_H