• 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 
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     std::string name = "StkController_";
44     name.append(std::to_string(slotId));
45     stkEventLoop_ = AppExecFwk::EventRunner::Create(name.c_str());
46     if (stkEventLoop_.get() == nullptr) {
47         TELEPHONY_LOGE("StkManager[%{public}d]::Init() failed to create EventRunner", slotId);
48         return;
49     }
50     stkController_ = std::make_shared<StkController>(stkEventLoop_, telRilManager_, simStateManager_, slotId);
51     if (stkController_ == nullptr) {
52         TELEPHONY_LOGE("StkManager[%{public}d]::Init() failed to create StkController", slotId);
53         return;
54     }
55     stkController_->Init();
56     stkEventLoop_->Run();
57     TELEPHONY_LOGI("StkManager[%{public}d]::Init() success", slotId);
58 }
59 
SendEnvelopeCmd(int32_t slotId,const std::string & cmd) const60 int32_t StkManager::SendEnvelopeCmd(int32_t slotId, const std::string &cmd) const
61 {
62     if (stkController_ == nullptr) {
63         TELEPHONY_LOGE("StkManager[%{public}d]::SendEnvelopeCmd() stkController_ is nullptr", slotId);
64         return TELEPHONY_ERR_LOCAL_PTR_NULL;
65     }
66     int32_t result = stkController_->SendEnvelopeCmd(cmd);
67     TELEPHONY_LOGI("StkManager[%{public}d]::SendEnvelopeCmd() result:%{public}s", slotId, (result ? "true" : "false"));
68     return result;
69 }
70 
SendTerminalResponseCmd(int32_t slotId,const std::string & cmd) const71 int32_t StkManager::SendTerminalResponseCmd(int32_t slotId, const std::string &cmd) const
72 {
73     if (stkController_ == nullptr) {
74         TELEPHONY_LOGE("StkManager[%{public}d]::SendTerminalResponseCmd() stkController_ is nullptr", slotId);
75         return TELEPHONY_ERR_LOCAL_PTR_NULL;
76     }
77     int32_t result = stkController_->SendTerminalResponseCmd(cmd);
78     TELEPHONY_LOGI("StkManager[%{public}d]::SendTerminalResponseCmd() result:%{public}s",
79         slotId, (result ? "true" : "false"));
80     return result;
81 }
82 
SendCallSetupRequestResult(int32_t slotId,bool accept) const83 int32_t StkManager::SendCallSetupRequestResult(int32_t slotId, bool accept) const
84 {
85     if (stkController_ == nullptr) {
86         TELEPHONY_LOGE("StkManager[%{public}d]::SendCallSetupRequestResult() stkController_ is nullptr", slotId);
87         return TELEPHONY_ERR_LOCAL_PTR_NULL;
88     }
89     int32_t result = stkController_->SendCallSetupRequestResult(accept);
90     TELEPHONY_LOGI("StkManager[%{public}d]::SendCallSetupRequestResult() result:%{public}d", slotId, result);
91     return result;
92 }
93 } // namespace Telephony
94 } // namespace OHOS
95