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 
16 #ifndef FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_SERVICES_COMMON_BGTASK_CONFIG_H
17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_SERVICES_COMMON_BGTASK_CONFIG_H
18 #include <string>
19 #include <set>
20 #include <mutex>
21 
22 #include "config_data_source_type.h"
23 #include "singleton.h"
24 #include "nlohmann/json.hpp"
25 
26 namespace OHOS {
27 namespace BackgroundTaskMgr {
28 class BgtaskConfig : public DelayedSingleton<BgtaskConfig> {
29 public:
30     void Init();
31     bool IsTransientTaskExemptedQuatoApp(const std::string &bundleName);
32     int32_t GetTransientTaskExemptedQuato();
33     bool AddExemptedQuatoData(const std::string &configData, int32_t sourceType);
34 
35 private:
36     void LoadConfigFile();
37     void ParseTransientTaskExemptedQuatoList(const nlohmann::json &jsonObj);
38     void ParseTransientTaskExemptedQuato(const nlohmann::json &jsonObj);
39     bool SetCloudConfigParam(const nlohmann::json &jsonObj);
40 
41 private:
42     bool isInit_ = false;
43     std::set<std::string> transientTaskExemptedQuatoList_ {};
44     std::set<std::string> transientTaskCloudExemptedQuatoList_ {};
45     int32_t transientTaskExemptedQuato_ = 10 * 1000; // 10s
46     std::mutex configMutex_;
47 };
48 }
49 }
50 #endif