From 260f2581bcdc652216be5ae79bd49b8031f96bb9 Mon Sep 17 00:00:00 2001 From: luojingsong Date: Wed, 6 Nov 2024 11:23:37 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AD=97=E8=8A=82=E9=95=BF=E5=BA=A6?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: luojingsong Change-Id: Iafb6f708a2f9633b43f2ddac7b3f32183dc458aa --- .../src/notification_long_text_content.cpp | 2 +- frameworks/js/napi/include/common.h | 2 + .../js/napi/src/common_convert_content.cpp | 109 +++++++++--------- 3 files changed, 58 insertions(+), 55 deletions(-) diff --git a/frameworks/ans/src/notification_long_text_content.cpp b/frameworks/ans/src/notification_long_text_content.cpp index 72f693110..8efbac17e 100644 --- a/frameworks/ans/src/notification_long_text_content.cpp +++ b/frameworks/ans/src/notification_long_text_content.cpp @@ -25,7 +25,7 @@ namespace OHOS { namespace Notification { -const std::size_t NotificationLongTextContent::MAX_LONGTEXT_LENGTH {1024}; +const std::size_t NotificationLongTextContent::MAX_LONGTEXT_LENGTH {3072}; NotificationLongTextContent::NotificationLongTextContent(const std::string &longText) { diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index adf7d992c..44c38dd0f 100644 --- a/frameworks/js/napi/include/common.h +++ b/frameworks/js/napi/include/common.h @@ -33,6 +33,8 @@ constexpr int32_t STR_MAX_SIZE = 204; constexpr int32_t LONG_STR_MAX_SIZE = 1028; constexpr uint8_t OPERATION_MAX_TYPE = 3; constexpr int32_t LONG_LONG_STR_MAX_SIZE = 25600; +constexpr int32_t COMMON_TEXT_SIZE = 3074; +constexpr int32_t SHORT_TEXT_SIZE = 1026; constexpr int8_t NO_ERROR = 0; constexpr int8_t ERROR = -1; constexpr uint8_t PARAM0 = 0; diff --git a/frameworks/js/napi/src/common_convert_content.cpp b/frameworks/js/napi/src/common_convert_content.cpp index d6dcc0436..8d9ca01eb 100644 --- a/frameworks/js/napi/src/common_convert_content.cpp +++ b/frameworks/js/napi/src/common_convert_content.cpp @@ -544,7 +544,8 @@ napi_value Common::GetNotificationBasicContentDetailed( ANS_LOGD("enter"); bool hasProperty = false; - char str[STR_MAX_SIZE] = {0}; + char commonStr[COMMON_TEXT_SIZE] = {0}; + char shortStr[SHORT_TEXT_SIZE] = {0}; size_t strLen = 0; // title: string @@ -553,13 +554,13 @@ napi_value Common::GetNotificationBasicContentDetailed( ANS_LOGE("Failed to get title from js."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, value, str, STR_MAX_SIZE - 1, &strLen)); - if (std::strlen(str) == 0) { + NAPI_CALL(env, napi_get_value_string_utf8(env, value, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); + if (std::strlen(shortStr) == 0) { ANS_LOGE("Property title is empty"); return nullptr; } - basicContent->SetTitle(str); - ANS_LOGD("normal::title = %{public}s", str); + basicContent->SetTitle(shortStr); + ANS_LOGD("normal::title = %{public}s", shortStr); // text: string value = AppExecFwk::GetPropertyValueByPropertyName(env, contentResult, "text", napi_string); @@ -567,13 +568,13 @@ napi_value Common::GetNotificationBasicContentDetailed( ANS_LOGE("Failed to get text from js."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, value, str, STR_MAX_SIZE - 1, &strLen)); - if (std::strlen(str) == 0) { + NAPI_CALL(env, napi_get_value_string_utf8(env, value, commonStr, COMMON_TEXT_SIZE - 1, &strLen)); + if (std::strlen(commonStr) == 0) { ANS_LOGE("Property text is empty"); return nullptr; } - basicContent->SetText(str); - ANS_LOGD("normal::text = %{public}s", str); + basicContent->SetText(commonStr); + ANS_LOGD("normal::text = %{public}s", commonStr); // additionalText?: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "additionalText", &hasProperty)); @@ -583,9 +584,9 @@ napi_value Common::GetNotificationBasicContentDetailed( ANS_LOGE("Failed to get additionalText from js."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, value, str, STR_MAX_SIZE - 1, &strLen)); - basicContent->SetAdditionalText(str); - ANS_LOGD("normal::additionalText = %{public}s", str); + NAPI_CALL(env, napi_get_value_string_utf8(env, value, commonStr, COMMON_TEXT_SIZE - 1, &strLen)); + basicContent->SetAdditionalText(commonStr); + ANS_LOGD("normal::additionalText = %{public}s", commonStr); } // lockScreenPicture?: pixelMap @@ -639,8 +640,8 @@ napi_value Common::GetNotificationLongTextContentDetailed( napi_valuetype valuetype = napi_undefined; napi_value longContentResult = nullptr; bool hasProperty = false; - char str[STR_MAX_SIZE] = {0}; - char long_str[LONG_STR_MAX_SIZE + 1] = {0}; + char commonStr[COMMON_TEXT_SIZE] = {0}; + char shortStr[SHORT_TEXT_SIZE] = {0}; size_t strLen = 0; if (GetNotificationBasicContentDetailed(env, contentResult, longContent) == nullptr) { @@ -659,13 +660,13 @@ napi_value Common::GetNotificationLongTextContentDetailed( ANS_LOGE("Wrong argument type. String expected."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, longContentResult, long_str, LONG_STR_MAX_SIZE, &strLen)); - if (std::strlen(long_str) == 0) { + NAPI_CALL(env, napi_get_value_string_utf8(env, longContentResult, commonStr, COMMON_TEXT_SIZE-1, &strLen)); + if (std::strlen(commonStr) == 0) { ANS_LOGE("Property longText is empty"); return nullptr; } - longContent->SetLongText(long_str); - ANS_LOGD("longText::longText = %{public}s", long_str); + longContent->SetLongText(commonStr); + ANS_LOGD("longText::longText = %{public}s", commonStr); // briefText: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "briefText", &hasProperty)); @@ -679,13 +680,13 @@ napi_value Common::GetNotificationLongTextContentDetailed( ANS_LOGE("Wrong argument type. String expected."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, longContentResult, str, STR_MAX_SIZE - 1, &strLen)); - if (std::strlen(str) == 0) { + NAPI_CALL(env, napi_get_value_string_utf8(env, longContentResult, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); + if (std::strlen(shortStr) == 0) { ANS_LOGE("Property briefText is empty"); return nullptr; } - longContent->SetBriefText(str); - ANS_LOGD("longText::briefText = %{public}s", str); + longContent->SetBriefText(shortStr); + ANS_LOGD("longText::briefText = %{public}s", shortStr); // expandedTitle: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "expandedTitle", &hasProperty)); @@ -699,13 +700,13 @@ napi_value Common::GetNotificationLongTextContentDetailed( ANS_LOGE("Wrong argument type. String expected."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, longContentResult, str, STR_MAX_SIZE - 1, &strLen)); - if (std::strlen(str) == 0) { + NAPI_CALL(env, napi_get_value_string_utf8(env, longContentResult, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); + if (std::strlen(shortStr) == 0) { ANS_LOGE("Property expandedTitle is empty"); return nullptr; } - longContent->SetExpandedTitle(str); - ANS_LOGD("longText::expandedTitle = %{public}s", str); + longContent->SetExpandedTitle(shortStr); + ANS_LOGD("longText::expandedTitle = %{public}s", shortStr); return NapiGetNull(env); } @@ -754,7 +755,7 @@ napi_value Common::GetNotificationPictureContentDetailed(const napi_env &env, napi_valuetype valuetype = napi_undefined; napi_value pictureContentResult = nullptr; bool hasProperty = false; - char str[STR_MAX_SIZE] = {0}; + char shortStr[SHORT_TEXT_SIZE] = {0}; size_t strLen = 0; if (GetNotificationBasicContentDetailed(env, contentResult, pictureContent) == nullptr) { @@ -773,12 +774,12 @@ napi_value Common::GetNotificationPictureContentDetailed(const napi_env &env, ANS_LOGE("Wrong argument type. String expected."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, pictureContentResult, str, STR_MAX_SIZE - 1, &strLen)); - if (std::strlen(str) == 0) { + NAPI_CALL(env, napi_get_value_string_utf8(env, pictureContentResult, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); + if (std::strlen(shortStr) == 0) { ANS_LOGE("Property briefText is empty"); return nullptr; } - pictureContent->SetBriefText(str); + pictureContent->SetBriefText(shortStr); // expandedTitle: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "expandedTitle", &hasProperty)); @@ -792,12 +793,12 @@ napi_value Common::GetNotificationPictureContentDetailed(const napi_env &env, ANS_LOGE("Wrong argument type. String expected."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, pictureContentResult, str, STR_MAX_SIZE - 1, &strLen)); - if (std::strlen(str) == 0) { + NAPI_CALL(env, napi_get_value_string_utf8(env, pictureContentResult, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); + if (std::strlen(shortStr) == 0) { ANS_LOGE("Property expandedTitle is empty"); return nullptr; } - pictureContent->SetExpandedTitle(str); + pictureContent->SetExpandedTitle(shortStr); // picture: image.PixelMap NAPI_CALL(env, napi_has_named_property(env, contentResult, "picture", &hasProperty)); @@ -1065,7 +1066,7 @@ napi_value Common::GetNotificationConversationalContentTitle( napi_valuetype valuetype = napi_undefined; napi_value conversationalContentResult = nullptr; bool hasProperty = false; - char str[STR_MAX_SIZE] = {0}; + char shortStr[SHORT_TEXT_SIZE] = {0}; size_t strLen = 0; // conversationTitle: string @@ -1080,9 +1081,9 @@ napi_value Common::GetNotificationConversationalContentTitle( ANS_LOGE("Wrong argument type. String expected."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, conversationalContentResult, str, STR_MAX_SIZE - 1, &strLen)); - conversationalContent->SetConversationTitle(str); - ANS_LOGD("conversationTitle = %{public}s", str); + NAPI_CALL(env, napi_get_value_string_utf8(env, conversationalContentResult, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); + conversationalContent->SetConversationTitle(shortStr); + ANS_LOGD("conversationTitle = %{public}s", shortStr); return NapiGetNull(env); } @@ -1183,7 +1184,7 @@ napi_value Common::GetConversationalMessageBasicInfo(const napi_env &env, const napi_valuetype valuetype = napi_undefined; bool hasProperty = false; - char str[STR_MAX_SIZE] = {0}; + char commonStr[COMMON_TEXT_SIZE] = {0}; size_t strLen = 0; std::string text; int64_t timestamp = 0; @@ -1202,9 +1203,9 @@ napi_value Common::GetConversationalMessageBasicInfo(const napi_env &env, const ANS_LOGE("Wrong argument type. String expected."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, textResult, str, STR_MAX_SIZE - 1, &strLen)); - text = str; - ANS_LOGI("conversationalMessage::text = %{public}s", str); + NAPI_CALL(env, napi_get_value_string_utf8(env, textResult, commonStr, COMMON_TEXT_SIZE - 1, &strLen)); + text = commonStr; + ANS_LOGI("conversationalMessage::text = %{public}s", commonStr); // timestamp: number NAPI_CALL(env, napi_has_named_property(env, conversationalMessage, "timestamp", &hasProperty)); @@ -1306,7 +1307,7 @@ napi_value Common::GetNotificationMultiLineContent( napi_value contentResult = nullptr; napi_value multiLineContentResult = nullptr; bool hasProperty = false; - char str[STR_MAX_SIZE] = {0}; + char shortStr[SHORT_TEXT_SIZE] = {0}; size_t strLen = 0; NAPI_CALL(env, napi_has_named_property(env, result, "multiLine", &hasProperty)); @@ -1344,13 +1345,13 @@ napi_value Common::GetNotificationMultiLineContent( ANS_LOGE("Wrong argument type. String expected."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, multiLineContentResult, str, STR_MAX_SIZE - 1, &strLen)); - if (std::strlen(str) == 0) { + NAPI_CALL(env, napi_get_value_string_utf8(env, multiLineContentResult, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); + if (std::strlen(shortStr) == 0) { ANS_LOGE("Property briefText is empty"); return nullptr; } - multiLineContent->SetBriefText(str); - ANS_LOGD("multiLine: briefText = %{public}s", str); + multiLineContent->SetBriefText(shortStr); + ANS_LOGD("multiLine: briefText = %{public}s", shortStr); // longTitle: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "longTitle", &hasProperty)); @@ -1364,13 +1365,13 @@ napi_value Common::GetNotificationMultiLineContent( ANS_LOGE("Wrong argument type. String expected."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, multiLineContentResult, str, STR_MAX_SIZE - 1, &strLen)); - if (std::strlen(str) == 0) { + NAPI_CALL(env, napi_get_value_string_utf8(env, multiLineContentResult, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); + if (std::strlen(shortStr) == 0) { ANS_LOGE("Property longTitle is empty"); return nullptr; } - multiLineContent->SetExpandedTitle(str); - ANS_LOGD("multiLine: longTitle = %{public}s", str); + multiLineContent->SetExpandedTitle(shortStr); + ANS_LOGD("multiLine: longTitle = %{public}s", shortStr); // lines: Array NAPI_CALL(env, napi_has_named_property(env, contentResult, "lines", &hasProperty)); @@ -1396,7 +1397,7 @@ napi_value Common::GetNotificationMultiLineContentLines(const napi_env &env, con bool isArray = false; napi_valuetype valuetype = napi_undefined; napi_value multilines = nullptr; - char str[STR_MAX_SIZE] = {0}; + char shortStr[SHORT_TEXT_SIZE] = {0}; size_t strLen = 0; uint32_t length = 0; @@ -1420,9 +1421,9 @@ napi_value Common::GetNotificationMultiLineContentLines(const napi_env &env, con ANS_LOGE("Wrong argument type. String expected."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, line, str, STR_MAX_SIZE - 1, &strLen)); - multiLineContent->AddSingleLine(str); - ANS_LOGI("multiLine: lines : addSingleLine = %{public}s", str); + NAPI_CALL(env, napi_get_value_string_utf8(env, line, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); + multiLineContent->AddSingleLine(shortStr); + ANS_LOGI("multiLine: lines : addSingleLine = %{public}s", shortStr); } return NapiGetNull(env); -- Gitee From 9944eb2dd2fa3a4d998e96f6fb5cafbd22ca79ff Mon Sep 17 00:00:00 2001 From: luojingsong Date: Wed, 6 Nov 2024 11:48:09 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AD=97=E8=8A=82=E9=95=BF=E5=BA=A6?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: luojingsong Change-Id: Ia6c20fd52dfd31e5aaaa94551a275eeb9eab0e99 --- frameworks/js/napi/src/common_convert_content.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/js/napi/src/common_convert_content.cpp b/frameworks/js/napi/src/common_convert_content.cpp index 8d9ca01eb..43edd2bf4 100644 --- a/frameworks/js/napi/src/common_convert_content.cpp +++ b/frameworks/js/napi/src/common_convert_content.cpp @@ -1081,7 +1081,8 @@ napi_value Common::GetNotificationConversationalContentTitle( ANS_LOGE("Wrong argument type. String expected."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, conversationalContentResult, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); + NAPI_CALL(env, napi_get_value_string_utf8( + env, conversationalContentResult, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); conversationalContent->SetConversationTitle(shortStr); ANS_LOGD("conversationTitle = %{public}s", shortStr); -- Gitee