1 /*
2  * Copyright (C) 2021 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 OHOS_WIFI_SCAN_IMPL
17 #define OHOS_WIFI_SCAN_IMPL
18 
19 #include "wifi_scan.h"
20 #include "wifi_scan_proxy.h"
21 
22 namespace OHOS {
23 namespace Wifi {
24 class WifiScanImpl : public Wifi::WifiScan {
25 public:
26     WifiScanImpl();
27     virtual ~WifiScanImpl();
28     bool Init(int systemAbilityId, int instId);
29 
30     /**
31      * @Description Set the Scan Control Info object
32      *
33      * @param info - ScanControlInfo object
34      * @return ErrCode - operation result
35      */
36     virtual ErrCode SetScanControlInfo(const ScanControlInfo &info) override;
37 
38     /**
39      * @Description Start scan Wifi
40      *
41      * @param compatible - indicates whether compatibility is maintained
42      * @return ErrCode - operation result
43      */
44     virtual ErrCode Scan(bool compatible) override;
45 
46     /**
47      * @Description Obtain the scanning result
48      *
49      * @param result - Get result venctor of WifiScanInfo
50      * @param compatible - indicates whether compatibility is maintained
51      * @return ErrCode - operation result
52      */
53     virtual ErrCode GetScanInfoList(std::vector<WifiScanInfo> &result, bool compatible) override;
54 
55 #ifdef OHOS_ARCH_LITE
56     virtual ErrCode RegisterCallBack(const std::shared_ptr<IWifiScanCallback> &callback,
57         const std::vector<std::string> &event) override;
58 #else
59     virtual ErrCode RegisterCallBack(const sptr<IWifiScanCallback> &callback,
60         const std::vector<std::string> &event) override;
61 #endif
62 
63     /**
64      * @Description Get supported features
65      *
66      * @param features - return supported features
67      * @return ErrCode - operation result
68      */
69     ErrCode GetSupportedFeatures(long &features) override;
70 
71     /**
72      * @Description Check if supported input feature
73      *
74      * @param feature - input feature
75      * @return true - supported
76      * @return false - unsupported
77      */
78     bool IsFeatureSupported(long feature) override;
79 
80     /**
81      * @Description Check whether the ScanAlways mode is enabled
82      *
83      * @param bOpen - true / false
84      * @return ErrCode - operation result
85      */
86     ErrCode IsWifiClosedScan(bool &bOpen);
87 
88     /**
89      * @Description Start scan with specified params
90      *
91      * @param params - WifiScanParams object
92      * @return ErrCode - operation result
93      */
94     ErrCode AdvanceScan(const WifiScanParams &params) override;
95 
96     /**
97      * @Description Check whether service is died.
98      *
99      * @return bool - true: service is died, false: service is not died.
100      */
101     bool IsRemoteDied(void);
102     /**
103      * @Description SetScanOnlyAvailable.
104      *
105      * @return ErrCode - operation result
106      */
107     ErrCode SetScanOnlyAvailable(bool bScanOnlyAvailable) override;
108     /**
109      * @Description GetScanOnlyAvailable.
110      *
111      * @return ErrCode - operation result
112      */
113     ErrCode GetScanOnlyAvailable(bool &bScanOnlyAvailable) override;
114 
115     /**
116      * @Description Start pno scan
117      *
118      * @param isStartAction - true:start pno scan; false:stop pno scan
119      * @param periodMs - pno scan interval
120      * @param suspendReason - pno scan suspent reason
121      * @return ErrCode - operation result
122      */
123     ErrCode StartWifiPnoScan(bool isStartAction, int periodMs, int suspendReason) override;
124 
125 private:
126     bool GetWifiScanProxy();
127     std::atomic<int> systemAbilityId_;
128     int instId_;
129     std::mutex mutex_;
130 #ifdef OHOS_ARCH_LITE
131     IWifiScan *client_;
132 #else
133     sptr<OHOS::Wifi::IWifiScan> client_;
134 #endif
135 };
136 }  // namespace Wifi
137 }  // namespace OHOS
138 #endif
139