• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef WIFI_SCAN_PROXY
17 #define WIFI_SCAN_PROXY
18 
19 #include <vector>
20 #ifdef OHOS_ARCH_LITE
21 #include "iproxy_client.h"
22 #else
23 #include "iremote_broker.h"
24 #include "iremote_object.h"
25 #include "iremote_proxy.h"
26 #endif
27 #include "i_wifi_scan.h"
28 #include "i_wifi_scan_callback.h"
29 #include "refbase.h"
30 #include "wifi_errcode.h"
31 #include "wifi_scan_msg.h"
32 
33 namespace OHOS {
34 namespace Wifi {
35 #ifdef OHOS_ARCH_LITE
36 class WifiScanProxy : public IWifiScan {
37 public:static WifiScanProxy *GetInstance(void);
38     static void ReleaseInstance(void);
39     explicit WifiScanProxy(void);
40     ErrCode Init(void);
41 #else
42 class WifiScanProxy : public IRemoteProxy<IWifiScan> {
43 public:
44     explicit WifiScanProxy(const sptr<IRemoteObject> &remote);
45 #endif
46     virtual ~WifiScanProxy();
47 
48     /**
49      * @Description Start scan Wifi
50      *
51      * @param compatible - indicates whether compatibility is maintained
52      * @return ErrCode - operation result
53      */
54     virtual ErrCode Scan(bool compatible) override;
55 
56     /**
57      * @Description Set the Scan Control Info object
58      *
59      * @param info - ScanControlInfo object
60      * @return ErrCode - operation result
61      */
62     virtual ErrCode SetScanControlInfo(const tagScanControlInfo &info) override;
63 
64     /**
65      * @Description Start scan with specified params
66      *
67      * @param params - WifiScanParams object
68      * @return ErrCode - operation result
69      */
70     virtual ErrCode AdvanceScan(const WifiScanParams &params) override;
71 
72     /**
73      * @Description Check whether the ScanAlways mode is enabled
74      *
75      * @param bOpen - true / false
76      * @return ErrCode - operation result
77      */
78     virtual ErrCode IsWifiClosedScan(bool &bOpen) override;
79 
80     /**
81      * @Description Obtain the scanning result
82      *
83      * @param result - Get result venctor of WifiScanInfo
84      * @param compatible - indicates whether compatibility is maintained
85      * @return ErrCode - operation result
86      */
87     virtual ErrCode GetScanInfoList(std::vector<WifiScanInfo> &result, bool compatible) override;
88 
89 #ifdef OHOS_ARCH_LITE
90     virtual ErrCode RegisterCallBack(const std::shared_ptr<IWifiScanCallback> &callback,
91         const std::vector<std::string> &event) override;
92 #else
93     virtual ErrCode RegisterCallBack(const sptr<IWifiScanCallback> &callback,
94         const std::vector<std::string> &event) override;
95 #endif
96 
97     /**
98      * @Description Get supported features
99      *
100      * @param features - return supported features
101      * @return ErrCode - operation result
102      */
103     ErrCode GetSupportedFeatures(long &features) override;
104 
105     /**
106      * @Description Check whether service is died.
107      *
108      * @return bool - true: service is died, false: service is not died.
109      */
110     bool IsRemoteDied(void) override;
111 
112     /**
113      * @Description SetScanOnlyAvailable.
114      *
115      * @return ErrCode - operation result
116      */
117     ErrCode SetScanOnlyAvailable(bool bScanOnlyAvailable) override;
118 
119     /**
120      * @Description GetScanAlways Whether Available.
121      *
122      * @return ErrCode - operation result
123      */
124     ErrCode GetScanOnlyAvailable(bool &bScanOnlyAvailable) override;
125 
126 #ifdef OHOS_ARCH_LITE
127     void OnRemoteDied(void);
128 private:
129     static WifiScanProxy *g_instance;
130     IClientProxy *remote_ = nullptr;
131     SvcIdentity svcIdentity_ = { 0 };
132     bool remoteDied_;
133 #else
134     void OnRemoteDied(const wptr<IRemoteObject>& remoteObject);
135 private:
136     class WifiDeathRecipient : public IRemoteObject::DeathRecipient {
137     public:
WifiDeathRecipient(WifiScanProxy & client)138         explicit WifiDeathRecipient(WifiScanProxy &client) : client_(client) {}
139         ~WifiDeathRecipient() override = default;
OnRemoteDied(const wptr<IRemoteObject> & remote)140         void OnRemoteDied(const wptr<IRemoteObject> &remote) override
141         {
142             client_.OnRemoteDied(remote);
143         }
144 
145     private:
146         WifiScanProxy &client_;
147     };
148 
149     void RemoveDeathRecipient(void);
150     static BrokerDelegator<WifiScanProxy> g_delegator;
151     bool mRemoteDied;
152     sptr<IRemoteObject> remote_ = nullptr;
153     std::mutex mutex_;
154     sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr;
155 #endif
156 };
157 }  // namespace Wifi
158 }  // namespace OHOS
159 #endif
160