优化RegisterSimAccountCallback

Signed-off-by: jierbumo866 <fangping5@huawei.com>
This commit is contained in:
jierbumo866 2024-11-11 14:49:19 +08:00
parent e172a133fc
commit bc040d821e
9 changed files with 31 additions and 21 deletions

View File

@ -215,13 +215,13 @@ int32_t CoreManagerInner::RegisterSimAccountCallback(
return simManager_->RegisterSimAccountCallback(tokenId, callback);
}
int32_t CoreManagerInner::UnregisterSimAccountCallback(const int32_t tokenId)
int32_t CoreManagerInner::UnregisterSimAccountCallback(const sptr<SimAccountCallback> &callback)
{
if (simManager_ == nullptr) {
TELEPHONY_LOGE("simManager_ is null");
return TELEPHONY_ERR_LOCAL_PTR_NULL;
}
return simManager_->UnregisterSimAccountCallback(tokenId);
return simManager_->UnregisterSimAccountCallback(callback);
}
/******************** telRilManager start *******************/

View File

@ -50,7 +50,7 @@ public:
int32_t GetDefaultSlotId(void);
int32_t GetMaxSimCount(void);
int32_t RegisterSimAccountCallback(const int32_t tokenId, const sptr<SimAccountCallback> &callback);
int32_t UnregisterSimAccountCallback(const int32_t tokenId);
int32_t UnregisterSimAccountCallback(const sptr<SimAccountCallback> &callback);
/******************** telRilManager start *******************/
int32_t SetRadioState(

View File

@ -79,7 +79,7 @@ public:
virtual int32_t GetDefaultCellularDataSimId(int32_t &simId) = 0;
virtual int32_t RegisterSimAccountCallback(
const int32_t tokenId, const sptr<SimAccountCallback> &callback) = 0;
virtual int32_t UnregisterSimAccountCallback(const int32_t tokenId) = 0;
virtual int32_t UnregisterSimAccountCallback(const sptr<SimAccountCallback> &callback) = 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

@ -47,7 +47,7 @@ public:
std::shared_ptr<Telephony::SimFileManager> simFileManager);
void RegisterCoreNotify(int32_t slotId, const std::shared_ptr<AppExecFwk::EventHandler> &handler, int what);
int32_t RegisterSimAccountCallback(const int32_t tokenId, const sptr<SimAccountCallback> &callback);
int32_t UnregisterSimAccountCallback(const int32_t tokenId);
int32_t UnregisterSimAccountCallback(const sptr<SimAccountCallback> &callback);
void NotifySimAccountChanged();
void RegisterSimNotify();
void RegisterSimNotify(int32_t slotId);

View File

@ -148,7 +148,7 @@ public:
int32_t QueryImsSwitch(int32_t, int32_t &imsSwitchValue) override;
int32_t RegisterSimAccountCallback(
const int32_t tokenId, const sptr<SimAccountCallback> &callback) override;
int32_t UnregisterSimAccountCallback(const int32_t tokenId) override;
int32_t UnregisterSimAccountCallback(const sptr<SimAccountCallback> &callback) override;
bool IsSetActiveSimInProgress(int32_t slotId) override;
bool IsSetPrimarySlotIdInProgress() override;

View File

@ -426,14 +426,16 @@ int32_t MultiSimMonitor::RegisterSimAccountCallback(
const int32_t tokenId, const sptr<SimAccountCallback> &callback)
{
if (callback == nullptr) {
TELEPHONY_LOGE(" callback is nullptr");
TELEPHONY_LOGE("callback is nullptr");
return TELEPHONY_ERR_ARGUMENT_NULL;
}
std::lock_guard<std::mutex> lock(mutexInner_);
bool isExisted = false;
for (auto &iter : listSimAccountCallbackRecord_) {
if (iter.tokenId == tokenId) {
iter.simAccountCallback = callback;
if (iter.simAccountCallback == nullptr) {
continue;
}
if (iter.simAccountCallback->AsObject().GetRefPtr() == callback->AsObject().GetRefPtr()) {
isExisted = true;
break;
}
@ -451,13 +453,21 @@ int32_t MultiSimMonitor::RegisterSimAccountCallback(
return TELEPHONY_SUCCESS;
}
int32_t MultiSimMonitor::UnregisterSimAccountCallback(const int32_t tokenId)
int32_t MultiSimMonitor::UnregisterSimAccountCallback(const sptr<SimAccountCallback> &callback)
{
if (callback == nullptr) {
TELEPHONY_LOGE("callback is nullptr");
return TELEPHONY_ERR_ARGUMENT_NULL;
}
std::lock_guard<std::mutex> lock(mutexInner_);
bool isSuccess = false;
auto iter = listSimAccountCallbackRecord_.begin();
for (; iter != listSimAccountCallbackRecord_.end();) {
if (iter->tokenId == tokenId) {
if (iter->simAccountCallback == nullptr) {
iter++;
continue;
}
if (iter->simAccountCallback->AsObject().GetRefPtr() == callback->AsObject().GetRefPtr()) {
iter = listSimAccountCallbackRecord_.erase(iter);
isSuccess = true;
break;

View File

@ -1202,13 +1202,13 @@ int32_t SimManager::RegisterSimAccountCallback(const int32_t tokenId, const sptr
return multiSimMonitor_->RegisterSimAccountCallback(tokenId, callback);
}
int32_t SimManager::UnregisterSimAccountCallback(const int32_t tokenId)
int32_t SimManager::UnregisterSimAccountCallback(const sptr<SimAccountCallback> &callback)
{
if (multiSimMonitor_ == nullptr) {
TELEPHONY_LOGE("multiSimMonitor is null");
return TELEPHONY_ERR_LOCAL_PTR_NULL;
}
return multiSimMonitor_->UnregisterSimAccountCallback(tokenId);
return multiSimMonitor_->UnregisterSimAccountCallback(callback);
}
bool SimManager::IsSetActiveSimInProgress(int32_t slotId)

View File

@ -287,7 +287,7 @@ HWTEST_F(CoreServiceNativeBranchTest, Telephony_CoreManagerInner_002, Function |
mInner.simManager_ = simManager;
sptr<SimAccountCallback> simAccountCallback;
EXPECT_EQ(mInner.RegisterSimAccountCallback(-1, simAccountCallback), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.UnregisterSimAccountCallback(-1), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.UnregisterSimAccountCallback(simAccountCallback), TELEPHONY_ERR_LOCAL_PTR_NULL);
mInner.telRilManager_ = nullptr;
std::shared_ptr<AppExecFwk::EventHandler> handler;
@ -502,7 +502,7 @@ HWTEST_F(CoreServiceNativeBranchTest, Telephony_CoreManagerInner_008, Function |
mInner.simManager_ = simManager;
sptr<SimAccountCallback> simAccountCallback;
EXPECT_EQ(mInner.RegisterSimAccountCallback(-1, simAccountCallback), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.UnregisterSimAccountCallback(-1), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.UnregisterSimAccountCallback(simAccountCallback), TELEPHONY_ERR_LOCAL_PTR_NULL);
mInner.telRilManager_ = nullptr;
std::shared_ptr<AppExecFwk::EventHandler> handler;
std::string testStr = "";
@ -531,7 +531,7 @@ HWTEST_F(CoreServiceNativeBranchTest, Telephony_CoreManagerInner_009, Function |
mInner.simManager_ = simManager;
sptr<SimAccountCallback> simAccountCallback;
EXPECT_EQ(mInner.RegisterSimAccountCallback(-1, simAccountCallback), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.UnregisterSimAccountCallback(-1), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.UnregisterSimAccountCallback(simAccountCallback), TELEPHONY_ERR_LOCAL_PTR_NULL);
mInner.telRilManager_ = nullptr;
std::shared_ptr<AppExecFwk::EventHandler> handler;
@ -558,7 +558,7 @@ HWTEST_F(CoreServiceNativeBranchTest, Telephony_CoreManagerInner_0010, Function
mInner.simManager_ = simManager;
sptr<SimAccountCallback> simAccountCallback;
EXPECT_EQ(mInner.RegisterSimAccountCallback(-1, simAccountCallback), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.UnregisterSimAccountCallback(-1), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.UnregisterSimAccountCallback(simAccountCallback), TELEPHONY_ERR_LOCAL_PTR_NULL);
mInner.telRilManager_ = nullptr;
std::shared_ptr<AppExecFwk::EventHandler> handler;
DtmfParam dtmfParam;
@ -594,7 +594,7 @@ HWTEST_F(CoreServiceNativeBranchTest, Telephony_CoreManagerInner_0011, Function
mInner.simManager_ = simManager;
sptr<SimAccountCallback> simAccountCallback;
EXPECT_EQ(mInner.RegisterSimAccountCallback(-1, simAccountCallback), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.UnregisterSimAccountCallback(-1), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.UnregisterSimAccountCallback(simAccountCallback), TELEPHONY_ERR_LOCAL_PTR_NULL);
mInner.telRilManager_ = nullptr;
std::shared_ptr<AppExecFwk::EventHandler> handler;

View File

@ -1216,7 +1216,7 @@ HWTEST_F(BranchTest, Telephony_CoreManagerInner_006, Function | MediumTest | Lev
sptr<SimAccountCallback> simAccountCallback;
int32_t imsSwitchValue = 1;
EXPECT_EQ(mInner.RegisterSimAccountCallback(tokenId, simAccountCallback), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.UnregisterSimAccountCallback(tokenId), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.UnregisterSimAccountCallback(simAccountCallback), 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);
@ -1588,7 +1588,7 @@ HWTEST_F(BranchTest, Telephony_SimManager_004, Function | MediumTest | Level1)
EXPECT_NE(simManager->QueryImsSwitch(0, imsSwitchValue), TELEPHONY_ERR_SUCCESS);
EXPECT_NE(simManager->QueryImsSwitch(INVALID_SLOTID, imsSwitchValue), TELEPHONY_ERR_SUCCESS);
EXPECT_NE(simManager->RegisterSimAccountCallback(tokenId, nullptr), TELEPHONY_ERR_SUCCESS);
EXPECT_NE(simManager->UnregisterSimAccountCallback(tokenId), TELEPHONY_ERR_SUCCESS);
EXPECT_NE(simManager->UnregisterSimAccountCallback(nullptr), TELEPHONY_ERR_SUCCESS);
int32_t dsdsMode = INVALID_VALUE;
simManager->GetDsdsMode(dsdsMode);
simManager->SetDsdsMode(0);
@ -3084,7 +3084,7 @@ HWTEST_F(BranchTest, Telephony_MultiSimMonitor_001, Function | MediumTest | Leve
int32_t tokenId = 123456789;
sptr<SimAccountCallback> callback = nullptr;
EXPECT_GT(multiSimMonitor->RegisterSimAccountCallback(tokenId, callback), TELEPHONY_ERROR);
EXPECT_EQ(multiSimMonitor->UnregisterSimAccountCallback(tokenId), TELEPHONY_ERROR);
EXPECT_GT(multiSimMonitor->UnregisterSimAccountCallback(callback), TELEPHONY_ERROR);
}
/**