• 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 OHOS_STK_CONTROLLER_H
17 #define OHOS_STK_CONTROLLER_H
18 
19 #include "event_handler.h"
20 #include "inner_event.h"
21 #include "i_tel_ril_manager.h"
22 #include "sim_state_manager.h"
23 #include "want.h"
24 
25 namespace OHOS {
26 namespace Telephony {
27 const int MSG_SIM_STK_TERMINAL_RESPONSE = 1;
28 const int MSG_SIM_STK_ENVELOPE = 2;
29 const int MSG_SIM_STK_IS_READY = 3;
30 
31 class StkController : public AppExecFwk::EventHandler {
32 public:
33     StkController(const std::shared_ptr<AppExecFwk::EventRunner> &runner);
34     ~StkController();
35     void Init(int slotId);
36     void SetRilAndSimStateManager(std::shared_ptr<Telephony::ITelRilManager> ril,
37         const std::shared_ptr<Telephony::SimStateManager> simstateMgr);
38     bool SendTerminalResponseCmd(int32_t slotId, const std::string &strCmd);
39     bool SendEnvelopeCmd(int32_t slotId, const std::string &strCmd);
40 
41 private:
42     void RegisterEvents();
43     void UnRegisterEvents();
44     bool OnsendRilSessionEnd(const AppExecFwk::InnerEvent::Pointer &event);
45     bool OnsendRilProactiveCommand(const AppExecFwk::InnerEvent::Pointer &event);
46     bool OnsendRilAlphaNotify(const AppExecFwk::InnerEvent::Pointer &event);
47     bool OnIccStateChanged(const AppExecFwk::InnerEvent::Pointer &event);
48     void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event);
49     bool PublishStkEvent(const AAFwk::Want &want, int eventCode, const std::string &eventData);
50     void GetTerminalResponseResult(const AppExecFwk::InnerEvent::Pointer &event);
51     void GetEnvelopeCmdResult(const AppExecFwk::InnerEvent::Pointer &event);
52 
53 private:
54     std::shared_ptr<Telephony::ITelRilManager> telRilManager_ = nullptr;
55     std::shared_ptr<Telephony::SimStateManager> simStateManager_ = nullptr;
56     int slotId_ = 0;
57     const std::string ACTION_SESSION_END = "usual.event.telpnony.STK_SESSION_END";
58     const std::string ACTION_ALPHA_IDENTIFIER = "usual.event.telpnony.STK_ALPHA_IDENTIFIER";
59     const std::string ACTION_CARD_STATUS_INFORM = "usual.event.telpnony.STK_CARD_STATUS_INFORM";
60     const std::string ACTION_STK_COMMAND = "usual.event.telpnony.STK_COMMAND";
61 
62     int32_t iccCardState_ = 0;
63     int32_t envelopeResponse_ = 0;
64     int32_t terminalResponse_ = 0;
65     bool responseReady_ = false;
66     std::mutex ctx_;
67     std::condition_variable cv_;
68 
69     const int32_t EVENT_CODE = 1;
70     const std::string PARAM_SLOTID = "slotID";
71     const std::string PARAM_MSG_CMD = "msgCmd";
72     const std::string PARAM_CARD_STATUS = "cardStatus";
73     const std::string PARAM_ALPHA_STRING = "alphaString";
74 
75     const int32_t ICC_CARD_STATE_ABSENT = 0;
76     const int32_t ICC_CARD_STATE_PRESENT = 1;
77 };
78 } // namespace Telephony
79 } // namespace OHOS
80 
81 #endif // OHOS_STK_CONTROLLER_H
82