1 /*
2  * Copyright (C) 2021-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 OHOS_BLUETOOTH_STANDARD_BLE_CENTRAL_MANAGER_SERVER_H
16 #define OHOS_BLUETOOTH_STANDARD_BLE_CENTRAL_MANAGER_SERVER_H
17 
18 #include <cstdint>
19 #include <mutex>
20 #include <set>
21 
22 #include "bluetooth_ble_central_manager_stub.h"
23 #include "bluetooth_types.h"
24 #include "i_bluetooth_ble_central_manager.h"
25 #include "if_system_ability_manager.h"
26 #include "iservice_registry.h"
27 #include "system_ability.h"
28 
29 namespace OHOS {
30 namespace Bluetooth {
31 class BluetoothBleCentralManagerServer : public BluetoothBleCentralManagerStub {
32 public:
33     BluetoothBleCentralManagerServer();
34     ~BluetoothBleCentralManagerServer() override;
35 
36     void RegisterBleCentralManagerCallback(int32_t &scannerId, bool enableRandomAddrMode,
37         const sptr<IBluetoothBleCentralManagerCallback> &callback) override;
38     void DeregisterBleCentralManagerCallback(int32_t scannerId,
39         const sptr<IBluetoothBleCentralManagerCallback> &callback) override;
40     int StartScan(int32_t scannerId, const BluetoothBleScanSettings &settings,
41         const std::vector<BluetoothBleScanFilter> &filters) override;
42     int StopScan(int32_t scannerId) override;
43     void RemoveScanFilter(int32_t scannerId) override;
44     bool FreezeByRss(std::set<int> pidSet, bool isProxy) override;
45     bool ResetAllProxy() override;
46     static bool IsResourceScheduleControlApp(int32_t pid);
47     int SetLpDeviceAdvParam(int duration, int maxExtAdvEvents, int window, int interval, int advHandle) override;
48     int SetScanReportChannelToLpDevice(int32_t scannerId, bool enable) override;
49     int EnableSyncDataToLpDevice() override;
50     int DisableSyncDataToLpDevice() override;
51     int SendParamsToLpDevice(const std::vector<uint8_t> &dataValue, int32_t type) override;
52     bool IsLpDeviceAvailable() override;
53     int SetLpDeviceParam(const BluetoothLpDeviceParamSet &paramSet) override;
54     int RemoveLpDeviceParam(const bluetooth::Uuid &uuid) override;
55     void DeregisterBleCentralManagerCallbackInner(const sptr<IBluetoothBleCentralManagerCallback> &callback,
56         int32_t scannerId);
57 private:
58     BLUETOOTH_DECLARE_IMPL();
59     BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(BluetoothBleCentralManagerServer);
60     static std::mutex proxyMutex_;
61     static std::set<int32_t> proxyPids_;
62     void SetScanParams(const BluetoothBleScanSettings &settings);
63     void SetWindowAndInterval(const int mode, uint16_t &window, uint16_t &interval);
64     void SetOtherWindowAndInterval(const int mode, uint16_t &window, uint16_t &interval);
65     bool IsNewScanParams();
66     bool IsAllStop();
67     int ConfigScanFilterInner(int32_t scannerId, const std::vector<BluetoothBleScanFilter> &filters);
68 };
69 }  // namespace Bluetooth
70 }  // namespace OHOS
71 #endif  // OHOS_BLUETOOTH_STANDARD_BLE_CENTRAL_MANAGER_SERVER_H
72