diff --git a/bundle.json b/bundle.json index 93938db..f5ac9b1 100644 --- a/bundle.json +++ b/bundle.json @@ -31,6 +31,7 @@ "c_utils", "data_share", "eventhandler", + "ffrt", "hilog", "hisysevent", "hitrace", diff --git a/services/security_component_service/sa/BUILD.gn b/services/security_component_service/sa/BUILD.gn index 4f9f2c1..ab29a48 100644 --- a/services/security_component_service/sa/BUILD.gn +++ b/services/security_component_service/sa/BUILD.gn @@ -267,6 +267,7 @@ ohos_source_set("security_component_service_src_set") { "c_utils:utils", "data_share:datashare_consumer", "eventhandler:libeventhandler", + "ffrt:libffrt", "graphic_2d:librender_service_client", "hilog:libhilog", "hisysevent:libhisysevent", diff --git a/services/security_component_service/sa/sa_main/app_state_observer.cpp b/services/security_component_service/sa/sa_main/app_state_observer.cpp index 3ca4372..4418818 100644 --- a/services/security_component_service/sa/sa_main/app_state_observer.cpp +++ b/services/security_component_service/sa/sa_main/app_state_observer.cpp @@ -35,7 +35,7 @@ AppStateObserver::~AppStateObserver() bool AppStateObserver::IsProcessForeground(int32_t pid, int32_t uid) { - Utils::UniqueWriteGuard infoGuard(this->fgProcLock_); + std::unique_lock infoGuard(this->fgProcLock_); for (auto iter = foregrandProcList_.begin(); iter != foregrandProcList_.end(); ++iter) { if (pid == iter->pid) { return true; @@ -51,7 +51,7 @@ bool AppStateObserver::IsProcessForeground(int32_t pid, int32_t uid) void AppStateObserver::AddProcessToForegroundSet(int32_t pid, const SecCompProcessData& data) { - Utils::UniqueWriteGuard infoGuard(this->fgProcLock_); + std::unique_lock infoGuard(this->fgProcLock_); for (auto iter = foregrandProcList_.begin(); iter != foregrandProcList_.end(); ++iter) { if (pid == -1) { if (iter->uid == data.uid) { @@ -88,7 +88,7 @@ void AppStateObserver::AddProcessToForegroundSet(const AppExecFwk::ProcessData & void AppStateObserver::RemoveProcessFromForegroundSet(int32_t pid) { - Utils::UniqueWriteGuard infoGuard(this->fgProcLock_); + std::unique_lock infoGuard(this->fgProcLock_); for (auto iter = foregrandProcList_.begin(); iter != foregrandProcList_.end(); ++iter) { if (pid == iter->pid) { foregrandProcList_.erase(iter); @@ -129,7 +129,7 @@ void AppStateObserver::OnAppCacheStateChanged(const AppExecFwk::AppStateData &ap void AppStateObserver::DumpProcess(std::string& dumpStr) { - Utils::UniqueWriteGuard infoGuard(this->fgProcLock_); + std::unique_lock infoGuard(this->fgProcLock_); for (auto iter = foregrandProcList_.begin(); iter != foregrandProcList_.end(); ++iter) { dumpStr.append("uid:" + std::to_string(iter->uid) + ", pid:" + std::to_string(iter->pid)); dumpStr.append(", procName:" + iter->bundleName + "\n"); diff --git a/services/security_component_service/sa/sa_main/app_state_observer.h b/services/security_component_service/sa/sa_main/app_state_observer.h index 69df358..8dc8721 100644 --- a/services/security_component_service/sa/sa_main/app_state_observer.h +++ b/services/security_component_service/sa/sa_main/app_state_observer.h @@ -19,8 +19,8 @@ #include #include "app_mgr_interface.h" #include "application_state_observer_stub.h" +#include "ffrt.h" #include "iremote_object.h" -#include "rwlock.h" namespace OHOS { namespace Security { @@ -48,7 +48,7 @@ public: private: void RemoveProcessFromForegroundSet(int32_t pid); std::vector foregrandProcList_; - OHOS::Utils::RWLock fgProcLock_; + ffrt::shared_mutex fgProcLock_; }; } // namespace SecurityComponent } // namespace Security diff --git a/services/security_component_service/sa/sa_main/sec_comp_manager.cpp b/services/security_component_service/sa/sa_main/sec_comp_manager.cpp index b924075..f2927e8 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_manager.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_manager.cpp @@ -63,7 +63,7 @@ SecCompManager& SecCompManager::GetInstance() } bool SecCompManager::IsScIdExist(int32_t scId) { - OHOS::Utils::UniqueReadGuard lk(this->componentInfoLock_); + std::shared_lock lk(this->componentInfoLock_); for (auto it = componentMap_.begin(); it != componentMap_.end(); ++it) { for (auto iter = it->second.compList.begin(); iter != it->second.compList.end(); ++iter) { std::shared_ptr sc = *iter; @@ -91,7 +91,7 @@ int32_t SecCompManager::CreateScId() int32_t SecCompManager::AddSecurityComponentToList(int32_t pid, AccessToken::AccessTokenID tokenId, std::shared_ptr newEntity) { - OHOS::Utils::UniqueWriteGuard lk(this->componentInfoLock_); + std::unique_lock lk(this->componentInfoLock_); if (isSaExit_) { SC_LOG_ERROR(LABEL, "SA is exiting, retry..."); return SC_SERVICE_ERROR_SERVICE_NOT_EXIST; @@ -120,7 +120,7 @@ int32_t SecCompManager::AddSecurityComponentToList(int32_t pid, int32_t SecCompManager::DeleteSecurityComponentFromList(int32_t pid, int32_t scId) { - OHOS::Utils::UniqueWriteGuard lk(this->componentInfoLock_); + std::unique_lock lk(this->componentInfoLock_); auto iter = componentMap_.find(pid); if (iter == componentMap_.end()) { SC_LOG_ERROR(LABEL, "Can not find registered process"); @@ -208,7 +208,7 @@ bool SecCompManager::IsCompExist() void SecCompManager::NotifyProcessForeground(int32_t pid) { - OHOS::Utils::UniqueWriteGuard lk(this->componentInfoLock_); + std::unique_lock lk(this->componentInfoLock_); auto iter = componentMap_.find(pid); if (iter == componentMap_.end()) { return; @@ -221,7 +221,7 @@ void SecCompManager::NotifyProcessForeground(int32_t pid) void SecCompManager::NotifyProcessBackground(int32_t pid) { - OHOS::Utils::UniqueWriteGuard lk(this->componentInfoLock_); + std::unique_lock lk(this->componentInfoLock_); auto iter = componentMap_.find(pid); if (iter == componentMap_.end()) { return; @@ -239,7 +239,7 @@ void SecCompManager::NotifyProcessDied(int32_t pid, bool isProcessCached) SecCompEnhanceAdapter::NotifyProcessDied(pid); malicious_.RemoveAppFromMaliciousAppList(pid); } - OHOS::Utils::UniqueWriteGuard lk(this->componentInfoLock_); + std::unique_lock lk(this->componentInfoLock_); auto iter = componentMap_.find(pid); if (iter == componentMap_.end()) { return; @@ -258,7 +258,7 @@ void SecCompManager::NotifyProcessDied(int32_t pid, bool isProcessCached) void SecCompManager::ExitSaProcess() { - OHOS::Utils::UniqueWriteGuard lk(this->componentInfoLock_); + std::unique_lock lk(this->componentInfoLock_); if (IsCompExist()) { SC_LOG_INFO(LABEL, "Apps using security component still exist, no exit sa"); return; @@ -284,7 +284,7 @@ void SecCompManager::ExitSaProcess() void SecCompManager::ExitWhenAppMgrDied() { - OHOS::Utils::UniqueWriteGuard lk(this->componentInfoLock_); + std::unique_lock lk(this->componentInfoLock_); for (auto iter = componentMap_.begin(); iter != componentMap_.end(); ++iter) { iter->second.compList.clear(); SecCompPermManager::GetInstance().RevokeAppPermissions(iter->second.tokenId); @@ -333,7 +333,7 @@ int32_t SecCompManager::AddSecurityComponentProcess(const SecCompCallerInfo& cal { DelayExitTask::GetInstance().Stop(); { - OHOS::Utils::UniqueWriteGuard lk(this->componentInfoLock_); + std::unique_lock lk(this->componentInfoLock_); if (isSaExit_) { SC_LOG_ERROR(LABEL, "SA is exiting, retry..."); return SC_SERVICE_ERROR_SERVICE_NOT_EXIST; @@ -408,7 +408,7 @@ int32_t SecCompManager::UpdateSecurityComponent(int32_t scId, const nlohmann::js return SC_ENHANCE_ERROR_IN_MALICIOUS_LIST; } - OHOS::Utils::UniqueWriteGuard lk(this->componentInfoLock_); + std::unique_lock lk(this->componentInfoLock_); std::shared_ptr sc = GetSecurityComponentFromList(caller.pid, scId); if (sc == nullptr) { SC_LOG_ERROR(LABEL, "Can not find target component"); @@ -595,7 +595,7 @@ int32_t SecCompManager::ReportSecurityComponentClickEvent(SecCompInfo& info, con if (res != SC_OK) { return res; } - OHOS::Utils::UniqueWriteGuard lk(this->componentInfoLock_); + std::unique_lock lk(this->componentInfoLock_); std::shared_ptr sc = GetSecurityComponentFromList(caller.pid, info.scId); if (sc == nullptr) { SC_LOG_ERROR(LABEL, "Can not find target component"); @@ -629,7 +629,7 @@ int32_t SecCompManager::ReportSecurityComponentClickEvent(SecCompInfo& info, con void SecCompManager::DumpSecComp(std::string& dumpStr) { - OHOS::Utils::UniqueReadGuard lk(this->componentInfoLock_); + std::shared_lock lk(this->componentInfoLock_); for (auto iter = componentMap_.begin(); iter != componentMap_.end(); ++iter) { AccessToken::AccessTokenID tokenId = iter->second.tokenId; bool locationPerm = SecCompPermManager::GetInstance().VerifyPermission(tokenId, LOCATION_COMPONENT); diff --git a/services/security_component_service/sa/sa_main/sec_comp_manager.h b/services/security_component_service/sa/sa_main/sec_comp_manager.h index 033ae97..ade6dd2 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_manager.h +++ b/services/security_component_service/sa/sa_main/sec_comp_manager.h @@ -23,9 +23,9 @@ #include #include "accesstoken_kit.h" #include "app_state_observer.h" +#include "ffrt.h" #include "first_use_dialog.h" #include "nocopyable.h" -#include "rwlock.h" #include "sec_comp_base.h" #include "sec_comp_entity.h" #include "sec_comp_info.h" @@ -88,7 +88,7 @@ private: int32_t CreateScId(); void GetFoldOffsetY(const CrossAxisState crossAxisState); - OHOS::Utils::RWLock componentInfoLock_; + ffrt::shared_mutex componentInfoLock_; std::mutex scIdMtx_; std::mutex superFoldOffsetMtx_; std::unordered_map componentMap_; diff --git a/services/security_component_service/sa/sa_main/sec_comp_perm_manager.h b/services/security_component_service/sa/sa_main/sec_comp_perm_manager.h index aaa2817..3e7d406 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_perm_manager.h +++ b/services/security_component_service/sa/sa_main/sec_comp_perm_manager.h @@ -19,7 +19,7 @@ #include #include #include "accesstoken_kit.h" -#include "rwlock.h" +#include "ffrt.h" #include "sec_comp_base.h" #include "sec_event_handler.h" diff --git a/services/security_component_service/sa/test/BUILD.gn b/services/security_component_service/sa/test/BUILD.gn index 5ea97b4..b3b4fa1 100644 --- a/services/security_component_service/sa/test/BUILD.gn +++ b/services/security_component_service/sa/test/BUILD.gn @@ -89,6 +89,7 @@ ohos_unittest("sec_comp_service_test") { "access_token:libtokenid_sdk", "c_utils:utils", "eventhandler:libeventhandler", + "ffrt:libffrt", "googletest:gmock_main", "graphic_2d:librender_service_client", "hilog:libhilog", @@ -169,6 +170,7 @@ ohos_unittest("sec_comp_service_mock_test") { "access_token:libtokenid_sdk", "c_utils:utils", "eventhandler:libeventhandler", + "ffrt:libffrt", "googletest:gmock_main", "graphic_2d:librender_service_client", "hilog:libhilog", diff --git a/test/fuzztest/security_component/service/security_component_fuzz.gni b/test/fuzztest/security_component/service/security_component_fuzz.gni index cd57730..6987cdd 100644 --- a/test/fuzztest/security_component/service/security_component_fuzz.gni +++ b/test/fuzztest/security_component/service/security_component_fuzz.gni @@ -45,6 +45,7 @@ sc_external_deps = [ "bundle_framework:appexecfwk_core", "c_utils:utils", "eventhandler:libeventhandler", + "ffrt:libffrt", "graphic_2d:librender_service_client", "hilog:libhilog", "hisysevent:libhisysevent",