1 /*
2  * Copyright (c) 2024 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_RDB_MANAGER_H
17 #define LOCATION_DATA_RDB_MANAGER_H
18 #include <unistd.h>
19 #include <string>
20 #include <mutex>
21 
22 #include "constant_definition.h"
23 
24 namespace OHOS {
25 namespace Location {
26 const std::string LOCATION_DATA_COLUMN_ENABLE = "location_switch_enable";
27 const std::string LOCATION_WORKING_STATE = "location_working_state";
28 class LocationDataRdbManager {
29 public:
30     static int GetSwitchStateFromSysparaForCurrentUser();
31     static bool SetSwitchStateToSysparaForCurrentUser(int value);
32     static std::string GetLocationDataUriByCurrentUserId(std::string key);
33     static std::string GetLocationDataUriForUser(std::string key, int32_t userId);
34     static LocationErrCode GetSwitchStateFromDbForUser(int32_t& state, int32_t userId);
35     static int QuerySwitchState();
36     static LocationErrCode SetSwitchStateToDb(int modeValue);
37     static LocationErrCode SetSwitchStateToDbForUser(int modeValue, int32_t userId);
38     static bool SetLocationWorkingState(int32_t state);
39     static bool GetLocationWorkingState(int32_t& state);
40     static int GetSwitchStateFromSysparaForUser(int32_t userId);
41     static bool SetSwitchStateToSysparaForUser(int value, int32_t userId);
42     static std::string GetLocationDataSecureUri(std::string key);
43     static bool SetLocationEnhanceStatus(int32_t state);
44     static bool GetLocationEnhanceStatus(int32_t& state);
45     static void SyncSwitchStatus();
46     static bool IsUserIdInActiveIds(std::vector<int> activeIds, std::string userId);
47     static bool SetGnssSessionState(int32_t state, std::string uri, std::string colName);
48 private:
49     static std::mutex locationSwitchModeMutex_;
50     static std::mutex locationWorkingStateMutex_;
51     static std::mutex gnssSessionStateMutex_;
52 };
53 } // namespace Location
54 } // namespace OHOS
55 #endif // LOCATION_DATA_RDB_MANAGER_H
56