diff --git a/frameworks/inner_api/security_component/include/sec_comp_dialog_callback.h b/frameworks/inner_api/security_component/include/sec_comp_dialog_callback.h index 05fbda0..907f19b 100644 --- a/frameworks/inner_api/security_component/include/sec_comp_dialog_callback.h +++ b/frameworks/inner_api/security_component/include/sec_comp_dialog_callback.h @@ -41,6 +41,7 @@ public: void OnDialogClosed(int32_t result) override; private: + std::mutex callbackMutex_; OnFirstUseDialogCloseFunc callback_; }; } // namespace SecurityComponent diff --git a/frameworks/inner_api/security_component/src/sec_comp_dialog_callback.cpp b/frameworks/inner_api/security_component/src/sec_comp_dialog_callback.cpp index ae44455..fa32ac6 100644 --- a/frameworks/inner_api/security_component/src/sec_comp_dialog_callback.cpp +++ b/frameworks/inner_api/security_component/src/sec_comp_dialog_callback.cpp @@ -25,6 +25,7 @@ static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { void SecCompDialogCallback::OnDialogClosed(int32_t result) { + std::unique_lock lock(callbackMutex_); if (callback_ == nullptr) { SC_LOG_ERROR(LABEL, "callback_ is nullptr"); return; 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 09c6b65..90def2f 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 @@ -539,6 +539,7 @@ static void ReportEvent(std::string eventName, HiviewDFX::HiSysEvent::EventType void SecCompManager::GetFoldOffsetY(const CrossAxisState crossAxisState) { + std::unique_lock lock(superFoldOffsetMtx_); if (crossAxisState == CrossAxisState::STATE_INVALID) { return; } 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 2032624..033ae97 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 @@ -90,6 +90,7 @@ private: OHOS::Utils::RWLock componentInfoLock_; std::mutex scIdMtx_; + std::mutex superFoldOffsetMtx_; std::unordered_map componentMap_; int32_t scIdStart_; bool isSaExit_ = false; diff --git a/services/security_component_service/sa/sa_main/sec_comp_service.cpp b/services/security_component_service/sa/sa_main/sec_comp_service.cpp index 55e66e7..50f3530 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_service.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_service.cpp @@ -95,6 +95,7 @@ void SecCompService::OnStop() bool SecCompService::RegisterAppStateObserver() { + std::unique_lock lock(secCompSrvMutex_); if (appStateObserver_ != nullptr) { SC_LOG_INFO(LABEL, "AppStateObserver instance already create"); return true; @@ -148,6 +149,7 @@ bool SecCompService::RegisterAppStateObserver() void SecCompService::UnregisterAppStateObserver() { + std::unique_lock lock(secCompSrvMutex_); if (iAppMgr_ != nullptr && appStateObserver_ != nullptr) { iAppMgr_->UnregisterApplicationStateObserver(appStateObserver_); } @@ -162,6 +164,7 @@ bool SecCompService::GetCallerInfo(SecCompCallerInfo& caller) SC_LOG_ERROR(LABEL, "Get caller tokenId invalid"); return false; } + std::unique_lock lock(secCompSrvMutex_); if ((uid != ROOT_UID) && (!appStateObserver_->IsProcessForeground(pid, uid))) { SC_LOG_ERROR(LABEL, "caller pid is not in foreground"); return false; @@ -642,6 +645,7 @@ int32_t SecCompService::VerifySavePermission(AccessToken::AccessTokenID tokenId, bool SecCompService::IsMediaLibraryCalling() { + std::unique_lock lock(mediaLibMutex_); int32_t uid = IPCSkeleton::GetCallingUid(); if (uid == ROOT_UID) { return true; @@ -670,6 +674,7 @@ int SecCompService::Dump(int fd, const std::vector& args) dprintf(fd, " -p: dump foreground processes\n"); } else if (arg0.compare("-p") == 0) { std::string dumpStr; + std::unique_lock lock(secCompSrvMutex_); appStateObserver_->DumpProcess(dumpStr); dprintf(fd, "%s\n", dumpStr.c_str()); } else if (arg0.compare("-a") == 0 || arg0 == "") { diff --git a/services/security_component_service/sa/sa_main/sec_comp_service.h b/services/security_component_service/sa/sa_main/sec_comp_service.h index 10bfd0e..08e4284 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_service.h +++ b/services/security_component_service/sa/sa_main/sec_comp_service.h @@ -79,6 +79,8 @@ private: bool GetCallerInfo(SecCompCallerInfo& caller); bool IsMediaLibraryCalling(); + std::mutex secCompSrvMutex_; + std::mutex mediaLibMutex_; ServiceRunningState state_; sptr iAppMgr_; sptr appStateObserver_;