!1851 core_service 应用身份标识排查整改

Merge pull request !1851 from ASheLock/master
This commit is contained in:
openharmony_ci 2024-04-10 14:48:58 +00:00 committed by Gitee
commit 1e9fc98d5e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
21 changed files with 721 additions and 47 deletions

View File

@ -206,22 +206,22 @@ void CoreManagerInner::UnRegisterCellularCallObject(const sptr<NetworkSearchCall
}
int32_t CoreManagerInner::RegisterSimAccountCallback(
const std::string &bundleName, const sptr<SimAccountCallback> &callback)
const int32_t tokenId, const sptr<SimAccountCallback> &callback)
{
if (simManager_ == nullptr) {
TELEPHONY_LOGE("simManager_ is null");
return TELEPHONY_ERR_LOCAL_PTR_NULL;
}
return simManager_->RegisterSimAccountCallback(bundleName, callback);
return simManager_->RegisterSimAccountCallback(tokenId, callback);
}
int32_t CoreManagerInner::UnregisterSimAccountCallback(const std::string &bundleName)
int32_t CoreManagerInner::UnregisterSimAccountCallback(const int32_t tokenId)
{
if (simManager_ == nullptr) {
TELEPHONY_LOGE("simManager_ is null");
return TELEPHONY_ERR_LOCAL_PTR_NULL;
}
return simManager_->UnregisterSimAccountCallback(bundleName);
return simManager_->UnregisterSimAccountCallback(tokenId);
}
/******************** telRilManager start *******************/

View File

@ -49,8 +49,8 @@ public:
int32_t InitExtraModule(int32_t slotId);
int32_t GetDefaultSlotId(void);
int32_t GetMaxSimCount(void);
int32_t RegisterSimAccountCallback(const std::string &bundleName, const sptr<SimAccountCallback> &callback);
int32_t UnregisterSimAccountCallback(const std::string &bundleName);
int32_t RegisterSimAccountCallback(const int32_t tokenId, const sptr<SimAccountCallback> &callback);
int32_t UnregisterSimAccountCallback(const int32_t tokenId);
/******************** telRilManager start *******************/
int32_t SetRadioState(

View File

@ -133,10 +133,10 @@ public:
* @return Returns the 5G New Radio (NR) status.
*/
virtual NrState GetNrState(int32_t slotId) = 0;
virtual int32_t RegisterImsRegInfoCallback(int32_t slotId, ImsServiceType imsSrvType, const std::string &bundleName,
virtual int32_t RegisterImsRegInfoCallback(int32_t slotId, ImsServiceType imsSrvType, const int32_t tokenId,
const sptr<ImsRegInfoCallback> &callback) = 0;
virtual int32_t UnregisterImsRegInfoCallback(
int32_t slotId, ImsServiceType imsSrvType, const std::string &bundleName) = 0;
int32_t slotId, ImsServiceType imsSrvType, const int32_t tokenId) = 0;
virtual int32_t GetBasebandVersion(int32_t slotId, std::string &version) = 0;
/**
* @brief Init airplane mode.

View File

@ -65,8 +65,8 @@ public:
virtual int32_t GetDefaultCellularDataSlotId() = 0;
virtual int32_t GetDefaultCellularDataSimId(int32_t &simId) = 0;
virtual int32_t RegisterSimAccountCallback(
const std::string &bundleName, const sptr<SimAccountCallback> &callback) = 0;
virtual int32_t UnregisterSimAccountCallback(const std::string &bundleName) = 0;
const int32_t tokenId, const sptr<SimAccountCallback> &callback) = 0;
virtual int32_t UnregisterSimAccountCallback(const int32_t tokenId) = 0;
virtual int32_t GetPrimarySlotId(int32_t &slotId) = 0;
virtual int32_t GetShowNumber(int32_t slotId, std::u16string &showNumber) = 0;
virtual int32_t GetShowName(int32_t slotId, std::u16string &showName) = 0;

View File

@ -1480,7 +1480,7 @@ int32_t CoreService::RegisterImsRegInfoCallback(
TELEPHONY_LOGE("failed! network search manager is nullptr!");
return TELEPHONY_ERR_LOCAL_PTR_NULL;
}
return networkSearchManager_->RegisterImsRegInfoCallback(slotId, imsSrvType, GetBundleName(), callback);
return networkSearchManager_->RegisterImsRegInfoCallback(slotId, imsSrvType, GetTokenID(), callback);
}
int32_t CoreService::UnregisterImsRegInfoCallback(int32_t slotId, ImsServiceType imsSrvType)
@ -1497,7 +1497,7 @@ int32_t CoreService::UnregisterImsRegInfoCallback(int32_t slotId, ImsServiceType
TELEPHONY_LOGE("failed! network search manager is nullptr!");
return TELEPHONY_ERR_LOCAL_PTR_NULL;
}
return networkSearchManager_->UnregisterImsRegInfoCallback(slotId, imsSrvType, GetBundleName());
return networkSearchManager_->UnregisterImsRegInfoCallback(slotId, imsSrvType, GetTokenID());
}
int32_t CoreService::GetBasebandVersion(int32_t slotId, std::string &version)

View File

@ -198,10 +198,10 @@ public:
int32_t SetNrOptionMode(int32_t slotId, int32_t mode, NSCALLBACK &callback) override;
int32_t GetNrOptionMode(int32_t slotId, NrMode &mode) override;
int32_t GetNrOptionMode(int32_t slotId, NSCALLBACK &callback) override;
int32_t RegisterImsRegInfoCallback(int32_t slotId, ImsServiceType imsSrvType, const std::string &bundleName,
int32_t RegisterImsRegInfoCallback(int32_t slotId, ImsServiceType imsSrvType, const int32_t tokenId,
const sptr<ImsRegInfoCallback> &callback) override;
int32_t UnregisterImsRegInfoCallback(
int32_t slotId, ImsServiceType imsSrvType, const std::string &bundleName) override;
int32_t slotId, ImsServiceType imsSrvType, const int32_t tokenId) override;
int32_t GetNetworkCapability(
int32_t slotId, int32_t networkCapabilityType, int32_t &networkCapabilityState) override;
int32_t SetNetworkCapability(
@ -336,7 +336,7 @@ private:
struct ImsRegInfoCallbackRecord {
int32_t slotId;
ImsServiceType imsSrvType;
std::string bundleName;
int32_t tokenId = 0;
sptr<ImsRegInfoCallback> imsCallback;
};

View File

@ -1606,7 +1606,7 @@ int32_t NetworkSearchManager::GetAirplaneMode(bool &airplaneMode)
}
int32_t NetworkSearchManager::RegisterImsRegInfoCallback(
int32_t slotId, ImsServiceType imsSrvType, const std::string &bundleName, const sptr<ImsRegInfoCallback> &callback)
int32_t slotId, ImsServiceType imsSrvType, const int32_t tokenId, const sptr<ImsRegInfoCallback> &callback)
{
if (callback == nullptr) {
TELEPHONY_LOGE("[slot%{public}d] callback is nullptr", slotId);
@ -1615,7 +1615,7 @@ int32_t NetworkSearchManager::RegisterImsRegInfoCallback(
bool isExisted = false;
std::lock_guard<std::mutex> lock(mutexIms_);
for (auto iter : listImsRegInfoCallbackRecord_) {
if ((iter.slotId == slotId) && (iter.imsSrvType == imsSrvType) && (iter.bundleName == bundleName)) {
if ((iter.slotId == slotId) && (iter.imsSrvType == imsSrvType) && (iter.tokenId == tokenId)) {
isExisted = true;
break;
}
@ -1628,7 +1628,7 @@ int32_t NetworkSearchManager::RegisterImsRegInfoCallback(
ImsRegInfoCallbackRecord imsRecord;
imsRecord.slotId = slotId;
imsRecord.imsSrvType = imsSrvType;
imsRecord.bundleName = bundleName;
imsRecord.tokenId = tokenId;
imsRecord.imsCallback = callback;
listImsRegInfoCallbackRecord_.push_back(imsRecord);
TELEPHONY_LOGD("[slot%{public}d] Register successfully, callback list size is %{public}zu", slotId,
@ -1637,13 +1637,13 @@ int32_t NetworkSearchManager::RegisterImsRegInfoCallback(
}
int32_t NetworkSearchManager::UnregisterImsRegInfoCallback(
int32_t slotId, ImsServiceType imsSrvType, const std::string &bundleName)
int32_t slotId, ImsServiceType imsSrvType, const int32_t tokenId)
{
bool isSuccess = false;
std::lock_guard<std::mutex> lock(mutexIms_);
auto iter = listImsRegInfoCallbackRecord_.begin();
for (; iter != listImsRegInfoCallbackRecord_.end(); ++iter) {
if ((iter->slotId == slotId) && (iter->imsSrvType == imsSrvType) && (iter->bundleName == bundleName)) {
if ((iter->slotId == slotId) && (iter->imsSrvType == imsSrvType) && (iter->tokenId == tokenId)) {
listImsRegInfoCallbackRecord_.erase(iter);
isSuccess = true;
break;

View File

@ -43,8 +43,8 @@ public:
void Init();
void RegisterCoreNotify(int32_t slotId, const std::shared_ptr<AppExecFwk::EventHandler> &handler, int what);
int32_t RegisterSimAccountCallback(const std::string &bundleName, const sptr<SimAccountCallback> &callback);
int32_t UnregisterSimAccountCallback(const std::string &bundleName);
int32_t RegisterSimAccountCallback(const int32_t tokenId, const sptr<SimAccountCallback> &callback);
int32_t UnregisterSimAccountCallback(const int32_t tokenId);
void NotifySimAccountChanged();
void RegisterSimNotify();
void UnRegisterSimNotify();
@ -57,7 +57,7 @@ public:
private:
struct SimAccountCallbackRecord {
std::string bundleName = "";
int32_t tokenId = 0;
sptr<SimAccountCallback> simAccountCallback = nullptr;
};

View File

@ -138,8 +138,8 @@ public:
int32_t SaveImsSwitch(int32_t slotId, int32_t imsSwitchValue) override;
int32_t QueryImsSwitch(int32_t, int32_t &imsSwitchValue) override;
int32_t RegisterSimAccountCallback(
const std::string &bundleName, const sptr<SimAccountCallback> &callback) override;
int32_t UnregisterSimAccountCallback(const std::string &bundleName) override;
const int32_t tokenId, const sptr<SimAccountCallback> &callback) override;
int32_t UnregisterSimAccountCallback(const int32_t tokenId) override;
private:
bool IsValidSlotId(int32_t slotId);

View File

@ -161,7 +161,7 @@ bool MultiSimMonitor::IsVSimSlotId(int32_t slotId)
}
int32_t MultiSimMonitor::RegisterSimAccountCallback(
const std::string &bundleName, const sptr<SimAccountCallback> &callback)
const int32_t tokenId, const sptr<SimAccountCallback> &callback)
{
if (callback == nullptr) {
TELEPHONY_LOGE(" callback is nullptr");
@ -170,7 +170,7 @@ int32_t MultiSimMonitor::RegisterSimAccountCallback(
std::lock_guard<std::mutex> lock(mutexInner_);
bool isExisted = false;
for (auto &iter : listSimAccountCallbackRecord_) {
if ((iter.bundleName == bundleName)) {
if (iter.tokenId == tokenId) {
iter.simAccountCallback = callback;
isExisted = true;
break;
@ -182,20 +182,20 @@ int32_t MultiSimMonitor::RegisterSimAccountCallback(
}
SimAccountCallbackRecord simAccountRecord;
simAccountRecord.bundleName = bundleName;
simAccountRecord.tokenId = tokenId;
simAccountRecord.simAccountCallback = callback;
listSimAccountCallbackRecord_.push_back(simAccountRecord);
TELEPHONY_LOGI("Register successfully, callback list size is %{public}zu", listSimAccountCallbackRecord_.size());
return TELEPHONY_SUCCESS;
}
int32_t MultiSimMonitor::UnregisterSimAccountCallback(const std::string &bundleName)
int32_t MultiSimMonitor::UnregisterSimAccountCallback(const int32_t tokenId)
{
std::lock_guard<std::mutex> lock(mutexInner_);
bool isSuccess = false;
auto iter = listSimAccountCallbackRecord_.begin();
for (; iter != listSimAccountCallbackRecord_.end();) {
if ((iter->bundleName == bundleName)) {
if (iter->tokenId == tokenId) {
iter = listSimAccountCallbackRecord_.erase(iter);
isSuccess = true;
break;

View File

@ -1155,22 +1155,22 @@ int32_t SimManager::QueryImsSwitch(int32_t slotId, int32_t &imsSwitchValue)
return multiSimController_->QueryImsSwitch(slotId, imsSwitchValue);
}
int32_t SimManager::RegisterSimAccountCallback(const std::string &bundleName, const sptr<SimAccountCallback> &callback)
int32_t SimManager::RegisterSimAccountCallback(const int32_t tokenId, const sptr<SimAccountCallback> &callback)
{
if (multiSimMonitor_ == nullptr) {
TELEPHONY_LOGE("multiSimMonitor is null");
return TELEPHONY_ERR_LOCAL_PTR_NULL;
}
return multiSimMonitor_->RegisterSimAccountCallback(bundleName, callback);
return multiSimMonitor_->RegisterSimAccountCallback(tokenId, callback);
}
int32_t SimManager::UnregisterSimAccountCallback(const std::string &bundleName)
int32_t SimManager::UnregisterSimAccountCallback(const int32_t tokenId)
{
if (multiSimMonitor_ == nullptr) {
TELEPHONY_LOGE("multiSimMonitor is null");
return TELEPHONY_ERR_LOCAL_PTR_NULL;
}
return multiSimMonitor_->UnregisterSimAccountCallback(bundleName);
return multiSimMonitor_->UnregisterSimAccountCallback(tokenId);
}
} // namespace Telephony
} // namespace OHOS

View File

@ -1133,11 +1133,11 @@ HWTEST_F(BranchTest, Telephony_CoreManagerInner_006, Function | MediumTest | Lev
TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.UnRegisterCoreNotify(INVALID_SLOTID, handler, RadioEvent::RADIO_SIM_GET_RADIO_PROTOCOL),
TELEPHONY_ERR_LOCAL_PTR_NULL);
std::string bundleName = "";
int32_t tokenId = 123456789;
sptr<SimAccountCallback> simAccountCallback;
int32_t imsSwitchValue = 1;
EXPECT_EQ(mInner.RegisterSimAccountCallback(bundleName, simAccountCallback), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.UnregisterSimAccountCallback(bundleName), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.RegisterSimAccountCallback(tokenId, simAccountCallback), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.UnregisterSimAccountCallback(tokenId), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetSmscAddr(INVALID_SLOTID, 1, handler), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.QueryImsSwitch(INVALID_SLOTID, imsSwitchValue), TELEPHONY_ERROR);
EXPECT_GT(mInner.SetVoNRSwitch(0, 0, 0, nullptr), TELEPHONY_ERR_SUCCESS);
@ -1483,10 +1483,11 @@ HWTEST_F(BranchTest, Telephony_SimManager_004, Function | MediumTest | Level1)
EXPECT_NE(simManager->SaveImsSwitch(0, 1), TELEPHONY_ERR_SUCCESS);
EXPECT_NE(simManager->SaveImsSwitch(INVALID_SLOTID, 1), TELEPHONY_ERR_SUCCESS);
int32_t imsSwitchValue;
int32_t tokenId = -1;
EXPECT_NE(simManager->QueryImsSwitch(0, imsSwitchValue), TELEPHONY_ERR_SUCCESS);
EXPECT_NE(simManager->QueryImsSwitch(INVALID_SLOTID, imsSwitchValue), TELEPHONY_ERR_SUCCESS);
EXPECT_NE(simManager->RegisterSimAccountCallback("", nullptr), TELEPHONY_ERR_SUCCESS);
EXPECT_NE(simManager->UnregisterSimAccountCallback(""), TELEPHONY_ERR_SUCCESS);
EXPECT_NE(simManager->RegisterSimAccountCallback(tokenId, nullptr), TELEPHONY_ERR_SUCCESS);
EXPECT_NE(simManager->UnregisterSimAccountCallback(tokenId), TELEPHONY_ERR_SUCCESS);
int32_t dsdsMode = INVALID_VALUE;
simManager->GetDsdsMode(dsdsMode);
simManager->SetDsdsMode(0);
@ -1972,7 +1973,7 @@ HWTEST_F(BranchTest, Telephony_NetworkSearchManager_002, Function | MediumTest |
inner->networkSearchState_ = networkSearchState;
inner->observerHandler_ = std::make_unique<ObserverHandler>();
inner->networkSearchHandler_ = networkSearchHandler;
std::string bundleName = "qwe";
int32_t tokenId = 123456789;
std::u16string imei = u"";
std::u16string imeiSv = u"";
sptr<ImsRegInfoCallback> callback = nullptr;
@ -2006,9 +2007,9 @@ HWTEST_F(BranchTest, Telephony_NetworkSearchManager_002, Function | MediumTest |
EXPECT_TRUE(networkSearchManager->GetNetworkSearchState(INVALID_SLOTID) != nullptr);
EXPECT_TRUE(networkSearchManager->IsRadioFirstPowerOn(INVALID_SLOTID));
EXPECT_EQ(networkSearchManager->RegisterImsRegInfoCallback(
INVALID_SLOTID, ImsServiceType::TYPE_SMS, bundleName, callback),
INVALID_SLOTID, ImsServiceType::TYPE_SMS, tokenId, callback),
TELEPHONY_ERR_ARGUMENT_NULL);
EXPECT_EQ(networkSearchManager->UnregisterImsRegInfoCallback(INVALID_SLOTID, ImsServiceType::TYPE_SMS, bundleName),
EXPECT_EQ(networkSearchManager->UnregisterImsRegInfoCallback(INVALID_SLOTID, ImsServiceType::TYPE_SMS, tokenId),
TELEPHONY_SUCCESS);
}
@ -2173,7 +2174,7 @@ HWTEST_F(BranchTest, Telephony_NetworkSearchManager_006, Function | MediumTest |
inner->networkSearchHandler_ = networkSearchHandler;
nsm->delayTime_ = 1;
int32_t status = 0;
std::string bundleName = "qwe";
int32_t tokenId = 123456789;
ImsRegInfo info;
sptr<INetworkSearchCallback> networkSearchCallback = nullptr;
nsm->AddManagerInner(INVALID_SLOTID, inner);
@ -2182,7 +2183,7 @@ HWTEST_F(BranchTest, Telephony_NetworkSearchManager_006, Function | MediumTest |
nsm->HandleNotifyStateChangeWithDelay(INVALID_SLOTID, true);
nsm->HandleNotifyStateChangeWithDelay(INVALID_SLOTID, false);
nsm->InitSimRadioProtocol(INVALID_SLOTID);
nsm->UnregisterImsRegInfoCallback(INVALID_SLOTID, ImsServiceType::TYPE_SMS, bundleName);
nsm->UnregisterImsRegInfoCallback(INVALID_SLOTID, ImsServiceType::TYPE_SMS, tokenId);
EXPECT_EQ(nsm->HandleRrcStateChanged(INVALID_SLOTID, 0), TELEPHONY_ERR_FAIL);
EXPECT_EQ(nsm->HandleRrcStateChanged(INVALID_SLOTID, 1), TELEPHONY_ERR_SUCCESS);
EXPECT_EQ(nsm->UpdateRrcConnectionState(INVALID_SLOTID, status), TELEPHONY_ERR_SUCCESS);
@ -2884,10 +2885,10 @@ HWTEST_F(BranchTest, Telephony_MultiSimMonitor_001, Function | MediumTest | Leve
multiSimMonitor->RefreshData(INVALID_SLOTID);
multiSimMonitor->RefreshData(0);
multiSimMonitor->NotifySimAccountChanged();
std::string bundleName = "123";
int32_t tokenId = 123456789;
sptr<SimAccountCallback> callback = nullptr;
EXPECT_GT(multiSimMonitor->RegisterSimAccountCallback(bundleName, callback), TELEPHONY_ERROR);
EXPECT_EQ(multiSimMonitor->UnregisterSimAccountCallback(bundleName), TELEPHONY_ERROR);
EXPECT_GT(multiSimMonitor->RegisterSimAccountCallback(tokenId, callback), TELEPHONY_ERROR);
EXPECT_EQ(multiSimMonitor->UnregisterSimAccountCallback(tokenId), TELEPHONY_ERROR);
}
/**

View File

@ -0,0 +1,53 @@
# Copyright (C) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
CORE_SERVICE_PATH = "../../.."
ohos_executable("tel_core_service_ui_test") {
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
branch_protector_ret = "pac_ret"
install_enable = true
sources = [
"ims_reg_info_callback_gtest.cpp",
"ui_client_test.cpp",
]
deps = [ "${CORE_SERVICE_PATH}/interfaces/innerkits:tel_core_service_api" ]
external_deps = [
"ability_base:want",
"ability_runtime:abilitykit_native",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"c_utils:utils",
"cellular_data:tel_cellular_data_api",
"hilog:libhilog",
"ipc:ipc_single",
"samgr:samgr_proxy",
"state_registry:tel_state_registry_api",
]
defines = [
"TELEPHONY_LOG_TAG = \"CoreServiceUiTest\"",
"LOG_DOMAIN = 0xD000F00",
]
part_name = "core_service"
subsystem_name = "telephony"
}

View File

@ -0,0 +1,33 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CORE_SERVICE_TEST_CODE_H
#define CORE_SERVICE_TEST_CODE_H
namespace OHOS {
namespace Telephony {
extern "C" {
enum CoreServiceTestCode {
REGISTER_SIM_ACCOUNT_CODE = 1,
UNREGISTER_SIM_ACCOUNT_CODE,
REGISTER_IMS_REG_CODE,
UNREGISTER_IMS_REG_CODE,
ADD_STATE_OBSERVER,
REMOVE_STATE_OBSERVER,
};
} // end extern
} // namespace Telephony
} // namespace OHOS
#endif // CORE_SERVICE_TEST_CODE_H

View File

@ -0,0 +1,31 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ims_reg_info_callback_gtest.h"
#include "telephony_errors.h"
#include "telephony_log_wrapper.h"
namespace OHOS {
namespace Telephony {
int32_t ImsRegInfoCallbackGtest::OnImsRegInfoChanged(int32_t slotId, ImsServiceType imsSrvType, const ImsRegInfo &info)
{
TELEPHONY_LOGI(
"slotId is %{public}d, imsSrvType is %{public}d, imsRegState is %{public}d, imsRegTech is %{public}d", slotId,
imsSrvType, info.imsRegState, info.imsRegTech);
return TELEPHONY_SUCCESS;
}
} // namespace Telephony
} // namespace OHOS

View File

@ -0,0 +1,29 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef IMS_REG_INFO_CALLBACK_GTEST_H
#define IMS_REG_INFO_CALLBACK_GTEST_H
#include "ims_reg_info_callback_stub.h"
namespace OHOS {
namespace Telephony {
class ImsRegInfoCallbackGtest : public ImsRegInfoCallbackStub {
public:
int32_t OnImsRegInfoChanged(int32_t slotId, ImsServiceType imsSrvType, const ImsRegInfo &info) override;
};
} // namespace Telephony
} // namespace OHOS
#endif // IMS_REG_INFO_CALLBACK_GTEST_H

View File

@ -0,0 +1,103 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef STATE_REGISTRY_OBSERVER_H
#define STATE_REGISTRY_OBSERVER_H
#include "string_ex.h"
#include "telephony_log_wrapper.h"
#include "telephony_observer.h"
namespace OHOS {
namespace Telephony {
class StateRegistryObserver : public Telephony::TelephonyObserver {
public:
StateRegistryObserver() = default;
~StateRegistryObserver() = default;
void OnCallStateUpdated(int32_t slotId, int32_t callState, const std::u16string &phoneNumber)
{
TELEPHONY_LOGI(
"StateRegistryObserver%{public}d::OnCallStateUpdated callState is %{public}d", slotId, callState);
}
void OnSignalInfoUpdated(int32_t slotId, const std::vector<sptr<SignalInformation>> &vec)
{
TELEPHONY_LOGI("StateRegistryObserver%{public}d::OnSignalInfoUpdated", slotId);
}
void OnSignalInfoUpdatedExt(int32_t slotId, const std::vector<sptr<SignalInformation>> &vec)
{
TELEPHONY_LOGI("StateRegistryObserver%{public}d::OnSignalInfoUpdatedExt", slotId);
}
void OnNetworkStateUpdated(int32_t slotId, const sptr<NetworkState> &networkState)
{
TELEPHONY_LOGI("StateRegistryObserver%{public}d::OnNetworkStateUpdated", slotId);
}
void OnNetworkStateUpdatedExt(int32_t slotId, const sptr<NetworkState> &networkState)
{
TELEPHONY_LOGI("StateRegistryObserver%{public}d::OnNetworkStateUpdatedExt", slotId);
}
void OnCellInfoUpdated(int32_t slotId, const std::vector<sptr<CellInformation>> &vec)
{
TELEPHONY_LOGI("StateRegistryObserver%{public}d::OnCellInfoUpdated", slotId);
}
void OnCellInfoUpdatedExt(int32_t slotId, const std::vector<sptr<CellInformation>> &vec)
{
TELEPHONY_LOGI("StateRegistryObserver%{public}d::OnCellInfoUpdatedExt", slotId);
}
void OnSimStateUpdated(int32_t slotId, CardType type, SimState state, LockReason reason)
{
TELEPHONY_LOGI("StateRegistryObserver%{public}d::OnSimStateUpdated state is %{public}d", slotId, state);
}
void OnCellularDataConnectStateUpdated(int32_t slotId, int32_t dataState, int32_t networkType)
{
TELEPHONY_LOGI("StateRegistryObserver%{public}d::OnCellularDataConnectStateUpdated dataState is %{public}d",
slotId, dataState);
}
void OnCellularDataFlowUpdated(int32_t slotId, int32_t dataFlowType)
{
TELEPHONY_LOGI("StateRegistryObserver%{public}d::OnCellularDataFlowUpdated dataFlowType is %{public}d", slotId,
dataFlowType);
}
void OnCfuIndicatorUpdated(int32_t slotId, bool cfuResult)
{
TELEPHONY_LOGI(
"StateRegistryObserver%{public}d::OnCfuIndicatorUpdated cfuResult is %{public}d", slotId, cfuResult);
}
void OnVoiceMailMsgIndicatorUpdated(int32_t slotId, bool voiceMailMsgResult)
{
TELEPHONY_LOGI(
"StateRegistryObserver%{public}d::OnVoiceMailMsgIndicatorUpdated voiceMailMsgResult is %{public}d", slotId,
voiceMailMsgResult);
}
void OnIccAccountUpdated()
{
TELEPHONY_LOGI("StateRegistryObserver::OnIccAccountUpdated");
}
};
} // namespace Telephony
} // namespace OHOS
#endif // STATE_REGISTRY_OBSERVER_H

View File

@ -0,0 +1,411 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <iostream>
#include <memory>
#include <securec.h>
#include <stack>
#include <string_ex.h>
#include <vector>
#define private public
#include "accesstoken_kit.h"
#include "cellular_data_client.h"
#include "core_service_client.h"
#include "core_service_test_code.h"
#include "ims_reg_info_callback_gtest.h"
#include "state_registry_observer.h"
#include "system_ability_definition.h"
#include "telephony_errors.h"
#include "telephony_observer_client.h"
#include "token_setproc.h"
namespace OHOS {
namespace Telephony {
using namespace OHOS::Security::AccessToken;
using OHOS::Security::AccessToken::AccessTokenID;
constexpr int16_t SIM1_SLOTID = 0;
constexpr int16_t DEFAULT_VALUE = 0;
enum class CallManagerInterfaceType {
REGISTER_CALLBACK_TYPE = 1,
INTERFACE_BLUETOOTH_CALL_TYPE,
};
CoreServiceClient &g_coreServiceClientPtr = CoreServiceClient::GetInstance();
CellularDataClient &g_cellularDataClient = CellularDataClient::GetInstance();
TelephonyObserverClient &g_observerDataClient = TelephonyObserverClient::GetInstance();
using CoreServiceFunc = void (*)();
std::map<uint32_t, CoreServiceFunc> g_memberFuncMap;
std::vector<AccessTokenIDEx> simAccountCallbackTokenIDVec_;
std::vector<AccessTokenIDEx> imsCallbackTokenIDVec_;
std::vector<AccessTokenIDEx> stateObserverTokenIDVec_;
AccessTokenID currentThreadTokenId_ = 0;
AccessTokenIDEx currentTokenIDEx_;
HapInfoParams testInfoParams = {
.userID = 1,
.bundleName = "tel_core_service_ui_test",
.instIndex = 0,
.appIDDesc = "test",
.isSystemApp = true,
};
PermissionDef testPermSetTelephonyStateDef = {
.permissionName = "ohos.permission.SET_TELEPHONY_STATE",
.bundleName = "tel_core_service_ui_test",
.grantMode = 1, // SYSTEM_GRANT
.availableLevel = APL_SYSTEM_BASIC,
.label = "label",
.labelId = 1,
.description = "Test call maneger",
.descriptionId = 1,
};
PermissionStateFull testSetTelephonyState = {
.permissionName = "ohos.permission.SET_TELEPHONY_STATE",
.isGeneral = true,
.resDeviceID = { "local" },
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.grantFlags = { 2 }, // PERMISSION_USER_SET
};
PermissionDef testPermGetTelephonyStateDef = {
.permissionName = "ohos.permission.GET_TELEPHONY_STATE",
.bundleName = "tel_core_service_ui_test",
.grantMode = 1, // SYSTEM_GRANT
.availableLevel = APL_SYSTEM_BASIC,
.label = "label",
.labelId = 1,
.description = "Test call maneger",
.descriptionId = 1,
};
PermissionStateFull testGetTelephonyState = {
.permissionName = "ohos.permission.GET_TELEPHONY_STATE",
.isGeneral = true,
.resDeviceID = { "local" },
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.grantFlags = { 2 }, // PERMISSION_USER_SET
};
PermissionDef testNetPermGetNetworkInfoDef = {
.permissionName = "ohos.permission.GET_NETWORK_INFO",
.bundleName = "tel_state_registry_test",
.grantMode = 1, // SYSTEM_GRANT
.availableLevel = APL_SYSTEM_BASIC,
.label = "label",
.labelId = 1,
.description = "Test state registry",
.descriptionId = 1,
};
PermissionStateFull testNetPermGetNetworkInfo = {
.permissionName = "ohos.permission.GET_NETWORK_INFO",
.isGeneral = true,
.resDeviceID = { "local" },
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.grantFlags = { 2 }, // PERMISSION_USER_SET
};
HapPolicyParams testPolicyParams = {
.apl = APL_SYSTEM_BASIC,
.domain = "test.domain",
.permList = { testPermSetTelephonyStateDef, testPermGetTelephonyStateDef, testNetPermGetNetworkInfoDef },
.permStateList = { testSetTelephonyState, testGetTelephonyState, testNetPermGetNetworkInfo },
};
class AccessToken {
public:
AccessToken()
{
currentID_ = GetSelfTokenID();
currentThreadTokenId_ = currentID_;
AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(testInfoParams, testPolicyParams);
accessID_ = tokenIdEx.tokenIdExStruct.tokenID;
SetSelfTokenID(tokenIdEx.tokenIDEx);
std::cout << "Current tokenId is: " << accessID_ << std::endl;
}
~AccessToken()
{
AccessTokenKit::DeleteToken(accessID_);
SetSelfTokenID(currentID_);
std::cout << "currentID_ tokenId is: " << currentID_ << std::endl;
}
private:
AccessTokenID currentID_ = 0;
AccessTokenID accessID_ = 0;
};
void RegisterSimAccountCallback()
{
g_cellularDataClient.RegisterSimAccountCallback();
std::cout << "RegisterSimAccountCallback success!" << std::endl;
g_cellularDataClient.registerStatus_ = false;
simAccountCallbackTokenIDVec_.push_back(currentTokenIDEx_);
}
void UnRegisterSimAccountCallback()
{
if (simAccountCallbackTokenIDVec_.empty()) {
std::cout << "no callback need to unregister!";
return;
}
std::cout << "Callback list: \n";
for (int32_t i = 0; i < simAccountCallbackTokenIDVec_.size(); i++) {
SetSelfTokenID(simAccountCallbackTokenIDVec_[i].tokenIDEx);
std::cout << i << ": tokenId is " << GetSelfTokenID() << "\n";
}
std::cout << "Please select tokeId which you need unregister...\n";
int32_t index = 0;
std::cin >> index;
AccessTokenIDEx currentIDEx = simAccountCallbackTokenIDVec_[index];
SetSelfTokenID(currentIDEx.tokenIDEx);
std::cout << "Selected tokenId is " << GetSelfTokenID() << std::endl;
g_cellularDataClient.UnregisterSimAccountCallback();
simAccountCallbackTokenIDVec_.erase(simAccountCallbackTokenIDVec_.begin() + index);
AccessTokenKit::DeleteToken(currentIDEx.tokenIdExStruct.tokenID);
SetSelfTokenID(currentThreadTokenId_);
std::cout << "UnRegisterSimAccountCallback success!" << std::endl;
}
void RegisterImsRegInfoCallback()
{
int32_t ret = TELEPHONY_SUCCESS;
sptr<ImsRegInfoCallback> imsRegInfoCallback = new ImsRegInfoCallbackGtest();
ret = g_coreServiceClientPtr.RegisterImsRegInfoCallback(
SIM1_SLOTID, ImsServiceType::TYPE_VOICE, imsRegInfoCallback);
if (ret == TELEPHONY_SUCCESS) {
std::cout << "RegisterImsRegInfoCallback success!" << std::endl;
imsCallbackTokenIDVec_.push_back(currentTokenIDEx_);
return;
}
std::cout << "RegisterImsRegInfoCallback fail!" << std::endl;
}
void UnRegisterImsRegInfoCallback()
{
if (imsCallbackTokenIDVec_.empty()) {
std::cout << "no callback need to unregister!";
return;
}
int32_t ret = TELEPHONY_SUCCESS;
std::cout << "Callback list: \n";
for (int32_t i = 0; i < imsCallbackTokenIDVec_.size(); i++) {
SetSelfTokenID(imsCallbackTokenIDVec_[i].tokenIDEx);
std::cout << i << ": tokenId is " << GetSelfTokenID() << "\n";
}
std::cout << "Please select tokeId which you need unregister...\n";
int32_t index = 0;
std::cin >> index;
AccessTokenIDEx currentIDEx = imsCallbackTokenIDVec_[index];
SetSelfTokenID(currentIDEx.tokenIDEx);
std::cout << "Selected tokenId is " << GetSelfTokenID() << std::endl;
ret = g_coreServiceClientPtr.UnregisterImsRegInfoCallback(SIM1_SLOTID, ImsServiceType::TYPE_VOICE);
if (ret == TELEPHONY_SUCCESS) {
imsCallbackTokenIDVec_.erase(imsCallbackTokenIDVec_.begin() + index);
AccessTokenKit::DeleteToken(currentIDEx.tokenIdExStruct.tokenID);
SetSelfTokenID(currentThreadTokenId_);
std::cout << "UnRegisterImsRegInfoCallback success!" << std::endl;
return;
}
std::cout << "UnRegisterImsRegInfoCallback fail!" << std::endl;
}
void AddStateObserver()
{
int32_t ret = TELEPHONY_SUCCESS;
sptr<StateRegistryObserver> telephonyObserver = std::make_unique<StateRegistryObserver>().release();
ret = g_observerDataClient.AddStateObserver(
telephonyObserver, SIM1_SLOTID, Telephony::TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE, true);
if (ret == TELEPHONY_SUCCESS) {
std::cout << "AddStateObserver success!" << std::endl;
stateObserverTokenIDVec_.push_back(currentTokenIDEx_);
return;
}
std::cout << "AddStateObserver fail!" << std::endl;
}
void RemoveStateObserver()
{
if (stateObserverTokenIDVec_.empty()) {
std::cout << "no callback need to unregister!";
return;
}
int32_t ret = TELEPHONY_SUCCESS;
std::cout << "Callback list: \n";
for (int32_t i = 0; i < stateObserverTokenIDVec_.size(); i++) {
SetSelfTokenID(stateObserverTokenIDVec_[i].tokenIDEx);
std::cout << i << ": tokenId is " << GetSelfTokenID() << "\n";
}
std::cout << "Please select tokeId which you need unregister...\n";
int32_t index = 0;
std::cin >> index;
AccessTokenIDEx currentIDEx = stateObserverTokenIDVec_[index];
SetSelfTokenID(currentIDEx.tokenIDEx);
std::cout << "Selected tokenId is " << GetSelfTokenID() << std::endl;
ret = g_observerDataClient.RemoveStateObserver(
SIM1_SLOTID, Telephony::TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE);
if (ret == TELEPHONY_SUCCESS) {
stateObserverTokenIDVec_.erase(stateObserverTokenIDVec_.begin() + index);
AccessTokenKit::DeleteToken(currentIDEx.tokenIdExStruct.tokenID);
SetSelfTokenID(currentThreadTokenId_);
std::cout << "RemoveStateObserver success!" << std::endl;
return;
}
std::cout << "RemoveStateObserver fail!" << std::endl;
}
void InitCallBasicPower()
{
g_memberFuncMap[static_cast<int32_t>(CoreServiceTestCode::REGISTER_SIM_ACCOUNT_CODE)] =
&OHOS::Telephony::RegisterSimAccountCallback;
g_memberFuncMap[static_cast<int32_t>(CoreServiceTestCode::UNREGISTER_SIM_ACCOUNT_CODE)] =
&OHOS::Telephony::UnRegisterSimAccountCallback;
g_memberFuncMap[static_cast<int32_t>(CoreServiceTestCode::REGISTER_IMS_REG_CODE)] =
&OHOS::Telephony::RegisterImsRegInfoCallback;
g_memberFuncMap[static_cast<int32_t>(CoreServiceTestCode::UNREGISTER_IMS_REG_CODE)] =
&OHOS::Telephony::UnRegisterImsRegInfoCallback;
g_memberFuncMap[static_cast<int32_t>(CoreServiceTestCode::ADD_STATE_OBSERVER)] = &OHOS::Telephony::AddStateObserver;
g_memberFuncMap[static_cast<int32_t>(CoreServiceTestCode::REMOVE_STATE_OBSERVER)] =
&OHOS::Telephony::RemoveStateObserver;
}
int32_t Init()
{
if (g_coreServiceClientPtr.GetProxy() == nullptr) {
std::cout << "\n--- telephonyService == nullptr\n" << std::endl;
return 0;
}
if (g_cellularDataClient.GetProxy() == nullptr) {
std::cout << "\n--- telephonyService == nullptr\n" << std::endl;
return 0;
}
if (g_observerDataClient.GetProxy() == nullptr) {
std::cout << "\n--- telephonyService == nullptr\n" << std::endl;
return 0;
}
InitCallBasicPower();
return TELEPHONY_SUCCESS;
}
void PrintfCallBasisInterface()
{
std::cout << "\n\n-----------start--------------\n"
<< "usage:please input a cmd num:\n"
<< "1:register sim account callback\n"
<< "2:unregister sim account callback\n"
<< "3:register ims reg callback\n"
<< "4:unregister ims reg callback\n"
<< "5:add state observer\n"
<< "6:remove state observer\n";
}
void PrintfUsage()
{
PrintfCallBasisInterface();
std::cout << "1000:exit\n";
}
int32_t mainExit()
{
std::vector<AccessTokenIDEx>::iterator it = simAccountCallbackTokenIDVec_.begin();
while (it != simAccountCallbackTokenIDVec_.end()) {
simAccountCallbackTokenIDVec_.erase(it);
}
it = imsCallbackTokenIDVec_.begin();
while (it != imsCallbackTokenIDVec_.end()) {
imsCallbackTokenIDVec_.erase(it);
}
it = stateObserverTokenIDVec_.begin();
while (it != stateObserverTokenIDVec_.end()) {
stateObserverTokenIDVec_.erase(it);
}
OHOS::Telephony::g_memberFuncMap.clear();
std::cout << "exit success" << std::endl;
return OHOS::Telephony::TELEPHONY_SUCCESS;
}
int32_t RunTest()
{
std::cout << "coreService test start...." << std::endl;
int32_t interfaceNum = DEFAULT_VALUE;
const int32_t exitNumber = 1000;
if (Init() != TELEPHONY_SUCCESS) {
std::cout << "coreService test init failed!" << std::endl;
return TELEPHONY_SUCCESS;
}
AccessToken token;
while (true) {
PrintfUsage();
std::cin >> interfaceNum;
if (interfaceNum == static_cast<int32_t>(CoreServiceTestCode::REGISTER_SIM_ACCOUNT_CODE) ||
interfaceNum == static_cast<int32_t>(CoreServiceTestCode::REGISTER_IMS_REG_CODE) ||
interfaceNum == static_cast<int32_t>(CoreServiceTestCode::ADD_STATE_OBSERVER)) {
std::cout << "Please input instIndex..." << std::endl;
int32_t index = DEFAULT_VALUE;
std::cin >> index;
testInfoParams.instIndex = index;
std::cout << "Please input userId..." << std::endl;
int32_t userId = DEFAULT_VALUE;
std::cin >> userId;
testInfoParams.userID = userId;
AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(testInfoParams, testPolicyParams);
currentTokenIDEx_ = tokenIdEx;
SetSelfTokenID(tokenIdEx.tokenIDEx);
std::cout << "Current userId is: " << testInfoParams.userID << std::endl
<< "bundleName is: " << testInfoParams.bundleName << std::endl
<< "instIndex is: " << testInfoParams.instIndex << std::endl
<< "tokenId is: " << GetSelfTokenID() << std::endl;
}
if (interfaceNum == exitNumber) {
std::cout << "start to exit now...." << std::endl;
break;
}
auto itFunc = g_memberFuncMap.find(interfaceNum);
if (itFunc != g_memberFuncMap.end() && itFunc->second != nullptr) {
auto memberFunc = itFunc->second;
(*memberFunc)();
continue;
}
std::cout << "err: invalid input!" << std::endl;
break;
}
return mainExit();
}
} // namespace Telephony
} // namespace OHOS
int32_t main()
{
int32_t code = OHOS::Telephony::DEFAULT_VALUE;
const int32_t exitCode = 1000;
std::cout << "Please select test type...." << std::endl;
while (true) {
std::cout << "1: Register callback\n"
<< "1000:exit\n";
std::cin >> code;
if (code == static_cast<int32_t>(OHOS::Telephony::CallManagerInterfaceType::REGISTER_CALLBACK_TYPE)) {
OHOS::Telephony::RunTest();
OHOS::Telephony::mainExit();
} else if (code == exitCode) {
break;
}
std::cout << "err: invalid input!" << std::endl;
}
return OHOS::Telephony::TELEPHONY_SUCCESS;
}

View File

@ -42,6 +42,13 @@ bool IsValidDecValue(const std::string &inputValue);
* @return Return {@code true} if the input value is a hexadecimal number, return {@code false} otherwise.
*/
bool IsValidHexValue(const std::string &inputValue);
/**
* @brief Get calling token id.
*
* @return Return token id of the caller.
*/
int32_t GetTokenID();
} // namespace Telephony
} // namespace OHOS
#endif // TELEPHONY_COMMON_UTILS_H

View File

@ -72,5 +72,10 @@ bool IsValidHexValue(const std::string &inputValue)
TELEPHONY_LOGI("InputValue is not a hexadecimal number");
return false;
}
int32_t GetTokenID()
{
return static_cast<int32_t>(IPCSkeleton::GetCallingTokenID());
}
} // namespace Telephony
} // namespace OHOS

View File

@ -26,6 +26,7 @@
OHOS::Telephony::ToUtf*;
"OHOS::Telephony::GetBoolValue(int)";
"OHOS::Telephony::GetBundleName()";
"OHOS::Telephony::GetTokenID()";
"OHOS::Telephony::GetCallState(int)";
"OHOS::Telephony::GetCardType(int)";
"OHOS::Telephony::GetCellularDataConnectionNetworkType(int)";