diff --git a/frameworks/js/napi/src/common.cpp b/frameworks/js/napi/src/common.cpp index 9348c56d02102b30fd88449dacfe6ae55480396e..6f37fe51dfe2327eaccbc707077bd1e08e278483 100644 --- a/frameworks/js/napi/src/common.cpp +++ b/frameworks/js/napi/src/common.cpp @@ -3621,41 +3621,53 @@ napi_value Common::GetNotificationSlotByVibration(const napi_env &env, const nap bool hasProperty = false; uint32_t length = 0; + // vibrationEnabled?: boolean + 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)); + if (valuetype != napi_boolean) { + ANS_LOGE("Wrong argument type. Bool expected."); + return nullptr; + } + + napi_get_value_bool(env, nobj, &vibrationEnabled); + slot.SetEnableVibration(vibrationEnabled); + } + + if (!vibrationEnabled) { + return NapiGetNull(env); + } + // vibrationValues?: Array NAPI_CALL(env, napi_has_named_property(env, value, "vibrationValues", &hasProperty)); 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."); + 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."); 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)); - NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); + if (valuetype != napi_number) { + ANS_LOGE("Wrong argument type. Number expected."); + return nullptr; + } napi_get_value_int64(env, nVibrationValue, &vibrationValue); - 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); } diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index b0165c39d1031b4a5fbf0c0c74d33516f5f8ab42..7653029df950029f703f2a5ce2895d8f0cb710e5 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 2bd254bad6145824438485acac53b7cb48f2c258..7a46b7805b29663a7757ae78000c0e5537f454fd 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.", userId); - return ERR_ANS_INVALID_PARAM; + 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