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 int GetCachePrivacyType(); 65 bool SetCachePrivacyType(int value); 66 67 /* 68 * @Description get settings bundle name 69 * 70 * @param name - bundle name 71 * @return bool - true success 72 */ 73 bool GetSettingsBundleName(std::string& name); 74 75 /* 76 * @Description get nlp service name 77 * 78 * @param name - service name 79 * @return bool - true success 80 */ 81 bool GetNlpServiceName(std::string& name); 82 83 /* 84 * @Description get nlp ability name 85 * 86 * @param name - ability name 87 * @return bool - true success 88 */ 89 bool GetNlpAbilityName(std::string& name); 90 91 /* 92 * @Description get geocode service name 93 * 94 * @param name - service name 95 * @return bool - true success 96 */ 97 bool GetGeocodeServiceName(std::string& name); 98 99 /* 100 * @Description get geocode ability name 101 * 102 * @param name - ability name 103 * @return bool - true success 104 */ 105 bool GetGeocodeAbilityName(std::string& name); 106 107 /* 108 * @Description get supl mode 109 * 110 * @return int - supl mode 111 */ 112 int GetSuplMode(); 113 114 /* 115 * @Description get agnss server address 116 * 117 * @param name - agnss server address 118 * @return bool - true success 119 */ 120 bool GetAgnssServerAddr(std::string& name); 121 122 /* 123 * @Description get agnss server port 124 * 125 * @return int - agnss server port 126 */ 127 int GetAgnssServerPort(); 128 private: 129 LocationConfigManager(); 130 std::string GetLocationSwitchConfigPath(); 131 132 bool GetStringParameter(const std::string& type, std::string& value); 133 int GetIntParameter(const std::string& type); 134 private: 135 std::atomic<int> mPrivacyTypeState[3]; 136 std::atomic<int> mLocationSwitchState; /* location switch state */ 137 std::mutex mutex_; 138 }; 139 } // namespace Location 140 } // namespace OHOS 141 #endif