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 af429e1e46dbea272d038edc83b07254efdbc2e6..9a4cb29e811e84691d5d3eae9c7d9b1035441a33 100644 --- a/frameworks/native/system_sound_manager/system_sound_manager_impl.cpp +++ b/frameworks/native/system_sound_manager/system_sound_manager_impl.cpp @@ -1113,9 +1113,16 @@ int32_t SystemSoundManagerImpl::SetSystemToneUri(const shared_ptr &cont std::string SystemSoundManagerImpl::GetShotToneUriByType(const DatabaseTool &databaseTool, const std::string &type) { + MEDIA_LOGI("Enter the GetShotToneUriByType interface."); + ToneAttrs toneAttrs = GetShotToneAttrsByType(databaseTool, type); + return toneAttrs.GetUri(); +} +ToneAttrs SystemSoundManagerImpl::GetShotToneAttrsByType(const DatabaseTool &databaseTool, const std::string &type) +{ + ToneAttrs toneAttrs = { "", "", "", CUSTOMISED, TONE_CATEGORY_TEXT_MESSAGE }; if (!databaseTool.isInitialized || databaseTool.dataShareHelper == nullptr) { MEDIA_LOGE("The database tool is not ready!"); - return ""; + return toneAttrs; } std::string uri = ""; @@ -1134,22 +1141,40 @@ std::string SystemSoundManagerImpl::GetShotToneUriByType(const DatabaseTool &dat } Uri queryUri(ringtoneLibraryUri); auto resultSet = databaseTool.dataShareHelper->Query(queryUri, queryPredicates, COLUMNS, &businessError); + MEDIA_LOGI("dataShareHelper->Query: errCode %{public}d", businessError.GetCode()); auto results = make_unique>(move(resultSet)); - CHECK_AND_RETURN_RET_LOG(results != nullptr, uri, "query failed, ringtone library error."); + CHECK_AND_RETURN_RET_LOG(results != nullptr, toneAttrs, "query failed, ringtone library error."); unique_ptr ringtoneAsset = results->GetFirstObject(); if (ringtoneAsset != nullptr) { - uri = ringtoneAsset->GetPath(); + toneAttrs.SetCategory(ringtoneAsset->GetToneType()); + toneAttrs.SetFileName(ringtoneAsset->GetDisplayName()); + toneAttrs.SetTitle(ringtoneAsset->GetTitle()); + toneAttrs.SetUri(ringtoneAsset->GetPath()); + if (ringtoneAsset->GetMediaType() == RINGTONE_MEDIA_TYPE_VIDEO) { + toneAttrs.SetMediaType(ToneMediaType::MEDIA_TYPE_VID); + } else { + toneAttrs.SetMediaType(ToneMediaType::MEDIA_TYPE_AUD); + } } resultSet == nullptr ? : resultSet->Close(); - return uri; + return toneAttrs; } std::string SystemSoundManagerImpl::GetPresetShotToneUriByType(const DatabaseTool &databaseTool, const std::string &type) { + MEDIA_LOGI("Enter the GetPresetShotToneUriByType interface."); + ToneAttrs toneAttrs = GetPresetShotToneAttrsByType(databaseTool, type); + return toneAttrs.GetUri(); +} + +ToneAttrs SystemSoundManagerImpl::GetPresetShotToneAttrsByType(const DatabaseTool &databaseTool, + const std::string &type) +{ + ToneAttrs toneAttrs = { "", "", "", CUSTOMISED, TONE_CATEGORY_TEXT_MESSAGE}; if (!databaseTool.isInitialized || databaseTool.dataShareHelper == nullptr) { MEDIA_LOGE("The database tool is not ready!"); - return ""; + return toneAttrs; } std::string uri = ""; @@ -1168,21 +1193,38 @@ std::string SystemSoundManagerImpl::GetPresetShotToneUriByType(const DatabaseToo } Uri queryUri(ringtoneLibraryUri); auto resultSet = databaseTool.dataShareHelper->Query(queryUri, queryPredicates, COLUMNS, &businessError); + MEDIA_LOGI("dataShareHelper->Query: errCode %{public}d", businessError.GetCode()); auto results = make_unique>(move(resultSet)); - CHECK_AND_RETURN_RET_LOG(results != nullptr, uri, "query failed, ringtone library error."); + CHECK_AND_RETURN_RET_LOG(results != nullptr, toneAttrs, "query failed, ringtone library error."); unique_ptr ringtoneAsset = results->GetFirstObject(); if (ringtoneAsset != nullptr) { - uri = ringtoneAsset->GetPath(); + toneAttrs.SetUri(ringtoneAsset->GetPath()); + toneAttrs.SetTitle(ringtoneAsset->GetTitle()); + toneAttrs.SetFileName(ringtoneAsset->GetDisplayName()); + toneAttrs.SetCategory(ringtoneAsset->GetToneType()); + if (ringtoneAsset->GetMediaType() == RINGTONE_MEDIA_TYPE_VIDEO) { + toneAttrs.SetMediaType(ToneMediaType::MEDIA_TYPE_VID); + } else { + toneAttrs.SetMediaType(ToneMediaType::MEDIA_TYPE_AUD); + } } resultSet == nullptr ? : resultSet->Close(); - return uri; + return toneAttrs; } std::string SystemSoundManagerImpl::GetNotificationToneUriByType(const DatabaseTool &databaseTool) { + MEDIA_LOGI("Enter the GetNotificationToneUriByType interface."); + ToneAttrs toneAttrs = GetNotificationToneAttrsByType(databaseTool); + return toneAttrs.GetUri(); +} + +ToneAttrs SystemSoundManagerImpl::GetNotificationToneAttrsByType(const DatabaseTool &databaseTool) +{ + ToneAttrs toneAttrs = { "", "", "", CUSTOMISED, TONE_CATEGORY_NOTIFICATION }; if (!databaseTool.isInitialized || databaseTool.dataShareHelper == nullptr) { MEDIA_LOGE("The database tool is not ready!"); - return ""; + return toneAttrs; } std::string uri = ""; @@ -1201,21 +1243,38 @@ std::string SystemSoundManagerImpl::GetNotificationToneUriByType(const DatabaseT } Uri queryUri(ringtoneLibraryUri); auto resultSet = databaseTool.dataShareHelper->Query(queryUri, queryPredicates, COLUMNS, &businessError); + MEDIA_LOGI("dataShareHelper->Query: errCode %{public}d", businessError.GetCode()); auto results = make_unique>(move(resultSet)); - CHECK_AND_RETURN_RET_LOG(results != nullptr, uri, "query failed, ringtone library error."); + CHECK_AND_RETURN_RET_LOG(results != nullptr, toneAttrs, "query failed, ringtone library error."); unique_ptr ringtoneAsset = results->GetFirstObject(); if (ringtoneAsset != nullptr) { - uri = ringtoneAsset->GetPath(); + toneAttrs.SetUri(ringtoneAsset->GetPath()); + toneAttrs.SetTitle(ringtoneAsset->GetTitle()); + toneAttrs.SetFileName(ringtoneAsset->GetDisplayName()); + toneAttrs.SetCategory(ringtoneAsset->GetToneType()); + if (ringtoneAsset->GetMediaType() == RINGTONE_MEDIA_TYPE_VIDEO) { + toneAttrs.SetMediaType(ToneMediaType::MEDIA_TYPE_VID); + } else { + toneAttrs.SetMediaType(ToneMediaType::MEDIA_TYPE_AUD); + } } resultSet == nullptr ? : resultSet->Close(); - return uri; + return toneAttrs; } std::string SystemSoundManagerImpl::GetPresetNotificationToneUri(const DatabaseTool &databaseTool) { + MEDIA_LOGI("Enter the GetPresetNotificationToneUri interface."); + ToneAttrs toneAttrs = GetPresetNotificationToneAttrs(databaseTool); + return toneAttrs.GetUri(); +} + +ToneAttrs SystemSoundManagerImpl::GetPresetNotificationToneAttrs(const DatabaseTool &databaseTool) +{ + ToneAttrs toneAttrs = { "", "", "", CUSTOMISED, TONE_CATEGORY_NOTIFICATION }; if (!databaseTool.isInitialized || databaseTool.dataShareHelper == nullptr) { MEDIA_LOGE("The database tool is not ready!"); - return ""; + return toneAttrs; } std::string uri = ""; @@ -1234,21 +1293,40 @@ std::string SystemSoundManagerImpl::GetPresetNotificationToneUri(const DatabaseT } Uri queryUri(ringtoneLibraryUri); auto resultSet = databaseTool.dataShareHelper->Query(queryUri, queryPredicates, COLUMNS, &businessError); + MEDIA_LOGI("dataShareHelper->Query: errCode %{public}d", businessError.GetCode()); auto results = make_unique>(move(resultSet)); - CHECK_AND_RETURN_RET_LOG(results != nullptr, uri, "query failed, ringtone library error."); + CHECK_AND_RETURN_RET_LOG(results != nullptr, toneAttrs, "query failed, ringtone library error."); unique_ptr ringtoneAsset = results->GetFirstObject(); if (ringtoneAsset != nullptr) { - uri = ringtoneAsset->GetPath(); + toneAttrs.SetUri(ringtoneAsset->GetPath()); + toneAttrs.SetTitle(ringtoneAsset->GetTitle()); + toneAttrs.SetFileName(ringtoneAsset->GetDisplayName()); + toneAttrs.SetCategory(ringtoneAsset->GetToneType()); + if (ringtoneAsset->GetMediaType() == RINGTONE_MEDIA_TYPE_VIDEO) { + toneAttrs.SetMediaType(ToneMediaType::MEDIA_TYPE_VID); + } else { + toneAttrs.SetMediaType(ToneMediaType::MEDIA_TYPE_AUD); + } } resultSet == nullptr ? : resultSet->Close(); - return uri; + return toneAttrs; } std::string SystemSoundManagerImpl::GetSystemToneUri(const std::shared_ptr &context, SystemToneType systemToneType) { - CHECK_AND_RETURN_RET_LOG(IsSystemToneTypeValid(systemToneType), "", "Invalid system tone type"); - std::string systemToneUri = ""; + MEDIA_LOGI("Enter the GetSystemToneUri interface."); + ToneAttrs toneAttrs = GetSystemToneAttrs(systemToneType); + return toneAttrs.GetUri(); +} + +ToneAttrs SystemSoundManagerImpl::GetSystemToneAttrs(SystemToneType systemToneType) +{ + MEDIA_LOGI("GetSystemToneAttrs: Start, systemToneType: %{public}d", systemToneType); + int32_t category = systemToneType == SYSTEM_TONE_TYPE_NOTIFICATION ? + TONE_CATEGORY_NOTIFICATION : TONE_CATEGORY_TEXT_MESSAGE; + ToneAttrs toneAttrs = { "", "", "", CUSTOMISED, category }; + CHECK_AND_RETURN_RET_LOG(IsSystemToneTypeValid(systemToneType), toneAttrs, "Invalid system tone type"); Security::AccessToken::AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); int32_t result = Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, @@ -1259,51 +1337,55 @@ std::string SystemSoundManagerImpl::GetSystemToneUri(const std::shared_ptr dataShareHelper = isProxy ? SystemSoundManagerUtils::CreateDataShareHelperUri(STORAGE_MANAGER_MANAGER_ID) : SystemSoundManagerUtils::CreateDataShareHelper(STORAGE_MANAGER_MANAGER_ID); - CHECK_AND_RETURN_RET_LOG(dataShareHelper != nullptr, "", + CHECK_AND_RETURN_RET_LOG(dataShareHelper != nullptr, toneAttrs, "Failed to CreateDataShareHelper! datashare or ringtone library error."); DatabaseTool databaseTool = {true, isProxy, dataShareHelper}; - systemToneUri = GetSystemToneUri(databaseTool, systemToneType); + toneAttrs = GetSystemToneAttrs(databaseTool, systemToneType); dataShareHelper->Release(); - MEDIA_LOGI("Finish to get system tone uri: type %{public}d, uri %{public}s", systemToneType, systemToneUri.c_str()); - return systemToneUri; + MEDIA_LOGI("Finish to get system tone uri: type %{public}d, uri %{public}s", systemToneType, + toneAttrs.GetUri().c_str()); + return toneAttrs; } -std::string SystemSoundManagerImpl::GetSystemToneUri(const DatabaseTool &databaseTool, SystemToneType systemToneType) +ToneAttrs SystemSoundManagerImpl::GetSystemToneAttrs(const DatabaseTool &databaseTool, SystemToneType systemToneType) { + int32_t category = systemToneType == SYSTEM_TONE_TYPE_NOTIFICATION ? + TONE_CATEGORY_NOTIFICATION : TONE_CATEGORY_TEXT_MESSAGE; + ToneAttrs toneAttrs = { "", "", "", CUSTOMISED, category}; if (!databaseTool.isInitialized || databaseTool.dataShareHelper == nullptr) { MEDIA_LOGE("The database tool is not ready!"); - return ""; + return toneAttrs; } - std::string systemToneUri = ""; switch (systemToneType) { case SYSTEM_TONE_TYPE_SIM_CARD_0: case SYSTEM_TONE_TYPE_SIM_CARD_1: - systemToneUri = GetShotToneUriByType(databaseTool, to_string(systemTypeMap_[systemToneType])); - if (systemToneUri.empty()) { - systemToneUri = GetShotToneUriByType(databaseTool, to_string(RING_TONE_TYPE_SIM_CARD_BOTH)); + toneAttrs = GetShotToneAttrsByType(databaseTool, to_string(systemTypeMap_[systemToneType])); + if (toneAttrs.GetUri().empty()) { + toneAttrs = GetShotToneAttrsByType(databaseTool, to_string(RING_TONE_TYPE_SIM_CARD_BOTH)); } - if (systemToneUri.empty()) { - systemToneUri = GetPresetShotToneUriByType(databaseTool, to_string(systemTypeMap_[systemToneType])); + if (toneAttrs.GetUri().empty()) { + toneAttrs = GetPresetShotToneAttrsByType(databaseTool, to_string(systemTypeMap_[systemToneType])); } - if (systemToneUri.empty()) { - systemToneUri = GetPresetShotToneUriByType(databaseTool, to_string(RING_TONE_TYPE_SIM_CARD_BOTH)); + if (toneAttrs.GetUri().empty()) { + toneAttrs = GetPresetShotToneAttrsByType(databaseTool, to_string(RING_TONE_TYPE_SIM_CARD_BOTH)); } break; case SYSTEM_TONE_TYPE_NOTIFICATION: - systemToneUri = GetNotificationToneUriByType(databaseTool); - if (systemToneUri.empty()) { - systemToneUri = GetPresetNotificationToneUri(databaseTool); + toneAttrs = GetNotificationToneAttrsByType(databaseTool); + if (toneAttrs.GetUri().empty()) { + toneAttrs = GetNotificationToneAttrsByType(databaseTool); } break; default: break; } - if (systemToneUri.empty()) { - MEDIA_LOGI("No system tone uri for type %{public}d. Return NO_SYSTEM_SOUND", systemToneType); - return NO_SYSTEM_SOUND; + if (toneAttrs.GetUri().empty()) { + MEDIA_LOGI("GetSystemToneAttrs: No system tone uri for type %{public}d. Return NO_SYSTEM_SOUND", + systemToneType); + toneAttrs.SetUri(NO_SYSTEM_SOUND); } - return systemToneUri; + return toneAttrs; } std::shared_ptr SystemSoundManagerImpl::GetDefaultRingtoneAttrs( @@ -1572,47 +1654,79 @@ int32_t SystemSoundManagerImpl::UpdataeAlarmToneUri( std::string SystemSoundManagerImpl::GetAlarmToneUri(const std::shared_ptr &context) { - int32_t count = 2; - std::string alarmToneUri = ""; + MEDIA_LOGI("Enter the GetAlarmToneUri interface."); + ToneAttrs toneAttrs = GetAlarmToneAttrs(context); + std::string alarmToneUri = toneAttrs.GetUri(); + MEDIA_LOGI("GetAlarmToneUri: alarm type %{public}d", + SystemSoundManagerUtils::GetTypeForSystemSoundUri(alarmToneUri)); + return alarmToneUri; +} + +ToneAttrs SystemSoundManagerImpl::GetAlarmToneAttrs(const std::shared_ptr &context) +{ + MEDIA_LOGI("GetAlarmToneAttrs: Start."); std::lock_guard lock(uriMutex_); - std::shared_ptr dataShareHelper = - SystemSoundManagerUtils::CreateDataShareHelperUri(STORAGE_MANAGER_MANAGER_ID); - CHECK_AND_RETURN_RET_LOG(dataShareHelper != nullptr, alarmToneUri, - "Create dataShare failed, datashare or ringtone library error."); - DataShare::DatashareBusinessError businessError; - DataShare::DataSharePredicates queryPredicates; - queryPredicates.EqualTo(RINGTONE_COLUMN_ALARM_TONE_TYPE, to_string(ALARM_TONE_TYPE)); - Uri RINGTONEURI_PROXY(RINGTONE_LIBRARY_PROXY_DATA_URI_TONE_FILES + "&user=" + - std::to_string(SystemSoundManagerUtils::GetCurrentUserId())); - auto resultSet = dataShareHelper->Query(RINGTONEURI_PROXY, queryPredicates, COLUMNS, &businessError); - int32_t errCode = businessError.GetCode(); + ToneAttrs toneAttrs = { "", "", "", CUSTOMISED, TONE_CATEGORY_ALARM }; Security::AccessToken::AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); int32_t result = Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, "ohos.permission.ACCESS_CUSTOM_RINGTONE"); - if (errCode != 0 || result != Security::AccessToken::PermissionState::PERMISSION_GRANTED || - !SystemSoundManagerUtils::GetScannerFirstParameter(RINGTONE_PARAMETER_SCANNER_FIRST_KEY, RINGTONEPARA_SIZE) || - !SystemSoundManagerUtils::CheckCurrentUser()) { - dataShareHelper = SystemSoundManagerUtils::CreateDataShareHelper(STORAGE_MANAGER_MANAGER_ID); - CHECK_AND_RETURN_RET_LOG(dataShareHelper != nullptr, alarmToneUri, "Invalid dataShare."); - resultSet = dataShareHelper->Query(RINGTONEURI, queryPredicates, COLUMNS, &businessError); + bool isProxy = (result == Security::AccessToken::PermissionState::PERMISSION_GRANTED && + SystemSoundManagerUtils::GetScannerFirstParameter(RINGTONE_PARAMETER_SCANNER_FIRST_KEY, RINGTONEPARA_SIZE) && + SystemSoundManagerUtils::CheckCurrentUser()) ? true : false; + std::shared_ptr dataShareHelper = isProxy ? + SystemSoundManagerUtils::CreateDataShareHelperUri(STORAGE_MANAGER_MANAGER_ID) : + SystemSoundManagerUtils::CreateDataShareHelper(STORAGE_MANAGER_MANAGER_ID); + CHECK_AND_RETURN_RET_LOG(dataShareHelper != nullptr, toneAttrs, + "Failed to CreateDataShareHelper! datashare or ringtone library error."); + DatabaseTool databaseTool = {true, isProxy, dataShareHelper}; + toneAttrs = GetAlarmToneAttrs(databaseTool); + MEDIA_LOGI("GetAlarmToneUri: alarm uri %{public}s", toneAttrs.GetUri().c_str()); + dataShareHelper->Release(); + return toneAttrs; +} + +ToneAttrs SystemSoundManagerImpl::GetAlarmToneAttrs(const DatabaseTool &databaseTool) +{ + int32_t count = 2; + ToneAttrs toneAttrs = { "", "", "", CUSTOMISED, TONE_CATEGORY_ALARM }; + if (!databaseTool.isInitialized || databaseTool.dataShareHelper == nullptr) { + MEDIA_LOGE("The database tool is not ready!"); + return toneAttrs; + } + DataShare::DatashareBusinessError businessError; + DataShare::DataSharePredicates queryPredicates; + queryPredicates.EqualTo(RINGTONE_COLUMN_ALARM_TONE_TYPE, to_string(ALARM_TONE_TYPE)); + std::string ringtoneLibraryUri = ""; + if (databaseTool.isProxy) { + ringtoneLibraryUri = RINGTONE_LIBRARY_PROXY_DATA_URI_TONE_FILES + + "&user=" + std::to_string(SystemSoundManagerUtils::GetCurrentUserId()); + } else { + ringtoneLibraryUri = RINGTONE_PATH_URI; } + Uri queryUri(ringtoneLibraryUri); + auto resultSet = databaseTool.dataShareHelper->Query(queryUri, queryPredicates, COLUMNS, &businessError); auto results = make_unique>(move(resultSet)); - CHECK_AND_RETURN_RET_LOG(results != nullptr, alarmToneUri, "query failed, ringtone library error."); + CHECK_AND_RETURN_RET_LOG(results != nullptr, toneAttrs, "query failed, ringtone library error."); unique_ptr ringtoneAsset = results->GetFirstObject(); while ((ringtoneAsset != nullptr) && (SOURCE_TYPE_CUSTOMISED != ringtoneAsset->GetAlarmtoneSourceType()) && (results->GetCount() == count)) { ringtoneAsset = results->GetNextObject(); } if (ringtoneAsset != nullptr) { - alarmToneUri = ringtoneAsset->GetPath(); - MEDIA_LOGI("GetAlarmToneUri: alarm type %{public}d", - SystemSoundManagerUtils::GetTypeForSystemSoundUri(alarmToneUri)); + toneAttrs.SetCategory(ringtoneAsset->GetToneType()); + toneAttrs.SetFileName(ringtoneAsset->GetDisplayName()); + toneAttrs.SetTitle(ringtoneAsset->GetTitle()); + toneAttrs.SetUri(ringtoneAsset->GetPath()); + if (ringtoneAsset->GetMediaType() == RINGTONE_MEDIA_TYPE_VIDEO) { + toneAttrs.SetMediaType(ToneMediaType::MEDIA_TYPE_VID); + } else { + toneAttrs.SetMediaType(ToneMediaType::MEDIA_TYPE_AUD); + } } else { - MEDIA_LOGE("GetAlarmToneUri: no alarmtone in the ringtone library!"); + MEDIA_LOGE("GetAlarmToneAttrs: no alarmtone in the ringtone library!"); } resultSet == nullptr ? : resultSet->Close(); - dataShareHelper->Release(); - return alarmToneUri; + return toneAttrs; } std::shared_ptr SystemSoundManagerImpl::GetDefaultAlarmToneAttrs( @@ -1719,32 +1833,89 @@ int32_t SystemSoundManagerImpl::OpenAlarmTone(const std::shared_ptr &context, const std::string &uri, int32_t toneType) { + MEDIA_LOGI("Enter the OpenToneUri interface."); std::lock_guard lock(uriMutex_); - std::shared_ptr dataShareHelper = + Security::AccessToken::AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); + int32_t result = Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, + "ohos.permission.ACCESS_CUSTOM_RINGTONE"); + bool isProxy = (result == Security::AccessToken::PermissionState::PERMISSION_GRANTED && + SystemSoundManagerUtils::GetScannerFirstParameter(RINGTONE_PARAMETER_SCANNER_FIRST_KEY, RINGTONEPARA_SIZE) && + SystemSoundManagerUtils::CheckCurrentUser()) ? true : false; + std::shared_ptr dataShareHelper = isProxy ? + SystemSoundManagerUtils::CreateDataShareHelperUri(STORAGE_MANAGER_MANAGER_ID) : SystemSoundManagerUtils::CreateDataShareHelper(STORAGE_MANAGER_MANAGER_ID); - CHECK_AND_RETURN_RET_LOG(dataShareHelper != nullptr, ERROR, "Create dataShare failed, datashare or library error."); + CHECK_AND_RETURN_RET_LOG(dataShareHelper != nullptr, ERROR, + "Failed to CreateDataShareHelper! datashare or ringtone library error."); + DatabaseTool databaseTool = {true, isProxy, dataShareHelper}; + int32_t ret = OpenToneUri(databaseTool, uri, toneType); + MEDIA_LOGI("Open tone uri: open result : %{public}d, type %{public}d, uri %{public}s,", + ret, toneType, uri.c_str()); + dataShareHelper->Release(); + return ret; +} + +int32_t SystemSoundManagerImpl::OpenToneUri(const DatabaseTool &databaseTool, + const std::string &uri, int32_t toneType) +{ + if (!databaseTool.isInitialized || databaseTool.dataShareHelper == nullptr) { + MEDIA_LOGE("The database tool is not ready!"); + return ERROR; + } + if (SystemSoundManagerUtils::VerifyCustomPath(uri)) { + MEDIA_LOGI("The audio uri is custom path."); + return OpenCustomToneUri(uri, toneType); + } DataShare::DatashareBusinessError businessError; DataShare::DataSharePredicates queryPredicates; - DataShare::DataSharePredicates queryPredicatesByUri; - queryPredicatesByUri.EqualTo(RINGTONE_COLUMN_DATA, uri); - auto resultSetByUri = dataShareHelper->Query(RINGTONEURI, queryPredicatesByUri, COLUMNS, &businessError); - auto resultsByUri = make_unique>(move(resultSetByUri)); - unique_ptr ringtoneAssetByUri = resultsByUri->GetFirstObject(); - if (ringtoneAssetByUri == nullptr) { - MEDIA_LOGE("OpenToneUri: tone of uri is not in the ringtone library!"); - resultSetByUri == nullptr ? : resultSetByUri->Close(); - dataShareHelper->Release(); - return ERROR; + std::vector args = {uri, to_string(toneType)}; + queryPredicates.SetWhereClause(RINGTONE_COLUMN_DATA + " = ? AND " + RINGTONE_COLUMN_TONE_TYPE + " = ? "); + queryPredicates.SetWhereArgs(args); + std::string ringtoneLibraryUri = ""; + if (databaseTool.isProxy) { + ringtoneLibraryUri = RINGTONE_LIBRARY_PROXY_DATA_URI_TONE_FILES + + "&user=" + std::to_string(SystemSoundManagerUtils::GetCurrentUserId()); + } else { + ringtoneLibraryUri = RINGTONE_PATH_URI; } - resultSetByUri == nullptr ? : resultSetByUri->Close(); - queryPredicates.EqualTo(RINGTONE_COLUMN_TONE_TYPE, toneType); - auto resultSet = dataShareHelper->Query(RINGTONEURI, queryPredicates, COLUMNS, &businessError); + Uri queryUri(ringtoneLibraryUri); + auto resultSet = databaseTool.dataShareHelper->Query(queryUri, queryPredicates, COLUMNS, &businessError); auto results = make_unique>(move(resultSet)); CHECK_AND_RETURN_RET_LOG(results != nullptr, ERROR, "query failed, ringtone library error."); unique_ptr ringtoneAsset = results->GetFirstObject(); - while ((ringtoneAsset != nullptr) && (uri != ringtoneAsset->GetPath())) { - ringtoneAsset = results->GetNextObject(); + if (ringtoneAsset == nullptr) { + MEDIA_LOGE("OpenTone: tone of uri failed!"); + resultSet == nullptr ? : resultSet->Close(); + return TYPEERROR; } + int32_t fd = 0; + if (databaseTool.isProxy) { + std::string absFilePath; + PathToRealPath(uri, absFilePath); + fd = open(absFilePath.c_str(), O_RDONLY); + } else { + string uriStr = RINGTONE_PATH_URI + RINGTONE_SLASH_CHAR + to_string(ringtoneAsset->GetId()); + Uri ofUri(uriStr); + fd = databaseTool.dataShareHelper->OpenFile(ofUri, "r"); + } + resultSet == nullptr ? : resultSet->Close(); + return fd > 0 ? fd : ERROR; +} + +int32_t SystemSoundManagerImpl::OpenCustomToneUri(const std::string &customAudioUri, int32_t toneType) +{ + DataShare::DatashareBusinessError businessError; + DataShare::DataSharePredicates queryPredicates; + std::vector args = {customAudioUri, to_string(toneType)}; + queryPredicates.SetWhereClause(RINGTONE_COLUMN_DATA + " = ? AND " + RINGTONE_COLUMN_TONE_TYPE + " = ? "); + queryPredicates.SetWhereArgs(args); + Uri ringtonePathUri(RINGTONE_PATH_URI); + std::shared_ptr dataShareHelper = + SystemSoundManagerUtils::CreateDataShareHelper(STORAGE_MANAGER_MANAGER_ID); + CHECK_AND_RETURN_RET_LOG(dataShareHelper != nullptr, ERROR, "Invalid dataShare"); + auto resultSet = dataShareHelper->Query(ringtonePathUri, queryPredicates, COLUMNS, &businessError); + auto results = make_unique>(move(resultSet)); + CHECK_AND_RETURN_RET_LOG(results != nullptr, ERROR, "query failed, ringtone library error."); + unique_ptr ringtoneAsset = results->GetFirstObject(); if (ringtoneAsset != nullptr) { string uriStr = RINGTONE_PATH_URI + RINGTONE_SLASH_CHAR + to_string(ringtoneAsset->GetId()); Uri ofUri(uriStr); @@ -1753,7 +1924,7 @@ int32_t SystemSoundManagerImpl::OpenToneUri(const std::shared_ptrRelease(); return fd > 0 ? fd : ERROR; } - MEDIA_LOGE("OpenTone: tone of uri failed!"); + MEDIA_LOGE("Open custom audio uri failed!"); resultSet == nullptr ? : resultSet->Close(); dataShareHelper->Release(); return TYPEERROR; @@ -2311,7 +2482,7 @@ std::string SystemSoundManagerImpl::GetCurrentToneUri(const DatabaseTool &databa if (ConvertToRingtoneType(toneHapticsType, ringtoneType)) { currentToneUri = GetRingtoneUri(databaseTool, ringtoneType); } else if (ConvertToSystemToneType(toneHapticsType, systemToneType)) { - currentToneUri = GetSystemToneUri(databaseTool, systemToneType); + currentToneUri = GetSystemToneAttrs(databaseTool, systemToneType).GetUri(); } else { MEDIA_LOGE("Invalid tone haptics type"); } 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 5c40a520bdf871a948472517452f2fc1c99be022..467dae629fb9291cdc0fc730fb58a75881c8613b 100644 --- a/frameworks/native/system_sound_manager/system_sound_manager_impl.h +++ b/frameworks/native/system_sound_manager/system_sound_manager_impl.h @@ -126,7 +126,9 @@ public: std::string GetRingtoneTitle(const std::string &ringtoneUri); std::string GetRingtoneUri(const DatabaseTool &databaseTool, RingtoneType ringtoneType); ToneAttrs GetRingtoneAttrs(const DatabaseTool &databaseTool, RingtoneType ringtoneType); - std::string GetSystemToneUri(const DatabaseTool &databaseTool, SystemToneType systemToneType); + ToneAttrs GetSystemToneAttrs(SystemToneType systemToneType); + ToneAttrs GetSystemToneAttrs(const DatabaseTool &databaseTool, SystemToneType systemToneType); + ToneAttrs GetAlarmToneAttrs(const std::shared_ptr &context); std::string OpenAudioUri(const DatabaseTool &databaseTool, const std::string &audioUri); std::string OpenHapticsUri(const DatabaseTool &databaseTool, const std::string &hapticsUri); std::string GetHapticsUriByStyle(const DatabaseTool &databaseTool, @@ -178,11 +180,18 @@ private: int32_t UpdateRingtoneUri(std::shared_ptr dataShareHelper, const int32_t &toneId, RingtoneType ringtoneType, const int32_t &num); std::string GetShotToneUriByType(const DatabaseTool &databaseTool, const std::string &type); + ToneAttrs GetShotToneAttrsByType(const DatabaseTool &databaseTool, const std::string &type); std::string GetNotificationToneUriByType(const DatabaseTool &databaseTool); + ToneAttrs GetNotificationToneAttrsByType(const DatabaseTool &databaseTool); std::string GetPresetShotToneUriByType(const DatabaseTool &databaseTool, const std::string &type); + ToneAttrs GetPresetShotToneAttrsByType(const DatabaseTool &databaseTool, const std::string &type); std::string GetPresetNotificationToneUri(const DatabaseTool &databaseTool); + ToneAttrs GetPresetNotificationToneAttrs(const DatabaseTool &databaseTool); + ToneAttrs GetAlarmToneAttrs(const DatabaseTool &databaseTool); int32_t UpdateShotToneUri(std::shared_ptr dataShareHelper, const int32_t &toneId, SystemToneType systemToneType, const int32_t &num); + int32_t OpenToneUri(const DatabaseTool &databaseTool, const std::string &uri, int32_t toneType); + int32_t OpenCustomToneUri(const std::string &customAudioUri, int32_t toneType); int32_t UpdateNotificatioToneUri(std::shared_ptr dataShareHelper, const int32_t &toneId); int32_t UpdataeAlarmToneUri(const std::shared_ptr dataShareHelper, 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 dfe354e375374534c86654dbd12b97703689bc9c..bfd530cab5dbb94fc01ccacfef78057da7e3c122 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 @@ -109,7 +109,7 @@ SystemTonePlayerImpl::SystemTonePlayerImpl(const shared_ptr &context, audioHapticManager_ = AudioHapticManagerFactory::CreateAudioHapticManager(); CHECK_AND_RETURN_LOG(audioHapticManager_ != nullptr, "Failed to get audio haptic manager"); - std::string systemToneUri = systemSoundMgr_.GetSystemToneUri(databaseTool_, systemToneType_); + std::string systemToneUri = systemSoundMgr_.GetSystemToneAttrs(databaseTool_, systemToneType_).GetUri(); InitPlayer(systemToneUri); ReleaseDatabaseTool(); } @@ -380,7 +380,7 @@ int32_t SystemTonePlayerImpl::Prepare() MEDIA_LOGE("The database tool is not ready!"); return ERRCODE_IOERROR; } - std::string audioUri = systemSoundMgr_.GetSystemToneUri(databaseTool_, systemToneType_); + std::string audioUri = systemSoundMgr_.GetSystemToneAttrs(databaseTool_, systemToneType_).GetUri(); int32_t result = InitPlayer(audioUri); ReleaseDatabaseTool(); CHECK_AND_RETURN_RET_LOG(result == MSERR_OK, result, diff --git a/frameworks/native/system_sound_manager/unittest/sound_manager_test/src/system_sound_manager_unit_next_test.cpp b/frameworks/native/system_sound_manager/unittest/sound_manager_test/src/system_sound_manager_unit_next_test.cpp index 21fc7a626438ff272d3cf6055d3c4efe086143fd..4c3a3cfb290f37cee9401d702927103aead1a6c2 100644 --- a/frameworks/native/system_sound_manager/unittest/sound_manager_test/src/system_sound_manager_unit_next_test.cpp +++ b/frameworks/native/system_sound_manager/unittest/sound_manager_test/src/system_sound_manager_unit_next_test.cpp @@ -728,10 +728,10 @@ HWTEST(SystemSoundManagerUnitNextTest, GetPresetNotificationToneUri_003, TestSiz /** * @tc.name : GetSystemToneUri_NotInitialized - * @tc.number: GetSystemToneUri_001 + * @tc.number: GetSystemToneAttrs_001 * @tc.desc : Test GetSystemToneUri when databaseTool is not initialized */ -HWTEST(SystemSoundManagerUnitNextTest, GetSystemToneUri_001, TestSize.Level0) +HWTEST(SystemSoundManagerUnitNextTest, GetSystemToneAttrs_001, TestSize.Level0) { auto systemSoundManager_ = SystemSoundManagerFactory::CreateSystemSoundManager(); std::shared_ptr systemSoundManagerImpl_ = @@ -742,16 +742,17 @@ HWTEST(SystemSoundManagerUnitNextTest, GetSystemToneUri_001, TestSize.Level0) databaseTool.isInitialized = false; databaseTool.dataShareHelper = nullptr; SystemToneType systemToneType = SYSTEM_TONE_TYPE_SIM_CARD_0; - std::string result = systemSoundManagerImpl_->GetSystemToneUri(databaseTool, systemToneType); + ToneAttrs toneAttrs_ = systemSoundManagerImpl_->GetSystemToneAttrs(databaseTool, systemToneType); + std::string result = toneAttrs_.GetUri(); EXPECT_EQ(result, ""); } /** * @tc.name : GetSystemToneUri_DataShareHelperNull - * @tc.number: GetSystemToneUri_002 + * @tc.number: GetSystemToneAttrs_002 * @tc.desc : Test GetSystemToneUri when dataShareHelper is null */ -HWTEST(SystemSoundManagerUnitNextTest, GetSystemToneUri_002, TestSize.Level0) +HWTEST(SystemSoundManagerUnitNextTest, GetSystemToneAttrs_002, TestSize.Level0) { auto systemSoundManager_ = SystemSoundManagerFactory::CreateSystemSoundManager(); std::shared_ptr systemSoundManagerImpl_ = @@ -762,7 +763,8 @@ HWTEST(SystemSoundManagerUnitNextTest, GetSystemToneUri_002, TestSize.Level0) databaseTool.isInitialized = true; databaseTool.dataShareHelper = nullptr; SystemToneType systemToneType = SYSTEM_TONE_TYPE_SIM_CARD_0; - std::string result = systemSoundManagerImpl_->GetSystemToneUri(databaseTool, systemToneType); + ToneAttrs toneAttrs_ = systemSoundManagerImpl_->GetSystemToneAttrs(databaseTool, systemToneType); + std::string result = toneAttrs_.GetUri(); EXPECT_EQ(result, ""); } diff --git a/frameworks/native/system_sound_manager/unittest/sound_manager_test/src/system_sound_manager_unit_test.cpp b/frameworks/native/system_sound_manager/unittest/sound_manager_test/src/system_sound_manager_unit_test.cpp index 7895c49a474d2f6d746162d0544d2fbb4d33f6c3..95b5f78a060d3faeedd1d405708f191ea27de0cf 100644 --- a/frameworks/native/system_sound_manager/unittest/sound_manager_test/src/system_sound_manager_unit_test.cpp +++ b/frameworks/native/system_sound_manager/unittest/sound_manager_test/src/system_sound_manager_unit_test.cpp @@ -206,6 +206,29 @@ HWTEST(SystemSoundManagerUnitTest, Media_SoundManager_GetAlarmToneUri_001, TestS EXPECT_NE(systemSoundManager_, nullptr); } +/** + * @tc.name : Test GetAlarmToneAttrs API + * @tc.number: Media_SoundManager_GetAlarmToneAttrs_001 + * @tc.desc : Test GetAlarmToneAttrs interface. Returns attributes of the default system tone. + */ +HWTEST(SystemSoundManagerUnitTest, Media_SoundManager_GetAlarmToneAttrs_001, TestSize.Level2) +{ + std::shared_ptr systemSoundManager_ = std::make_shared(); + std::shared_ptr context_ = std::make_shared(); + bool isProxy = false; + DatabaseTool databaseTool = {true, isProxy, nullptr}; + ToneAttrs toneAttrs_ = systemSoundManager_->GetAlarmToneAttrs(context_); + EXPECT_EQ(toneAttrs_.GetUri().empty(), false); + toneAttrs_ = systemSoundManager_->GetAlarmToneAttrs(databaseTool); + EXPECT_EQ(toneAttrs_.GetUri().empty(), true); + std::shared_ptr dataShareHelper = + SystemSoundManagerUtils::CreateDataShareHelper(STORAGE_MANAGER_MANAGER_ID); + databaseTool = {true, isProxy, dataShareHelper}; + toneAttrs_ = systemSoundManager_->GetAlarmToneAttrs(databaseTool); + EXPECT_EQ(toneAttrs_.GetUri().empty(), false); + dataShareHelper->Release(); +} + /** * @tc.name : Test SetAlarmToneUri API * @tc.number: Media_SoundManager_SetAlarmToneUri_001 @@ -558,11 +581,11 @@ HWTEST(SystemSoundManagerUnitTest, Media_SoundManager_GetHapticsUriByStyle_001, std::shared_ptr systemSoundManagerImpl_ = std::static_pointer_cast(systemSoundManager_); EXPECT_NE(systemSoundManagerImpl_, nullptr); - - std::shared_ptr dataShareHelper = CreateDataShareHelper(STORAGE_MANAGER_MANAGER_ID); + std::shared_ptr dataShareHelper = + SystemSoundManagerUtils::CreateDataShareHelper(STORAGE_MANAGER_MANAGER_ID); EXPECT_NE(dataShareHelper, nullptr); - DatabaseTool databaseTool = {false, false, dataShareHelper}; + DatabaseTool databaseTool = {true, false, dataShareHelper}; std::string hapticsUri = systemSoundManagerImpl_->GetHapticsUriByStyle(databaseTool, "test", HapticsStyle::HAPTICS_STYLE_GENTLE); EXPECT_EQ(hapticsUri.empty(), true); @@ -893,6 +916,82 @@ HWTEST(SystemSoundManagerUnitTest, Media_SoundManager_GetSystemToneUri_001, Test EXPECT_NE(systemSoundManager_, nullptr); } +/** + * @tc.name : Test GetSystemToneAttrs API + * @tc.number: Media_SoundManager_GetSystemToneAttrs_001 + * @tc.desc : Test GetSystemToneAttrs interface. + */ +HWTEST(SystemSoundManagerUnitTest, Media_SoundManager_GetSystemToneAttrs_001, TestSize.Level2) +{ + std::shared_ptr systemSoundManager_ = std::make_shared(); + bool isProxy = false; + DatabaseTool databaseTool = {true, isProxy, nullptr}; + ToneAttrs toneAttrs_ = systemSoundManager_->GetSystemToneAttrs(databaseTool, SYSTEM_TONE_TYPE_SIM_CARD_0); + EXPECT_EQ(toneAttrs_.GetUri().empty(), true); + std::shared_ptr dataShareHelper = + SystemSoundManagerUtils::CreateDataShareHelper(STORAGE_MANAGER_MANAGER_ID); + databaseTool = {true, isProxy, dataShareHelper}; + toneAttrs_ = systemSoundManager_->GetSystemToneAttrs(databaseTool, static_cast(2)); + EXPECT_EQ(toneAttrs_.GetUri().empty(), false); +} + +/** + * @tc.name : Test GetSystemToneAttrs API + * @tc.number: Media_SoundManager_GetSystemToneAttrs_002 + * @tc.desc : Test GetSystemToneAttrs interface. + */ +HWTEST(SystemSoundManagerUnitTest, Media_SoundManager_GetSystemToneAttrs_002, TestSize.Level2) +{ + std::shared_ptr systemSoundManager_ = std::make_shared(); + bool isProxy = true; + DatabaseTool databaseTool = {true, isProxy, nullptr}; + ToneAttrs toneAttrs_ = systemSoundManager_->GetSystemToneAttrs(databaseTool, SYSTEM_TONE_TYPE_NOTIFICATION); + EXPECT_EQ(toneAttrs_.GetUri().empty(), true); + std::shared_ptr dataShareHelper = + SystemSoundManagerUtils::CreateDataShareHelperUri(STORAGE_MANAGER_MANAGER_ID); + databaseTool = {true, isProxy, dataShareHelper}; + toneAttrs_ = systemSoundManager_->GetSystemToneAttrs(databaseTool, static_cast(2)); + EXPECT_EQ(toneAttrs_.GetUri().empty(), false); +} + +/** + * @tc.name : Test GetSystemToneAttrs API + * @tc.number: Media_SoundManager_GetSystemToneAttrs_003 + * @tc.desc : Test GetSystemToneAttrs interface. + */ +HWTEST(SystemSoundManagerUnitTest, Media_SoundManager_GetSystemToneAttrs_003, TestSize.Level2) +{ + std::shared_ptr systemSoundManager_ = std::make_shared(); + bool isProxy = false; + DatabaseTool databaseTool = {true, isProxy, nullptr}; + ToneAttrs toneAttrs_ = systemSoundManager_->GetSystemToneAttrs(databaseTool, SYSTEM_TONE_TYPE_NOTIFICATION); + EXPECT_EQ(toneAttrs_.GetUri().empty(), true); + std::shared_ptr dataShareHelper = + SystemSoundManagerUtils::CreateDataShareHelperUri(STORAGE_MANAGER_MANAGER_ID); + databaseTool = {true, isProxy, dataShareHelper}; + toneAttrs_ = systemSoundManager_->GetSystemToneAttrs(databaseTool, static_cast(2)); + EXPECT_EQ(toneAttrs_.GetUri().empty(), false); +} + +/** + * @tc.name : Test GetSystemToneAttrs API + * @tc.number: Media_SoundManager_GetSystemToneAttrs_004 + * @tc.desc : Test GetSystemToneAttrs interface. + */ +HWTEST(SystemSoundManagerUnitTest, Media_SoundManager_GetSystemToneAttrs_004, TestSize.Level2) +{ + std::shared_ptr systemSoundManager_ = std::make_shared(); + bool isProxy = true; + DatabaseTool databaseTool = {true, isProxy, nullptr}; + ToneAttrs toneAttrs_ = systemSoundManager_->GetSystemToneAttrs(databaseTool, SYSTEM_TONE_TYPE_SIM_CARD_0); + EXPECT_EQ(toneAttrs_.GetUri().empty(), true); + std::shared_ptr dataShareHelper = + SystemSoundManagerUtils::CreateDataShareHelperUri(STORAGE_MANAGER_MANAGER_ID); + databaseTool = {true, isProxy, dataShareHelper}; + toneAttrs_ = systemSoundManager_->GetSystemToneAttrs(databaseTool, static_cast(2)); + EXPECT_EQ(toneAttrs_.GetUri().empty(), false); +} + /** * @tc.name : Test AddCustomizedToneByFdAndOffset API * @tc.number: Media_SoundManager_AddCustomizedToneByFdAndOffset_002 @@ -1564,6 +1663,68 @@ HWTEST(SystemSoundManagerUnitTest, Media_SoundManager_OpenToneUri_001, TestSize. EXPECT_NE(systemSoundManager_, nullptr); } +/** + * @tc.name : Test OpenToneUri API + * @tc.number: Media_SoundManager_OpenToneUri_002 + * @tc.desc : Test OpenToneUri interface. Returns attributes of the default system tone. + */ +HWTEST(SystemSoundManagerUnitTest, Media_SoundManager_OpenToneUri_002, TestSize.Level2) +{ + auto systemSoundManager_ = SystemSoundManagerFactory::CreateSystemSoundManager(); + std::shared_ptr context_ = std::make_shared(); + int fd = systemSoundManager_->OpenToneUri(context_, "test", ToneType::TONE_TYPE_ALARM); + EXPECT_LT(fd, 0); + auto vec = systemSoundManager_->GetAlarmToneAttrList(context_); + if (vec.size() > 0) { + std::string uri = vec[0]->GetUri(); + fd = systemSoundManager_->OpenToneUri(context_, uri, ToneType::TONE_TYPE_ALARM); + } + EXPECT_NE(systemSoundManager_, nullptr); +} + +/** + * @tc.name : Test OpenToneUri + * @tc.number: Media_SoundManager_OpenToneUri_003 + * @tc.desc : Test OpenToneUri interface. Returns attributes of the default system tone. + */ +HWTEST(SystemSoundManagerUnitTest, Media_SoundManager_OpenToneUri_003, TestSize.Level2) +{ + std::shared_ptr systemSoundManager_ = std::make_shared(); + std::shared_ptr context_ = std::make_shared(); + bool isProxy = false; + std::shared_ptr dataShareHelper = + SystemSoundManagerUtils::CreateDataShareHelper(STORAGE_MANAGER_MANAGER_ID); + DatabaseTool databaseTool = {true, isProxy, dataShareHelper}; + int fd = systemSoundManager_->OpenToneUri(databaseTool, "test", ToneType::TONE_TYPE_ALARM); + EXPECT_LT(fd, 0); + ToneAttrs toneAttrs_ = systemSoundManager_->GetAlarmToneAttrs(context_); + std::string uri = toneAttrs_.GetUri(); + fd = systemSoundManager_->OpenToneUri(context_, uri, ToneType::TONE_TYPE_ALARM); + + EXPECT_NE(systemSoundManager_, nullptr); +} + +/** + * @tc.name : Test OpenToneUri + * @tc.number: Media_SoundManager_OpenToneUri_004 + * @tc.desc : Test OpenToneUri interface. Returns attributes of the default system tone. + */ +HWTEST(SystemSoundManagerUnitTest, Media_SoundManager_OpenToneUri_004, TestSize.Level2) +{ + std::shared_ptr systemSoundManager_ = std::make_shared(); + std::shared_ptr context_ = std::make_shared(); + bool isProxy = true; + std::shared_ptr dataShareHelper = + SystemSoundManagerUtils::CreateDataShareHelperUri(STORAGE_MANAGER_MANAGER_ID); + DatabaseTool databaseTool = {true, isProxy, dataShareHelper}; + int fd = systemSoundManager_->OpenToneUri(databaseTool, "test", ToneType::TONE_TYPE_ALARM); + EXPECT_LT(fd, 0); + ToneAttrs toneAttrs_ = systemSoundManager_->GetAlarmToneAttrs(context_); + std::string uri = toneAttrs_.GetUri(); + fd = systemSoundManager_->OpenToneUri(context_, uri, ToneType::TONE_TYPE_ALARM); + EXPECT_NE(systemSoundManager_, nullptr); +} + /** * @tc.name : GetDefaultRingtoneUri_ShouldReturnUri_WhenTypeIsValid * @tc.number: GetDefaultRingtoneUri_ShouldReturnUri_WhenTypeIsValid_001