• 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_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 "cellular_data_rdb_observer.h"
24 #include "system_ability_status_change_stub.h"
25 
26 namespace OHOS {
27 namespace Telephony {
28 class CellularDataController : public AppExecFwk::EventHandler {
29 public:
30     explicit CellularDataController(std::shared_ptr<AppExecFwk::EventRunner> &runner, 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 IsCellularDataEnabled(bool &dataEnabled) const;
37     int32_t SetCellularDataRoamingEnabled(bool dataRoamingEnabled);
38     ApnProfileState GetCellularDataState() const;
39     ApnProfileState GetCellularDataState(const std::string &apnType) const;
40     int32_t IsCellularDataRoamingEnabled(bool &dataRoamingEnabled) const;
41     void SetDataPermitted(bool dataPermitted) const;
42     void AsynchronousRegister();
43     bool HandleApnChanged();
44     int32_t GetCellularDataFlowType();
45     void EstablishDataConnection();
46     void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event);
47     int32_t SetPolicyDataOn(bool enable);
48     bool IsRestrictedMode() const;
49     DisConnectionReason GetDisConnectionReason();
50     bool HasInternetCapability(const int32_t cid) const;
51     bool ClearAllConnections(DisConnectionReason reason) const;
52 
53 private:
54     void RegisterEvents();
55     void UnRegisterEvents();
56     void RegisterDatabaseObserver();
57     void UnRegisterDatabaseObserver();
58 
59 private:
60     std::shared_ptr<CellularDataHandler> cellularDataHandler_;
61     sptr<CellularDataRdbObserver> cellularDataRdbObserver_;
62     sptr<ISystemAbilityStatusChange> netManagerListener_ = nullptr;
63     const int32_t slotId_;
64 
65 private:
66     class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub {
67     public:
68         explicit SystemAbilityStatusChangeListener(int32_t slotId, std::shared_ptr<CellularDataHandler> handler);
69         ~SystemAbilityStatusChangeListener() = default;
70         void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
71         void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
72 
73     private:
74         bool isNetStopped_ = false;
75         const int32_t slotId_;
76         std::shared_ptr<CellularDataHandler> handler_;
77     };
78 };
79 } // namespace Telephony
80 } // namespace OHOS
81 #endif // CELLULAR_DATA_CONTROLLER_H
82