• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 #include "proxy_freeze_manager.h"
17 
18 
19 namespace OHOS {
20 namespace Location {
21 
GetInstance()22 ProxyFreezeManager* ProxyFreezeManager::GetInstance()
23 {
24     static ProxyFreezeManager data;
25     return &data;
26 }
27 
ProxyForFreeze(std::set<int> pidList,bool isProxy)28 void ProxyFreezeManager::ProxyForFreeze(std::set<int> pidList, bool isProxy)
29 {
30     std::unique_lock<std::mutex> lock(proxyPidsMutex_);
31     if (isProxy) {
32         for (auto it = pidList.begin(); it != pidList.end(); it++) {
33             proxyPids_.insert(*it);
34             LBSLOGI(LOCATOR, "Start locator proxy, pid: %{public}d, isProxy: %{public}d, timestamp = %{public}s",
35                 *it, isProxy, std::to_string(CommonUtils::GetCurrentTimeStamp()).c_str());
36         }
37     } else {
38         for (auto it = pidList.begin(); it != pidList.end(); it++) {
39             proxyPids_.erase(*it);
40             LBSLOGI(LOCATOR, "Start locator proxy, pid: %{public}d, isProxy: %{public}d, timestamp = %{public}s",
41                 *it, isProxy, std::to_string(CommonUtils::GetCurrentTimeStamp()).c_str());
42         }
43     }
44 }
45 
ResetAllProxy()46 void ProxyFreezeManager::ResetAllProxy()
47 {
48     std::unique_lock<std::mutex> lock(proxyPidsMutex_);
49     proxyPids_.clear();
50 }
51 
IsProxyPid(int32_t pid)52 bool ProxyFreezeManager::IsProxyPid(int32_t pid)
53 {
54     std::unique_lock<std::mutex> lock(proxyPidsMutex_);
55     return proxyPids_.find(pid) != proxyPids_.end();
56 }
57 } // namespace Location
58 } // namespace OHOS
59