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 bool IsConnect() const; 34 int32_t EnableCellularData(bool enable); 35 int32_t IsCellularDataEnabled(bool &dataEnabled); 36 int32_t GetCellularDataState(); 37 int32_t IsCellularDataRoamingEnabled(int32_t slotId, bool &dataRoamingEnabled); 38 int32_t EnableCellularDataRoaming(int32_t slotId, bool enable); 39 int32_t GetDefaultCellularDataSlotId(); 40 int32_t SetDefaultCellularDataSlotId(int32_t slotId); 41 int32_t GetCellularDataFlowType(); 42 int32_t HasInternetCapability(int32_t slotId, int32_t cid); 43 int32_t ClearCellularDataConnections(int32_t slotId); 44 sptr<ICellularDataManager> GetProxy(); 45 int32_t UpdateDefaultCellularDataSlotId(); 46 47 private: 48 class CellularDataDeathRecipient : public IRemoteObject::DeathRecipient { 49 public: CellularDataDeathRecipient(CellularDataClient & client)50 explicit CellularDataDeathRecipient(CellularDataClient &client) : client_(client) {} 51 ~CellularDataDeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)52 void OnRemoteDied(const wptr<IRemoteObject> &remote) override 53 { 54 client_.OnRemoteDied(remote); 55 } 56 57 private: 58 CellularDataClient &client_; 59 }; 60 61 void OnRemoteDied(const wptr<IRemoteObject> &remote); 62 void RegisterSimAccountCallback(); 63 void UnregisterSimAccountCallback(); 64 65 private: 66 std::mutex mutexProxy_; 67 sptr<ICellularDataManager> proxy_ {nullptr}; 68 sptr<IRemoteObject::DeathRecipient> deathRecipient_ { nullptr }; 69 sptr<SimAccountCallback> callback_ { nullptr }; 70 int32_t defaultCellularDataSlotId_; 71 bool registerStatus_ = false; 72 }; 73 } // namespace Telephony 74 } // namespace OHOS 75 #endif // CELLULAR_DATA_CLIENT_H