mirror of
https://gitee.com/openharmony/telephony_core_service
synced 2024-11-23 16:09:48 +00:00
STK拉起处理
Signed-off-by: liuxiyao223 <liuxiyao223@huawei.com>
This commit is contained in:
parent
9a32771333
commit
f95fa96557
2
BUILD.gn
2
BUILD.gn
@ -161,6 +161,8 @@ ohos_shared_library("tel_core_service") {
|
||||
"ability_runtime:data_ability_helper",
|
||||
"ability_runtime:dataobs_manager",
|
||||
"ability_runtime:wantagent_innerkits",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"config_policy:configpolicy_util",
|
||||
|
@ -76,7 +76,8 @@ template<typename T, std::enable_if_t<std::is_same_v<T, char>, int32_t> = 0>
|
||||
napi_status NapiValueConverted(napi_env env, napi_value arg, T *buf)
|
||||
{
|
||||
size_t result {0};
|
||||
constexpr size_t bufSize {64};
|
||||
const size_t buffLength = 255;
|
||||
constexpr size_t bufSize { buffLength };
|
||||
return napi_get_value_string_utf8(env, arg, buf, bufSize, &result);
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ public:
|
||||
const std::weak_ptr<Telephony::SimStateManager> &simStateManager, int32_t slotId);
|
||||
virtual ~StkController() = default;
|
||||
void Init();
|
||||
std::string initStkBudleName();
|
||||
int32_t SendTerminalResponseCmd(const std::string &strCmd);
|
||||
int32_t SendEnvelopeCmd(const std::string &strCmd);
|
||||
int32_t SendCallSetupRequestResult(bool accept);
|
||||
@ -39,15 +40,17 @@ private:
|
||||
void RegisterEvents();
|
||||
void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
|
||||
void OnIccStateChanged(const AppExecFwk::InnerEvent::Pointer &event);
|
||||
void OnSendRilSessionEnd(const AppExecFwk::InnerEvent::Pointer &event) const;
|
||||
void OnSendRilProactiveCommand(const AppExecFwk::InnerEvent::Pointer &event) const;
|
||||
void OnSendRilAlphaNotify(const AppExecFwk::InnerEvent::Pointer &event) const;
|
||||
void OnSendRilEventNotify(const AppExecFwk::InnerEvent::Pointer &event) const;
|
||||
void OnIccRefresh(const AppExecFwk::InnerEvent::Pointer &event) const;
|
||||
bool PublishStkEvent(const AAFwk::Want &want) const;
|
||||
void OnSendRilSessionEnd(const AppExecFwk::InnerEvent::Pointer &event);
|
||||
void OnSendRilProactiveCommand(const AppExecFwk::InnerEvent::Pointer &event);
|
||||
void OnSendRilAlphaNotify(const AppExecFwk::InnerEvent::Pointer &event);
|
||||
void OnSendRilEventNotify(const AppExecFwk::InnerEvent::Pointer &event);
|
||||
void OnIccRefresh(const AppExecFwk::InnerEvent::Pointer &event);
|
||||
bool PublishStkEvent(AAFwk::Want &want);
|
||||
void OnSendTerminalResponseResult(const AppExecFwk::InnerEvent::Pointer &event);
|
||||
void OnSendEnvelopeCmdResult(const AppExecFwk::InnerEvent::Pointer &event);
|
||||
void OnSendCallSetupRequestResult(const AppExecFwk::InnerEvent::Pointer &event);
|
||||
bool CheckIsSystemApp(const std::string &bundleName);
|
||||
sptr<OHOS::IRemoteObject> GetBundleMgr();
|
||||
|
||||
private:
|
||||
std::weak_ptr<Telephony::ITelRilManager> telRilManager_;
|
||||
@ -58,6 +61,7 @@ private:
|
||||
int32_t terminalResponseResult_ = 0;
|
||||
int32_t callSetupResponseResult_ = 0;
|
||||
bool responseFinished_ = false;
|
||||
std::string stkBundleName_ = "";
|
||||
std::mutex stkMutex_;
|
||||
std::condition_variable stkCv_;
|
||||
};
|
||||
|
@ -15,12 +15,19 @@
|
||||
|
||||
#include "stk_controller.h"
|
||||
|
||||
#include "ability_manager_client.h"
|
||||
#include "bundle_mgr_proxy.h"
|
||||
#include "common_event_data.h"
|
||||
#include "common_event_manager.h"
|
||||
#include "common_event_publish_info.h"
|
||||
#include "common_event_support.h"
|
||||
#include "extension_ability_info.h"
|
||||
#include "hril_types.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "parameters.h"
|
||||
#include "radio_event.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "telephony_errors.h"
|
||||
#include "telephony_log_wrapper.h"
|
||||
|
||||
@ -30,11 +37,15 @@ namespace {
|
||||
const int32_t ICC_CARD_STATE_ABSENT = 0;
|
||||
const int32_t ICC_CARD_STATE_PRESENT = 1;
|
||||
const int32_t WAIT_TIME_SECOND = 2; // Set the timeout for sending the stk command
|
||||
const int32_t PARAMETER_LENGTH = 128;
|
||||
const std::string PARAM_SLOTID = "slotId";
|
||||
const std::string PARAM_MSG_CMD = "msgCmd";
|
||||
const std::string PARAM_CARD_STATUS = "cardStatus";
|
||||
const std::string PARAM_ALPHA_STRING = "alphaString";
|
||||
const std::string PARAM_REFRESH_RESULT = "refreshResult";
|
||||
const std::string STK_BUNDLE = "const.telephony.stk_bundle_name";
|
||||
const std::string ABILITY_NAME = "ServiceExtAbility";
|
||||
const std::string DEFAULT_BUNDLE = "";
|
||||
} // namespace
|
||||
|
||||
StkController::StkController(const std::weak_ptr<Telephony::ITelRilManager> &telRilManager,
|
||||
@ -45,9 +56,28 @@ StkController::StkController(const std::weak_ptr<Telephony::ITelRilManager> &tel
|
||||
|
||||
void StkController::Init()
|
||||
{
|
||||
stkBundleName_ = initStkBudleName();
|
||||
RegisterEvents();
|
||||
}
|
||||
|
||||
std::string StkController::initStkBudleName()
|
||||
{
|
||||
char bundleName[PARAMETER_LENGTH] = { 0 };
|
||||
GetParameter(STK_BUNDLE.c_str(), DEFAULT_BUNDLE.c_str(), bundleName, PARAMETER_LENGTH);
|
||||
return bundleName;
|
||||
}
|
||||
|
||||
sptr<OHOS::IRemoteObject> StkController::GetBundleMgr()
|
||||
{
|
||||
OHOS::sptr<OHOS::ISystemAbilityManager> systemAbilityManager =
|
||||
OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (systemAbilityManager == nullptr) {
|
||||
TELEPHONY_LOGE("Failed to get ability mgr.");
|
||||
return nullptr;
|
||||
}
|
||||
return systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
|
||||
}
|
||||
|
||||
void StkController::RegisterEvents()
|
||||
{
|
||||
std::shared_ptr<ITelRilManager> telRilManager = telRilManager_.lock();
|
||||
@ -175,7 +205,7 @@ void StkController::OnIccStateChanged(const AppExecFwk::InnerEvent::Pointer &eve
|
||||
}
|
||||
}
|
||||
|
||||
void StkController::OnSendRilSessionEnd(const AppExecFwk::InnerEvent::Pointer &event) const
|
||||
void StkController::OnSendRilSessionEnd(const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
AAFwk::Want want;
|
||||
want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_STK_SESSION_END);
|
||||
@ -185,7 +215,7 @@ void StkController::OnSendRilSessionEnd(const AppExecFwk::InnerEvent::Pointer &e
|
||||
slotId_, publishResult);
|
||||
}
|
||||
|
||||
void StkController::OnSendRilProactiveCommand(const AppExecFwk::InnerEvent::Pointer &event) const
|
||||
void StkController::OnSendRilProactiveCommand(const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
auto stkData = event->GetSharedObject<std::string>();
|
||||
if (stkData == nullptr) {
|
||||
@ -202,7 +232,7 @@ void StkController::OnSendRilProactiveCommand(const AppExecFwk::InnerEvent::Poin
|
||||
"publishResult = %{public}d", slotId_, cmdData.c_str(), publishResult);
|
||||
}
|
||||
|
||||
void StkController::OnSendRilAlphaNotify(const AppExecFwk::InnerEvent::Pointer &event) const
|
||||
void StkController::OnSendRilAlphaNotify(const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
auto alphaData = event->GetSharedObject<std::string>();
|
||||
if (alphaData == nullptr) {
|
||||
@ -219,7 +249,7 @@ void StkController::OnSendRilAlphaNotify(const AppExecFwk::InnerEvent::Pointer &
|
||||
"publishResult = %{public}d", slotId_, cmdData.c_str(), publishResult);
|
||||
}
|
||||
|
||||
void StkController::OnSendRilEventNotify(const AppExecFwk::InnerEvent::Pointer &event) const
|
||||
void StkController::OnSendRilEventNotify(const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
auto eventData = event->GetSharedObject<std::string>();
|
||||
if (eventData == nullptr) {
|
||||
@ -236,7 +266,7 @@ void StkController::OnSendRilEventNotify(const AppExecFwk::InnerEvent::Pointer &
|
||||
"publishResult = %{public}d", slotId_, cmdData.c_str(), publishResult);
|
||||
}
|
||||
|
||||
void StkController::OnIccRefresh(const AppExecFwk::InnerEvent::Pointer &event) const
|
||||
void StkController::OnIccRefresh(const AppExecFwk::InnerEvent::Pointer &event)
|
||||
{
|
||||
auto refreshResult = event->GetSharedObject<int32_t>();
|
||||
if (refreshResult == nullptr) {
|
||||
@ -254,12 +284,48 @@ void StkController::OnIccRefresh(const AppExecFwk::InnerEvent::Pointer &event) c
|
||||
slotId_, result, publishResult);
|
||||
}
|
||||
|
||||
bool StkController::PublishStkEvent(const AAFwk::Want &want) const
|
||||
bool StkController::PublishStkEvent(AAFwk::Want &want)
|
||||
{
|
||||
EventFwk::CommonEventData data(want);
|
||||
EventFwk::CommonEventPublishInfo publishInfo;
|
||||
publishInfo.SetOrdered(true);
|
||||
return EventFwk::CommonEventManager::PublishCommonEvent(data, publishInfo, nullptr);
|
||||
if (stkBundleName_.empty()) {
|
||||
TELEPHONY_LOGE("stkBundleName_ is empty");
|
||||
return false;
|
||||
}
|
||||
if (!CheckIsSystemApp(stkBundleName_)) {
|
||||
TELEPHONY_LOGE("is not system app");
|
||||
return false;
|
||||
}
|
||||
AppExecFwk::ElementName element("", stkBundleName_, ABILITY_NAME);
|
||||
want.SetElement(element);
|
||||
int32_t accountId = -1;
|
||||
return AAFwk::AbilityManagerClient::GetInstance()->StartExtensionAbility(
|
||||
want, nullptr, accountId, AppExecFwk::ExtensionAbilityType::SERVICE);
|
||||
}
|
||||
|
||||
bool StkController::CheckIsSystemApp(const std::string &bundleName)
|
||||
{
|
||||
if (bundleName.empty()) {
|
||||
TELEPHONY_LOGE("bundleName is empty");
|
||||
return false;
|
||||
}
|
||||
sptr<OHOS::IRemoteObject> remoteObject = GetBundleMgr();
|
||||
if (remoteObject == nullptr) {
|
||||
TELEPHONY_LOGE("error to get bundleMgr");
|
||||
return false;
|
||||
}
|
||||
sptr<AppExecFwk::IBundleMgr> iBundleMgr = OHOS::iface_cast<AppExecFwk::IBundleMgr>(remoteObject);
|
||||
if (iBundleMgr == nullptr) {
|
||||
TELEPHONY_LOGE("iBundleMgr is null");
|
||||
return false;
|
||||
}
|
||||
OHOS::AppExecFwk::BundleInfo info;
|
||||
info.applicationInfo.isSystemApp = false;
|
||||
if (!iBundleMgr->GetBundleInfo(
|
||||
bundleName, OHOS::AppExecFwk::GET_BUNDLE_DEFAULT, info, AppExecFwk::Constants::ALL_USERID)) {
|
||||
TELEPHONY_LOGE("Failed to get bundleInfo from bundleMgr");
|
||||
} else {
|
||||
TELEPHONY_LOGI("isSystemApp =%{public}d", info.applicationInfo.isSystemApp);
|
||||
}
|
||||
return info.applicationInfo.isSystemApp;
|
||||
}
|
||||
|
||||
int32_t StkController::SendTerminalResponseCmd(const std::string &strCmd)
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "sim_rdb_helper.h"
|
||||
#include "telephony_log_wrapper.h"
|
||||
#include "usim_dialling_numbers_service.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Telephony {
|
||||
@ -42,6 +43,7 @@ using namespace testing::ext;
|
||||
namespace {
|
||||
constexpr int32_t SLOT_ID = 0;
|
||||
constexpr int INVALID_MCC = 100;
|
||||
const int32_t INVALID_SLOTID = 2;
|
||||
} // namespace
|
||||
|
||||
class DemoHandler : public AppExecFwk::EventHandler {
|
||||
@ -194,6 +196,26 @@ HWTEST_F(SimRilBranchTest, Telephony_StkManager_001, Function | MediumTest | Lev
|
||||
EXPECT_EQ(stkManager->SendCallSetupRequestResult(0, false), TELEPHONY_ERR_LOCAL_PTR_NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number Telephony_StkController_002
|
||||
* @tc.name test error branch
|
||||
* @tc.desc Function test
|
||||
*/
|
||||
HWTEST_F(SimRilBranchTest, Telephony_StkController_002, Function | MediumTest | Level1)
|
||||
{
|
||||
std::string name = "StkController_";
|
||||
AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_STK_CALL_SETUP, 1);
|
||||
std::shared_ptr<TelRilManager> telRilManager = nullptr;
|
||||
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
|
||||
auto stkController = std::make_shared<StkController>(telRilManager, simStateManager, INVALID_SLOTID);
|
||||
std::string bundleNameEmpty = "";
|
||||
std::string bundleName = "123";
|
||||
EXPECT_FALSE(stkController->CheckIsSystemApp(bundleNameEmpty));
|
||||
EXPECT_FALSE(stkController->CheckIsSystemApp(bundleName));
|
||||
AAFwk::Want want;
|
||||
EXPECT_FALSE(stkController->PublishStkEvent(want));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number Telephony_SimStateTracker_001
|
||||
* @tc.name test error branch
|
||||
@ -610,8 +632,8 @@ HWTEST_F(SimRilBranchTest, Telephony_SimManager_001, Function | MediumTest | Lev
|
||||
simManager->slotCount_ = 1;
|
||||
int32_t slotId;
|
||||
std::u16string testU = u"";
|
||||
simManager->SetShowNumber(SLOT_ID, testU);
|
||||
simManager->GetShowNumber(SLOT_ID, testU);
|
||||
simManager->SetShowNumber(INVALID_SLOTID, testU);
|
||||
simManager->GetShowNumber(INVALID_SLOTID, testU);
|
||||
simManager->GetDefaultVoiceSimId(slotId);
|
||||
simManager->GetDefaultSmsSlotId();
|
||||
simManager->slotCount_ = 1;
|
||||
@ -621,13 +643,13 @@ HWTEST_F(SimRilBranchTest, Telephony_SimManager_001, Function | MediumTest | Lev
|
||||
simManager->GetDsdsMode(dsdsMode);
|
||||
simManager->stkManager_.resize(slotCount);
|
||||
simManager->simFileManager_.resize(slotCount);
|
||||
simManager->SendCallSetupRequestResult(SLOT_ID, true);
|
||||
simManager->GetSimGid2(SLOT_ID);
|
||||
simManager->GetOpName(SLOT_ID, testU);
|
||||
simManager->GetOpKey(SLOT_ID, testU);
|
||||
simManager->GetOpKeyExt(SLOT_ID, testU);
|
||||
simManager->GetSimTeleNumberIdentifier(SLOT_ID);
|
||||
simManager->ObtainSpnCondition(SLOT_ID, false, testS);
|
||||
simManager->SendCallSetupRequestResult(INVALID_SLOTID, true);
|
||||
simManager->GetSimGid2(INVALID_SLOTID);
|
||||
simManager->GetOpName(INVALID_SLOTID, testU);
|
||||
simManager->GetOpKey(INVALID_SLOTID, testU);
|
||||
simManager->GetOpKeyExt(INVALID_SLOTID, testU);
|
||||
simManager->GetSimTeleNumberIdentifier(INVALID_SLOTID);
|
||||
simManager->ObtainSpnCondition(INVALID_SLOTID, false, testS);
|
||||
simManager->slotCount_ = 0;
|
||||
simManager->GetPrimarySlotId(slotId);
|
||||
EXPECT_GT(simManager->GetDefaultSmsSlotId(), TELEPHONY_PERMISSION_ERROR);
|
||||
|
Loading…
Reference in New Issue
Block a user