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 NET_ACCESS_POLICY_CONFIG_H 17 #define NET_ACCESS_POLICY_CONFIG_H 18 19 #include "cJSON.h" 20 #include "ffrt.h" 21 #include "string" 22 23 namespace OHOS { 24 namespace NetManagerStandard { 25 struct NetAccessPolicyConfig { 26 std::string bundleName; 27 bool disableWlanSwitch = false; 28 bool disableCellularSwitch = false; 29 }; 30 class NetAccessPolicyConfigUtils { 31 public: 32 static NetAccessPolicyConfigUtils &GetInstance(); 33 std::vector<NetAccessPolicyConfig> GetNetAccessPolicyConfig(); 34 35 private: 36 NetAccessPolicyConfigUtils() = default; 37 ~NetAccessPolicyConfigUtils() = default; 38 void Init(); 39 void ParseNetAccessPolicyConfigs(); 40 bool ReadFile(std::string &content, const std::string &fileName); 41 std::string ParseString(cJSON *value); 42 bool ParseBoolean(cJSON *value); 43 int32_t ParseInt32(cJSON *value); 44 45 private: 46 static NetAccessPolicyConfigUtils instance_; 47 48 std::vector<NetAccessPolicyConfig> netAccessPolicyConfigs_; 49 std::atomic<bool> isInit_ = false; 50 ffrt::mutex lock_; 51 }; 52 } // namespace NetManagerStandard 53 } // namespace OHOS 54 55 #endif