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, 1 data enable success, 0 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 * @brief Get recovery state 82 */ 83 int32_t GetDataRecoveryState(); 84 85 /** 86 * @brief Whether roaming is allowed 87 * 88 * @param slotId Indicates card slot identification 89 * @param dataRoamingEnabled Indicates the result of data roaming enabled status. 90 * @return Returns error code. 91 */ 92 int32_t IsCellularDataRoamingEnabled(int32_t slotId, bool &dataRoamingEnabled); 93 94 /** 95 * @brief Whether roaming switches are allowed 96 * 97 * @param slotId card slot identification 98 * @param enable Whether roaming switches are allowed 99 * @return Returns 0 on failure, 1 on failure. 84082688 invalid parameter 100 */ 101 int32_t EnableCellularDataRoaming(int32_t slotId, bool enable); 102 103 /** 104 * @brief Get the slotId that uses the data traffic by default 105 * 106 * @return Returns the default settings data card, -1 error code 107 */ 108 int32_t GetDefaultCellularDataSlotId(); 109 110 /** 111 * Get the simId that uses the data traffic by default 112 * 113 * @param simId Returns default settings data sim id 114 * @return Returns 0 on success, others on failure. 115 */ 116 int32_t GetDefaultCellularDataSimId(int32_t &simId); 117 118 /** 119 * @brief Set the slotId that uses the data traffic by default 120 * 121 * @param slotId card slot identification 122 * @return 1 set success, 0 set fail, 84082688 invalid parameter 123 */ 124 int32_t SetDefaultCellularDataSlotId(int32_t slotId); 125 126 /** 127 * @brief Get data packet type 128 * 129 * @return Returns cell data flow type defined in CellDataFlowType. 130 */ 131 int32_t GetCellularDataFlowType(); 132 133 /** 134 * @brief Whether cellular data has internet capability. 135 * 136 * @param slotId Card slot identification. 137 * @param cid Context identification. 138 * @return Return 1 if has, 0 if hasn't. 139 */ 140 int32_t HasInternetCapability(int32_t slotId, int32_t cid); 141 142 /** 143 * @brief Clear cellular data connections. 144 * 145 * @param slotId Card slot identification. 146 * @return 1 set success, 0 set fail, 84082688 invalid parameter 147 */ 148 int32_t ClearCellularDataConnections(int32_t slotId); 149 150 int32_t ClearAllConnections(int32_t slotId, DisConnectionReason reason); 151 152 int32_t HandleApnChanged(int32_t slotId); 153 154 /** 155 * @brief Get cellular data proxy. 156 * 157 * @return Cellular data service. 158 */ 159 sptr<ICellularDataManager> GetProxy(); 160 161 /** 162 * @brief Update the slotId that uses the data traffic by default 163 * 164 * @return Returns the default settings data card, -1 error code 165 */ 166 int32_t UpdateDefaultCellularDataSlotId(); 167 168 /** 169 * @brief Get data connections apn attribute. 170 * 171 * @param slotId Card slot identification. 172 * @param apnType Indicates the APN attribute used by the data connection. 173 * @return 1 set success, 0 set fail 174 */ 175 int32_t GetDataConnApnAttr(int32_t slotId, ApnItem::Attribute &apnAttr); 176 177 /** 178 * @brief Get data connections ip type. 179 * 180 * @param slotId Card slot identification. 181 * @param ipType Indicates IP array after data connection. 182 * @return 1 set success, 0 set fail 183 */ 184 int32_t GetDataConnIpType(int32_t slotId, std::string &ipType); 185 186 /** 187 * @brief Whether do recovery is needed. 188 * 189 * @param slotId Card slot identification. 190 * @param needDoRecovery Whether do recovery is needed. 191 * @return 1 set success, 0 set fail 192 */ 193 int32_t IsNeedDoRecovery(int32_t slotId, bool needDoRecovery); 194 195 private: 196 class CellularDataDeathRecipient : public IRemoteObject::DeathRecipient { 197 public: CellularDataDeathRecipient(CellularDataClient & client)198 explicit CellularDataDeathRecipient(CellularDataClient &client) : client_(client) {} 199 ~CellularDataDeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)200 void OnRemoteDied(const wptr<IRemoteObject> &remote) override 201 { 202 client_.OnRemoteDied(remote); 203 } 204 205 private: 206 CellularDataClient &client_; 207 }; 208 209 void OnRemoteDied(const wptr<IRemoteObject> &remote); 210 void RegisterSimAccountCallback(); 211 void UnregisterSimAccountCallback(); 212 bool IsValidSlotId(int32_t slotId); 213 214 private: 215 std::mutex mutexProxy_; 216 sptr<ICellularDataManager> proxy_ { nullptr }; 217 sptr<IRemoteObject::DeathRecipient> deathRecipient_ { nullptr }; 218 sptr<SimAccountCallback> callback_ { nullptr }; 219 static int32_t defaultCellularDataSlotId_; 220 static int32_t defaultCellularDataSimId_; 221 bool registerStatus_ = false; 222 }; 223 } // namespace Telephony 224 } // namespace OHOS 225 #endif // CELLULAR_DATA_CLIENT_H 226