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 #include "want.h" 25 26 namespace OHOS { 27 namespace Location { 28 class LocationConfigManager { 29 public: 30 ~LocationConfigManager(); 31 static LocationConfigManager* GetInstance(); 32 33 /* 34 * @Description Init the LocationConfigManager object 35 * 36 * @return int - init result, when 0 means success, other means some fails happened 37 */ 38 int Init(); 39 40 /* 41 * @Description Get current location switch state 42 * 43 * @return int - the location switch state, open/close 44 */ 45 int GetLocationSwitchState(); 46 47 /* 48 * @Description set location switch state 49 * 50 * @param state - the location switch state 51 * @return int - 0 success 52 */ 53 int SetLocationSwitchState(int state); 54 55 bool IsExistFile(const std::string& filename); 56 bool CreateFile(const std::string& filename, const std::string& filedata); 57 58 std::string GetPrivacyTypeConfigPath(const int type); 59 LocationErrCode GetPrivacyTypeState(const int type, bool& isConfirmed); 60 LocationErrCode SetPrivacyTypeState(const int type, bool isConfirmed); 61 void OpenPrivacyDialog(); 62 void ConnectExtensionAbility(const AAFwk::Want &want, const std::string &commandStr); 63 std::string GenerateStartCommand(); 64 bool SetCachePrivacyType(int value); 65 66 /* 67 * @Description get settings bundle name 68 * 69 * @param name - bundle name 70 * @return bool - true success 71 */ 72 bool GetSettingsBundleName(std::string& name); 73 74 /* 75 * @Description get nlp service name 76 * 77 * @param name - service name 78 * @return bool - true success 79 */ 80 bool GetNlpServiceName(std::string& name); 81 82 /* 83 * @Description get nlp ability name 84 * 85 * @param name - ability name 86 * @return bool - true success 87 */ 88 bool GetNlpAbilityName(std::string& name); 89 90 /* 91 * @Description get geocode service name 92 * 93 * @param name - service name 94 * @return bool - true success 95 */ 96 bool GetGeocodeServiceName(std::string& name); 97 98 /* 99 * @Description get geocode ability name 100 * 101 * @param name - ability name 102 * @return bool - true success 103 */ 104 bool GetGeocodeAbilityName(std::string& name); 105 106 /* 107 * @Description get supl mode 108 * 109 * @return int - supl mode 110 */ 111 int GetSuplMode(); 112 113 /* 114 * @Description get agnss server address 115 * 116 * @param name - agnss server address 117 * @return bool - true success 118 */ 119 bool GetAgnssServerAddr(std::string& name); 120 121 /* 122 * @Description get agnss server port 123 * 124 * @return int - agnss server port 125 */ 126 int GetAgnssServerPort(); 127 private: 128 LocationConfigManager(); 129 std::string GetLocationSwitchConfigPath(); 130 131 bool GetStringParameter(const std::string& type, std::string& value); 132 int GetIntParameter(const std::string& type); 133 private: 134 std::atomic<int> mPrivacyTypeState[3]; 135 std::atomic<int> mLocationSwitchState; /* location switch state */ 136 std::mutex mutex_; 137 }; 138 } // namespace Location 139 } // namespace OHOS 140 #endif