• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 INCALL_DATA_STATE_MACHINE_H
17 #define INCALL_DATA_STATE_MACHINE_H
18 
19 #include <map>
20 #include <memory>
21 
22 #include "apn_manager.h"
23 #include "cellular_data_constant.h"
24 #include "inner_event.h"
25 #include "refbase.h"
26 #include "state_machine.h"
27 #include "tel_event_handler.h"
28 
29 namespace OHOS {
30 namespace Telephony {
31 class IncallDataStateMachine : public StateMachine, public std::enable_shared_from_this<IncallDataStateMachine> {
32 public:
IncallDataStateMachine(int32_t slotId,std::weak_ptr<TelEventHandler> && cellularDataHandler,sptr<ApnManager> & apnManager)33     IncallDataStateMachine(
34         int32_t slotId, std::weak_ptr<TelEventHandler> &&cellularDataHandler, sptr<ApnManager> &apnManager)
35         : StateMachine("IncallDataStateMachine"), cellularDataHandler_(std::move(cellularDataHandler)),
36           apnManager_(apnManager), slotId_(slotId)
37     {}
38     ~IncallDataStateMachine() = default;
39     sptr<State> GetCurrentState() const;
40     int32_t GetSlotId() const;
41     int32_t GetCallState() const;
42     bool HasAnyConnectedState() const;
43     void UpdateCallState(int32_t state);
44     void Init(int32_t callState);
45     bool IsSecondaryActiveState() const;
46     void DeInit();
47 
48 protected:
49     sptr<State> idleState_;
50     sptr<State> secondaryActiveState_;
51     sptr<State> activatingSecondaryState_;
52     sptr<State> activatedSecondaryState_;
53     sptr<State> deactivatingSecondaryState_;
54     sptr<State> currentState_;
55     std::weak_ptr<TelEventHandler> cellularDataHandler_;
56     sptr<ApnManager> apnManager_;
57 
58 private:
59     void SetCurrentState(const sptr<State> &&state);
60     bool IsIncallDataSwitchOn();
61     bool IsSecondaryCanActiveData();
62     bool CanActiveDataByRadioTech();
63 
64 private:
65     friend class IdleState;
66     friend class SecondaryActiveState;
67     friend class ActivatingSecondaryState;
68     friend class ActivatedSecondaryState;
69     friend class DeactivatingSecondaryState;
70     int32_t slotId_ = INVALID_SLOT_ID;
71     int32_t callState_ = static_cast<int32_t>(TelCallStatus::CALL_STATUS_IDLE);
72 };
73 
74 class IdleState : public State {
75 public:
IdleState(std::weak_ptr<IncallDataStateMachine> && incallData,std::string && name)76     IdleState(std::weak_ptr<IncallDataStateMachine> &&incallData, std::string &&name)
77         : State(std::move(name)), stateMachine_(std::move(incallData))
78     {}
79     virtual ~IdleState() = default;
80     virtual void StateBegin();
81     virtual void StateEnd();
82     virtual bool StateProcess(const AppExecFwk::InnerEvent::Pointer &event);
83 
84 private:
85     bool ProcessCallStarted(const AppExecFwk::InnerEvent::Pointer &event);
86     bool ProcessCallEnded(const AppExecFwk::InnerEvent::Pointer &event);
87     bool ProcessSettingsOn(const AppExecFwk::InnerEvent::Pointer &event);
88     bool ProcessDsdsChanged(const AppExecFwk::InnerEvent::Pointer &event);
89 
90 private:
91     using Fun = std::function<bool(const AppExecFwk::InnerEvent::Pointer &data)>;
92     std::map<uint32_t, Fun> eventIdFunMap_ {
93         { CellularDataEventCode::MSG_SM_INCALL_DATA_CALL_STARTED,
94             [this](const AppExecFwk::InnerEvent::Pointer &data) { return ProcessCallStarted(data); } },
95         { CellularDataEventCode::MSG_SM_INCALL_DATA_CALL_ENDED,
96             [this](const AppExecFwk::InnerEvent::Pointer &data) { return ProcessCallEnded(data); } },
97         { CellularDataEventCode::MSG_SM_INCALL_DATA_SETTINGS_ON,
98             [this](const AppExecFwk::InnerEvent::Pointer &data) { return ProcessSettingsOn(data); } },
99         { CellularDataEventCode::MSG_SM_INCALL_DATA_DSDS_CHANGED,
100             [this](const AppExecFwk::InnerEvent::Pointer &data) { return ProcessDsdsChanged(data); } },
101     };
102     std::weak_ptr<IncallDataStateMachine> stateMachine_;
103 };
104 
105 class SecondaryActiveState : public State {
106 public:
SecondaryActiveState(std::weak_ptr<IncallDataStateMachine> && incallData,std::string && name)107     SecondaryActiveState(std::weak_ptr<IncallDataStateMachine> &&incallData, std::string &&name)
108         : State(std::move(name)), stateMachine_(std::move(incallData))
109     {}
110     virtual ~SecondaryActiveState() = default;
111     virtual void StateBegin();
112     virtual void StateEnd();
113     virtual bool StateProcess(const AppExecFwk::InnerEvent::Pointer &event);
114 
115 private:
116     bool ProcessSettingsOn(const AppExecFwk::InnerEvent::Pointer &event);
117     bool ProcessCallEnded(const AppExecFwk::InnerEvent::Pointer &event);
118     bool ProcessSettingsOff(const AppExecFwk::InnerEvent::Pointer &event);
119     bool ProcessDsdsChanged(const AppExecFwk::InnerEvent::Pointer &event);
120 
121 private:
122     using Fun = std::function<bool(const AppExecFwk::InnerEvent::Pointer &data)>;
123     std::map<uint32_t, Fun> eventIdFunMap_ {
124         { CellularDataEventCode::MSG_SM_INCALL_DATA_SETTINGS_ON,
125             [this](const AppExecFwk::InnerEvent::Pointer &data) { return ProcessSettingsOn(data); } },
126         { CellularDataEventCode::MSG_SM_INCALL_DATA_CALL_ENDED,
127             [this](const AppExecFwk::InnerEvent::Pointer &data) { return ProcessCallEnded(data); } },
128         { CellularDataEventCode::MSG_SM_INCALL_DATA_SETTINGS_OFF,
129             [this](const AppExecFwk::InnerEvent::Pointer &data) { return ProcessSettingsOff(data); } },
130         { CellularDataEventCode::MSG_SM_INCALL_DATA_DSDS_CHANGED,
131             [this](const AppExecFwk::InnerEvent::Pointer &data) { return ProcessDsdsChanged(data); } },
132     };
133     std::weak_ptr<IncallDataStateMachine> stateMachine_;
134 };
135 
136 class ActivatingSecondaryState : public State {
137 public:
ActivatingSecondaryState(std::weak_ptr<IncallDataStateMachine> && incallData,std::string && name)138     ActivatingSecondaryState(std::weak_ptr<IncallDataStateMachine> &&incallData, std::string &&name)
139         : State(std::move(name)), stateMachine_(std::move(incallData))
140     {}
141     virtual ~ActivatingSecondaryState() = default;
142     virtual void StateBegin();
143     virtual void StateEnd();
144     virtual bool StateProcess(const AppExecFwk::InnerEvent::Pointer &event);
145 
146 private:
147     std::weak_ptr<IncallDataStateMachine> stateMachine_;
148 };
149 
150 class ActivatedSecondaryState : public State {
151 public:
ActivatedSecondaryState(std::weak_ptr<IncallDataStateMachine> && incallData,std::string && name)152     ActivatedSecondaryState(std::weak_ptr<IncallDataStateMachine> &&incallData, std::string &&name)
153         : State(std::move(name)), stateMachine_(std::move(incallData))
154     {}
155     virtual ~ActivatedSecondaryState() = default;
156     virtual void StateBegin();
157     virtual void StateEnd();
158     virtual bool StateProcess(const AppExecFwk::InnerEvent::Pointer &event);
159 
160 private:
161     std::weak_ptr<IncallDataStateMachine> stateMachine_;
162 };
163 
164 class DeactivatingSecondaryState : public State {
165 public:
DeactivatingSecondaryState(std::weak_ptr<IncallDataStateMachine> && incallData,std::string && name)166     DeactivatingSecondaryState(std::weak_ptr<IncallDataStateMachine> &&incallData, std::string &&name)
167         : State(std::move(name)), stateMachine_(std::move(incallData))
168     {}
169     virtual ~DeactivatingSecondaryState() = default;
170     virtual void StateBegin();
171     virtual void StateEnd();
172     virtual bool StateProcess(const AppExecFwk::InnerEvent::Pointer &event);
173 
174 private:
175     std::weak_ptr<IncallDataStateMachine> stateMachine_;
176 };
177 } // namespace Telephony
178 } // namespace OHOS
179 #endif // INCALL_DATA_STATE_MACHINE_H