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 "system_ability_definition.h" 20 #include "system_ability_status_change_stub.h" 21 #include "common_event_subscriber.h" 22 #include "telephony_state_registry_client.h" 23 #include "i_tel_ril_manager.h" 24 #include "inner_event.h" 25 #include "sim_constant.h" 26 #include "sim_state_manager.h" 27 #include "tel_event_handler.h" 28 #include "want.h" 29 30 #define STK_CMD_CMD_LEN_INDEX 2 31 #define STK_CMD_CMD_LEN_81 "81" 32 #define STK_CMD_CMD_LEN_82 "82" 33 #define STK_CMD_CMD_LEN_83 "83" 34 #define STK_CMD_TYPE_80_INDEX 10 35 #define STK_CMD_TYPE_81_INDEX 12 36 #define STK_CMD_TYPE_82_INDEX 14 37 #define STK_CMD_TYPE_83_INDEX 16 38 #define STK_CMD_TYPE_LEN 2 39 #define STK_BIP_CMD_OPEN_CHANNEL "40" 40 #define STK_BIP_CMD_SEND_DATA "43" 41 #define STK_BIP_CMD_RECEVIE_DATA "42" 42 #define STK_BIP_CMD_GET_CHANNEL_STATUS "44" 43 #define STK_BIP_CMD_CLOSE_CHANNEL "41" 44 #define STK_BIP_CMD_SET_UP_EVENT_LIST "05" 45 #define STK_APP_CMD_TYPE_TAG_LEN 2 46 #define STK_APP_CMD_TYPE_USER_CONFIRM "00" 47 48 namespace OHOS { 49 namespace Telephony { 50 using namespace OHOS::EventFwk; 51 using CommonEventSubscribeInfo = OHOS::EventFwk::CommonEventSubscribeInfo; 52 using CommonEventSubscriber = OHOS::EventFwk::CommonEventSubscriber; 53 class StkController : public TelEventHandler { 54 public: 55 explicit StkController(const std::weak_ptr<Telephony::ITelRilManager> &telRilManager, 56 const std::weak_ptr<Telephony::SimStateManager> &simStateManager, int32_t slotId); 57 ~StkController(); 58 void Init(); 59 std::string initStkBudleName(); 60 int32_t SendTerminalResponseCmd(const std::string &strCmd); 61 int32_t SendEnvelopeCmd(const std::string &strCmd); 62 int32_t SendCallSetupRequestResult(bool accept); 63 void UnRegisterEvents(); 64 65 public: 66 enum { 67 RETRY_SEND_RIL_PROACTIVE_COMMAND = 10000, 68 }; 69 70 private: 71 void RegisterEvents(); 72 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; 73 void OnIccStateChanged(const AppExecFwk::InnerEvent::Pointer &event); 74 void OnSendRilSessionEnd(const AppExecFwk::InnerEvent::Pointer &event); 75 void OnSendRilProactiveCommand(const AppExecFwk::InnerEvent::Pointer &event); 76 void OnSendRilAlphaNotify(const AppExecFwk::InnerEvent::Pointer &event); 77 void OnSendRilEventNotify(const AppExecFwk::InnerEvent::Pointer &event); 78 void OnIccRefresh(const AppExecFwk::InnerEvent::Pointer &event); 79 bool PublishStkEvent(AAFwk::Want &want); 80 void OnSendTerminalResponseResult(const AppExecFwk::InnerEvent::Pointer &event); 81 void OnSendEnvelopeCmdResult(const AppExecFwk::InnerEvent::Pointer &event); 82 void OnSendCallSetupRequestResult(const AppExecFwk::InnerEvent::Pointer &event); 83 bool CheckIsSystemApp(const std::string &bundleName); 84 void HandleStkBipCmd(const std::string &cmdData); 85 sptr<OHOS::IRemoteObject> GetBundleMgr(); 86 void RetrySendRilProactiveCommand(); 87 void UnSubscribeListeners(); 88 void InitListener(); 89 void SubscribeBundleScanFinished(); 90 void OnReceiveBms(); 91 void ProcessEventExt(uint32_t id, const AppExecFwk::InnerEvent::Pointer &event); 92 void OnRadioStateChanged(const AppExecFwk::InnerEvent::Pointer &event); 93 94 private: 95 class BundleScanFinishedEventSubscriber : public CommonEventSubscriber { 96 public: BundleScanFinishedEventSubscriber(const CommonEventSubscribeInfo & info,StkController & handler)97 explicit BundleScanFinishedEventSubscriber( 98 const CommonEventSubscribeInfo &info, StkController &handler) 99 : CommonEventSubscriber(info), handler_(handler) {} 100 ~BundleScanFinishedEventSubscriber() = default; 101 void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data) override; 102 StkController &handler_; 103 }; 104 105 class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub { 106 public: SystemAbilityStatusChangeListener(StkController & handler)107 explicit SystemAbilityStatusChangeListener(StkController &handler) : handler_(handler) {}; 108 ~SystemAbilityStatusChangeListener() = default; 109 virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 110 virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 111 112 private: 113 StkController &handler_; 114 }; 115 116 private: 117 std::weak_ptr<Telephony::ITelRilManager> telRilManager_; 118 std::weak_ptr<Telephony::SimStateManager> simStateManager_; 119 int slotId_ = 0; 120 int32_t iccCardState_ = 0; 121 int32_t envelopeResponseResult_ = 0; 122 int32_t terminalResponseResult_ = 0; 123 int32_t callSetupResponseResult_ = 0; 124 bool responseFinished_ = false; 125 std::string stkBundleName_ = ""; 126 std::mutex stkMutex_; 127 std::condition_variable stkCv_; 128 AAFwk::Want retryWant_; 129 int32_t remainTryCount_ = 0; 130 bool isProactiveCommandSucc = false; 131 std::shared_ptr<BundleScanFinishedEventSubscriber> bundleScanFinishedSubscriber_ = nullptr; 132 sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr; 133 }; 134 } // namespace Telephony 135 } // namespace OHOS 136 #endif // OHOS_STK_CONTROLLER_H 137