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_SERVICE_H 17 #define CELLULAR_DATA_SERVICE_H 18 19 #include "iremote_object.h" 20 #include "nocopyable.h" 21 #include "singleton.h" 22 #include "system_ability.h" 23 24 #include "cellular_data_manager_stub.h" 25 #include "cellular_data_constant.h" 26 #include "cellular_data_controller.h" 27 #include "traffic_management.h" 28 #include "apn_activate_report_info.h" 29 #include "apn_attribute.h" 30 #include "apn_item.h" 31 32 namespace OHOS { 33 namespace Telephony { 34 enum class ServiceRunningState { 35 STATE_NOT_START, 36 STATE_RUNNING, 37 }; 38 39 class CellularDataService : public SystemAbility, public CellularDataManagerStub { 40 DECLARE_DELAYED_REF_SINGLETON(CellularDataService) 41 DECLARE_SYSTEM_ABILITY(CellularDataService) 42 43 public: 44 /** 45 * service Start 46 */ 47 void OnStart() override; 48 /** 49 * service OnStop 50 */ 51 void OnStop() override; 52 int32_t Dump(std::int32_t fd, const std::vector<std::u16string>& args) override; 53 std::string GetBeginTime(); 54 std::string GetEndTime(); 55 std::string GetCellularDataSlotIdDump(); 56 std::string GetStateMachineCurrentStatusDump(); 57 std::string GetFlowDataInfoDump(); 58 int32_t IsCellularDataEnabled(bool &dataEnabled) override; 59 int32_t EnableCellularData(bool enable) override; 60 int32_t GetCellularDataState(int32_t &state) override; 61 int32_t IsCellularDataRoamingEnabled(const int32_t slotId, bool &dataRoamingEnabled) override; 62 int32_t EnableCellularDataRoaming(const int32_t slotId, bool enable) override; 63 int32_t HandleApnChanged(const int32_t slotId) override; 64 int32_t GetDefaultCellularDataSlotId(int32_t &slotId) override; 65 int32_t GetDefaultCellularDataSimId(int32_t &simId) override; 66 int32_t SetDefaultCellularDataSlotId(const int32_t slotId) override; 67 int32_t GetCellularDataFlowType(int32_t &type) override; 68 void DispatchEvent(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event); 69 int32_t HasInternetCapability(const int32_t slotId, const int32_t cid, int32_t &capability) override; 70 int32_t ClearCellularDataConnections(const int32_t slotId) override; 71 int32_t ClearAllConnections(const int32_t slotId, const int32_t reason) override; 72 int32_t ChangeConnectionForDsds(const int32_t slotId, bool enable); 73 int32_t StrategySwitch(int32_t slotId, bool enable); 74 int32_t RequestNet(const NetRequest &request); 75 int32_t ReleaseNet(const NetRequest &request); 76 int32_t AddUid(const NetRequest &request); 77 int32_t RemoveUid(const NetRequest &request); 78 int32_t GetServiceRunningState(); 79 int64_t GetSpendTime(); 80 int32_t GetApnState(int32_t slotId, const std::string &apnType, int &state) override; 81 int32_t GetDataRecoveryState(int32_t &state) override; 82 int32_t RegisterSimAccountCallback(const sptr<SimAccountCallback> &callback) override; 83 int32_t UnregisterSimAccountCallback(const sptr<SimAccountCallback> &callback) override; 84 int32_t GetDataConnApnAttr(int32_t slotId, ApnAttribute &apnAttr) override; 85 int32_t GetDataConnIpType(int32_t slotId, std::string &ipType) override; 86 int32_t IsNeedDoRecovery(int32_t slotId, bool needDoRecovery) override; 87 int32_t EnableIntelligenceSwitch(bool enable) override; 88 int32_t InitCellularDataController(int32_t slotId) override; 89 int32_t GetIntelligenceSwitchState(bool &switchState) override; 90 int32_t EstablishAllApnsIfConnectable(int32_t slotId) override; 91 int32_t ReleaseCellularDataConnection(int32_t slotId) override; 92 int32_t GetCellularDataSupplierId(int32_t slotId, uint64_t capability, uint32_t &supplierId) override; 93 int32_t CorrectNetSupplierNoAvailable(int32_t slotId) override; 94 int32_t GetSupplierRegisterState(uint32_t supplierId, int32_t ®State) override; 95 int32_t GetIfSupportDunApn(bool &isSupportDun) override; 96 int32_t GetDefaultActReportInfo(int32_t slotId, ApnActivateReportInfoIpc &info) override; 97 int32_t GetInternalActReportInfo(int32_t slotId, ApnActivateReportInfoIpc &info) override; 98 int32_t QueryApnIds(const ApnInfo& apnInfo, std::vector<uint32_t> &apnIdList) override; 99 int32_t SetPreferApn(int32_t apnId) override; 100 int32_t QueryAllApnInfo(std::vector<ApnInfo> &apnInfoList) override; 101 int32_t SendUrspDecodeResult(int32_t slotId, const std::vector<uint8_t>& buffer) override; 102 int32_t SendUePolicySectionIdentifier(int32_t slotId, const std::vector<uint8_t>& buffer) override; 103 int32_t SendImsRsdList(int32_t slotId, const std::vector<uint8_t>& buffer) override; 104 int32_t GetNetworkSliceAllowedNssai(int32_t slotId, const std::vector<uint8_t>& buffer) override; 105 int32_t GetNetworkSliceEhplmn(int32_t slotId) override; 106 int32_t GetActiveApnName(std::string &apnName) override; 107 108 private: 109 bool Init(); 110 void InitModule(); 111 void UnRegisterAllNetSpecifier(); 112 void AddNetSupplier(int32_t slotId, CellularDataNetAgent &netAgent, std::vector<uint64_t> &netCapabilities); 113 void ClearCellularDataControllers(); 114 void AddCellularDataControllers(int32_t slotId, std::shared_ptr<CellularDataController> cellularDataController); 115 std::shared_ptr<CellularDataController> GetCellularDataController(int32_t slotId); 116 117 private: 118 std::map<int32_t, std::shared_ptr<CellularDataController>> cellularDataControllers_; 119 bool registerToService_; 120 int64_t beginTime_ = 0L; 121 int64_t endTime_ = 0L; 122 ServiceRunningState state_; 123 std::mutex mapLock_; 124 bool isInitSuccess_ = false; 125 }; 126 } // namespace Telephony 127 } // namespace OHOS 128 #endif // CELLULAR_DATA_SERVICE_H 129