• 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 
27 namespace OHOS {
28 namespace Telephony {
29 class CellularDataClient : public DelayedRefSingleton<CellularDataClient> {
30     DECLARE_DELAYED_REF_SINGLETON(CellularDataClient);
31 
32 public:
33     /**
34      * @brief Whether cellular data service is connected.
35      *
36      * @return Return true on connected, false on not connected.
37      */
38     bool IsConnect() const;
39 
40     /**
41      * @brief Whether to enable cellular data user switch
42      *
43      * @param enable Enable or not.
44      * @return Return 84082688 invalid parameter, 1 data enable success, 0 enable fail.
45      */
46     int32_t EnableCellularData(bool enable);
47 
48     /**
49      * @brief Whether the cellular data user switch is enabled
50      *
51      * @param dataEnabled Indicates the result of data enabled status.
52      * @return Returns error code.
53      */
54     int32_t IsCellularDataEnabled(bool &dataEnabled);
55 
56     /**
57      * @brief Cellular data connection status
58      *
59      * @return Returns data connection status defined in DataConnectionStatus.
60      */
61     int32_t GetCellularDataState();
62 
63     /**
64      * @brief Whether roaming is allowed
65      *
66      * @param slotId Indicates card slot identification
67      * @param dataRoamingEnabled Indicates the result of data roaming enabled status.
68      * @return Returns error code.
69      */
70     int32_t IsCellularDataRoamingEnabled(int32_t slotId, bool &dataRoamingEnabled);
71 
72     /**
73      * @brief Whether roaming switches are allowed
74      *
75      * @param slotId card slot identification
76      * @param enable Whether roaming switches are allowed
77      * @return Returns 0 on failure, 1 on failure. 84082688 invalid parameter
78      */
79     int32_t EnableCellularDataRoaming(int32_t slotId, bool enable);
80 
81     /**
82      * @brief Get the slotId that uses the data traffic by default
83      *
84      * @return Returns the default settings data card, -1 error code
85      */
86     int32_t GetDefaultCellularDataSlotId();
87 
88     /**
89      * Get the simId that uses the data traffic by default
90      *
91      * @param simId Returns default settings data sim id
92      * @return Returns 0 on success, others on failure.
93      */
94     int32_t GetDefaultCellularDataSimId(int32_t &simId);
95 
96     /**
97      * @brief Set the slotId that uses the data traffic by default
98      *
99      * @param slotId card slot identification
100      * @return 1 set success, 0 set fail, 84082688 invalid parameter
101      */
102     int32_t SetDefaultCellularDataSlotId(int32_t slotId);
103 
104     /**
105      * @brief Get data packet type
106      *
107      * @return Returns cell data flow type defined in CellDataFlowType.
108      */
109     int32_t GetCellularDataFlowType();
110 
111     /**
112      * @brief Whether cellular data has internet capability.
113      *
114      * @param slotId Card slot identification.
115      * @param cid Context identification.
116      * @return Return 1 if has, 0 if hasn't.
117      */
118     int32_t HasInternetCapability(int32_t slotId, int32_t cid);
119 
120     /**
121      * @brief Clear cellular data connections.
122      *
123      * @param slotId Card slot identification.
124      * @return 1 set success, 0 set fail, 84082688 invalid parameter
125      */
126     int32_t ClearCellularDataConnections(int32_t slotId);
127 
128     /**
129      * @brief Get cellular data proxy.
130      *
131      * @return Cellular data service.
132      */
133     sptr<ICellularDataManager> GetProxy();
134 
135     /**
136      * @brief Update the slotId that uses the data traffic by default
137      *
138      * @return Returns the default settings data card, -1 error code
139      */
140     int32_t UpdateDefaultCellularDataSlotId();
141 
142 private:
143     class CellularDataDeathRecipient : public IRemoteObject::DeathRecipient {
144     public:
CellularDataDeathRecipient(CellularDataClient & client)145         explicit CellularDataDeathRecipient(CellularDataClient &client) : client_(client) {}
146         ~CellularDataDeathRecipient() override = default;
OnRemoteDied(const wptr<IRemoteObject> & remote)147         void OnRemoteDied(const wptr<IRemoteObject> &remote) override
148         {
149             client_.OnRemoteDied(remote);
150         }
151 
152     private:
153         CellularDataClient &client_;
154     };
155 
156     void OnRemoteDied(const wptr<IRemoteObject> &remote);
157     void RegisterSimAccountCallback();
158     void UnregisterSimAccountCallback();
159 
160 private:
161     std::mutex mutexProxy_;
162     sptr<ICellularDataManager> proxy_ { nullptr };
163     sptr<IRemoteObject::DeathRecipient> deathRecipient_ { nullptr };
164     sptr<SimAccountCallback> callback_ { nullptr };
165     static int32_t defaultCellularDataSlotId_;
166     static int32_t defaultCellularDataSimId_;
167     bool registerStatus_ = false;
168 };
169 } // namespace Telephony
170 } // namespace OHOS
171 #endif // CELLULAR_DATA_CLIENT_H
172