From 82393558f4c20411a164d50582e796307baa2c3c Mon Sep 17 00:00:00 2001 From: songshenke Date: Mon, 28 Apr 2025 09:48:37 +0000 Subject: [PATCH] Add log for AlarmTone Signed-off-by: songshenke Change-Id: Ic3284a9af84002a70676efe3677668dea9797a9f --- .../audio_haptic/audio_haptic_player_impl.cpp | 2 +- .../system_sound_manager_impl.cpp | 44 ++++++++++++------- .../system_sound_manager_impl.h | 2 + .../system_sound_manager_utils.cpp | 23 ++++++++++ .../system_sound_manager_utils.h | 1 + .../system_sound_vibrator.cpp | 1 + .../system_tone_player_impl.cpp | 8 ++-- 7 files changed, 62 insertions(+), 19 deletions(-) diff --git a/frameworks/native/audio_haptic/audio_haptic_player_impl.cpp b/frameworks/native/audio_haptic/audio_haptic_player_impl.cpp index 8599b145d..54a1cf891 100644 --- a/frameworks/native/audio_haptic/audio_haptic_player_impl.cpp +++ b/frameworks/native/audio_haptic/audio_haptic_player_impl.cpp @@ -164,7 +164,7 @@ int32_t AudioHapticPlayerImpl::Start() result = audioHapticSound_->StartSound(); SendHapticPlayerEvent(MSERR_OK, "START_HAPTIC_PLAYER"); CHECK_AND_RETURN_RET_LOG(result == MSERR_OK, result, "Failed to start sound."); - + MEDIA_LOGW("StartSound() has been executed successfully!"); playerState_ = AudioHapticPlayerState::STATE_RUNNING; return result; } diff --git a/frameworks/native/system_sound_manager/system_sound_manager_impl.cpp b/frameworks/native/system_sound_manager/system_sound_manager_impl.cpp index f39670742..876aa7ba7 100644 --- a/frameworks/native/system_sound_manager/system_sound_manager_impl.cpp +++ b/frameworks/native/system_sound_manager/system_sound_manager_impl.cpp @@ -1388,6 +1388,8 @@ int32_t SystemSoundManagerImpl::SetAlarmToneUri(const std::shared_ptr lock(uriMutex_); + MEDIA_LOGI("SetAlarmToneUri: alarm type %{public}s", + SystemSoundManagerUtils::GetTypeForSystemSoundUri(uri).c_str()); std::shared_ptr dataShareHelper = SystemSoundManagerUtils::CreateDataShareHelper(STORAGE_MANAGER_MANAGER_ID); CHECK_AND_RETURN_RET_LOG(dataShareHelper != nullptr, ERROR, "Create dataShare failed."); @@ -1399,6 +1401,7 @@ int32_t SystemSoundManagerImpl::SetAlarmToneUri(const std::shared_ptr>(move(resultSetByUri)); unique_ptr ringtoneAssetByUri = resultsByUri->GetFirstObject(); if (ringtoneAssetByUri == nullptr) { + MEDIA_LOGE("Failed to find uri in ringtone library. The input uri is invalid!"); resultSetByUri == nullptr ? : resultSetByUri->Close(); dataShareHelper->Release(); return ERROR; @@ -1413,30 +1416,39 @@ int32_t SystemSoundManagerImpl::SetAlarmToneUri(const std::shared_ptrGetNextObject(); } if (ringtoneAsset != nullptr) { - DataSharePredicates updateOldPredicates; - DataShareValuesBucket updateOldValuesBucket; - updateOldPredicates.SetWhereClause(RINGTONE_COLUMN_ALARM_TONE_SOURCE_TYPE + " = ? "); - updateOldPredicates.SetWhereArgs({to_string(SOURCE_TYPE_CUSTOMISED)}); - updateOldValuesBucket.Put(RINGTONE_COLUMN_ALARM_TONE_TYPE, ALARM_TONE_TYPE_NOT); - updateOldValuesBucket.Put(RINGTONE_COLUMN_ALARM_TONE_SOURCE_TYPE, SOURCE_TYPE_INVALID); - dataShareHelper->Update(RINGTONEURI, updateOldPredicates, updateOldValuesBucket); - DataSharePredicates updatePredicates; - DataShareValuesBucket updateValuesBucket; - updatePredicates.SetWhereClause(RINGTONE_COLUMN_TONE_ID + " = ? "); - updatePredicates.SetWhereArgs({to_string(ringtoneAsset->GetId())}); - updateValuesBucket.Put(RINGTONE_COLUMN_ALARM_TONE_TYPE, ALARM_TONE_TYPE); - updateValuesBucket.Put(RINGTONE_COLUMN_ALARM_TONE_SOURCE_TYPE, SOURCE_TYPE_CUSTOMISED); - int32_t changedRows = dataShareHelper->Update(RINGTONEURI, updatePredicates, updateValuesBucket); + int32_t changedRows = UpdataeAlarmToneUri(dataShareHelper, ringtoneAsset->GetId()); resultSet == nullptr ? : resultSet->Close(); dataShareHelper->Release(); SetExtRingtoneUri(uri, ringtoneAsset->GetTitle(), TONE_TYPE_ALARM, TONE_TYPE_ALARM, changedRows); return changedRows > 0 ? SUCCESS : ERROR; } + MEDIA_LOGE("Failed to find uri in ringtone library!"); resultSet == nullptr ? : resultSet->Close(); dataShareHelper->Release(); return TYPEERROR; } +int32_t SystemSoundManagerImpl::UpdataeAlarmToneUri( + const std::shared_ptr dataShareHelper, const int32_t ringtoneAssetId) +{ + DataSharePredicates updateOldPredicates; + DataShareValuesBucket updateOldValuesBucket; + updateOldPredicates.SetWhereClause(RINGTONE_COLUMN_ALARM_TONE_SOURCE_TYPE + " = ? "); + updateOldPredicates.SetWhereArgs({to_string(SOURCE_TYPE_CUSTOMISED)}); + updateOldValuesBucket.Put(RINGTONE_COLUMN_ALARM_TONE_TYPE, ALARM_TONE_TYPE_NOT); + updateOldValuesBucket.Put(RINGTONE_COLUMN_ALARM_TONE_SOURCE_TYPE, SOURCE_TYPE_INVALID); + dataShareHelper->Update(RINGTONEURI, updateOldPredicates, updateOldValuesBucket); + DataSharePredicates updatePredicates; + DataShareValuesBucket updateValuesBucket; + updatePredicates.SetWhereClause(RINGTONE_COLUMN_TONE_ID + " = ? "); + updatePredicates.SetWhereArgs({to_string(ringtoneAssetId)}); + updateValuesBucket.Put(RINGTONE_COLUMN_ALARM_TONE_TYPE, ALARM_TONE_TYPE); + updateValuesBucket.Put(RINGTONE_COLUMN_ALARM_TONE_SOURCE_TYPE, SOURCE_TYPE_CUSTOMISED); + int32_t changedRows = dataShareHelper->Update(RINGTONEURI, updatePredicates, updateValuesBucket); + MEDIA_LOGI("UpdataeAlarmToneUri: result(changedRows) %{public}d", changedRows); + return changedRows; +} + std::string SystemSoundManagerImpl::GetAlarmToneUri(const std::shared_ptr &context) { int32_t count = 2; @@ -1456,7 +1468,7 @@ std::string SystemSoundManagerImpl::GetAlarmToneUri(const std::shared_ptrGetPath(); + MEDIA_LOGI("GetAlarmToneUri: alarm type %{public}s", + SystemSoundManagerUtils::GetTypeForSystemSoundUri(alarmToneUri).c_str()); } else { MEDIA_LOGE("GetAlarmToneUri: no alarmtone in the ringtone library!"); } diff --git a/frameworks/native/system_sound_manager/system_sound_manager_impl.h b/frameworks/native/system_sound_manager/system_sound_manager_impl.h index 29bf5763a..3182c990b 100644 --- a/frameworks/native/system_sound_manager/system_sound_manager_impl.h +++ b/frameworks/native/system_sound_manager/system_sound_manager_impl.h @@ -175,6 +175,8 @@ private: SystemToneType systemToneType, const int32_t &num); int32_t UpdateNotificatioToneUri(std::shared_ptr dataShareHelper, const int32_t &toneId); + int32_t UpdataeAlarmToneUri(const std::shared_ptr dataShareHelper, + const int32_t ringtoneAssetId); int32_t SetNoSystemToneUri(std::shared_ptr dataShareHelper, SystemToneType systemToneType); int32_t RemoveSourceTypeForSystemTone(std::shared_ptr dataShareHelper, diff --git a/frameworks/native/system_sound_manager/system_sound_manager_utils.cpp b/frameworks/native/system_sound_manager/system_sound_manager_utils.cpp index f4d375ae9..41e83d98a 100644 --- a/frameworks/native/system_sound_manager/system_sound_manager_utils.cpp +++ b/frameworks/native/system_sound_manager/system_sound_manager_utils.cpp @@ -172,5 +172,28 @@ bool SystemSoundManagerUtils::GetScannerFirstParameter(const char* key, int32_t } return false; } + +std::string SystemSoundManagerUtils::GetTypeForSystemSoundUri(const std::string &uri) +{ + if (uri == NO_SYSTEM_SOUND) { + return NO_SYSTEM_SOUND; + } + if (uri == NO_RING_SOUND) { + return NO_RING_SOUND; + } + + size_t pos = uri.find_first_of("sys_prod"); + if (pos == 0 || pos == 1) { + // The uri of a preset ringtone starts with "sys_prod" or "/sys_prod". + return "pre_installed"; + } + pos = uri.find_first_of("data"); + if (pos == 0 || pos == 1) { + // The uri of a custom ringtone starts with "data" or "/data". + return "customised"; + } + + return "unknown"; +} } // namesapce Media } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/system_sound_manager/system_sound_manager_utils.h b/frameworks/native/system_sound_manager/system_sound_manager_utils.h index c4b12d11f..cec47f887 100644 --- a/frameworks/native/system_sound_manager/system_sound_manager_utils.h +++ b/frameworks/native/system_sound_manager/system_sound_manager_utils.h @@ -37,6 +37,7 @@ public: static bool IdExists(const std::string &ids, int32_t id); static bool CheckCurrentUser(); static bool GetScannerFirstParameter(const char* key, int32_t maxSize); + static std::string GetTypeForSystemSoundUri(const std::string &uri); }; } // namespace Media } // namespace OHOS diff --git a/frameworks/native/system_sound_manager/system_sound_vibrator/system_sound_vibrator.cpp b/frameworks/native/system_sound_manager/system_sound_vibrator/system_sound_vibrator.cpp index 4710357fa..543f62f5a 100644 --- a/frameworks/native/system_sound_manager/system_sound_vibrator/system_sound_vibrator.cpp +++ b/frameworks/native/system_sound_manager/system_sound_vibrator/system_sound_vibrator.cpp @@ -108,6 +108,7 @@ int32_t SystemSoundVibrator::StartVibratorForSystemTone(const std::string &hapti Sensors::SetUsage(USAGE_NOTIFICATION); Sensors::SetLoopCount(1); result = Sensors::PlayVibratorCustom(fd, 0, statbuf.st_size); + MEDIA_LOGW("Start vibrator: PlayVibratorCustom result [%{public}d]", result); close(fd); #endif diff --git a/frameworks/native/system_sound_manager/system_tone_player/system_tone_player_impl.cpp b/frameworks/native/system_sound_manager/system_tone_player/system_tone_player_impl.cpp index f6c68bcf5..0cb8e3f77 100644 --- a/frameworks/native/system_sound_manager/system_tone_player/system_tone_player_impl.cpp +++ b/frameworks/native/system_sound_manager/system_tone_player/system_tone_player_impl.cpp @@ -157,7 +157,8 @@ bool SystemTonePlayerImpl::IsSameHapticMaps(const std::map lock(systemTonePlayerMutex_); CHECK_AND_RETURN_RET_LOG(systemToneState_ != SystemToneState::STATE_RELEASED, MSERR_INVALID_STATE, @@ -411,6 +412,7 @@ int32_t SystemTonePlayerImpl::Start(const SystemToneOptions &systemToneOptions) bool actualMuteHaptics = ringerModeOptions.muteHaptics || systemToneOptions.muteHaptics || isHapticUriEmpty_ || isNoneHaptics_; if (actualMuteAudio) { + MEDIA_LOGW("The audio of system tone player is muted!"); int32_t delayTime = DEFAULT_DELAY; // the audio of system tone player has been muted. Only start vibrator. if (!actualMuteHaptics) { @@ -446,7 +448,7 @@ int32_t SystemTonePlayerImpl::Start(const SystemToneOptions &systemToneOptions) int32_t SystemTonePlayerImpl::Stop(const int32_t &streamId) { - MEDIA_LOGI("Enter Stop() with streamId %{public}d", streamId); + MEDIA_LOGW("Enter Stop() with streamId %{public}d", streamId); std::lock_guard lock(systemTonePlayerMutex_); CHECK_AND_RETURN_RET_LOG(systemToneState_ != SystemToneState::STATE_RELEASED, MSERR_INVALID_STATE, "System tone player has been released!"); -- Gitee