diff --git a/services/native/src/runninglock/running_lock_mgr.cpp b/services/native/src/runninglock/running_lock_mgr.cpp index 504c05a225deaa2115bc673224b251238d13e946..9b4e57f6db65999fb2a185220540be6afb64358f 100644 --- a/services/native/src/runninglock/running_lock_mgr.cpp +++ b/services/native/src/runninglock/running_lock_mgr.cpp @@ -42,6 +42,7 @@ const string TASK_RUNNINGLOCK_FORCEUNLOCK = "RunningLock_ForceUnLock"; constexpr int32_t VALID_PID_LIMIT = 1; sptr g_runningLockCallback = nullptr; const string INCALL_APP_BUNDLE_NAME = "com.ohos.callui"; +const string WECHAT_APP_BUNDLE_NAME = "com.tencent.wechat"; #ifdef HAS_SENSORS_SENSOR_PART constexpr uint32_t FOREGROUND_INCALL_DELAY_TIME_MS = 300; constexpr uint32_t BACKGROUND_INCALL_DELAY_TIME_MS = 800; @@ -935,6 +936,33 @@ void RunningLockMgr::ProximityController::OnAway() runningLock->HandleProximityAwayEvent(); } +bool RunningLockMgr::IsVoiceAppForeground() +{ + if (PowerUtils::IsForegroundApplication(INCALL_APP_BUNDLE_NAME)) { + POWER_HILOGI(FEATURE_RUNNING_LOCK, "call in foreground"); + return true; + } + + if (!PowerUtils::IsForegroundApplication(WECHAT_APP_BUNDLE_NAME)) { + POWER_HILOGI(FEATURE_RUNNING_LOCK, "WeChat is not in foreground"); + return false; + } + + std::lock_guard lock(mutex_); + for (auto& iter : runningLocks_) { + if (iter.second == nullptr) { + POWER_HILOGE(FEATURE_RUNNING_LOCK, "GetRunningLockInnerByName nullptr"); + continue; + } + if (iter.second->GetBundleName() == WECHAT_APP_BUNDLE_NAME && + iter.second->GetType() == RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL) { + POWER_HILOGI(FEATURE_RUNNING_LOCK, "WeChat is in foreground with voicing or calling."); + return true; + } + } + return false; +} + void RunningLockMgr::HandleProximityCloseEvent() { auto pms = DelayedSpSingleton::GetInstance(); @@ -950,7 +978,7 @@ void RunningLockMgr::HandleProximityCloseEvent() if (GetValidRunningLockNum(RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL) > 0) { POWER_HILOGI(FEATURE_RUNNING_LOCK, "Change state to INACITVE when holding PROXIMITY LOCK"); uint32_t delayTime = FOREGROUND_INCALL_DELAY_TIME_MS; - if (!PowerUtils::IsForegroundApplication(INCALL_APP_BUNDLE_NAME)) { + if (!IsVoiceAppForeground()) { delayTime = BACKGROUND_INCALL_DELAY_TIME_MS; } POWER_HILOGI(FEATURE_RUNNING_LOCK, "Start proximity-screen-off timer, delay time:%{public}u", delayTime); diff --git a/services/native/src/runninglock/running_lock_mgr.h b/services/native/src/runninglock/running_lock_mgr.h index ef94ff26b747148bc55fd5f6f930155a7c121037..ca317018253eab96662861308a29c183bbc6c574 100644 --- a/services/native/src/runninglock/running_lock_mgr.h +++ b/services/native/src/runninglock/running_lock_mgr.h @@ -90,6 +90,7 @@ private: bool InitProximityController(); void HandleProximityCloseEvent(); void HandleProximityAwayEvent(); + bool IsVoiceAppForeground(); #endif class LockCounter {