diff --git a/bundle.json b/bundle.json index 9d41c2c36debb1691762b8f9fd2fef8c41555cea..842545ac5de8abffdebbdd9a8ff4b55b333c753c 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 6d245b18265db799b103696ba23a9d007f2fa393..12739d3dde5c8fc08d4eae1cc0a8091e0f10a038 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 e0c998fc7e192c08179d9733256328b1a2cc3d64..926aad4a529e3b5437bbc048212c8fb1a1e19212 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 124ec328f990e7474ad6f41f87273b00ec19fa6e..7d55fb9f4f821adad12b4128b5655d7a77c3b694 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 43dff2503a9ed42ea771542e6005e17231f4071d..ca63e1de3f224569cf6c9bc69b190e07bb712ce7 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 1d94e70caad47acc51590162120fee4c94e73fce..29832cd80594a2104e18978405451fd74620c058 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 36c620a2fa40b7c803c4296168cebf9c1dc9ec41..60b27de122c700b5468584625acc3e81c04f3ff9 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 88b1f64f8c4a4226f139f491dc7a19a82737052d..e3e414ec45075742ab5a6e6e716f76b6598a9675 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 2000ac5be137a884d5423027966baa976ec3fdf3..27af9c37974b9d618e0ab45a715e37a1e07ed0fd 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 5460563f519d279facba4705dac03362ac0c42a2..eb10d63c18af7e1993de7c71ef96b048a25ecf54 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 e8b788dec353ba4dce9d73a0b057ceb94a4a751e..c855f85f81925cbc1807ea9420ce5c08c3ef0069 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 6301332ab121e8555d8163b0a69edba835c79ab2..1e02c9ddfe753b3f73fad753ca0aeb15c72a9c20 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 ca32a429f593fc6bab15b118018a5852515c45bb..687dbde3aa64e8496699cd3c31b28132fc9ba526 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 ee5e93245c2cf631f1fd2133a06a9df3f8382e93..6b5f24d21a9629b42e2a7453b8bedd822ef635a6 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 d6de174f8cae958c7da90ffe1982157004d95d0b..21ce0af9fa0703c0ecd9812641a5ec123b5531d9 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 152a71667d1df4132d59dd3e6095d3457d8861ad..36b02277e038f8e998d061bf451dd89a977dad3e 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);