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 30 typedef struct { 31 AppIdentity appIdentity; 32 int lastState; 33 } AppSwitchState; 34 35 class LocationDataManager { 36 public: 37 LocationDataManager(); 38 ~LocationDataManager(); 39 LocationErrCode ReportSwitchState(bool isEnabled); 40 LocationErrCode RegisterSwitchCallback(const sptr<IRemoteObject>& callback, AppIdentity& appIdentity); 41 LocationErrCode UnregisterSwitchCallback(const sptr<IRemoteObject>& callback); 42 bool IsSwitchObserverReg(); 43 void SetIsSwitchObserverReg(bool isSwitchObserverReg); 44 bool IsFirstReport(); 45 void SetIsFirstReport(bool isFirstReport); 46 void RegisterLocationSwitchObserver(); 47 static LocationDataManager* GetInstance(); 48 49 private: 50 std::mutex mutex_; 51 std::mutex isSwitchObserverRegMutex_; 52 bool isSwitchObserverReg_ = false; 53 std::map<sptr<IRemoteObject>, AppSwitchState > switchCallbackMap_; 54 std::mutex isFirstReportMutex_; 55 bool isFirstReport_ = true; 56 }; 57 } // namespace Location 58 } // namespace OHOS 59 #endif // LOCATION_DATA_MANAGER_H 60