1 /* 2 * Copyright (C) 2022 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 OHOS_LOCATION_CONFIG_MANAGER_H 17 #define OHOS_LOCATION_CONFIG_MANAGER_H 18 19 #include <atomic> 20 #include <mutex> 21 #include <string> 22 23 #include "constant_definition.h" 24 25 namespace OHOS { 26 namespace Location { 27 class LocationConfigManager { 28 public: 29 ~LocationConfigManager(); 30 static LocationConfigManager &GetInstance(); 31 32 /* 33 * @Description Init the LocationConfigManager object 34 * 35 * @return int - init result, when 0 means success, other means some fails happened 36 */ 37 int Init(); 38 39 /* 40 * @Description Get current location switch state 41 * 42 * @return int - the location switch state, open/close 43 */ 44 int GetLocationSwitchState(); 45 46 /* 47 * @Description set location switch state 48 * 49 * @param state - the location switch state 50 * @return int - 0 success 51 */ 52 int SetLocationSwitchState(int state); 53 54 bool IsExistFile(const std::string& filename); 55 bool CreateFile(const std::string& filename, const std::string& filedata); 56 57 std::string GetPrivacyTypeConfigPath(const int type); 58 LocationErrCode GetPrivacyTypeState(const int type, bool& isConfirmed); 59 LocationErrCode SetPrivacyTypeState(const int type, bool isConfirmed); 60 61 /* 62 * @Description get nlp service name 63 * 64 * @param name - service name 65 * @return bool - true success 66 */ 67 bool GetNlpServiceName(std::string& name); 68 69 /* 70 * @Description get nlp ability name 71 * 72 * @param name - ability name 73 * @return bool - true success 74 */ 75 bool GetNlpAbilityName(std::string& name); 76 77 /* 78 * @Description get geocode service name 79 * 80 * @param name - service name 81 * @return bool - true success 82 */ 83 bool GetGeocodeServiceName(std::string& name); 84 85 /* 86 * @Description get geocode ability name 87 * 88 * @param name - ability name 89 * @return bool - true success 90 */ 91 bool GetGeocodeAbilityName(std::string& name); 92 private: 93 LocationConfigManager(); 94 std::string GetLocationSwitchConfigPath(); 95 96 bool GetStringParameter(const std::string& type, std::string& value); 97 private: 98 std::atomic<int> mPrivacyTypeState[3]; 99 std::atomic<int> mLocationSwitchState; /* location switch state */ 100 std::mutex mutex_; 101 }; 102 } // namespace Location 103 } // namespace OHOS 104 #endif