diff --git a/frameworks/ans/src/notification_multiline_content.cpp b/frameworks/ans/src/notification_multiline_content.cpp index 8fdb23049a890c98778ed0b2576ebfe9a6d757d4..8b0893c9ab11d3e3a252ff7a4c7ac7bf5151e216 100644 --- a/frameworks/ans/src/notification_multiline_content.cpp +++ b/frameworks/ans/src/notification_multiline_content.cpp @@ -58,6 +58,16 @@ std::vector NotificationMultiLineContent::GetAllLines() const return allLines_; } +void SetLineWantAgents(std::vector> lineWantAgents) +{ + lineWantAgents_ = lineWantAgents; +} + +std::vector> GetLineWantAgents() +{ + return lineWantAgents_; +} + std::string NotificationMultiLineContent::Dump() { std::string lines {}; @@ -141,6 +151,18 @@ bool NotificationMultiLineContent::Marshalling(Parcel &parcel) const return false; } + std::uint8_t lineWantAgentsLength = lineWantAgents_.size(); + if (!parcel.WriteUint8(lineWantAgentsLength)) { + ANS_LOGE("Failed to write lineWantAgentsLength"); + return false; + } + for (auto it = lineWantAgents_.begin(); it != lineWantAgents_.end(); ++it) { + if (!parcel.WriteParcelable(it->get())) { + ANS_LOGE("Fail to write wantAgent of lineWantAgent."); + return false; + } + } + return true; } @@ -176,6 +198,16 @@ bool NotificationMultiLineContent::ReadFromParcel(Parcel &parcel) ANS_LOGE("Failed to read all lines"); return false; } + std::uint8_t lineWantAgentsLength = 0; + if (!parcel.ReadUint8(lineWantAgentsLength)) { + ANS_LOGE("Failed to read lineWantAgentsLength"); + return false; + } + for (std::uint8_t i = 0; i < lineWantAgentsLength; i++) { + auto wantAgent = std::shared_ptr( + paecel.ReadParcelable()); + lineWantAgents_.push(wantAgent); + } return true; } diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index fd5dc6cd5387515898f3a8e4b10c54d6c15704b2..11b23d4a3903877297ff2b15f67d66af48f6f589 100644 --- a/frameworks/js/napi/include/common.h +++ b/frameworks/js/napi/include/common.h @@ -1558,6 +1558,17 @@ public: */ static napi_value GetMessageUserByCustom(const napi_env &env, const napi_value &result, MessageUser &messageUser); + /** + * @brief Gets the multi-line content of NotificationRequest object from specified js object + * + * @param env Indicates the environment that the API is invoked under + * @param result Indicates a js object to be converted + * @param multiLineContent Indicates a NotificationMultiLineContent object from specified js object + * @return Returns the null object if success, returns the null value otherwise + */ + static napi_value GetNotificationContentLineWantAgents(const napi_env &env, const napi_value &result, + std::shared_ptr &multiLineContent); + /** * @brief Gets the multi-line content of NotificationRequest object from specified js object * diff --git a/frameworks/js/napi/src/common_convert_content.cpp b/frameworks/js/napi/src/common_convert_content.cpp index 7ffbfaf642de905b5a32d4b6baaf86b9e1c47197..5f12d940ad5da4c0dbcdabba09010a5fbbd2b043 100644 --- a/frameworks/js/napi/src/common_convert_content.cpp +++ b/frameworks/js/napi/src/common_convert_content.cpp @@ -330,6 +330,18 @@ napi_value Common::SetNotificationMultiLineContent( } napi_set_named_property(env, result, "lines", arr); + //lineWantAgents: Array + auto lineWantAgents = multiLineContent->GetLineWantAgents(); + if (lineWantAgents.size() > 0) { + napi_value lineWantAgentsArr = nullptr; + int lineWantAgentCount = 0; + for (auto item: lineWantAgents) { + value = CreateWantAgentByJS(env, item); + napi_set_element(env, lineWantAgentsArr, lineWantAgentCount++, value); + } + napi_set_named_property(env, result, "lineWantAgents", lineWantAgentsArr); + } + return NapiGetBoolean(env, true); } @@ -1424,14 +1436,22 @@ napi_value Common::GetNotificationMultiLineContent( return nullptr; } + // lineWantAgents: Array + NAPI_CALL(env, napi_has_named_property(env, contentResult, "lineWantAgents", &hasProperty)); + if (hasProperty) { + if (GetNotificationContentLineWantAgents(env, contentResult, multiLineContent) == nullptr) { + return nullptr; + } + } + request.SetContent(std::make_shared(multiLineContent)); ANS_LOGD("end"); return NapiGetNull(env); } -napi_value Common::GetNotificationMultiLineContentLines(const napi_env &env, const napi_value &result, - std::shared_ptr &multiLineContent) +napi_value Common::GetNotificationMultiLineContentLines( + const napi_env &env, const napi_value &result, std::shared_ptr &multiLineContent) { ANS_LOGD("enter"); @@ -1470,6 +1490,54 @@ napi_value Common::GetNotificationMultiLineContentLines(const napi_env &env, con return NapiGetNull(env); } +napi_value Common::GetNotificationContentLineWantAgents( + const napi_env &env, const napi_value &result, std::shared_ptr &multiLineContent) +{ + ANS_LOGD("GetNotificationContentLineWantAgents enter"); + + bool hasProperty; + bool isArray; + napi_value value = nullptr; + napi_valuetype valuetype = napi_undefined; + std::vector> lineWantAgents; + uint32_t length = 0; + + NAPI_CALL(env, napi_has_named_property(env, result, "lineWantAgents", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, result, "lineWantAgents", &value); + NAPI_CALL(env, napi_typeof(env, value, &valuetype)); + napi_is_array(env, value, &isArray); + if (!isArray) { + ANS_LOGE("lineWantAgents is expected to be an array."); + std::string msg = "Incorrect parameter types. The type of lineWantAgents must be array."; + Common::NapiThrow(env, ERROR_PARAM_INVALID); + return nullptr; + } + napi_get_array_length(env, value, &length); + for (size_t i = 0; i < length; i++) { + napi_value wantAgentValue; + napi_get_element(env, value, i, &wantAgentValue); + NAPI_CALL(env, napi_typeof(env, wantAgentValue, &valuetype)); + if (valuetype != napi_object) { + ANS_LOGE("Wrong agrument type. Object expected."); + std::string msg = "Incorrect parameter types. The type of lineWantAgents item must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID); + return nullptr; + } + AbilityRuntime::WantAgent::WantAgent *wantAgent = nullptr; + napi_unwrap(env, wantAgentValue, (void **)&wantAgent); + if (wantAgent == nullptr) { + ANS_LOGE("Invalid object lineWantAgents"); + return nullptr; + } + lineWantAgents.push_back(std:make_shared(*wantAgent)); + } + multiLineContent->SetLineWantAgents(lineWantAgents); + } + + return NapiGetNull(env); +} + napi_value Common::GetLockScreenPicture( const napi_env &env, const napi_value &contentResult, std::shared_ptr basicContent) { diff --git a/interfaces/inner_api/notification_multiline_content.h b/interfaces/inner_api/notification_multiline_content.h index c5841bfd8fc663896fd33522eb859a0af3d61a30..d84384fcbbdea0e640482064489422dce370d0be 100644 --- a/interfaces/inner_api/notification_multiline_content.h +++ b/interfaces/inner_api/notification_multiline_content.h @@ -17,6 +17,7 @@ #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_MULTILINE_CONTENT_H #include "notification_basic_content.h" +#include "want_agent.h" #include "parcel.h" namespace OHOS { @@ -77,6 +78,20 @@ public: */ std::vector GetAllLines() const; + /** + * @brief Sets the wantAgents for lines included in this multi-line notification. + * + * @param lineWantAgents which seted to line. + */ + void SetLineWantAgents(std::vector> lineWantAgents); + + /** + * @brief Obtains the lineWantAgents included in the multi-line notification. + * + * @return lineWantAgents included in the multi-line notification. + */ + std::vector> GetLineWantAgents(); + /** * @brief Returns a string representation of the object. * @@ -135,6 +150,7 @@ private: std::string expandedTitle_ {}; std::string briefText_ {}; std::vector allLines_ {}; + std::vector> lineWantAgents_; }; } // namespace Notification } // namespace OHOS