diff --git a/frameworks/cj/ffi/src/notification_utils.cpp b/frameworks/cj/ffi/src/notification_utils.cpp index 51b9c918c745bfd61a906181ff0566687cc83bbd..7df538ff7c49cabd03159f1c41527ac468826c77 100644 --- a/frameworks/cj/ffi/src/notification_utils.cpp +++ b/frameworks/cj/ffi/src/notification_utils.cpp @@ -227,6 +227,7 @@ namespace Notification { std::shared_ptr basicContent) { char str[STR_MAX_SIZE] = {0}; + char longStr[LONG_STR_MAX_SIZE] = {0}; // title: String if (strcpy_s(str, STR_MAX_SIZE, contentResult->title) != EOK) { return false; @@ -237,19 +238,19 @@ namespace Notification { } basicContent->SetTitle(std::string(str)); // text: String - if (strcpy_s(str, STR_MAX_SIZE, contentResult->text) != EOK) { + if (strcpy_s(longStr, LONG_STR_MAX_SIZE, contentResult->text) != EOK) { return false; } - if (strlen(str) == 0) { + if (strlen(longStr) == 0) { LOGE("Property text is empty"); return false; } - basicContent->SetText(std::string(str)); + basicContent->SetText(std::string(longStr)); // additionalText: string - if (strcpy_s(str, STR_MAX_SIZE, contentResult->additionalText) != EOK) { + if (strcpy_s(longStr, LONG_STR_MAX_SIZE, contentResult->additionalText) != EOK) { return false; } - basicContent->SetAdditionalText(std::string(str)); + basicContent->SetAdditionalText(std::string(longStr)); // lockScreenPicture?: pixelMap if (contentResult->lockscreenPicture != -1) { @@ -283,7 +284,7 @@ namespace Notification { std::shared_ptr &longContent) { char str[STR_MAX_SIZE] = {0}; - char long_str[LONG_STR_MAX_SIZE + 1] = {0}; + char long_str[LONG_STR_MAX_SIZE] = {0}; std::shared_ptr tempContent = std::make_shared(); tempContent->title = contentResult->title; @@ -295,7 +296,7 @@ namespace Notification { } // longText: String - if (strcpy_s(long_str, LONG_STR_MAX_SIZE + 1, contentResult->longText) != EOK) { + if (strcpy_s(long_str, LONG_STR_MAX_SIZE, contentResult->longText) != EOK) { return false; } if (strlen(long_str) == 0) { diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index 44c38dd0fcc1b0f983084fbe385060aa94489c7b..e8f5fdc7a7c27dc452059b0ec79a5868ba84187c 100644 --- a/frameworks/js/napi/include/common.h +++ b/frameworks/js/napi/include/common.h @@ -29,12 +29,10 @@ namespace OHOS { namespace NotificationNapi { using namespace OHOS::Notification; -constexpr int32_t STR_MAX_SIZE = 204; -constexpr int32_t LONG_STR_MAX_SIZE = 1028; +constexpr int32_t STR_MAX_SIZE = 1026; +constexpr int32_t LONG_STR_MAX_SIZE = 3074; 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 43edd2bf4a5415852ce5fbb0b3041e7966117851..c88da8d0fd62a59936768f9409b07c9635b2fbf1 100644 --- a/frameworks/js/napi/src/common_convert_content.cpp +++ b/frameworks/js/napi/src/common_convert_content.cpp @@ -544,8 +544,8 @@ napi_value Common::GetNotificationBasicContentDetailed( ANS_LOGD("enter"); bool hasProperty = false; - char commonStr[COMMON_TEXT_SIZE] = {0}; - char shortStr[SHORT_TEXT_SIZE] = {0}; + char longStr[LONG_STR_MAX_SIZE] = {0}; + char shortStr[STR_MAX_SIZE] = {0}; size_t strLen = 0; // title: string @@ -554,7 +554,7 @@ napi_value Common::GetNotificationBasicContentDetailed( ANS_LOGE("Failed to get title from js."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, value, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); + NAPI_CALL(env, napi_get_value_string_utf8(env, value, shortStr, STR_MAX_SIZE - 1, &strLen)); if (std::strlen(shortStr) == 0) { ANS_LOGE("Property title is empty"); return nullptr; @@ -568,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, commonStr, COMMON_TEXT_SIZE - 1, &strLen)); - if (std::strlen(commonStr) == 0) { + NAPI_CALL(env, napi_get_value_string_utf8(env, value, longStr, LONG_STR_MAX_SIZE - 1, &strLen)); + if (std::strlen(longStr) == 0) { ANS_LOGE("Property text is empty"); return nullptr; } - basicContent->SetText(commonStr); - ANS_LOGD("normal::text = %{public}s", commonStr); + basicContent->SetText(longStr); + ANS_LOGD("normal::text = %{public}s", longStr); // additionalText?: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "additionalText", &hasProperty)); @@ -584,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, commonStr, COMMON_TEXT_SIZE - 1, &strLen)); - basicContent->SetAdditionalText(commonStr); - ANS_LOGD("normal::additionalText = %{public}s", commonStr); + NAPI_CALL(env, napi_get_value_string_utf8(env, value, longStr, LONG_STR_MAX_SIZE - 1, &strLen)); + basicContent->SetAdditionalText(longStr); + ANS_LOGD("normal::additionalText = %{public}s", longStr); } // lockScreenPicture?: pixelMap @@ -640,8 +640,8 @@ napi_value Common::GetNotificationLongTextContentDetailed( napi_valuetype valuetype = napi_undefined; napi_value longContentResult = nullptr; bool hasProperty = false; - char commonStr[COMMON_TEXT_SIZE] = {0}; - char shortStr[SHORT_TEXT_SIZE] = {0}; + char longStr[LONG_STR_MAX_SIZE] = {0}; + char shortStr[STR_MAX_SIZE] = {0}; size_t strLen = 0; if (GetNotificationBasicContentDetailed(env, contentResult, longContent) == nullptr) { @@ -660,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, commonStr, COMMON_TEXT_SIZE-1, &strLen)); - if (std::strlen(commonStr) == 0) { + NAPI_CALL(env, napi_get_value_string_utf8(env, longContentResult, longStr, LONG_STR_MAX_SIZE-1, &strLen)); + if (std::strlen(longStr) == 0) { ANS_LOGE("Property longText is empty"); return nullptr; } - longContent->SetLongText(commonStr); - ANS_LOGD("longText::longText = %{public}s", commonStr); + longContent->SetLongText(longStr); + ANS_LOGD("longText::longText = %{public}s", longStr); // briefText: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "briefText", &hasProperty)); @@ -680,7 +680,7 @@ napi_value Common::GetNotificationLongTextContentDetailed( ANS_LOGE("Wrong argument type. String expected."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, longContentResult, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); + NAPI_CALL(env, napi_get_value_string_utf8(env, longContentResult, shortStr, STR_MAX_SIZE - 1, &strLen)); if (std::strlen(shortStr) == 0) { ANS_LOGE("Property briefText is empty"); return nullptr; @@ -700,7 +700,7 @@ napi_value Common::GetNotificationLongTextContentDetailed( ANS_LOGE("Wrong argument type. String expected."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, longContentResult, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); + NAPI_CALL(env, napi_get_value_string_utf8(env, longContentResult, shortStr, STR_MAX_SIZE - 1, &strLen)); if (std::strlen(shortStr) == 0) { ANS_LOGE("Property expandedTitle is empty"); return nullptr; @@ -755,7 +755,7 @@ napi_value Common::GetNotificationPictureContentDetailed(const napi_env &env, napi_valuetype valuetype = napi_undefined; napi_value pictureContentResult = nullptr; bool hasProperty = false; - char shortStr[SHORT_TEXT_SIZE] = {0}; + char shortStr[STR_MAX_SIZE] = {0}; size_t strLen = 0; if (GetNotificationBasicContentDetailed(env, contentResult, pictureContent) == nullptr) { @@ -774,7 +774,7 @@ 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, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); + NAPI_CALL(env, napi_get_value_string_utf8(env, pictureContentResult, shortStr, STR_MAX_SIZE - 1, &strLen)); if (std::strlen(shortStr) == 0) { ANS_LOGE("Property briefText is empty"); return nullptr; @@ -793,7 +793,7 @@ 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, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); + NAPI_CALL(env, napi_get_value_string_utf8(env, pictureContentResult, shortStr, STR_MAX_SIZE - 1, &strLen)); if (std::strlen(shortStr) == 0) { ANS_LOGE("Property expandedTitle is empty"); return nullptr; @@ -1066,7 +1066,7 @@ napi_value Common::GetNotificationConversationalContentTitle( napi_valuetype valuetype = napi_undefined; napi_value conversationalContentResult = nullptr; bool hasProperty = false; - char shortStr[SHORT_TEXT_SIZE] = {0}; + char shortStr[STR_MAX_SIZE] = {0}; size_t strLen = 0; // conversationTitle: string @@ -1082,7 +1082,7 @@ napi_value Common::GetNotificationConversationalContentTitle( return nullptr; } NAPI_CALL(env, napi_get_value_string_utf8( - env, conversationalContentResult, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); + env, conversationalContentResult, shortStr, STR_MAX_SIZE - 1, &strLen)); conversationalContent->SetConversationTitle(shortStr); ANS_LOGD("conversationTitle = %{public}s", shortStr); @@ -1185,7 +1185,7 @@ napi_value Common::GetConversationalMessageBasicInfo(const napi_env &env, const napi_valuetype valuetype = napi_undefined; bool hasProperty = false; - char commonStr[COMMON_TEXT_SIZE] = {0}; + char longStr[LONG_STR_MAX_SIZE] = {0}; size_t strLen = 0; std::string text; int64_t timestamp = 0; @@ -1204,9 +1204,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, commonStr, COMMON_TEXT_SIZE - 1, &strLen)); - text = commonStr; - ANS_LOGI("conversationalMessage::text = %{public}s", commonStr); + NAPI_CALL(env, napi_get_value_string_utf8(env, textResult, longStr, LONG_STR_MAX_SIZE - 1, &strLen)); + text = longStr; + ANS_LOGI("conversationalMessage::text = %{public}s", longStr); // timestamp: number NAPI_CALL(env, napi_has_named_property(env, conversationalMessage, "timestamp", &hasProperty)); @@ -1308,7 +1308,7 @@ napi_value Common::GetNotificationMultiLineContent( napi_value contentResult = nullptr; napi_value multiLineContentResult = nullptr; bool hasProperty = false; - char shortStr[SHORT_TEXT_SIZE] = {0}; + char shortStr[STR_MAX_SIZE] = {0}; size_t strLen = 0; NAPI_CALL(env, napi_has_named_property(env, result, "multiLine", &hasProperty)); @@ -1346,7 +1346,7 @@ napi_value Common::GetNotificationMultiLineContent( ANS_LOGE("Wrong argument type. String expected."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, multiLineContentResult, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); + NAPI_CALL(env, napi_get_value_string_utf8(env, multiLineContentResult, shortStr, STR_MAX_SIZE - 1, &strLen)); if (std::strlen(shortStr) == 0) { ANS_LOGE("Property briefText is empty"); return nullptr; @@ -1366,7 +1366,7 @@ napi_value Common::GetNotificationMultiLineContent( ANS_LOGE("Wrong argument type. String expected."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, multiLineContentResult, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); + NAPI_CALL(env, napi_get_value_string_utf8(env, multiLineContentResult, shortStr, STR_MAX_SIZE - 1, &strLen)); if (std::strlen(shortStr) == 0) { ANS_LOGE("Property longTitle is empty"); return nullptr; @@ -1398,7 +1398,7 @@ napi_value Common::GetNotificationMultiLineContentLines(const napi_env &env, con bool isArray = false; napi_valuetype valuetype = napi_undefined; napi_value multilines = nullptr; - char shortStr[SHORT_TEXT_SIZE] = {0}; + char shortStr[STR_MAX_SIZE] = {0}; size_t strLen = 0; uint32_t length = 0; @@ -1422,7 +1422,7 @@ 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, shortStr, SHORT_TEXT_SIZE - 1, &strLen)); + NAPI_CALL(env, napi_get_value_string_utf8(env, line, shortStr, STR_MAX_SIZE - 1, &strLen)); multiLineContent->AddSingleLine(shortStr); ANS_LOGI("multiLine: lines : addSingleLine = %{public}s", shortStr); }