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