• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 CELLULAR_DATA_CLIENT_H
17 #define CELLULAR_DATA_CLIENT_H
18 
19 #include <cstdint>
20 #include <iremote_object.h>
21 #include <singleton.h>
22 
23 #include "data_sim_account_call_back.h"
24 #include "i_cellular_data_manager.h"
25 #include "sim_account_callback.h"
26 #include "apn_item.h"
27 #include "cellular_data_constant.h"
28 
29 namespace OHOS {
30 namespace Telephony {
31 class CellularDataClient : public DelayedRefSingleton<CellularDataClient> {
32     DECLARE_DELAYED_REF_SINGLETON(CellularDataClient);
33 
34 public:
35     /**
36      * @brief Whether cellular data service is connected.
37      *
38      * @return Return true on connected, false on not connected.
39      */
40     bool IsConnect();
41 
42     /**
43      * @brief Whether to enable cellular data user switch
44      *
45      * @param enable Enable or not.
46      * @return Return 84082688 invalid parameter, 0 data enable success, others enable fail.
47      */
48     int32_t EnableCellularData(bool enable);
49 
50     /**
51      * @brief Whether to enable intelligence switch
52      *
53      * @param enable Enable or not.
54      * @return Return 84082688 invalid parameter, 1 data enable success, 0 enable fail.
55      */
56     int32_t EnableIntelligenceSwitch(bool enable);
57 
58     /**
59      * @brief Whether the cellular data user switch is enabled
60      *
61      * @param dataEnabled Indicates the result of data enabled status.
62      * @return Returns error code.
63      */
64     int32_t IsCellularDataEnabled(bool &dataEnabled);
65 
66     /**
67      * @brief Cellular data connection status
68      *
69      * @return Returns data connection status defined in DataConnectionStatus.
70      */
71     int32_t GetCellularDataState();
72 
73     /**
74      * @brief Get the apn status based on slotId and apnType
75      *
76      * @return Returns apn status
77      */
78     int32_t GetApnState(int32_t slotId, const std::string &apnType);
79 
80     /**
81      * Get IntelligenceSwitch State
82      *
83      * @param switchState Returns IntelligenceSwitch State
84      * @return Returns 0 on success, others on failure.
85      */
86     int32_t GetIntelligenceSwitchState(bool &switchState);
87 
88     /**
89      * @brief Get recovery state
90      */
91     int32_t GetDataRecoveryState();
92 
93     /**
94      * @brief Whether roaming is allowed
95      *
96      * @param slotId Indicates card slot identification
97      * @param dataRoamingEnabled Indicates the result of data roaming enabled status.
98      * @return Returns error code.
99      */
100     int32_t IsCellularDataRoamingEnabled(int32_t slotId, bool &dataRoamingEnabled);
101 
102     /**
103      * @brief Whether roaming switches are allowed
104      *
105      * @param slotId card slot identification
106      * @param enable Whether roaming switches are allowed
107      * @return Returns 0 on failure, 1 on failure. 84082688 invalid parameter
108      */
109     int32_t EnableCellularDataRoaming(int32_t slotId, bool enable);
110 
111     /**
112      * @brief Get the slotId that uses the data traffic by default
113      *
114      * @return Returns the default settings data card, -1 error code
115      */
116     int32_t GetDefaultCellularDataSlotId();
117 
118     /**
119      * Get the simId that uses the data traffic by default
120      *
121      * @param simId Returns default settings data sim id
122      * @return Returns 0 on success, others on failure.
123      */
124     int32_t GetDefaultCellularDataSimId(int32_t &simId);
125 
126     /**
127      * @brief Set the slotId that uses the data traffic by default
128      *
129      * @param slotId card slot identification
130      * @return 0 set success, others set fail, 84082688 invalid parameter
131      */
132     int32_t SetDefaultCellularDataSlotId(int32_t slotId);
133 
134     /**
135      * @brief Get data packet type
136      *
137      * @return Returns cell data flow type defined in CellDataFlowType.
138      */
139     int32_t GetCellularDataFlowType();
140 
141     /**
142      * @brief Whether cellular data has internet capability.
143      *
144      * @param slotId Card slot identification.
145      * @param cid Context identification.
146      * @return Return 1 if has, 0 if hasn't.
147      */
148     int32_t HasInternetCapability(int32_t slotId, int32_t cid);
149 
150     /**
151      * @brief Clear cellular data connections.
152      *
153      * @param slotId Card slot identification.
154      * @return 1 set success, 0 set fail, 84082688 invalid parameter
155      */
156     int32_t ClearCellularDataConnections(int32_t slotId);
157 
158     int32_t ClearAllConnections(int32_t slotId, DisConnectionReason reason);
159 
160     int32_t HandleApnChanged(int32_t slotId);
161 
162     /**
163      * @brief Get cellular data proxy.
164      *
165      * @return Cellular data service.
166      */
167     sptr<ICellularDataManager> GetProxy();
168 
169     /**
170      * @brief Update the slotId that uses the data traffic by default
171      *
172      * @return Returns the default settings data card, -1 error code
173      */
174     int32_t UpdateDefaultCellularDataSlotId();
175 
176     /**
177      * @brief Get data connections apn attribute.
178      *
179      * @param slotId Card slot identification.
180      * @param apnType Indicates the APN attribute used by the data connection.
181      * @return 1 set success, 0 set fail
182      */
183     int32_t GetDataConnApnAttr(int32_t slotId, ApnItem::Attribute &apnAttr);
184 
185     /**
186      * @brief Get data connections ip type.
187      *
188      * @param slotId Card slot identification.
189      * @param ipType Indicates IP array after data connection.
190      * @return 1 set success, 0 set fail
191      */
192     int32_t GetDataConnIpType(int32_t slotId, std::string &ipType);
193 
194     /**
195      * @brief Whether do recovery is needed.
196      *
197      * @param slotId Card slot identification.
198      * @param needDoRecovery Whether do recovery is needed.
199      * @return 1 set success, 0 set fail
200      */
201     int32_t IsNeedDoRecovery(int32_t slotId, bool needDoRecovery);
202 
203     /**
204      * @brief Init CellularDataController instance.
205      *
206      * @param slotId Card slot identification.
207      * @return 1 set success, 0 set fail
208      */
209     int32_t InitCellularDataController(int32_t slotId);
210 
211     int32_t EstablishAllApnsIfConnectable(int32_t slotId);
212 
213     /**
214      * @brief Release cellular data connection.
215      *
216      * @param slotId Card slot identification.
217      * @return 1 set success, 0 set fail
218      */
219     int32_t ReleaseCellularDataConnection(int32_t slotId);
220 
221     /**
222      * @brief Get cellular data supplierId.
223      *
224      * @param slotId Card slot identification.
225      * @param capability Net capability.
226      * @param supplierId Cellular supplier id.
227      * @return 0 get success, others get fail.
228      */
229     int32_t GetCellularDataSupplierId(int32_t slotId, uint64_t capability, uint32_t &supplierId);
230 
231     /**
232      * @brief Correct net supplier available is false.
233      *
234      * @param slotId Card slot identification.
235      * @return 0 set success, others set fail.
236      */
237     int32_t CorrectNetSupplierNoAvailable(int32_t slotId);
238 
239     /**
240      * @brief Get supplier register state.
241      *
242      * @param supplierId Cellular supplier id.
243      * @param regState Supplier register state.
244      * @return 0 set success, others set fail.
245      */
246     int32_t GetSupplierRegisterState(uint32_t supplierId, int32_t &regState);
247 
248     /**
249     * @brief Get If Cellular data Support Dun Apn
250     *
251     * @param isSupportDun if support dun apn.
252     * @return 0 set success, others set fail.
253     */
254     int32_t GetIfSupportDunApn(bool &isSupportDun);
255 
256     /**
257      * @brief Get last 30 default apn activate info
258      *
259      * @param slotId slotId
260      * @param ApnActivateReportInfo default apn act info
261      * @return 0 set success, others set fail.
262      */
263     int32_t GetDefaultActReportInfo(int32_t slotId, ApnActivateReportInfo &info);
264 
265     /**
266      * @brief Get last 30 internal_default apn activate info
267      *
268      * @param slotId slotId
269      * @param ApnActivateReportInfo internal_default apn act info
270      * @return 0 set success, others set fail.
271      */
272     int32_t GetInternalActReportInfo(int32_t slotId, ApnActivateReportInfo &info);
273 
274     /**
275      * @brief Query APN ids that meet apn info.
276      *
277      * @param apnInfo apnInfo needed to be queried.
278      * @param apnIdList ALL apn ids that meet apn info.
279      * @return 0 query success, others query fail.
280      */
281     int32_t QueryApnIds(ApnInfo apnInfo, std::vector<uint32_t> &apnIdList);
282 
283     /**
284      * @brief Set prefer Apn.
285      *
286      * @param apnId ApnId needed to be set.
287      * @return 0 set success, others set fail.
288      */
289     int32_t SetPreferApn(int32_t apnId);
290 
291     /**
292      * @brief Query all apn info of default cellular data slotId.
293      *
294      * @param apnInfoList All apn info of default cellular data slotId.
295      * @return 0 query success, others query fail.
296      */
297     int32_t QueryAllApnInfo(std::vector<ApnInfo> &apnInfoList);
298 
299 private:
300     class CellularDataDeathRecipient : public IRemoteObject::DeathRecipient {
301     public:
CellularDataDeathRecipient(CellularDataClient & client)302         explicit CellularDataDeathRecipient(CellularDataClient &client) : client_(client) {}
303         ~CellularDataDeathRecipient() override = default;
OnRemoteDied(const wptr<IRemoteObject> & remote)304         void OnRemoteDied(const wptr<IRemoteObject> &remote) override
305         {
306             client_.OnRemoteDied(remote);
307         }
308 
309     private:
310         CellularDataClient &client_;
311     };
312 
313     void OnRemoteDied(const wptr<IRemoteObject> &remote);
314     void RegisterSimAccountCallback();
315     void UnregisterSimAccountCallback();
316     bool IsValidSlotId(int32_t slotId);
317     bool IsCellularDataSysAbilityExist(sptr<IRemoteObject> &object);
318 
319 private:
320     std::mutex mutexProxy_;
321     sptr<ICellularDataManager> proxy_ { nullptr };
322     sptr<IRemoteObject::DeathRecipient> deathRecipient_ { nullptr };
323     sptr<SimAccountCallback> callback_ { nullptr };
324     static int32_t defaultCellularDataSlotId_;
325     static int32_t defaultCellularDataSimId_;
326     bool registerStatus_ = false;
327 };
328 } // namespace Telephony
329 } // namespace OHOS
330 #endif // CELLULAR_DATA_CLIENT_H
331