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_CONTROLLER_H 17 #define CELLULAR_DATA_CONTROLLER_H 18 19 #include <memory> 20 21 #include "cellular_data_constant.h" 22 #include "cellular_data_handler.h" 23 #include "system_ability_status_change_stub.h" 24 #include "tel_event_handler.h" 25 26 namespace OHOS { 27 namespace Telephony { 28 class CellularDataController : public TelEventHandler { 29 public: 30 explicit CellularDataController(int32_t slotId); 31 ~CellularDataController(); 32 void Init(); 33 bool ReleaseNet(const NetRequest &request); 34 bool RequestNet(const NetRequest &request); 35 int32_t SetCellularDataEnable(bool userDataEnabled); 36 int32_t SetIntelligenceSwitchEnable(bool userDataEnabled); 37 int32_t IsCellularDataEnabled(bool &dataEnabled) const; 38 int32_t SetCellularDataRoamingEnabled(bool dataRoamingEnabled); 39 ApnProfileState GetCellularDataState() const; 40 ApnProfileState GetCellularDataState(const std::string &apnType) const; 41 int32_t IsCellularDataRoamingEnabled(bool &dataRoamingEnabled) const; 42 void AsynchronousRegister(); 43 bool HandleApnChanged(); 44 int32_t GetCellularDataFlowType(); 45 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event); 46 int32_t SetPolicyDataOn(bool enable); 47 bool IsRestrictedMode() const; 48 DisConnectionReason GetDisConnectionReason(); 49 bool HasInternetCapability(const int32_t cid) const; 50 bool ClearAllConnections(DisConnectionReason reason) const; 51 void GetDataConnApnAttr(ApnItem::Attribute &apnAttr) const; 52 std::string GetDataConnIpType() const; 53 int32_t GetDataRecoveryState(); 54 void IsNeedDoRecovery(bool needDoRecovery) const; 55 bool ChangeConnectionForDsds(bool enable) const; 56 int32_t GetIntelligenceSwitchState(bool &switchState); 57 58 private: 59 void RegisterEvents(); 60 void UnRegisterEvents(); 61 62 private: 63 std::shared_ptr<CellularDataHandler> cellularDataHandler_; 64 sptr<ISystemAbilityStatusChange> systemAbilityListener_ = nullptr; 65 const int32_t slotId_; 66 67 private: 68 class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub { 69 public: 70 explicit SystemAbilityStatusChangeListener(int32_t slotId, std::shared_ptr<CellularDataHandler> handler); 71 ~SystemAbilityStatusChangeListener() = default; 72 void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 73 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 74 75 private: 76 const int32_t slotId_; 77 std::shared_ptr<CellularDataHandler> handler_; 78 }; 79 }; 80 } // namespace Telephony 81 } // namespace OHOS 82 #endif // CELLULAR_DATA_CONTROLLER_H 83