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(const std::vector<int32_t> & pidList,bool isProxy)28 void ProxyFreezeManager::ProxyForFreeze(const std::vector<int32_t>& pidList, bool isProxy)
29 {
30 size_t size = pidList.size();
31 size = size > MAX_BUFF_SIZE ? MAX_BUFF_SIZE : size;
32 std::set<int> pids;
33 for (size_t i = 0; i < size; i++) {
34 pids.insert(pidList[i]);
35 }
36 std::unique_lock<std::mutex> lock(proxyPidsMutex_);
37 if (isProxy) {
38 for (auto it = pids.begin(); it != pids.end(); it++) {
39 proxyPids_.insert(*it);
40 LBSLOGI(PROXY_FREEZE_MANAGER,
41 "Start locator proxy, pid: %{public}d, isProxy: %{public}d, timestamp = %{public}s",
42 *it, isProxy, std::to_string(CommonUtils::GetCurrentTimeMilSec()).c_str());
43 }
44 } else {
45 for (auto it = pids.begin(); it != pids.end(); it++) {
46 proxyPids_.erase(*it);
47 LBSLOGI(PROXY_FREEZE_MANAGER,
48 "Start locator proxy, pid: %{public}d, isProxy: %{public}d, timestamp = %{public}s",
49 *it, isProxy, std::to_string(CommonUtils::GetCurrentTimeMilSec()).c_str());
50 }
51 }
52 }
53
ResetAllProxy()54 void ProxyFreezeManager::ResetAllProxy()
55 {
56 std::unique_lock<std::mutex> lock(proxyPidsMutex_);
57 proxyPids_.clear();
58 }
59
IsProxyPid(int32_t pid)60 bool ProxyFreezeManager::IsProxyPid(int32_t pid)
61 {
62 std::unique_lock<std::mutex> lock(proxyPidsMutex_);
63 return proxyPids_.find(pid) != proxyPids_.end();
64 }
65 } // namespace Location
66 } // namespace OHOS
67