1 /*
2  * Copyright (C) 2022 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 #ifndef LOG_TAG
16 #define LOG_TAG "bt_fwk_proxy_manager"
17 #endif
18 
19 #include "bluetooth_proxy_manager.h"
20 
21 #include "bluetooth_ble_central_manager.h"
22 #include "bluetooth_def.h"
23 #include "bluetooth_host.h"
24 #include "bluetooth_log.h"
25 #include "bluetooth_profile_manager.h"
26 #include "i_bluetooth_ble_central_manager.h"
27 
28 namespace OHOS {
29 namespace Bluetooth {
GetInstance()30 BluetoothProxyManager& BluetoothProxyManager::GetInstance()
31 {
32 #ifdef DTFUZZ_TEST
33     static BluetoothNoDestructor<BluetoothProxyManager> instance;
34     return *instance;
35 #else
36     static BluetoothProxyManager instance;
37     return instance;
38 #endif
39 }
40 
FreezeByRss(std::set<int> pidSet,bool isProxy)41 bool BluetoothProxyManager::FreezeByRss(std::set<int> pidSet, bool isProxy)
42 {
43     if (!IS_BLE_ENABLED()) {
44         HILOGD("bluetooth is off.");
45         return false;
46     }
47     sptr<IBluetoothBleCentralManager> proxy =
48         GetRemoteProxy<IBluetoothBleCentralManager>(BLE_CENTRAL_MANAGER_SERVER);
49     CHECK_AND_RETURN_LOG_RET(proxy, false, "failed: no proxy");
50     return proxy->FreezeByRss(pidSet, isProxy);
51 }
52 
ResetAllProxy()53 bool BluetoothProxyManager::ResetAllProxy()
54 {
55     HILOGI("ResetAllProxy start.");
56     if (!IS_BLE_ENABLED()) {
57         HILOGD("bluetooth is off.");
58         return false;
59     }
60     sptr<IBluetoothBleCentralManager> proxy =
61         GetRemoteProxy<IBluetoothBleCentralManager>(BLE_CENTRAL_MANAGER_SERVER);
62     CHECK_AND_RETURN_LOG_RET(proxy, false, "failed: no proxy");
63     return proxy->ResetAllProxy();
64 }
65 } // namespace Bluetooth
66 } // namespace OHOS