From 6d59bd1854081fe6227be0083a7141db59f6ce4c Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Wed, 14 May 2025 16:43:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=93=83=E5=A3=B0=E9=80=9A?= =?UTF-8?q?=E9=81=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gaojiaqi --- bundle.json | 1 + .../napi/include/reminder/reminder_common.h | 4 ++++ .../src/reminder/native_module_manager.cpp | 10 ++++++++++ frameworks/js/napi/src/reminder/publish.cpp | 5 +++++ .../js/napi/src/reminder/reminder_common.cpp | 20 +++++++++++++++++++ frameworks/reminder/src/reminder_request.cpp | 16 +++++++++++++++ .../test/unittest/reminder_request_test.cpp | 15 ++++++++++++++ interfaces/inner_api/reminder_request.h | 15 ++++++++++++++ services/reminder/BUILD.gn | 1 + services/reminder/include/reminder_table.h | 2 ++ .../src/reminder_agent_service_ability.cpp | 2 -- .../reminder/src/reminder_data_manager.cpp | 18 ++++++++++++++++- services/reminder/src/reminder_store.cpp | 20 +++++++++++-------- .../reminder/src/reminder_store_strategy.cpp | 5 +++++ services/reminder/src/reminder_table.cpp | 2 ++ .../test/unittest/reminder_store_test.cpp | 2 ++ 16 files changed, 127 insertions(+), 11 deletions(-) diff --git a/bundle.json b/bundle.json index 9d41c2c36..842545ac5 100644 --- a/bundle.json +++ b/bundle.json @@ -79,6 +79,7 @@ "safwk", "ability_runtime", "ability_base", + "audio_framework", "common_event_service", "os_account", "hisysevent", diff --git a/frameworks/js/napi/include/reminder/reminder_common.h b/frameworks/js/napi/include/reminder/reminder_common.h index 6d245b182..12739d3dd 100644 --- a/frameworks/js/napi/include/reminder/reminder_common.h +++ b/frameworks/js/napi/include/reminder/reminder_common.h @@ -81,6 +81,7 @@ const char* TAPDISMISSED = "tapDismissed"; const char* AUTODELETEDTIME = "autoDeletedTime"; const char* GROUP_ID = "groupId"; const char* CUSTOM_RING_URI = "customRingUri"; +const char* RING_CHANNEL = "ringChannel"; const char* SNOOZE_SLOT_TYPE = "snoozeSlotType"; const char* REMINDER_INFO_REMINDER_REQ = "reminderReq"; const char* REMINDER_INFO_REMINDER_ID = "reminderId"; @@ -173,6 +174,9 @@ private: static bool GenActionButtons( const napi_env &env, const napi_value &value, std::shared_ptr& reminder, bool isSysApp); + static bool GenRingChannel(const napi_env& env, const napi_value& value, + std::shared_ptr& reminder); + static napi_value GenReminder( const napi_env &env, const napi_value &value, std::shared_ptr& reminder); diff --git a/frameworks/js/napi/src/reminder/native_module_manager.cpp b/frameworks/js/napi/src/reminder/native_module_manager.cpp index e0c998fc7..926aad4a5 100644 --- a/frameworks/js/napi/src/reminder/native_module_manager.cpp +++ b/frameworks/js/napi/src/reminder/native_module_manager.cpp @@ -71,9 +71,19 @@ napi_value ConstantInit(napi_env env, napi_value exports) napi_set_named_property(env, objButtonType, "ACTION_BUTTON_TYPE_CUSTOM", prop); } + napi_value objRingChannel = nullptr; + napi_create_object(env, &objRingChannel); + if (napi_create_int32(env, static_cast(ReminderRequest::RingChannel::MEDIA), &prop) == napi_ok) { + napi_set_named_property(env, objRingChannel, "RING_CHANNEL_MEDIA", prop); + } + if (napi_create_int32(env, static_cast(ReminderRequest::RingChannel::ALARM), &prop) == napi_ok) { + napi_set_named_property(env, objRingChannel, "RING_CHANNEL_ALARM", prop); + } + napi_property_descriptor exportFuncs[] = { DECLARE_NAPI_PROPERTY("ReminderType", objReminderType), DECLARE_NAPI_PROPERTY("ActionButtonType", objButtonType), + DECLARE_NAPI_PROPERTY("RingChannel", objRingChannel), }; napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs); diff --git a/frameworks/js/napi/src/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp index 124ec328f..7d55fb9f4 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -793,6 +793,11 @@ napi_value SetValidReminder(const napi_env &env, ReminderRequest &reminder, napi napi_create_string_utf8(env, reminder.GetCustomRingUri().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, CUSTOM_RING_URI, value); + // type + ReminderRequest::RingChannel channel = reminder.GetRingChannel(); + napi_create_int32(env, static_cast(channel), &value); + napi_set_named_property(env, result, RING_CHANNEL, value); + // wantAgent ParseWantAgent(env, reminder, result); diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index 43dff2503..ca63e1de3 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -94,6 +94,21 @@ bool ReminderCommon::GenActionButtons( return true; } +bool ReminderCommon::GenRingChannel(const napi_env& env, const napi_value& value, + std::shared_ptr& reminder) +{ + int32_t ringChannel = static_cast(ReminderRequest::RingChannel::ALARM); + if (GetInt32(env, value, ReminderAgentNapi::RING_CHANNEL, ringChannel, false)) { + if (!(ReminderRequest::RingChannel(ringChannel) == ReminderRequest::RingChannel::ALARM || + ReminderRequest::RingChannel(ringChannel) == ReminderRequest::RingChannel::MEDIA)) { + ANSR_LOGE("Wrong argument type:%{public}s. ringChannel not support.", RING_CHANNEL); + return false; + } + reminder->SetRingChannel(static_cast(ringChannel)); + } + return true; +} + void ReminderCommon::HandleActionButtonTitle(const napi_env &env, const napi_value &actionButton, std::shared_ptr& reminder, const char* str, int32_t buttonType) { @@ -499,6 +514,11 @@ napi_value ReminderCommon::GenReminder( return nullptr; } + // ringChannel + if (!GenRingChannel(env, value, reminder)) { + return nullptr; + } + return NotificationNapi::Common::NapiGetNull(env); } diff --git a/frameworks/reminder/src/reminder_request.cpp b/frameworks/reminder/src/reminder_request.cpp index 1d94e70ca..29832cd80 100644 --- a/frameworks/reminder/src/reminder_request.cpp +++ b/frameworks/reminder/src/reminder_request.cpp @@ -149,6 +149,7 @@ ReminderRequest::ReminderRequest(const ReminderRequest &other) this->customButtonUri_ = other.customButtonUri_; this->groupId_ = other.groupId_; this->customRingUri_ = other.customRingUri_; + this->ringChannel_ = other.ringChannel_; this->creatorBundleName_ = other.creatorBundleName_; this->titleResourceId_ = other.titleResourceId_; this->contentResourceId_ = other.contentResourceId_; @@ -943,6 +944,16 @@ uint64_t ReminderRequest::GetTriggerTimeInMilli() const return triggerTimeInMilli_; } +void ReminderRequest::SetRingChannel(const RingChannel type) +{ + ringChannel_ = type; +} + +ReminderRequest::RingChannel ReminderRequest::GetRingChannel() const +{ + return ringChannel_; +} + int32_t ReminderRequest::GetUserId() const { return userId_; @@ -1224,6 +1235,8 @@ bool ReminderRequest::WriteParcel(Parcel &parcel) const WRITE_INT32_RETURN_FALSE_LOG(parcel, contentResourceId_, "contentResourceId"); WRITE_INT32_RETURN_FALSE_LOG(parcel, expiredContentResourceId_, "expiredContentResourceId"); WRITE_INT32_RETURN_FALSE_LOG(parcel, snoozeContentResourceId_, "snoozeContentResourceId"); + int32_t ringChannel = static_cast(ringChannel_); + WRITE_INT32_RETURN_FALSE_LOG(parcel, ringChannel, "ringChannel"); if (!MarshallingActionButton(parcel)) { return false; @@ -1362,6 +1375,9 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) READ_INT32_RETURN_FALSE_LOG(parcel, contentResourceId_, "contentResourceId"); READ_INT32_RETURN_FALSE_LOG(parcel, expiredContentResourceId_, "expiredContentResourceId"); READ_INT32_RETURN_FALSE_LOG(parcel, snoozeContentResourceId_, "snoozeContentResourceId"); + int32_t ringChannel = static_cast(ReminderRequest::RingChannel::ALARM); + READ_INT32_RETURN_FALSE_LOG(parcel, ringChannel, "ringChannel"); + ringChannel_ = static_cast(ringChannel); if (!ReadActionButtonFromParcel(parcel)) { return false; } diff --git a/frameworks/reminder/test/unittest/reminder_request_test.cpp b/frameworks/reminder/test/unittest/reminder_request_test.cpp index 36c620a2f..60b27de12 100644 --- a/frameworks/reminder/test/unittest/reminder_request_test.cpp +++ b/frameworks/reminder/test/unittest/reminder_request_test.cpp @@ -2394,5 +2394,20 @@ HWTEST_F(ReminderRequestTest, ReminderRequestTest_005, Function | SmallTest | Le EXPECT_EQ(invalid, nullptr); delete invalid; } + +/** + * @tc.name: ReminderRequestTest_006 + * @tc.desc: Test StringToInt parameters. + * @tc.type: FUNC + * @tc.require: issueI8CDH3 + */ +HWTEST_F(ReminderRequestTest, ReminderRequestTest_006, Function | SmallTest | Level1) +{ + ReminderRequestChild child; + child.SetRingChannel(ReminderRequest::RingChannel::ALARM); + EXPECT_EQ(child.GetRingChannel(), ReminderRequest::RingChannel::ALARM); + child.SetRingChannel(ReminderRequest::RingChannel::MEDIA); + EXPECT_EQ(child.GetRingChannel(), ReminderRequest::RingChannel::MEDIA); +} } } diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index 88b1f64f8..e3e414ec4 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -200,6 +200,14 @@ public: HM }; + /** + * @brief audio stream type + */ + enum class RingChannel : uint8_t { + ALARM, + MEDIA, + }; + struct ButtonWantAgent { std::string pkgName = ""; std::string abilityName = ""; @@ -456,6 +464,12 @@ public: snoozeContentResourceId_ = snoozeContentResourceId; } + /** + * @brief Set/Get ring channel. + */ + void SetRingChannel(const RingChannel channel); + RingChannel GetRingChannel() const; + int32_t GetUserId() const; int32_t GetUid() const; @@ -1154,6 +1168,7 @@ private: uint8_t snoozeTimes_ {0}; uint8_t snoozeTimesDynamic_ {0}; uint8_t state_ {0}; + RingChannel ringChannel_ {RingChannel::ALARM}; int32_t notificationId_ {0}; std::string groupId_ {}; int32_t reminderId_ {-1}; diff --git a/services/reminder/BUILD.gn b/services/reminder/BUILD.gn index 2000ac5be..27af9c379 100644 --- a/services/reminder/BUILD.gn +++ b/services/reminder/BUILD.gn @@ -134,6 +134,7 @@ ohos_source_set("reminder_service_sources") { if (player_framework) { external_deps += [ "player_framework:media_client" ] + external_deps += [ "audio_framework:audio_client" ] defines += [ "PLAYER_FRAMEWORK_ENABLE" ] } diff --git a/services/reminder/include/reminder_table.h b/services/reminder/include/reminder_table.h index 5460563f5..eb10d63c1 100644 --- a/services/reminder/include/reminder_table.h +++ b/services/reminder/include/reminder_table.h @@ -187,6 +187,8 @@ public: */ static const std::string CREATOR_UID; + static const std::string RING_CHANNEL; + public: static void InitDbColumns(); diff --git a/services/reminder/src/reminder_agent_service_ability.cpp b/services/reminder/src/reminder_agent_service_ability.cpp index e8b788dec..c855f85f8 100644 --- a/services/reminder/src/reminder_agent_service_ability.cpp +++ b/services/reminder/src/reminder_agent_service_ability.cpp @@ -22,8 +22,6 @@ constexpr int32_t REMINDER_AGENT_SERVICE_ID = 3204; REGISTER_SYSTEM_ABILITY_BY_ID(ReminderAgentServiceAbility, REMINDER_AGENT_SERVICE_ID, false); } -const std::string EXTENSION_BACKUP = "backup"; -const std::string EXTENSION_RESTORE = "restore"; constexpr int64_t INIT_DELAY_TIME = 60 * 1000 * 1000; ReminderAgentServiceAbility::ReminderAgentServiceAbility(const int32_t systemAbilityId, bool runOnCreate) diff --git a/services/reminder/src/reminder_data_manager.cpp b/services/reminder/src/reminder_data_manager.cpp index 6301332ab..1e02c9ddf 100644 --- a/services/reminder/src/reminder_data_manager.cpp +++ b/services/reminder/src/reminder_data_manager.cpp @@ -49,6 +49,10 @@ #include "notification_helper.h" #include "reminder_datashare_helper.h" #include "reminder_calendar_share_table.h" +#ifdef PLAYER_FRAMEWORK_ENABLE +#include "audio_session_manager.h" +#include "audio_stream_info.h" +#endif namespace OHOS { namespace Notification { @@ -1626,6 +1630,12 @@ void ReminderDataManager::PlaySoundAndVibration(const sptr &rem return; } } + auto audioManager = AudioStandard::AudioSessionManager::GetInstance(); + if (audioManager != nullptr && reminder->GetRingChannel() == ReminderRequest::RingChannel::MEDIA) { + AudioStandard::AudioSessionStrategy strategy; + strategy.concurrencyMode = AudioStandard::AudioConcurrencyMode::PAUSE_OTHERS; + audioManager->ActivateAudioSession(strategy); + } std::string customRingUri = reminder->GetCustomRingUri(); if (customRingUri.empty()) { // use default ring @@ -1649,7 +1659,9 @@ void ReminderDataManager::PlaySoundAndVibration(const sptr &rem } ANSR_LOGI("Play custom sound, reminderId:[%{public}d].", reminder->GetReminderId()); } - constexpr int32_t STREAM_ALARM = 4; + int32_t STREAM_ALARM = reminder->GetRingChannel() == ReminderRequest::RingChannel::MEDIA ? + static_cast(AudioStandard::StreamUsage::STREAM_USAGE_MEDIA) : + static_cast(AudioStandard::StreamUsage::STREAM_USAGE_ALARM); constexpr int32_t DEFAULT_VALUE = 0; // CONTENT_UNKNOWN Media::Format format; (void)format.PutIntValue(Media::PlayerKeys::CONTENT_TYPE, DEFAULT_VALUE); @@ -1695,6 +1707,10 @@ void ReminderDataManager::StopSoundAndVibration(const sptr &rem soundPlayer_->Release(); soundPlayer_ = nullptr; } + auto audioManager = AudioStandard::AudioSessionManager::GetInstance(); + if (audioManager != nullptr && reminder->GetRingChannel() == ReminderRequest::RingChannel::MEDIA) { + audioManager->DeactivateAudioSession(); + } #endif sptr nullReminder = nullptr; SetAlertingReminder(nullReminder); diff --git a/services/reminder/src/reminder_store.cpp b/services/reminder/src/reminder_store.cpp index ca32a429f..687dbde3a 100644 --- a/services/reminder/src/reminder_store.cpp +++ b/services/reminder/src/reminder_store.cpp @@ -33,14 +33,15 @@ namespace OHOS { namespace Notification { namespace { -const int32_t REMINDER_RDB_VERSION_V1 = 1; -const int32_t REMINDER_RDB_VERSION_V2 = 2; -const int32_t REMINDER_RDB_VERSION_V3 = 3; -const int32_t REMINDER_RDB_VERSION_V4 = 4; -const int32_t REMINDER_RDB_VERSION_V5 = 5; -const int32_t REMINDER_RDB_VERSION_V6 = 6; -const int32_t REMINDER_RDB_VERSION_V7 = 7; -const int32_t REMINDER_RDB_VERSION = 8; +constexpr int32_t REMINDER_RDB_VERSION_V1 = 1; +constexpr int32_t REMINDER_RDB_VERSION_V2 = 2; +constexpr int32_t REMINDER_RDB_VERSION_V3 = 3; +constexpr int32_t REMINDER_RDB_VERSION_V4 = 4; +constexpr int32_t REMINDER_RDB_VERSION_V5 = 5; +constexpr int32_t REMINDER_RDB_VERSION_V6 = 6; +constexpr int32_t REMINDER_RDB_VERSION_V7 = 7; +constexpr int32_t REMINDER_RDB_VERSION_V8 = 8; +constexpr int32_t REMINDER_RDB_VERSION = 9; constexpr int64_t DURATION_PRELOAD_TIME = 10 * 60 * 60 * 1000; // 10h, millisecond } @@ -91,6 +92,9 @@ int32_t ReminderStore::ReminderStoreDataCallBack::OnUpgrade( AddRdbColum(store, ReminderBaseTable::TABLE_NAME, ReminderBaseTable::EXPIRED_CONTENT_RESOURCE_ID, "INT", "0"); [[fallthrough]]; + case REMINDER_RDB_VERSION_V8: + AddRdbColum(store, ReminderBaseTable::TABLE_NAME, ReminderBaseTable::RING_CHANNEL, "INT", "0"); + [[fallthrough]]; default: break; } diff --git a/services/reminder/src/reminder_store_strategy.cpp b/services/reminder/src/reminder_store_strategy.cpp index ee5e93245..6b5f24d21 100644 --- a/services/reminder/src/reminder_store_strategy.cpp +++ b/services/reminder/src/reminder_store_strategy.cpp @@ -71,6 +71,7 @@ void ReminderStrategy::AppendValuesBucket(const sptr& reminder, values.PutLong(ReminderBaseTable::AUTO_DELETED_TIME, reminder->GetAutoDeletedTime()); values.PutString(ReminderBaseTable::GROUP_ID, reminder->GetGroupId()); values.PutString(ReminderBaseTable::CUSTOM_RING_URI, reminder->GetCustomRingUri()); + values.PutInt(ReminderBaseTable::RING_CHANNEL, static_cast(reminder->GetRingChannel())); values.PutString(ReminderBaseTable::CREATOR_BUNDLE_NAME, reminder->GetCreatorBundleName()); values.PutInt(ReminderBaseTable::CREATOR_UID, reminder->GetCreatorUid()); } @@ -388,6 +389,10 @@ void ReminderStrategy::RecoverFromDb(sptr& reminder, std::string tapDismissed; ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::TAP_DISMISSED, tapDismissed); reminder->SetTapDismissed(tapDismissed == "true" ? true : false); + + int32_t ringChannel; + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::RING_CHANNEL, ringChannel); + reminder->SetRingChannel(static_cast(ringChannel)); } void ReminderTimerStrategy::AppendValuesBucket(const sptr& reminder, diff --git a/services/reminder/src/reminder_table.cpp b/services/reminder/src/reminder_table.cpp index d6de174f8..21ce0af9f 100644 --- a/services/reminder/src/reminder_table.cpp +++ b/services/reminder/src/reminder_table.cpp @@ -54,6 +54,7 @@ const std::string ReminderBaseTable::GROUP_ID = "group_id"; const std::string ReminderBaseTable::CUSTOM_RING_URI = "custom_ring_uri"; const std::string ReminderBaseTable::CREATOR_BUNDLE_NAME = "creator_bundle_name"; const std::string ReminderBaseTable::CREATOR_UID = "creator_uid"; +const std::string ReminderBaseTable::RING_CHANNEL = "ring_channel"; // reminder alarm table const std::string ReminderAlarmTable::TABLE_NAME = "reminder_alarm"; @@ -147,6 +148,7 @@ void ReminderBaseTable::InitDbColumns() AddColumn(AUTO_DELETED_TIME, "BIGINT", ADD_COLUMNS, SELECT_COLUMNS); AddColumn(GROUP_ID, "TEXT", ADD_COLUMNS, SELECT_COLUMNS); AddColumn(CUSTOM_RING_URI, "TEXT", ADD_COLUMNS, SELECT_COLUMNS); + AddColumn(RING_CHANNEL, "INT", ADD_COLUMNS, SELECT_COLUMNS); AddColumn(CREATOR_BUNDLE_NAME, "TEXT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS); AddColumnEnd(CREATOR_UID, "INT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS); } diff --git a/services/reminder/test/unittest/reminder_store_test.cpp b/services/reminder/test/unittest/reminder_store_test.cpp index 152a71667..36b02277e 100644 --- a/services/reminder/test/unittest/reminder_store_test.cpp +++ b/services/reminder/test/unittest/reminder_store_test.cpp @@ -447,6 +447,7 @@ HWTEST_F(ReminderStoreTest, ReminderTimerStrategyTest_00003, Function | SmallTes reminder->reminderId_ = 999; reminder->reminderType_ = ReminderRequest::ReminderType::TIMER; reminder->customButtonUri_ = "customButtonUri_"; + reminder->ringChannel_ = ReminderRequest::RingChannel::MEDIA; if (reminder->wantAgentInfo_ == nullptr) { reminder->InitServerObj(); } @@ -467,6 +468,7 @@ HWTEST_F(ReminderStoreTest, ReminderTimerStrategyTest_00003, Function | SmallTes } EXPECT_EQ(reminder->customButtonUri_, each->customButtonUri_); + EXPECT_EQ(reminder->ringChannel_, each->ringChannel_); EXPECT_EQ(reminder->wantAgentInfo_->pkgName, each->wantAgentInfo_->pkgName); EXPECT_EQ(reminder->wantAgentInfo_->abilityName, each->wantAgentInfo_->abilityName); EXPECT_EQ(reminder->wantAgentInfo_->uri, each->wantAgentInfo_->uri); -- Gitee