From d33f752bcf23dc93bf1c9db47cfa4659de9a5b0b Mon Sep 17 00:00:00 2001 From: qiaoyanqing Date: Tue, 10 Oct 2023 18:08:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=8F=90=E9=86=92=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E9=80=9A=E7=9F=A5=E6=94=AF=E6=8C=81=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=90=BA=E5=B8=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/ans/src/reminder_request.cpp | 28 ++++++++++++++----- .../napi/include/reminder/reminder_common.h | 5 ++-- frameworks/js/napi/src/reminder/publish.cpp | 4 +-- .../js/napi/src/reminder/reminder_common.cpp | 17 +++++++---- interfaces/inner_api/reminder_request.h | 3 +- 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index 1f7f10979..12c4d1b53 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -646,6 +646,9 @@ void ReminderRequest::RecoverWantAgent(const std::string &wantAgentInfo, const u auto wai = std::make_shared(); wai->pkgName = info.at(0); wai->abilityName = info.at(1); + if (info.size() > minLen) { + wai->uri = info.at(2); + } SetWantAgentInfo(wai); break; } @@ -992,6 +995,10 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const ANSR_LOGE("Failed to write wantAgentInfo`s pkgName"); return false; } + if (!parcel.WriteString(wantAgentInfo_->uri)) { + ANSR_LOGE("Failed to write wantAgentInfo`s uri"); + return false; + } if (!parcel.WriteString(maxScreenWantAgentInfo_->abilityName)) { ANSR_LOGE("Failed to write maxScreenWantAgentInfo`s abilityName"); return false; @@ -1142,6 +1149,10 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) ANSR_LOGE("Failed to read wantAgentInfo`s pkgName"); return false; } + if (!parcel.ReadString(wantAgentInfo_->uri)) { + ANSR_LOGE("Failed to read wantAgentInfo`s uri"); + return false; + } if (!parcel.ReadString(maxScreenWantAgentInfo_->abilityName)) { ANSR_LOGE("Failed to read maxScreenWantAgentInfo`s abilityName"); return false; @@ -1488,14 +1499,16 @@ void ReminderRequest::AddRemovalWantAgent() } std::shared_ptr ReminderRequest::CreateWantAgent( - AppExecFwk::ElementName &element) const + AppExecFwk::ElementName &element, bool isWantAgent) const { int32_t requestCode = 10; std::vector flags; flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); auto want = std::make_shared(); want->SetElement(element); - want->SetUri(customButtonUri_); + if (isWantAgent) { + want->SetUri(wantAgentInfo_->uri); + } std::vector> wants; wants.push_back(want); AbilityRuntime::WantAgent::WantAgentInfo wantAgentInfo( @@ -1513,13 +1526,13 @@ std::shared_ptr ReminderRequest::CreateWan void ReminderRequest::SetMaxScreenWantAgent(AppExecFwk::ElementName &element) { - std::shared_ptr wantAgent = CreateWantAgent(element); + std::shared_ptr wantAgent = CreateWantAgent(element, false); notificationRequest_->SetMaxScreenWantAgent(wantAgent); } void ReminderRequest::SetWantAgent(AppExecFwk::ElementName &element) { - std::shared_ptr wantAgent = CreateWantAgent(element); + std::shared_ptr wantAgent = CreateWantAgent(element, true); notificationRequest_->SetWantAgent(wantAgent); } @@ -1761,11 +1774,12 @@ void ReminderRequest::AppendValuesBucket(const sptr &reminder, values.PutString(EXPIRED_CONTENT, reminder->GetExpiredContent()); auto wantAgentInfo = reminder->GetWantAgentInfo(); if (wantAgentInfo == nullptr) { - std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null"; + std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null" + ReminderRequest::SEP_WANT_AGENT + "null"; values.PutString(AGENT, info); } else { - values.PutString(AGENT, wantAgentInfo->pkgName - + ReminderRequest::SEP_WANT_AGENT + wantAgentInfo->abilityName); + std::string info = wantAgentInfo->pkgName + ReminderRequest::SEP_WANT_AGENT + + wantAgentInfo->abilityName + ReminderRequest::SEP_WANT_AGENT + wantAgentInfo->uri; + values.PutString(AGENT, info); } auto maxScreenWantAgentInfo = reminder->GetMaxScreenWantAgentInfo(); if (maxScreenWantAgentInfo == nullptr) { diff --git a/frameworks/js/napi/include/reminder/reminder_common.h b/frameworks/js/napi/include/reminder/reminder_common.h index 2efcf4f4b..a25febc7b 100644 --- a/frameworks/js/napi/include/reminder/reminder_common.h +++ b/frameworks/js/napi/include/reminder/reminder_common.h @@ -59,6 +59,7 @@ const char* TIMER_COUNT_DOWN_TIME = "triggerTimeInSeconds"; const char* WANT_AGENT = "wantAgent"; const char* WANT_AGENT_PKG = "pkgName"; const char* WANT_AGENT_ABILITY = "abilityName"; +const char* WANT_AGENT_URI = "uri"; const char* BUTTON_WANT_AGENT = "wantAgent"; const char* BUTTON_WANT_AGENT_PKG = "pkgName"; const char* BUTTON_WANT_AGENT_ABILITY = "abilityName"; @@ -134,8 +135,8 @@ private: static bool GetPropertyValIfExist(const napi_env &env, const napi_value &value, const char* propertyName, napi_value& propertyVal); - static void GenWantAgent( - const napi_env &env, const napi_value &value, std::shared_ptr& reminder); + static bool GenWantAgent( + const napi_env &env, const napi_value &value, std::shared_ptr& reminder, bool isSysApp); static void GenMaxScreenWantAgent( const napi_env &env, const napi_value &value, std::shared_ptr& reminder); diff --git a/frameworks/js/napi/src/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp index 849d63316..f75cd24f9 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -559,8 +559,8 @@ void ParseWantAgent(const napi_env &env, ReminderRequest &reminder, napi_value & napi_create_string_utf8(env, (reminder.GetWantAgentInfo()->abilityName).c_str(), NAPI_AUTO_LENGTH, &info); napi_set_named_property(env, wantAgentInfo, WANT_AGENT_ABILITY, info); - napi_create_string_utf8(env, (reminder.GetCustomButtonUri()).c_str(), NAPI_AUTO_LENGTH, &info); - napi_set_named_property(env, wantAgentInfo, BUTTON_WANT_AGENT_URI, info); + napi_create_string_utf8(env, (reminder.GetWantAgentInfo()->uri).c_str(), NAPI_AUTO_LENGTH, &info); + napi_set_named_property(env, wantAgentInfo, WANT_AGENT_URI, info); } void ParseMaxScreenWantAgent(const napi_env &env, ReminderRequest &reminder, napi_value &result) diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index 2df3e89fc..3e5aa4050 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -131,8 +131,8 @@ void ReminderCommon::GetButtonWantAgent(const napi_env &env, const napi_value &v } } -void ReminderCommon::GenWantAgent( - const napi_env &env, const napi_value &value, std::shared_ptr& reminder) +bool ReminderCommon::GenWantAgent( + const napi_env &env, const napi_value &value, std::shared_ptr& reminder, bool isSysApp) { char str[NotificationNapi::STR_MAX_SIZE] = {0}; napi_value wantAgent = nullptr; @@ -146,11 +146,16 @@ void ReminderCommon::GenWantAgent( wantAgentInfo->abilityName = str; } if (GetStringUtf8(env, wantAgent, - ReminderAgentNapi::BUTTON_WANT_AGENT_URI, str, NotificationNapi::STR_MAX_SIZE)) { - reminder->SetCustomButtonUri(str); + ReminderAgentNapi::WANT_AGENT_URI, str, NotificationNapi::STR_MAX_SIZE)) { + if (!isSysApp) { + ANSR_LOGW("not system app, want uri is not support."); + return false; + } + wantAgentInfo->uri = str; } reminder->SetWantAgentInfo(wantAgentInfo); } + return true; } void ReminderCommon::GenMaxScreenWantAgent( @@ -300,7 +305,9 @@ napi_value ReminderCommon::GenReminder( } // wantAgent - GenWantAgent(env, value, reminder); + if (!GenWantAgent(env, value, reminder, isSysApp)) { + return nullptr; + } // maxScreenWantAgent GenMaxScreenWantAgent(env, value, reminder); diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index ce0e224e2..3cec37b15 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -136,6 +136,7 @@ public: struct WantAgentInfo { std::string pkgName = ""; std::string abilityName = ""; + std::string uri = ""; }; struct MaxScreenAgentInfo { @@ -748,7 +749,7 @@ protected: private: void AddActionButtons(const bool includeSnooze); void AddRemovalWantAgent(); - std::shared_ptr CreateWantAgent(AppExecFwk::ElementName &element) const; + std::shared_ptr CreateWantAgent(AppExecFwk::ElementName &element, bool isWantAgent) const; std::string GetButtonInfo() const; uint64_t GetNowInstantMilli() const; std::string GetShowTime(const uint64_t showTime) const; -- Gitee From 185bf268b2968193f77d2d9f5db3d935e622c08b Mon Sep 17 00:00:00 2001 From: qiaoyanqing Date: Tue, 10 Oct 2023 18:08:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=8F=90=E9=86=92=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E9=80=9A=E7=9F=A5=E6=94=AF=E6=8C=81=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=90=BA=E5=B8=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qiao --- frameworks/ans/src/reminder_request.cpp | 28 ++++++++++++++----- .../napi/include/reminder/reminder_common.h | 5 ++-- frameworks/js/napi/src/reminder/publish.cpp | 4 +-- .../js/napi/src/reminder/reminder_common.cpp | 17 +++++++---- interfaces/inner_api/reminder_request.h | 3 +- 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index 1f7f10979..12c4d1b53 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -646,6 +646,9 @@ void ReminderRequest::RecoverWantAgent(const std::string &wantAgentInfo, const u auto wai = std::make_shared(); wai->pkgName = info.at(0); wai->abilityName = info.at(1); + if (info.size() > minLen) { + wai->uri = info.at(2); + } SetWantAgentInfo(wai); break; } @@ -992,6 +995,10 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const ANSR_LOGE("Failed to write wantAgentInfo`s pkgName"); return false; } + if (!parcel.WriteString(wantAgentInfo_->uri)) { + ANSR_LOGE("Failed to write wantAgentInfo`s uri"); + return false; + } if (!parcel.WriteString(maxScreenWantAgentInfo_->abilityName)) { ANSR_LOGE("Failed to write maxScreenWantAgentInfo`s abilityName"); return false; @@ -1142,6 +1149,10 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) ANSR_LOGE("Failed to read wantAgentInfo`s pkgName"); return false; } + if (!parcel.ReadString(wantAgentInfo_->uri)) { + ANSR_LOGE("Failed to read wantAgentInfo`s uri"); + return false; + } if (!parcel.ReadString(maxScreenWantAgentInfo_->abilityName)) { ANSR_LOGE("Failed to read maxScreenWantAgentInfo`s abilityName"); return false; @@ -1488,14 +1499,16 @@ void ReminderRequest::AddRemovalWantAgent() } std::shared_ptr ReminderRequest::CreateWantAgent( - AppExecFwk::ElementName &element) const + AppExecFwk::ElementName &element, bool isWantAgent) const { int32_t requestCode = 10; std::vector flags; flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); auto want = std::make_shared(); want->SetElement(element); - want->SetUri(customButtonUri_); + if (isWantAgent) { + want->SetUri(wantAgentInfo_->uri); + } std::vector> wants; wants.push_back(want); AbilityRuntime::WantAgent::WantAgentInfo wantAgentInfo( @@ -1513,13 +1526,13 @@ std::shared_ptr ReminderRequest::CreateWan void ReminderRequest::SetMaxScreenWantAgent(AppExecFwk::ElementName &element) { - std::shared_ptr wantAgent = CreateWantAgent(element); + std::shared_ptr wantAgent = CreateWantAgent(element, false); notificationRequest_->SetMaxScreenWantAgent(wantAgent); } void ReminderRequest::SetWantAgent(AppExecFwk::ElementName &element) { - std::shared_ptr wantAgent = CreateWantAgent(element); + std::shared_ptr wantAgent = CreateWantAgent(element, true); notificationRequest_->SetWantAgent(wantAgent); } @@ -1761,11 +1774,12 @@ void ReminderRequest::AppendValuesBucket(const sptr &reminder, values.PutString(EXPIRED_CONTENT, reminder->GetExpiredContent()); auto wantAgentInfo = reminder->GetWantAgentInfo(); if (wantAgentInfo == nullptr) { - std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null"; + std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null" + ReminderRequest::SEP_WANT_AGENT + "null"; values.PutString(AGENT, info); } else { - values.PutString(AGENT, wantAgentInfo->pkgName - + ReminderRequest::SEP_WANT_AGENT + wantAgentInfo->abilityName); + std::string info = wantAgentInfo->pkgName + ReminderRequest::SEP_WANT_AGENT + + wantAgentInfo->abilityName + ReminderRequest::SEP_WANT_AGENT + wantAgentInfo->uri; + values.PutString(AGENT, info); } auto maxScreenWantAgentInfo = reminder->GetMaxScreenWantAgentInfo(); if (maxScreenWantAgentInfo == nullptr) { diff --git a/frameworks/js/napi/include/reminder/reminder_common.h b/frameworks/js/napi/include/reminder/reminder_common.h index 2efcf4f4b..a25febc7b 100644 --- a/frameworks/js/napi/include/reminder/reminder_common.h +++ b/frameworks/js/napi/include/reminder/reminder_common.h @@ -59,6 +59,7 @@ const char* TIMER_COUNT_DOWN_TIME = "triggerTimeInSeconds"; const char* WANT_AGENT = "wantAgent"; const char* WANT_AGENT_PKG = "pkgName"; const char* WANT_AGENT_ABILITY = "abilityName"; +const char* WANT_AGENT_URI = "uri"; const char* BUTTON_WANT_AGENT = "wantAgent"; const char* BUTTON_WANT_AGENT_PKG = "pkgName"; const char* BUTTON_WANT_AGENT_ABILITY = "abilityName"; @@ -134,8 +135,8 @@ private: static bool GetPropertyValIfExist(const napi_env &env, const napi_value &value, const char* propertyName, napi_value& propertyVal); - static void GenWantAgent( - const napi_env &env, const napi_value &value, std::shared_ptr& reminder); + static bool GenWantAgent( + const napi_env &env, const napi_value &value, std::shared_ptr& reminder, bool isSysApp); static void GenMaxScreenWantAgent( const napi_env &env, const napi_value &value, std::shared_ptr& reminder); diff --git a/frameworks/js/napi/src/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp index 849d63316..f75cd24f9 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -559,8 +559,8 @@ void ParseWantAgent(const napi_env &env, ReminderRequest &reminder, napi_value & napi_create_string_utf8(env, (reminder.GetWantAgentInfo()->abilityName).c_str(), NAPI_AUTO_LENGTH, &info); napi_set_named_property(env, wantAgentInfo, WANT_AGENT_ABILITY, info); - napi_create_string_utf8(env, (reminder.GetCustomButtonUri()).c_str(), NAPI_AUTO_LENGTH, &info); - napi_set_named_property(env, wantAgentInfo, BUTTON_WANT_AGENT_URI, info); + napi_create_string_utf8(env, (reminder.GetWantAgentInfo()->uri).c_str(), NAPI_AUTO_LENGTH, &info); + napi_set_named_property(env, wantAgentInfo, WANT_AGENT_URI, info); } void ParseMaxScreenWantAgent(const napi_env &env, ReminderRequest &reminder, napi_value &result) diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index 2df3e89fc..69f6c869c 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -131,8 +131,8 @@ void ReminderCommon::GetButtonWantAgent(const napi_env &env, const napi_value &v } } -void ReminderCommon::GenWantAgent( - const napi_env &env, const napi_value &value, std::shared_ptr& reminder) +bool ReminderCommon::GenWantAgent( + const napi_env &env, const napi_value &value, std::shared_ptr& reminder, bool isSysApp) { char str[NotificationNapi::STR_MAX_SIZE] = {0}; napi_value wantAgent = nullptr; @@ -146,11 +146,16 @@ void ReminderCommon::GenWantAgent( wantAgentInfo->abilityName = str; } if (GetStringUtf8(env, wantAgent, - ReminderAgentNapi::BUTTON_WANT_AGENT_URI, str, NotificationNapi::STR_MAX_SIZE)) { - reminder->SetCustomButtonUri(str); + ReminderAgentNapi::WANT_AGENT_URI, str, NotificationNapi::STR_MAX_SIZE)) { + if (!isSysApp) { + ANSR_LOGW("not system app, want uri is not support use."); + return false; + } + wantAgentInfo->uri = str; } reminder->SetWantAgentInfo(wantAgentInfo); } + return true; } void ReminderCommon::GenMaxScreenWantAgent( @@ -300,7 +305,9 @@ napi_value ReminderCommon::GenReminder( } // wantAgent - GenWantAgent(env, value, reminder); + if (!GenWantAgent(env, value, reminder, isSysApp)) { + return nullptr; + } // maxScreenWantAgent GenMaxScreenWantAgent(env, value, reminder); diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index ce0e224e2..3cec37b15 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -136,6 +136,7 @@ public: struct WantAgentInfo { std::string pkgName = ""; std::string abilityName = ""; + std::string uri = ""; }; struct MaxScreenAgentInfo { @@ -748,7 +749,7 @@ protected: private: void AddActionButtons(const bool includeSnooze); void AddRemovalWantAgent(); - std::shared_ptr CreateWantAgent(AppExecFwk::ElementName &element) const; + std::shared_ptr CreateWantAgent(AppExecFwk::ElementName &element, bool isWantAgent) const; std::string GetButtonInfo() const; uint64_t GetNowInstantMilli() const; std::string GetShowTime(const uint64_t showTime) const; -- Gitee