diff --git a/services/miscdevice_service/include/vibration_priority_manager.h b/services/miscdevice_service/include/vibration_priority_manager.h index 3f5bd436bf068a272db94ee3283a5b767e207368..f727f86ce172f66aa9c6c2f1e415d639d3d85051 100644 --- a/services/miscdevice_service/include/vibration_priority_manager.h +++ b/services/miscdevice_service/include/vibration_priority_manager.h @@ -135,6 +135,7 @@ private: std::vector doNotDisturbWhiteList_; sptr currentUserObserver_; std::mutex currentUserObserverMutex_; + std::mutex whiteListMutex_; #endif // OHOS_BUILD_ENABLE_DO_NOT_DISTURB #ifdef OHOS_BUILD_ENABLE_VIBRATOR_CROWN std::atomic_int32_t miscCrownFeedback_ = FEEDBACK_MODE_INVALID; diff --git a/services/miscdevice_service/src/vibration_priority_manager.cpp b/services/miscdevice_service/src/vibration_priority_manager.cpp index 2cada5a0190a75263953a46e28cd7590d4c93120..865fb5ffe368541ad0e3d1da557bf34dcb1e8bc2 100644 --- a/services/miscdevice_service/src/vibration_priority_manager.cpp +++ b/services/miscdevice_service/src/vibration_priority_manager.cpp @@ -151,6 +151,7 @@ void VibrationPriorityManager::InitDoNotDisturbData() doNotDisturbSwitch_ = switchTemp; MISC_HILOGI("doNotDisturbSwitch:%{public}d", switchTemp); } + std::lock_guard whiteListLock(whiteListMutex_); if (doNotDisturbSwitch_ == DONOTDISTURB_SWITCH_ON) { std::vector whiteListTemp; int32_t whiteListRet = GetWhiteListValue(DO_NOT_DISTURB_WHITE_LIST, whiteListTemp); @@ -443,6 +444,7 @@ bool VibrationPriorityManager::IgnoreAppVibrations(const VibrateInfo &vibrateInf MISC_HILOGD("DoNotDisturbSwitch is off"); return false; } + std::lock_guard whiteListLock(whiteListMutex_); for (const WhiteListAppInfo &whiteListAppInfo : doNotDisturbWhiteList_) { if (vibrateInfo.packageName == whiteListAppInfo.bundle) { MISC_HILOGD("Not ignore app vibration, the app is on the whitelist, bundleName::%{public}s", diff --git a/utils/common/src/file_utils.cpp b/utils/common/src/file_utils.cpp index 78419ef27dea35150a1778e5fbc700fcd5ea0ea6..fff2eacc41fa6d20e4977c3e3dc98ebaefb379ec 100755 --- a/utils/common/src/file_utils.cpp +++ b/utils/common/src/file_utils.cpp @@ -187,16 +187,23 @@ std::string ReadFd(const RawFileDescriptor &rawFd) int64_t fdSize = GetFileSize(rawFd.fd); if ((rawFd.offset < 0) || (rawFd.offset > fdSize)) { MISC_HILOGE("offset is invalid, offset:%{public}" PRId64, rawFd.offset); - close(rawFd.fd); return {}; } if ((rawFd.length <= 0) || (rawFd.length > fdSize - rawFd.offset)) { MISC_HILOGE("length is invalid, length:%{public}" PRId64, rawFd.length); - close(rawFd.fd); return {}; } - FILE *fp = fdopen(rawFd.fd, "r"); - CHKPS(fp); + int dupFd = dup(rawFd.fd); + if (dupFd < 0) { + MISC_HILOGE("dup fd failed, fd:%{public}d, errno:%{public}d", rawFd.fd, errno); + return {}; + } + FILE *fp = fdopen(dupFd, "r"); + if (fp == nullptr) { + MISC_HILOGE("fdopen failed, fd:%{public}d, errno:%{public}d", dupFd, errno); + close(dupFd); + return {}; + } if (fseek(fp, rawFd.offset, SEEK_SET) != 0) { MISC_HILOGE("fseek failed, errno:%{public}d", errno); if (fclose(fp) != 0) {