From ea8a7280f04da11860332b63449bda70a7f793b8 Mon Sep 17 00:00:00 2001 From: fangjinliang Date: Thu, 7 Jul 2022 10:14:55 +0800 Subject: [PATCH 1/3] slot modify Signed-off-by: fangjinliang --- frameworks/js/napi/src/common.cpp | 62 +++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/frameworks/js/napi/src/common.cpp b/frameworks/js/napi/src/common.cpp index 9348c56d0..eca144a5c 100644 --- a/frameworks/js/napi/src/common.cpp +++ b/frameworks/js/napi/src/common.cpp @@ -3457,20 +3457,25 @@ napi_value Common::GetNotificationSlot(const napi_env &env, const napi_value &va napi_get_value_int32(env, nobj, &slotType); NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; if (!Common::SlotTypeJSToC(SlotType(slotType), outType)) { + ANS_LOGE("SlotTypeJSToC, type=%{public}d", outType); return nullptr; } slot.SetType(outType); if (GetNotificationSlotByString(env, value, slot) == nullptr) { + ANS_LOGE("GetNotificationSlotByString"); return nullptr; } if (GetNotificationSlotByNumber(env, value, slot) == nullptr) { + ANS_LOGE("GetNotificationSlotByNumber"); return nullptr; } if (GetNotificationSlotByVibration(env, value, slot) == nullptr) { + ANS_LOGE("GetNotificationSlotByVibration"); return nullptr; } if (GetNotificationSlotByBool(env, value, slot) == nullptr) { + ANS_LOGE("GetNotificationSlotByBool"); return nullptr; } return NapiGetNull(env); @@ -3621,41 +3626,68 @@ napi_value Common::GetNotificationSlotByVibration(const napi_env &env, const nap bool hasProperty = false; uint32_t length = 0; + // vibrationEnabled?: boolean + ANS_LOGI("GetNotificationSlotByVibration 7"); + bool vibrationEnabled = false; + NAPI_CALL(env, napi_has_named_property(env, value, "vibrationEnabled", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, value, "vibrationEnabled", &nobj); + NAPI_CALL(env, napi_typeof(env, nobj, &valuetype)); + ANS_LOGI("GetNotificationSlotByVibration 8"); + if (valuetype != napi_boolean) { + ANS_LOGE("Wrong argument type. Bool expected."); + return nullptr; + } + + napi_get_value_bool(env, nobj, &vibrationEnabled); + ANS_LOGI("vibrationEnabled is: %{public}d", vibrationEnabled); + ANS_LOGI("GetNotificationSlotByVibration 9"); + slot.SetEnableVibration(vibrationEnabled); + } + ANS_LOGI("GetNotificationSlotByVibration 10"); + + if (!vibrationEnabled) { + return NapiGetNull(env); + } + // vibrationValues?: Array NAPI_CALL(env, napi_has_named_property(env, value, "vibrationValues", &hasProperty)); + ANS_LOGI("GetNotificationSlotByVibration 1"); if (hasProperty) { bool isArray = false; napi_get_named_property(env, value, "vibrationValues", &nobj); napi_is_array(env, nobj, &isArray); - NAPI_ASSERT(env, isArray, "Property vibrationValues is expected to be an array."); + ANS_LOGI("GetNotificationSlotByVibration 2"); + if (!isArray) { + ANS_LOGE("Property vibrationValues is expected to be an array."); + return nullptr; + } napi_get_array_length(env, nobj, &length); - NAPI_ASSERT(env, length > 0, "The array is empty."); + ANS_LOGI("GetNotificationSlotByVibration 3"); + if (length <= 0) { + ANS_LOGE("The array is empty."); + return nullptr; + } std::vector vibrationValues; + ANS_LOGI("GetNotificationSlotByVibration 4"); for (size_t i = 0; i < length; i++) { napi_value nVibrationValue = nullptr; int64_t vibrationValue = 0; napi_get_element(env, nobj, i, &nVibrationValue); NAPI_CALL(env, napi_typeof(env, nVibrationValue, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); + ANS_LOGI("GetNotificationSlotByVibration 5"); + if (valuetype != napi_number) { + ANS_LOGE("Wrong argument type. Number expected."); + return nullptr; + } napi_get_value_int64(env, nVibrationValue, &vibrationValue); + ANS_LOGI("GetNotificationSlotByVibration 6"); ANS_LOGI("vibrationValue is: %{public}" PRId64, vibrationValue); vibrationValues.emplace_back(vibrationValue); } slot.SetVibrationStyle(vibrationValues); } - // vibrationEnabled?: boolean - NAPI_CALL(env, napi_has_named_property(env, value, "vibrationEnabled", &hasProperty)); - if (hasProperty) { - bool vibrationEnabled = false; - napi_get_named_property(env, value, "vibrationEnabled", &nobj); - NAPI_CALL(env, napi_typeof(env, nobj, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); - napi_get_value_bool(env, nobj, &vibrationEnabled); - ANS_LOGI("vibrationEnabled is: %{public}d", vibrationEnabled); - slot.SetEnableVibration(vibrationEnabled); - } - return NapiGetNull(env); } -- Gitee From d2d1302aad3086b960e2a64fa73b5bcc78a2ec8b Mon Sep 17 00:00:00 2001 From: fangjinliang Date: Wed, 13 Jul 2022 11:48:59 +0800 Subject: [PATCH 2/3] slot modify Signed-off-by: fangjinliang --- frameworks/js/napi/src/common.cpp | 44 +++++++------------ .../ans/src/advanced_notification_service.cpp | 5 ++- .../src/distributed_preferences_info.cpp | 4 +- 3 files changed, 20 insertions(+), 33 deletions(-) diff --git a/frameworks/js/napi/src/common.cpp b/frameworks/js/napi/src/common.cpp index eca144a5c..0f5d56b06 100644 --- a/frameworks/js/napi/src/common.cpp +++ b/frameworks/js/napi/src/common.cpp @@ -3620,31 +3620,26 @@ napi_value Common::GetNotificationSlotByNumber(const napi_env &env, const napi_v napi_value Common::GetNotificationSlotByVibration(const napi_env &env, const napi_value &value, NotificationSlot &slot) { - ANS_LOGI("enter"); + ANS_LOGI("enter"); napi_value nobj = nullptr; napi_valuetype valuetype = napi_undefined; bool hasProperty = false; uint32_t length = 0; // vibrationEnabled?: boolean - ANS_LOGI("GetNotificationSlotByVibration 7"); bool vibrationEnabled = false; NAPI_CALL(env, napi_has_named_property(env, value, "vibrationEnabled", &hasProperty)); if (hasProperty) { napi_get_named_property(env, value, "vibrationEnabled", &nobj); NAPI_CALL(env, napi_typeof(env, nobj, &valuetype)); - ANS_LOGI("GetNotificationSlotByVibration 8"); if (valuetype != napi_boolean) { ANS_LOGE("Wrong argument type. Bool expected."); return nullptr; } napi_get_value_bool(env, nobj, &vibrationEnabled); - ANS_LOGI("vibrationEnabled is: %{public}d", vibrationEnabled); - ANS_LOGI("GetNotificationSlotByVibration 9"); slot.SetEnableVibration(vibrationEnabled); } - ANS_LOGI("GetNotificationSlotByVibration 10"); if (!vibrationEnabled) { return NapiGetNull(env); @@ -3652,40 +3647,31 @@ napi_value Common::GetNotificationSlotByVibration(const napi_env &env, const nap // vibrationValues?: Array NAPI_CALL(env, napi_has_named_property(env, value, "vibrationValues", &hasProperty)); - ANS_LOGI("GetNotificationSlotByVibration 1"); if (hasProperty) { bool isArray = false; napi_get_named_property(env, value, "vibrationValues", &nobj); napi_is_array(env, nobj, &isArray); - ANS_LOGI("GetNotificationSlotByVibration 2"); if (!isArray) { ANS_LOGE("Property vibrationValues is expected to be an array."); return nullptr; } napi_get_array_length(env, nobj, &length); - ANS_LOGI("GetNotificationSlotByVibration 3"); - if (length <= 0) { - ANS_LOGE("The array is empty."); - return nullptr; - } - std::vector vibrationValues; - ANS_LOGI("GetNotificationSlotByVibration 4"); - for (size_t i = 0; i < length; i++) { - napi_value nVibrationValue = nullptr; - int64_t vibrationValue = 0; - napi_get_element(env, nobj, i, &nVibrationValue); - NAPI_CALL(env, napi_typeof(env, nVibrationValue, &valuetype)); - ANS_LOGI("GetNotificationSlotByVibration 5"); - if (valuetype != napi_number) { - ANS_LOGE("Wrong argument type. Number expected."); - return nullptr; + if (length > 0) { + std::vector vibrationValues; + for (size_t i = 0; i < length; i++) { + napi_value nVibrationValue = nullptr; + int64_t vibrationValue = 0; + napi_get_element(env, nobj, i, &nVibrationValue); + NAPI_CALL(env, napi_typeof(env, nVibrationValue, &valuetype)); + if (valuetype != napi_number) { + ANS_LOGE("Wrong argument type. Number expected."); + return nullptr; + } + napi_get_value_int64(env, nVibrationValue, &vibrationValue); + vibrationValues.emplace_back(vibrationValue); } - napi_get_value_int64(env, nVibrationValue, &vibrationValue); - ANS_LOGI("GetNotificationSlotByVibration 6"); - ANS_LOGI("vibrationValue is: %{public}" PRId64, vibrationValue); - vibrationValues.emplace_back(vibrationValue); + slot.SetVibrationStyle(vibrationValues); } - slot.SetVibrationStyle(vibrationValues); } return NapiGetNull(env); diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index b0165c39d..7653029df 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -3687,8 +3687,9 @@ ErrCode AdvancedNotificationService::GetEnabledForBundleSlot( return; } if (slot == nullptr) { - ANS_LOGE("Get enable slot: object is null"); - result = ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST; + ANS_LOGW("Get enable slot: object is null, enabled default true"); + enabled = true; + result = ERR_OK; return; } enabled = slot->GetEnable(); diff --git a/services/distributed/src/distributed_preferences_info.cpp b/services/distributed/src/distributed_preferences_info.cpp index 2bd254bad..ca455c362 100644 --- a/services/distributed/src/distributed_preferences_info.cpp +++ b/services/distributed/src/distributed_preferences_info.cpp @@ -65,8 +65,8 @@ ErrCode DistributedPreferencesInfo::GetSyncEnabledWithoutApp(const int32_t userI { auto iter = enabledWithoutApp_.find(userId); if (iter == enabledWithoutApp_.end()) { - ANS_LOGW("userId(%{public}d) not found.", userId); - return ERR_ANS_INVALID_PARAM; + ANS_LOGW("userId(%{public}d) not found. enabled default false", userId); + enabled = false; } enabled = iter->second; -- Gitee From e42075a97ed3875bddeeb3677342f21b464af8ed Mon Sep 17 00:00:00 2001 From: fangjinliang Date: Wed, 13 Jul 2022 14:21:02 +0800 Subject: [PATCH 3/3] slot modify Signed-off-by: fangjinliang --- frameworks/js/napi/src/common.cpp | 34 ++++++++----------- .../src/distributed_preferences_info.cpp | 7 ++-- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/frameworks/js/napi/src/common.cpp b/frameworks/js/napi/src/common.cpp index 0f5d56b06..6f37fe51d 100644 --- a/frameworks/js/napi/src/common.cpp +++ b/frameworks/js/napi/src/common.cpp @@ -3457,25 +3457,20 @@ napi_value Common::GetNotificationSlot(const napi_env &env, const napi_value &va napi_get_value_int32(env, nobj, &slotType); NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; if (!Common::SlotTypeJSToC(SlotType(slotType), outType)) { - ANS_LOGE("SlotTypeJSToC, type=%{public}d", outType); return nullptr; } slot.SetType(outType); if (GetNotificationSlotByString(env, value, slot) == nullptr) { - ANS_LOGE("GetNotificationSlotByString"); return nullptr; } if (GetNotificationSlotByNumber(env, value, slot) == nullptr) { - ANS_LOGE("GetNotificationSlotByNumber"); return nullptr; } if (GetNotificationSlotByVibration(env, value, slot) == nullptr) { - ANS_LOGE("GetNotificationSlotByVibration"); return nullptr; } if (GetNotificationSlotByBool(env, value, slot) == nullptr) { - ANS_LOGE("GetNotificationSlotByBool"); return nullptr; } return NapiGetNull(env); @@ -3620,7 +3615,7 @@ napi_value Common::GetNotificationSlotByNumber(const napi_env &env, const napi_v napi_value Common::GetNotificationSlotByVibration(const napi_env &env, const napi_value &value, NotificationSlot &slot) { - ANS_LOGI("enter"); + ANS_LOGI("enter"); napi_value nobj = nullptr; napi_valuetype valuetype = napi_undefined; bool hasProperty = false; @@ -3655,23 +3650,22 @@ napi_value Common::GetNotificationSlotByVibration(const napi_env &env, const nap ANS_LOGE("Property vibrationValues is expected to be an array."); return nullptr; } + napi_get_array_length(env, nobj, &length); - if (length > 0) { - std::vector vibrationValues; - for (size_t i = 0; i < length; i++) { - napi_value nVibrationValue = nullptr; - int64_t vibrationValue = 0; - napi_get_element(env, nobj, i, &nVibrationValue); - NAPI_CALL(env, napi_typeof(env, nVibrationValue, &valuetype)); - if (valuetype != napi_number) { - ANS_LOGE("Wrong argument type. Number expected."); - return nullptr; - } - napi_get_value_int64(env, nVibrationValue, &vibrationValue); - vibrationValues.emplace_back(vibrationValue); + std::vector vibrationValues; + for (size_t i = 0; i < length; i++) { + napi_value nVibrationValue = nullptr; + int64_t vibrationValue = 0; + napi_get_element(env, nobj, i, &nVibrationValue); + NAPI_CALL(env, napi_typeof(env, nVibrationValue, &valuetype)); + if (valuetype != napi_number) { + ANS_LOGE("Wrong argument type. Number expected."); + return nullptr; } - slot.SetVibrationStyle(vibrationValues); + napi_get_value_int64(env, nVibrationValue, &vibrationValue); + vibrationValues.emplace_back(vibrationValue); } + slot.SetVibrationStyle(vibrationValues); } return NapiGetNull(env); diff --git a/services/distributed/src/distributed_preferences_info.cpp b/services/distributed/src/distributed_preferences_info.cpp index ca455c362..7a46b7805 100644 --- a/services/distributed/src/distributed_preferences_info.cpp +++ b/services/distributed/src/distributed_preferences_info.cpp @@ -65,11 +65,12 @@ ErrCode DistributedPreferencesInfo::GetSyncEnabledWithoutApp(const int32_t userI { auto iter = enabledWithoutApp_.find(userId); if (iter == enabledWithoutApp_.end()) { - ANS_LOGW("userId(%{public}d) not found. enabled default false", userId); enabled = false; + ANS_LOGW("userId(%{public}d) not found. enabled default false", userId); + } else { + enabled = iter->second; + ANS_LOGI("userId(%{public}d) enabled = %{public}d", userId, enabled); } - - enabled = iter->second; return ERR_OK; } } // namespace Notification -- Gitee