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
26namespace OHOS {
27namespace Telephony {
28class CellularDataController : public TelEventHandler {
29public:
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    bool EstablishAllApnsIfConnectable() const;
58    bool AddUid(const NetRequest &request);
59    bool RemoveUid(const NetRequest &request);
60    bool ReleaseCellularDataConnection() const;
61    bool UpdateNetworkInfo();
62
63private:
64    void RegisterEvents();
65    void UnRegisterEvents();
66
67private:
68    std::shared_ptr<CellularDataHandler> cellularDataHandler_;
69    sptr<ISystemAbilityStatusChange> systemAbilityListener_ = nullptr;
70    const int32_t slotId_;
71
72private:
73    class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub {
74    public:
75        explicit SystemAbilityStatusChangeListener(int32_t slotId, std::shared_ptr<CellularDataHandler> handler);
76        ~SystemAbilityStatusChangeListener() = default;
77        void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
78        void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
79
80    private:
81        const int32_t slotId_;
82        std::shared_ptr<CellularDataHandler> handler_;
83    };
84};
85} // namespace Telephony
86} // namespace OHOS
87#endif // CELLULAR_DATA_CONTROLLER_H
88