add mutex

Signed-off-by: BaoYang <baoyang9@h-partners.com>
Change-Id: Ifb6873fa0f98d6191f2b0f3e62d138e475afc751
This commit is contained in:
BaoYang
2025-11-03 22:23:04 +08:00
parent b7c8c7897f
commit 248c0b583e
6 changed files with 11 additions and 0 deletions
@@ -41,6 +41,7 @@ public:
void OnDialogClosed(int32_t result) override;
private:
std::mutex callbackMutex_;
OnFirstUseDialogCloseFunc callback_;
};
} // namespace SecurityComponent
@@ -25,6 +25,7 @@ static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
void SecCompDialogCallback::OnDialogClosed(int32_t result)
{
std::unique_lock<std::mutex> lock(callbackMutex_);
if (callback_ == nullptr) {
SC_LOG_ERROR(LABEL, "callback_ is nullptr");
return;
@@ -539,6 +539,7 @@ static void ReportEvent(std::string eventName, HiviewDFX::HiSysEvent::EventType
void SecCompManager::GetFoldOffsetY(const CrossAxisState crossAxisState)
{
std::unique_lock<std::mutex> lock(superFoldOffsetMtx_);
if (crossAxisState == CrossAxisState::STATE_INVALID) {
return;
}
@@ -90,6 +90,7 @@ private:
OHOS::Utils::RWLock componentInfoLock_;
std::mutex scIdMtx_;
std::mutex superFoldOffsetMtx_;
std::unordered_map<int32_t, ProcessCompInfos> componentMap_;
int32_t scIdStart_;
bool isSaExit_ = false;
@@ -95,6 +95,7 @@ void SecCompService::OnStop()
bool SecCompService::RegisterAppStateObserver()
{
std::unique_lock<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::u16string>& args)
dprintf(fd, " -p: dump foreground processes\n");
} else if (arg0.compare("-p") == 0) {
std::string dumpStr;
std::unique_lock<std::mutex> lock(secCompSrvMutex_);
appStateObserver_->DumpProcess(dumpStr);
dprintf(fd, "%s\n", dumpStr.c_str());
} else if (arg0.compare("-a") == 0 || arg0 == "") {
@@ -79,6 +79,8 @@ private:
bool GetCallerInfo(SecCompCallerInfo& caller);
bool IsMediaLibraryCalling();
std::mutex secCompSrvMutex_;
std::mutex mediaLibMutex_;
ServiceRunningState state_;
sptr<AppExecFwk::IAppMgr> iAppMgr_;
sptr<AppStateObserver> appStateObserver_;