• 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 
29 namespace OHOS {
30 namespace Telephony {
31 enum class ServiceRunningState {
32     STATE_NOT_START,
33     STATE_RUNNING,
34 };
35 
36 class CellularDataService : public SystemAbility, public CellularDataServiceStub {
37     DECLARE_DELAYED_REF_SINGLETON(CellularDataService)
38     DECLARE_SYSTEM_ABILITY(CellularDataService)
39 
40 public:
41     /**
42      * service Start
43      */
44     void OnStart() override;
45     /**
46      * service OnStop
47      */
48     void OnStop() override;
49     int32_t Dump(std::int32_t fd, const std::vector<std::u16string>& args) override;
50     std::string GetBeginTime();
51     std::string GetEndTime();
52     std::string GetCellularDataSlotIdDump();
53     std::string GetStateMachineCurrentStatusDump();
54     std::string GetFlowDataInfoDump();
55     int32_t IsCellularDataEnabled(bool &dataEnabled) override;
56     int32_t EnableCellularData(bool enable) override;
57     int32_t GetCellularDataState() override;
58     int32_t IsCellularDataRoamingEnabled(const int32_t slotId, bool &dataRoamingEnabled) override;
59     int32_t EnableCellularDataRoaming(const int32_t slotId, bool enable) override;
60     int32_t HandleApnChanged(const int32_t slotId) override;
61     int32_t GetDefaultCellularDataSlotId() override;
62     int32_t GetDefaultCellularDataSimId(int32_t &simId) override;
63     int32_t SetDefaultCellularDataSlotId(const int32_t slotId) override;
64     int32_t GetCellularDataFlowType() override;
65     void DispatchEvent(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event);
66     int32_t HasInternetCapability(const int32_t slotId, const int32_t cid) override;
67     int32_t ClearCellularDataConnections(const int32_t slotId) override;
68     int32_t ClearAllConnections(const int32_t slotId, DisConnectionReason reason);
69     int32_t StrategySwitch(int32_t slotId, bool enable);
70     int32_t RequestNet(const NetRequest &request);
71     int32_t ReleaseNet(const NetRequest &request);
72     int32_t GetServiceRunningState();
73     int64_t GetSpendTime();
74     int32_t RegisterSimAccountCallback(const sptr<SimAccountCallback> &callback) override;
75     int32_t UnregisterSimAccountCallback() override;
76 
77 private:
78     bool Init();
79     void InitModule();
80     bool CheckParamValid(const int32_t slotId);
81     void UnRegisterAllNetSpecifier();
82 
83 private:
84     std::map<int32_t, std::shared_ptr<CellularDataController>> cellularDataControllers_;
85     std::shared_ptr<AppExecFwk::EventRunner> eventLoop_;
86     bool registerToService_;
87     int64_t beginTime_ = 0L;
88     int64_t endTime_ = 0L;
89     ServiceRunningState state_;
90 };
91 } // namespace Telephony
92 } // namespace OHOS
93 #endif // CELLULAR_DATA_SERVICE_H
94