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