• 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 #include "stk_manager.h"
17 
18 #include "telephony_errors.h"
19 #include "telephony_log_wrapper.h"
20 #include "telephony_ext_wrapper.h"
21 
22 namespace OHOS {
23 namespace Telephony {
StkManager(std::shared_ptr<ITelRilManager> telRilManager,std::shared_ptr<SimStateManager> simStateManager)24 StkManager::StkManager(std::shared_ptr<ITelRilManager> telRilManager, std::shared_ptr<SimStateManager> simStateManager)
25     : telRilManager_(telRilManager), simStateManager_(simStateManager)
26 {
27     TELEPHONY_LOGI("StkManager::StkManager()");
28 }
29 
~StkManager()30 StkManager::~StkManager()
31 {
32     if (stkController_ != nullptr) {
33         stkController_->UnRegisterEvents();
34     }
35 }
36 
Init(int slotId)37 void StkManager::Init(int slotId)
38 {
39     if (telRilManager_ == nullptr || simStateManager_ == nullptr) {
40         TELEPHONY_LOGE("StkManager[%{public}d]::Init() telRilManager or simStateManager_ is nullptr", slotId);
41         return;
42     }
43     stkController_ = std::make_shared<StkController>(telRilManager_, simStateManager_, slotId);
44     if (stkController_ == nullptr) {
45         TELEPHONY_LOGE("StkManager[%{public}d]::Init() failed to create StkController", slotId);
46         return;
47     }
48     stkController_->Init();
49     TELEPHONY_LOGI("StkManager[%{public}d]::Init() success", slotId);
50 }
51 
SendEnvelopeCmd(int32_t slotId,const std::string & cmd) const52 int32_t StkManager::SendEnvelopeCmd(int32_t slotId, const std::string &cmd) const
53 {
54     if (stkController_ == nullptr) {
55         TELEPHONY_LOGE("StkManager[%{public}d]::SendEnvelopeCmd() stkController_ is nullptr", slotId);
56         return TELEPHONY_ERR_LOCAL_PTR_NULL;
57     }
58     int32_t result = stkController_->SendEnvelopeCmd(cmd);
59     TELEPHONY_LOGI("StkManager[%{public}d]::SendEnvelopeCmd() result:%{public}s", slotId, (result ? "true" : "false"));
60     return result;
61 }
62 
SendTerminalResponseCmd(int32_t slotId,const std::string & cmd) const63 int32_t StkManager::SendTerminalResponseCmd(int32_t slotId, const std::string &cmd) const
64 {
65     if (stkController_ == nullptr) {
66         TELEPHONY_LOGE("StkManager[%{public}d]::SendTerminalResponseCmd() stkController_ is nullptr", slotId);
67         return TELEPHONY_ERR_LOCAL_PTR_NULL;
68     }
69 
70     if (cmd.substr(0, STK_CMD_TYPE_LEN) == STK_APP_CMD_TYPE_USER_CONFIRM) {
71         if (TELEPHONY_EXT_WRAPPER.sendEvent_ &&
72             TELEPHONY_EXT_WRAPPER.sendEvent_(std::make_shared<std::string>(cmd), slotId)) {
73             TELEPHONY_LOGI("SendTerminalResponseCmd user confirm slotId [%{public}d] ", slotId);
74         }
75         return TELEPHONY_SUCCESS;
76     }
77 
78     int32_t result = stkController_->SendTerminalResponseCmd(cmd);
79     TELEPHONY_LOGI("StkManager[%{public}d]::SendTerminalResponseCmd() result:%{public}s",
80         slotId, (result ? "true" : "false"));
81     return result;
82 }
83 
SendCallSetupRequestResult(int32_t slotId,bool accept) const84 int32_t StkManager::SendCallSetupRequestResult(int32_t slotId, bool accept) const
85 {
86     if (stkController_ == nullptr) {
87         TELEPHONY_LOGE("StkManager[%{public}d]::SendCallSetupRequestResult() stkController_ is nullptr", slotId);
88         return TELEPHONY_ERR_LOCAL_PTR_NULL;
89     }
90     int32_t result = stkController_->SendCallSetupRequestResult(accept);
91     TELEPHONY_LOGI("StkManager[%{public}d]::SendCallSetupRequestResult() result:%{public}d", slotId, result);
92     return result;
93 }
94 } // namespace Telephony
95 } // namespace OHOS
96