• 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 
46 protected:
47     sptr<State> idleState_;
48     sptr<State> secondaryActiveState_;
49     sptr<State> activatingSecondaryState_;
50     sptr<State> activatedSecondaryState_;
51     sptr<State> deactivatingSecondaryState_;
52     sptr<State> currentState_;
53     std::weak_ptr<TelEventHandler> cellularDataHandler_;
54     sptr<ApnManager> apnManager_;
55 
56 private:
57     void SetCurrentState(const sptr<State> &&state);
58     bool IsIncallDataSwitchOn();
59     bool IsSecondaryCanActiveData();
60     bool CanActiveDataByRadioTech();
61 
62 private:
63     friend class IdleState;
64     friend class SecondaryActiveState;
65     friend class ActivatingSecondaryState;
66     friend class ActivatedSecondaryState;
67     friend class DeactivatingSecondaryState;
68     int32_t slotId_ = INVALID_SLOT_ID;
69     int32_t callState_ = static_cast<int32_t>(TelCallStatus::CALL_STATUS_IDLE);
70 };
71 
72 class IdleState : public State {
73 public:
IdleState(std::weak_ptr<IncallDataStateMachine> && incallData,std::string && name)74     IdleState(std::weak_ptr<IncallDataStateMachine> &&incallData, std::string &&name)
75         : State(std::move(name)), stateMachine_(std::move(incallData))
76     {}
77     virtual ~IdleState() = default;
78     virtual void StateBegin();
79     virtual void StateEnd();
80     virtual bool StateProcess(const AppExecFwk::InnerEvent::Pointer &event);
81 
82 private:
83     bool ProcessCallStarted(const AppExecFwk::InnerEvent::Pointer &event);
84     bool ProcessCallEnded(const AppExecFwk::InnerEvent::Pointer &event);
85     bool ProcessSettingsOn(const AppExecFwk::InnerEvent::Pointer &event);
86     bool ProcessDsdsChanged(const AppExecFwk::InnerEvent::Pointer &event);
87 
88 private:
89     using Fun = bool (IdleState::*)(const AppExecFwk::InnerEvent::Pointer &data);
90     std::map<uint32_t, Fun> eventIdFunMap_ {
91         { CellularDataEventCode::MSG_SM_INCALL_DATA_CALL_STARTED, &IdleState::ProcessCallStarted },
92         { CellularDataEventCode::MSG_SM_INCALL_DATA_CALL_ENDED, &IdleState::ProcessCallEnded },
93         { CellularDataEventCode::MSG_SM_INCALL_DATA_SETTINGS_ON, &IdleState::ProcessSettingsOn },
94         { CellularDataEventCode::MSG_SM_INCALL_DATA_DSDS_CHANGED, &IdleState::ProcessDsdsChanged },
95     };
96     std::weak_ptr<IncallDataStateMachine> stateMachine_;
97 };
98 
99 class SecondaryActiveState : public State {
100 public:
SecondaryActiveState(std::weak_ptr<IncallDataStateMachine> && incallData,std::string && name)101     SecondaryActiveState(std::weak_ptr<IncallDataStateMachine> &&incallData, std::string &&name)
102         : State(std::move(name)), stateMachine_(std::move(incallData))
103     {}
104     virtual ~SecondaryActiveState() = default;
105     virtual void StateBegin();
106     virtual void StateEnd();
107     virtual bool StateProcess(const AppExecFwk::InnerEvent::Pointer &event);
108 
109 private:
110     bool ProcessSettingsOn(const AppExecFwk::InnerEvent::Pointer &event);
111     bool ProcessCallEnded(const AppExecFwk::InnerEvent::Pointer &event);
112     bool ProcessSettingsOff(const AppExecFwk::InnerEvent::Pointer &event);
113     bool ProcessDsdsChanged(const AppExecFwk::InnerEvent::Pointer &event);
114 
115 private:
116     using Fun = bool (SecondaryActiveState::*)(const AppExecFwk::InnerEvent::Pointer &data);
117     std::map<uint32_t, Fun> eventIdFunMap_ {
118         { CellularDataEventCode::MSG_SM_INCALL_DATA_SETTINGS_ON, &SecondaryActiveState::ProcessSettingsOn },
119         { CellularDataEventCode::MSG_SM_INCALL_DATA_CALL_ENDED, &SecondaryActiveState::ProcessCallEnded },
120         { CellularDataEventCode::MSG_SM_INCALL_DATA_SETTINGS_OFF, &SecondaryActiveState::ProcessSettingsOff },
121         { CellularDataEventCode::MSG_SM_INCALL_DATA_DSDS_CHANGED, &SecondaryActiveState::ProcessDsdsChanged },
122     };
123     std::weak_ptr<IncallDataStateMachine> stateMachine_;
124 };
125 
126 class ActivatingSecondaryState : public State {
127 public:
ActivatingSecondaryState(std::weak_ptr<IncallDataStateMachine> && incallData,std::string && name)128     ActivatingSecondaryState(std::weak_ptr<IncallDataStateMachine> &&incallData, std::string &&name)
129         : State(std::move(name)), stateMachine_(std::move(incallData))
130     {}
131     virtual ~ActivatingSecondaryState() = default;
132     virtual void StateBegin();
133     virtual void StateEnd();
134     virtual bool StateProcess(const AppExecFwk::InnerEvent::Pointer &event);
135 
136 private:
137     std::weak_ptr<IncallDataStateMachine> stateMachine_;
138 };
139 
140 class ActivatedSecondaryState : public State {
141 public:
ActivatedSecondaryState(std::weak_ptr<IncallDataStateMachine> && incallData,std::string && name)142     ActivatedSecondaryState(std::weak_ptr<IncallDataStateMachine> &&incallData, std::string &&name)
143         : State(std::move(name)), stateMachine_(std::move(incallData))
144     {}
145     virtual ~ActivatedSecondaryState() = default;
146     virtual void StateBegin();
147     virtual void StateEnd();
148     virtual bool StateProcess(const AppExecFwk::InnerEvent::Pointer &event);
149 
150 private:
151     std::weak_ptr<IncallDataStateMachine> stateMachine_;
152 };
153 
154 class DeactivatingSecondaryState : public State {
155 public:
DeactivatingSecondaryState(std::weak_ptr<IncallDataStateMachine> && incallData,std::string && name)156     DeactivatingSecondaryState(std::weak_ptr<IncallDataStateMachine> &&incallData, std::string &&name)
157         : State(std::move(name)), stateMachine_(std::move(incallData))
158     {}
159     virtual ~DeactivatingSecondaryState() = default;
160     virtual void StateBegin();
161     virtual void StateEnd();
162     virtual bool StateProcess(const AppExecFwk::InnerEvent::Pointer &event);
163 
164 private:
165     std::weak_ptr<IncallDataStateMachine> stateMachine_;
166 };
167 } // namespace Telephony
168 } // namespace OHOS
169 #endif // INCALL_DATA_STATE_MACHINE_H