1 /* 2 * Copyright (C) 2023 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 LOCATION_DATA_MANAGER_H 17 #define LOCATION_DATA_MANAGER_H 18 19 #include <map> 20 #include <singleton.h> 21 #include "iremote_object.h" 22 #include "constant_definition.h" 23 #include "i_switch_callback.h" 24 #include "common_utils.h" 25 #include "app_identity.h" 26 27 namespace OHOS { 28 namespace Location { 29 class LocationDataManager { 30 public: 31 LocationDataManager(); 32 ~LocationDataManager(); 33 LocationErrCode ReportSwitchState(bool isEnabled); 34 LocationErrCode RegisterSwitchCallback(const sptr<IRemoteObject>& callback, AppIdentity& appIdentity); 35 LocationErrCode UnregisterSwitchCallback(const sptr<IRemoteObject>& callback); 36 bool IsSwitchObserverReg(); 37 void SetIsSwitchObserverReg(bool isSwitchObserverReg); 38 bool IsFirstReport(); 39 void SetIsFirstReport(bool isFirstReport); 40 void RegisterLocationSwitchObserver(); 41 static LocationDataManager* GetInstance(); 42 private: 43 std::mutex mutex_; 44 std::mutex isSwitchObserverRegMutex_; 45 bool isSwitchObserverReg_ = false; 46 std::map<sptr<IRemoteObject>, std::vector<int>> switchCallbackMap_; 47 std::mutex isFirstReportMutex_; 48 bool isFirstReport_ = true; 49 }; 50 } // namespace Location 51 } // namespace OHOS 52 #endif // LOCATION_DATA_MANAGER_H 53