From 57ebc93fe600a15c689cfbdda3a7b34750384ee8 Mon Sep 17 00:00:00 2001 From: songshenke Date: Sat, 2 Aug 2025 13:42:26 +0000 Subject: [PATCH] Fix the code formatting issues Signed-off-by: songshenke Change-Id: Ib4ffe14e3c85aa73835235b8072255878e4b9a4a --- .../include/audio_system_manager.h | 126 +++++++++--------- .../src/audio_background_manager.cpp | 118 ++++++++-------- 2 files changed, 124 insertions(+), 120 deletions(-) diff --git a/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h b/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h index 9085892ca7..efa2fd157c 100644 --- a/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h +++ b/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h @@ -1147,23 +1147,23 @@ public: int32_t InjectInterruption(const std::string networkId, InterruptEvent &event); /** - * @brief Load the split module for audio stream separation. - * - * @param splitArgs Specifies the types of audio to be split into different streams. - * @param networkId The network identifier of the output device. - * @return Returns {@link SUCCESS} if the module is loaded successfully; otherwise, returns an error code defined - * in {@link audio_errors.h}. - * @since 12 - */ + * @brief Load the split module for audio stream separation. + * + * @param splitArgs Specifies the types of audio to be split into different streams. + * @param networkId The network identifier of the output device. + * @return Returns {@link SUCCESS} if the module is loaded successfully; otherwise, returns an error code defined + * in {@link audio_errors.h}. + * @since 12 + */ int32_t LoadSplitModule(const std::string &splitArgs, const std::string &networkId); /** - * @brief Set Custmoized Ring Back Tone mute state. - * - * @param isMute Specifies whether the Customized Ring Back Tone is muted. - * @return Returns {@link SUCCESS} if the settings is successfully; otherwise, returns an error code defined - * in {@link audio_errors.h}. - */ + * @brief Set Custmoized Ring Back Tone mute state. + * + * @param isMute Specifies whether the Customized Ring Back Tone is muted. + * @return Returns {@link SUCCESS} if the settings is successfully; otherwise, returns an error code defined + * in {@link audio_errors.h}. + */ int32_t SetVoiceRingtoneMute(bool isMute); /** @@ -1177,54 +1177,54 @@ public: int32_t SetForegroundList(std::vector list); /** - * @brief Get standby state. - * - * @param sessionId Specifies which stream to be check. - * @param isStandby true means the stream is in standby status. - * @param enterStandbyTime Specifies when the stream enter standby status, in MONOTONIC time. - * @return Returns {@link SUCCESS} if the operation is successfully. - * @return Returns {@link ERR_ILLEGAL_STATE} if the server is not available. - * @return Returns {@link ERR_INVALID_PARAM} if the sessionId is not exist. - */ + * @brief Get standby state. + * + * @param sessionId Specifies which stream to be check. + * @param isStandby true means the stream is in standby status. + * @param enterStandbyTime Specifies when the stream enter standby status, in MONOTONIC time. + * @return Returns {@link SUCCESS} if the operation is successfully. + * @return Returns {@link ERR_ILLEGAL_STATE} if the server is not available. + * @return Returns {@link ERR_INVALID_PARAM} if the sessionId is not exist. + */ int32_t GetStandbyStatus(uint32_t sessionId, bool &isStandby, int64_t &enterStandbyTime); /** - * @brief Set App AVSession state change. - * - * @param uid Specifies uid of app. - * @param pid Specifies pid of app. - * @param hasSession Specifies whether app has AVSession. - * @return Returns {@link SUCCESS} if the settings is successfully; otherwise, returns an error code defined - * in {@link audio_errors.h}. - */ + * @brief Set App AVSession state change. + * + * @param uid Specifies uid of app. + * @param pid Specifies pid of app. + * @param hasSession Specifies whether app has AVSession. + * @return Returns {@link SUCCESS} if the settings is successfully; otherwise, returns an error code defined + * in {@link audio_errors.h}. + */ int32_t NotifySessionStateChange(const int32_t uid, const int32_t pid, const bool hasSession); /** - * @brief Set App Freeze state change. - * - * @param pidList Specifies all pid list to change state. - * @param isFreeze Specifies Freeze or Unfreeze state. - * @return Returns {@link SUCCESS} if the settings is successfully; otherwise, returns an error code defined - * in {@link audio_errors.h}. - */ + * @brief Set App Freeze state change. + * + * @param pidList Specifies all pid list to change state. + * @param isFreeze Specifies Freeze or Unfreeze state. + * @return Returns {@link SUCCESS} if the settings is successfully; otherwise, returns an error code defined + * in {@link audio_errors.h}. + */ int32_t NotifyFreezeStateChange(const std::set &pidList, const bool isFreeze); /** - * @brief RSS reboot reset all proxy Freeze state change. - * - * @return Returns {@link SUCCESS} if the settings is successfully; otherwise, returns an error code defined - * in {@link audio_errors.h}. - */ + * @brief RSS reboot reset all proxy Freeze state change. + * + * @return Returns {@link SUCCESS} if the settings is successfully; otherwise, returns an error code defined + * in {@link audio_errors.h}. + */ int32_t ResetAllProxy(); /** - * @brief Notify process background state. - * - * @param uid Specifies uid of app. - * @param pid Specifies pid of app. - * @return Returns {@link SUCCESS} if the settings is successfully; otherwise, returns an error code defined - * in {@link audio_errors.h}. - */ + * @brief Notify process background state. + * + * @param uid Specifies uid of app. + * @param pid Specifies pid of app. + * @return Returns {@link SUCCESS} if the settings is successfully; otherwise, returns an error code defined + * in {@link audio_errors.h}. + */ int32_t NotifyProcessBackgroundState(const int32_t uid, const int32_t pid); /** @@ -1239,22 +1239,22 @@ public: #ifdef HAS_FEATURE_INNERCAPTURER /** - * @brief check capture limit - * - * @param AudioPlaybackCaptureConfig inner capture filter info - * @param innerCapId unique identifier of inner capture - * @return Returns {@link SUCCESS} if the operation is successfully. - * @test - */ + * @brief check capture limit + * + * @param AudioPlaybackCaptureConfig inner capture filter info + * @param innerCapId unique identifier of inner capture + * @return Returns {@link SUCCESS} if the operation is successfully. + * @test + */ int32_t CheckCaptureLimit(const AudioPlaybackCaptureConfig &config, int32_t &innerCapId); /** - * @brief release capture limit - * - * @param innerCapId unique identifier of inner capture - * @return Returns {@link SUCCESS} if the operation is successfully. - * @test - */ + * @brief release capture limit + * + * @param innerCapId unique identifier of inner capture + * @return Returns {@link SUCCESS} if the operation is successfully. + * @test + */ int32_t ReleaseCaptureLimit(int32_t innerCapId); #endif diff --git a/services/audio_policy/server/infra/appclient/src/audio_background_manager.cpp b/services/audio_policy/server/infra/appclient/src/audio_background_manager.cpp index a900b37920..97d606bd81 100644 --- a/services/audio_policy/server/infra/appclient/src/audio_background_manager.cpp +++ b/services/audio_policy/server/infra/appclient/src/audio_background_manager.cpp @@ -74,19 +74,20 @@ bool AudioBackgroundManager::IsAllowedPlayback(const int32_t &uid, const int32_t AUDIO_INFO_LOG("appStatesMap_ start pid: %{public}d with hasSession: %{public}d, isBack: %{public}d, " "hasBackgroundTask: %{public}d, isFreeze: %{public}d", pid, appState.hasSession, appState.isBack, appState.hasBackTask, appState.isFreeze); - if (appState.isBack) { - bool mute = appState.hasBackTask ? false : (appState.isBinder ? true : false); - if (!appState.hasSession) { - // for media - HandleSessionStateChange(uid, pid); - // for others - streamCollector_.HandleStartStreamMuteState(uid, pid, mute, true); - } else { - streamCollector_.HandleStartStreamMuteState(uid, pid, mute, false); - } - } else { + + if (!appState.isBack) { streamCollector_.HandleStartStreamMuteState(uid, pid, false, false); + return true; } + bool mute = appState.hasBackTask ? false : (appState.isBinder ? true : false); + if (appState.hasSession) { + streamCollector_.HandleStartStreamMuteState(uid, pid, mute, false); + return true; + } + // for media + HandleSessionStateChange(uid, pid); + // for others + streamCollector_.HandleStartStreamMuteState(uid, pid, mute, true); return true; } @@ -100,31 +101,32 @@ void AudioBackgroundManager::NotifyAppStateChange(const int32_t uid, const int32 AppState appState; appState.isBack = isBack; InsertIntoAppStatesMap(pid, appState); - } else { - bool notifyMute = false; - { - std::lock_guard lock(appStatesMapMutex_); - AppState &appState = appStatesMap_[pid]; - CHECK_AND_RETURN(appState.isBack != isBack); - appState.isBack = isBack; - appState.isFreeze = isBack ? appState.isFreeze : false; - appState.isBinder = isBack ? appState.isBinder : false; - AUDIO_INFO_LOG("appStatesMap_ change pid: %{public}d with hasSession: %{public}d, isBack: %{public}d, " - "hasBackgroundTask: %{public}d, isFreeze: %{public}d", pid, appState.hasSession, appState.isBack, - appState.hasBackTask, appState.isFreeze); - if (!isBack) { - return streamCollector_.HandleForegroundUnmute(uid, pid); - } - bool needMute = !appState.hasSession && appState.isBack && !CheckoutSystemAppUtil::CheckoutSystemApp(uid); - streamCollector_.HandleAppStateChange(uid, pid, needMute, notifyMute, appState.hasBackTask); - streamCollector_.HandleKaraokeAppToBack(uid, pid); - } - if (notifyMute && !VolumeUtils::IsPCVolumeEnable()) { - lock_guard lock(g_backgroundMuteListenerMutex); - CHECK_AND_RETURN_LOG(backgroundMuteListener_ != nullptr, "backgroundMuteListener_ is nulptr"); - AUDIO_INFO_LOG("OnBackground with uid: %{public}d", uid); - backgroundMuteListener_->OnBackgroundMute(uid); + return; + } + + bool notifyMute = false; + { + std::lock_guard lock(appStatesMapMutex_); + AppState &appState = appStatesMap_[pid]; + CHECK_AND_RETURN(appState.isBack != isBack); + appState.isBack = isBack; + appState.isFreeze = isBack ? appState.isFreeze : false; + appState.isBinder = isBack ? appState.isBinder : false; + AUDIO_INFO_LOG("appStatesMap_ change pid: %{public}d with hasSession: %{public}d, isBack: %{public}d, " + "hasBackgroundTask: %{public}d, isFreeze: %{public}d", pid, appState.hasSession, appState.isBack, + appState.hasBackTask, appState.isFreeze); + if (!isBack) { + return streamCollector_.HandleForegroundUnmute(uid, pid); } + bool needMute = !appState.hasSession && appState.isBack && !CheckoutSystemAppUtil::CheckoutSystemApp(uid); + streamCollector_.HandleAppStateChange(uid, pid, needMute, notifyMute, appState.hasBackTask); + streamCollector_.HandleKaraokeAppToBack(uid, pid); + } + if (notifyMute && !VolumeUtils::IsPCVolumeEnable()) { + lock_guard lock(g_backgroundMuteListenerMutex); + CHECK_AND_RETURN_LOG(backgroundMuteListener_ != nullptr, "backgroundMuteListener_ is nulptr"); + AUDIO_INFO_LOG("OnBackground with uid: %{public}d", uid); + backgroundMuteListener_->OnBackgroundMute(uid); } } @@ -134,17 +136,18 @@ void AudioBackgroundManager::NotifyBackgroundTaskStateChange(const int32_t uid, AppState appState; appState.hasBackTask = hasBackgroundTask; InsertIntoAppStatesMap(pid, appState); - } else { - std::lock_guard lock(appStatesMapMutex_); - AppState &appState = appStatesMap_[pid]; - CHECK_AND_RETURN(appState.hasBackTask != hasBackgroundTask); - appState.hasBackTask = hasBackgroundTask; - AUDIO_INFO_LOG("appStatesMap_ change pid: %{public}d with hasSession: %{public}d, isBack: %{public}d, " - "hasBackgroundTask: %{public}d, isFreeze: %{public}d", pid, appState.hasSession, appState.isBack, - appState.hasBackTask, appState.isFreeze); - if (appState.hasBackTask && !appState.isFreeze) { - streamCollector_.HandleBackTaskStateChange(uid, appState.hasSession); - } + return; + } + + std::lock_guard lock(appStatesMapMutex_); + AppState &appState = appStatesMap_[pid]; + CHECK_AND_RETURN(appState.hasBackTask != hasBackgroundTask); + appState.hasBackTask = hasBackgroundTask; + AUDIO_INFO_LOG("appStatesMap_ change pid: %{public}d with hasSession: %{public}d, isBack: %{public}d, " + "hasBackgroundTask: %{public}d, isFreeze: %{public}d", pid, appState.hasSession, appState.isBack, + appState.hasBackTask, appState.isFreeze); + if (appState.hasBackTask && !appState.isFreeze) { + streamCollector_.HandleBackTaskStateChange(uid, appState.hasSession); } } @@ -154,16 +157,17 @@ int32_t AudioBackgroundManager::NotifySessionStateChange(const int32_t uid, cons AppState appState; appState.hasSession = hasSession; InsertIntoAppStatesMap(pid, appState); - } else { - std::lock_guard lock(appStatesMapMutex_); - AppState &appState = appStatesMap_[pid]; - CHECK_AND_RETURN_RET(appState.hasSession != hasSession, SUCCESS); - appState.hasSession = hasSession; - AUDIO_INFO_LOG("appStatesMap_ change pid: %{public}d with hasSession: %{public}d, isBack: %{public}d, " - "hasBackgroundTask: %{public}d, isFreeze: %{public}d", pid, appState.hasSession, appState.isBack, - appState.hasBackTask, appState.isFreeze); - HandleSessionStateChange(uid, pid); + return SUCCESS; } + + std::lock_guard lock(appStatesMapMutex_); + AppState &appState = appStatesMap_[pid]; + CHECK_AND_RETURN_RET(appState.hasSession != hasSession, SUCCESS); + appState.hasSession = hasSession; + AUDIO_INFO_LOG("appStatesMap_ change pid: %{public}d with hasSession: %{public}d, isBack: %{public}d, " + "hasBackgroundTask: %{public}d, isFreeze: %{public}d", pid, appState.hasSession, appState.isBack, + appState.hasBackTask, appState.isFreeze); + HandleSessionStateChange(uid, pid); return SUCCESS; } @@ -254,5 +258,5 @@ bool AudioBackgroundManager::FindKeyInMap(int32_t pid) std::lock_guard lock(appStatesMapMutex_); return appStatesMap_.find(pid) != appStatesMap_.end(); } -} -} +} // namespace AudioStandard +} // namespace OHOS -- Gitee