!2312 【挑单】resolve coreservice crash when use copyoperatorconfig

Merge pull request !2312 from wanx194/OpenHarmony-5.0-Release
This commit is contained in:
openharmony_ci 2024-09-25 08:01:05 +00:00 committed by Gitee
commit 843cb6d1cd
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 74 additions and 148 deletions

View File

@ -21,6 +21,7 @@
#include "common_event_subscriber.h"
#include "iservice_registry.h"
#include "multi_sim_controller.h"
#include "os_account_manager_wrapper.h"
#include "sim_constant.h"
#include "sim_file_manager.h"
#include "system_ability_definition.h"
@ -75,6 +76,8 @@ private:
std::list<SimAccountCallbackRecord> GetSimAccountCallbackRecords();
void InitListener();
void SubscribeDataShareReady();
void SubscribeUserSwitch();
void SubscribeBundleScanFinished();
void UnSubscribeListeners();
void CheckOpcNeedUpdata(const bool isDataShareError);
int32_t CheckUpdateOpcVersion();
@ -95,6 +98,16 @@ private:
MultiSimMonitor &handler_;
};
class UserSwitchEventSubscriber : public CommonEventSubscriber {
public:
explicit UserSwitchEventSubscriber(
const CommonEventSubscribeInfo &info, MultiSimMonitor &handler)
: CommonEventSubscriber(info), handler_(handler) {}
~UserSwitchEventSubscriber() = default;
void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data) override;
MultiSimMonitor &handler_;
};
class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub {
public:
explicit SystemAbilityStatusChangeListener(MultiSimMonitor &handler) : handler_(handler) {};
@ -115,11 +128,13 @@ private:
std::unique_ptr<ObserverHandler> observerHandler_ = nullptr;
std::list<SimAccountCallbackRecord> listSimAccountCallbackRecord_;
std::shared_ptr<DataShareEventSubscriber> dataShareSubscriber_ = nullptr;
std::shared_ptr<UserSwitchEventSubscriber> userSwitchSubscriber_ = nullptr;
sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr;
std::mutex mutexInner_;
std::mutex mutexForData_;
std::atomic<int32_t> remainCount_ = 15;
int32_t maxSlotCount_ = 0;
bool isDataShareReady_ = false;
bool isForgetAllDataDone_ = false;
};
} // namespace Telephony

View File

@ -29,6 +29,7 @@ public:
void ClearAllCache(int32_t slotId);
void ClearMemoryCache(int32_t slotId);
void ClearOperatorValue(int32_t slotId);
void ClearMemoryAndOpkey(int32_t slotId);
int32_t LoadOperatorConfig(int32_t slotId, OperatorConfig &poc, int32_t state = 0);
int32_t GetOperatorConfigs(int32_t slotId, OperatorConfig &poc);
int32_t UpdateOperatorConfigs(int32_t slotId);

View File

@ -18,25 +18,19 @@
#include <string>
#include "common_event_subscriber.h"
#include "iservice_registry.h"
#include "operator_config_cache.h"
#include "operator_config_loader.h"
#include "system_ability_definition.h"
#include "system_ability_status_change_stub.h"
#include "telephony_log_wrapper.h"
namespace OHOS {
namespace Telephony {
using namespace OHOS::EventFwk;
using CommonEventSubscribeInfo = OHOS::EventFwk::CommonEventSubscribeInfo;
using CommonEventSubscriber = OHOS::EventFwk::CommonEventSubscriber;
class SimStateTracker : public TelEventHandler {
public:
SimStateTracker(std::weak_ptr<SimFileManager> simFileManager,
std::shared_ptr<OperatorConfigCache> operatorConfigCache, int32_t slotId);
~SimStateTracker();
void InitListener();
void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event);
bool RegisterForIccLoaded();
bool RegisterOpkeyLoaded();
@ -57,34 +51,6 @@ private:
void ProcessSimRecordLoad(const AppExecFwk::InnerEvent::Pointer &event);
void ProcessSimOpkeyLoad(const AppExecFwk::InnerEvent::Pointer &event);
void ProcessOperatorCacheDel(const AppExecFwk::InnerEvent::Pointer &event);
private:
class UserSwitchEventSubscriber : public CommonEventSubscriber {
public:
explicit UserSwitchEventSubscriber(
const CommonEventSubscribeInfo &info, int32_t slotId, std::shared_ptr<OperatorConfigLoader> configLoader)
: CommonEventSubscriber(info), slotId_(slotId), configLoader_(configLoader)
{}
~UserSwitchEventSubscriber() = default;
void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data) override;
private:
const int32_t slotId_;
std::shared_ptr<OperatorConfigLoader> configLoader_ = nullptr;
};
class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub {
public:
explicit SystemAbilityStatusChangeListener(int32_t slotId, std::shared_ptr<OperatorConfigLoader> configLoader);
~SystemAbilityStatusChangeListener() = default;
virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
private:
const int32_t slotId_;
std::shared_ptr<OperatorConfigLoader> configLoader_ = nullptr;
std::shared_ptr<UserSwitchEventSubscriber> userSwitchSubscriber_ = nullptr;
bool isUserSwitchSubscribered = false;
};
};
} // namespace Telephony
} // namespace OHOS

View File

@ -29,6 +29,7 @@
namespace OHOS {
namespace Telephony {
const int64_t DELAY_TIME = 1000;
const int32_t ACTIVE_USER_ID = 100;
const int INIT_TIMES = 15;
const int INIT_DATA_TIMES = 5;
MultiSimMonitor::MultiSimMonitor(const std::shared_ptr<MultiSimController> &controller,
@ -274,6 +275,10 @@ void MultiSimMonitor::UnSubscribeListeners()
dataShareSubscriber_ = nullptr;
TELEPHONY_LOGI("Unsubscribe datashare ready success");
}
if (userSwitchSubscriber_ != nullptr && CommonEventManager::UnSubscribeCommonEvent(userSwitchSubscriber_)) {
userSwitchSubscriber_ = nullptr;
TELEPHONY_LOGI("Unsubscribe UserSwitch success");
}
if (statusChangeListener_ != nullptr) {
auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgrProxy != nullptr) {
@ -304,6 +309,7 @@ void MultiSimMonitor::SystemAbilityStatusChangeListener::OnAddSystemAbility(int3
case COMMON_EVENT_SERVICE_ID: {
TELEPHONY_LOGI("COMMON_EVENT_SERVICE_ID is running");
handler_.SubscribeDataShareReady();
handler_.SubscribeUserSwitch();
break;
}
default:
@ -318,6 +324,7 @@ void MultiSimMonitor::SystemAbilityStatusChangeListener::OnRemoveSystemAbility(i
switch (systemAbilityId) {
case COMMON_EVENT_SERVICE_ID: {
TELEPHONY_LOGI("COMMON_EVENT_SERVICE_ID stopped");
handler_.UnSubscribeListeners();
break;
}
default:
@ -343,7 +350,25 @@ void MultiSimMonitor::SubscribeDataShareReady()
dataShareSubscriber_ = nullptr;
TELEPHONY_LOGE("Subscribe datashare ready fail");
}
CheckDataShareError();
}
void MultiSimMonitor::SubscribeUserSwitch()
{
if (userSwitchSubscriber_ != nullptr) {
TELEPHONY_LOGW("UserSwitch has Subscribed");
return;
}
MatchingSkills matchingSkills;
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
CommonEventSubscribeInfo subscriberInfo(matchingSkills);
subscriberInfo.SetThreadMode(CommonEventSubscribeInfo::COMMON);
userSwitchSubscriber_ = std::make_shared<UserSwitchEventSubscriber>(subscriberInfo, *this);
if (CommonEventManager::SubscribeCommonEvent(userSwitchSubscriber_)) {
TELEPHONY_LOGI("Subscribe UserSwitch success");
} else {
userSwitchSubscriber_ = nullptr;
TELEPHONY_LOGE("Subscribe UserSwitch fail");
}
}
void MultiSimMonitor::DataShareEventSubscriber::OnReceiveEvent(const CommonEventData &data)
@ -351,9 +376,29 @@ void MultiSimMonitor::DataShareEventSubscriber::OnReceiveEvent(const CommonEvent
OHOS::EventFwk::Want want = data.GetWant();
std::string action = want.GetAction();
TELEPHONY_LOGI("action = %{public}s", action.c_str());
std::vector<int32_t> activeList = { 0 };
DelayedSingleton<AppExecFwk::OsAccountManagerWrapper>::GetInstance()->QueryActiveOsAccountIds(activeList);
if (action == DATASHARE_READY_EVENT) {
handler_.CheckDataShareError();
handler_.CheckSimNotifyRegister();
handler_.isDataShareReady_ = true;
if (activeList[0] == ACTIVE_USER_ID) {
handler_.CheckDataShareError();
handler_.CheckSimNotifyRegister();
}
}
}
void MultiSimMonitor::UserSwitchEventSubscriber::OnReceiveEvent(const CommonEventData &data)
{
OHOS::EventFwk::Want want = data.GetWant();
std::string action = want.GetAction();
TELEPHONY_LOGI("action = %{public}s", action.c_str());
if (action == CommonEventSupport::COMMON_EVENT_USER_SWITCHED) {
int32_t userId = data.GetCode();
TELEPHONY_LOGI("current user id is :%{public}d", userId);
if (userId == ACTIVE_USER_ID && handler_.isDataShareReady_) {
handler_.CheckDataShareError();
handler_.CheckSimNotifyRegister();
}
}
}

View File

@ -43,6 +43,14 @@ void OperatorConfigCache::ClearAllCache(int32_t slotId)
lock.unlock();
}
void OperatorConfigCache::ClearMemoryAndOpkey(int32_t slotId)
{
std::unique_lock<std::mutex> lock(mutex_);
ClearOperatorValue(slotId);
ClearMemoryCache(slotId);
lock.unlock();
}
void OperatorConfigCache::ClearOperatorValue(int32_t slotId)
{
auto simFileManager = simFileManager_.lock();
@ -325,7 +333,7 @@ bool OperatorConfigCache::IsNeedOperatorLoad(int32_t slotId)
return true;
}
std::string iccid = Str16ToStr8(simFileManager->GetSimIccId());
std::string filename = EncryptIccId(iccid) + ".json";
std::string filename = EncryptIccId(iccid + opkey) + ".json";
std::string path = parser_.GetOperatorConfigFilePath(filename);
std::ifstream f(path.c_str());
return !f.good();

View File

@ -18,7 +18,6 @@
#include "common_event_manager.h"
#include "common_event_support.h"
#include "core_manager_inner.h"
#include "os_account_manager_wrapper.h"
#include "radio_event.h"
#include "telephony_ext_wrapper.h"
#include "thread"
@ -26,7 +25,6 @@
namespace OHOS {
namespace Telephony {
constexpr int32_t OPKEY_VMSG_LENTH = 3;
const int32_t ACTIVE_USER_ID = 100;
SimStateTracker::SimStateTracker(std::weak_ptr<SimFileManager> simFileManager,
std::shared_ptr<OperatorConfigCache> operatorConfigCache, int32_t slotId)
: TelEventHandler("SimStateTracker"), simFileManager_(simFileManager), operatorConfigCache_(operatorConfigCache),
@ -36,7 +34,6 @@ SimStateTracker::SimStateTracker(std::weak_ptr<SimFileManager> simFileManager,
TELEPHONY_LOGE("can not make OperatorConfigLoader");
}
operatorConfigLoader_ = std::make_shared<OperatorConfigLoader>(simFileManager, operatorConfigCache);
InitListener();
}
SimStateTracker::~SimStateTracker()
@ -51,20 +48,6 @@ SimStateTracker::~SimStateTracker()
}
}
void SimStateTracker::InitListener()
{
auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
statusChangeListener_ = new (std::nothrow) SystemAbilityStatusChangeListener(slotId_, operatorConfigLoader_);
if (samgrProxy == nullptr || statusChangeListener_ == nullptr) {
TELEPHONY_LOGE("samgrProxy or statusChangeListener_ is nullptr");
return;
}
int32_t ret = samgrProxy->SubscribeSystemAbility(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN, statusChangeListener_);
TELEPHONY_LOGI("SubscribeSystemAbility SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN result:%{public}d", ret);
ret = samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusChangeListener_);
TELEPHONY_LOGI("SubscribeSystemAbility COMMON_EVENT_SERVICE_ID result:%{public}d", ret);
}
void SimStateTracker::ProcessSimRecordLoad(const AppExecFwk::InnerEvent::Pointer &event)
{
TELEPHONY_LOGI("SimStateTracker::Refresh config");
@ -134,8 +117,7 @@ void SimStateTracker::ProcessOperatorCacheDel(const AppExecFwk::InnerEvent::Poin
TELEPHONY_LOGE("operatorConfigCache is nullptr");
return;
}
operatorConfigCache_->ClearOperatorValue(slotId);
operatorConfigCache_->ClearMemoryCache(slotId);
operatorConfigCache_->ClearMemoryAndOpkey(slotId);
}
void SimStateTracker::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
@ -232,92 +214,5 @@ bool SimStateTracker::UnregisterOperatorCacheDel()
simFileManager->UnRegisterCoreNotify(shared_from_this(), RadioEvent::RADIO_OPERATOR_CACHE_DELETE);
return true;
}
SimStateTracker::SystemAbilityStatusChangeListener::SystemAbilityStatusChangeListener(
int32_t slotId, std::shared_ptr<OperatorConfigLoader> configLoader)
: slotId_(slotId), configLoader_(configLoader)
{}
void SimStateTracker::SystemAbilityStatusChangeListener::OnAddSystemAbility(
int32_t systemAbilityId, const std::string &deviceId)
{
if (configLoader_ == nullptr) {
TELEPHONY_LOGE("configLoader_ is nullptr.");
return;
}
switch (systemAbilityId) {
case SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN: {
TELEPHONY_LOGI("SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN running");
std::vector<int32_t> activeList = { 0 };
DelayedSingleton<AppExecFwk::OsAccountManagerWrapper>::GetInstance()->QueryActiveOsAccountIds(activeList);
TELEPHONY_LOGI("current active user id is :%{public}d", activeList[0]);
if (activeList[0] == ACTIVE_USER_ID) {
configLoader_->LoadOperatorConfig(slotId_);
}
break;
}
case COMMON_EVENT_SERVICE_ID: {
TELEPHONY_LOGI("COMMON_EVENT_SERVICE_ID running, isUserSwitchSubscribered is :%{public}d",
isUserSwitchSubscribered);
if (isUserSwitchSubscribered) {
return;
}
MatchingSkills matchingSkills;
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
CommonEventSubscribeInfo subscriberInfo(matchingSkills);
subscriberInfo.SetThreadMode(CommonEventSubscribeInfo::COMMON);
userSwitchSubscriber_ = std::make_shared<UserSwitchEventSubscriber>(subscriberInfo, slotId_, configLoader_);
if (CommonEventManager::SubscribeCommonEvent(userSwitchSubscriber_)) {
isUserSwitchSubscribered = true;
TELEPHONY_LOGI("Subscribe user switched success");
}
break;
}
default:
TELEPHONY_LOGE("systemAbilityId is invalid");
break;
}
}
void SimStateTracker::SystemAbilityStatusChangeListener::OnRemoveSystemAbility(
int32_t systemAbilityId, const std::string &deviceId)
{
switch (systemAbilityId) {
case SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN: {
TELEPHONY_LOGE("SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN stopped");
break;
}
case COMMON_EVENT_SERVICE_ID: {
TELEPHONY_LOGI("COMMON_EVENT_SERVICE_ID stopped, isUserSwitchSubscribered is :%{public}d",
isUserSwitchSubscribered);
if (!isUserSwitchSubscribered) {
return;
}
if (userSwitchSubscriber_ != nullptr && CommonEventManager::UnSubscribeCommonEvent(userSwitchSubscriber_)) {
userSwitchSubscriber_ = nullptr;
isUserSwitchSubscribered = false;
TELEPHONY_LOGI("Unsubscribe user switched success");
}
break;
}
default:
TELEPHONY_LOGE("systemAbilityId is invalid");
break;
}
}
void SimStateTracker::UserSwitchEventSubscriber::OnReceiveEvent(const CommonEventData &data)
{
OHOS::EventFwk::Want want = data.GetWant();
std::string action = data.GetWant().GetAction();
TELEPHONY_LOGI("action = %{public}s", action.c_str());
if (action == CommonEventSupport::COMMON_EVENT_USER_SWITCHED) {
int32_t userId = data.GetCode();
TELEPHONY_LOGI("current user id is :%{public}d", userId);
if (userId == ACTIVE_USER_ID) {
configLoader_->LoadOperatorConfig(slotId_);
}
}
}
} // namespace Telephony
} // namespace OHOS

View File

@ -241,10 +241,6 @@ HWTEST_F(SimRilBranchTest, Telephony_SimStateTracker_001, Function | MediumTest
simStateTracker->ProcessEvent(event);
simFileManager = nullptr;
simStateTracker->simFileManager_ = simFileManager;
std::shared_ptr<OperatorConfigLoader> operatorConfigLoader_ = nullptr;
auto statusChangeListener_ =
new (std::nothrow) SimStateTracker::SystemAbilityStatusChangeListener(0, operatorConfigLoader_);
statusChangeListener_->OnAddSystemAbility(0, "test");
EXPECT_FALSE(simStateTracker->RegisterForIccLoaded());
EXPECT_FALSE(simStateTracker->UnRegisterForIccLoaded());
}