diff --git a/frameworks/ets/ani/include/sts_subscribe_info.h b/frameworks/ets/ani/include/sts_subscribe_info.h index 5342188b8f488620623f94e672027254fe6edefc..b5adb5c932cac3c8f29bda53cffb41ae915393d9 100644 --- a/frameworks/ets/ani/include/sts_subscribe_info.h +++ b/frameworks/ets/ani/include/sts_subscribe_info.h @@ -23,6 +23,7 @@ namespace NotificationSts { using NotificationSubscribeInfo = OHOS::Notification::NotificationSubscribeInfo; bool UnwarpNotificationSubscribeInfo(ani_env *env, ani_object value, NotificationSubscribeInfo &info); +void UnwarpNotificationSoltType(ani_env *env, ani_object value, NotificationSubscribeInfo &info); } // namespace NotificationSts } // OHOS #endif \ No newline at end of file diff --git a/frameworks/ets/ani/src/sts_request.cpp b/frameworks/ets/ani/src/sts_request.cpp index 71972128ef2656ea93559e95038ae6a2fc554c23..7f29eda660a6b3ecee6590532c77884ced8393b6 100644 --- a/frameworks/ets/ani/src/sts_request.cpp +++ b/frameworks/ets/ani/src/sts_request.cpp @@ -542,7 +542,7 @@ void GetNotificationExtraInfo(ani_env *env, ani_object obj, std::shared_ptrSetAdditionalData(extras); } +void GetNotificationExtendInfo(ani_env *env, ani_object obj, std::shared_ptr &request) +{ + ani_boolean isUndefined = ANI_TRUE; + ani_ref extendInfoRef = {}; + if (ANI_OK != GetPropertyRef(env, obj, "extendInfo", isUndefined, extendInfoRef) + || isUndefined == ANI_TRUE || extendInfoRef == nullptr) { + ANS_LOGE("GetNotificationExtendInfo: get ref failed"); + return; + } + WantParams wantParams = {}; + UnwrapWantParams(env, extendInfoRef, wantParams); + std::shared_ptr extend = std::make_shared(wantParams); + request->SetExtendInfo(extend); +} + void GetNotificationRemovalWantAgent(ani_env *env, ani_object obj, std::shared_ptr &request) { @@ -725,6 +740,7 @@ ani_status GetNotificationRequestByCustom(ani_env *env, ani_object obj, GetNotificationWantAgent(env, obj, notificationRequest); GetNotificationExtraInfo(env, obj, notificationRequest); GetNotificationRemovalWantAgent(env, obj, notificationRequest); + GetNotificationExtendInfo(env, obj, notificationRequest); GetNotificationActionButtons(env, obj, notificationRequest); GetNotificationSmallIcon(env, obj, notificationRequest); GetNotificationLargeIcon(env, obj, notificationRequest); @@ -972,12 +988,26 @@ bool SetRequestExtraInfo(ani_env *env, const OHOS::Notification::NotificationReq return true; } ani_ref extraInfo = OHOS::AppExecFwk::WrapWantParams(env, *additionalData); - if (extraInfo == nullptr || !SetPropertyByRef(env, object, "extendInfo", extraInfo)) { + if (extraInfo == nullptr || !SetPropertyByRef(env, object, "extraInfo", extraInfo)) { ANS_LOGD("SetNotificationRequestByCustom: set extraInfo failed"); } return true; } +bool SetRequestExtendInfo(ani_env *env, const OHOS::Notification::NotificationRequest *request, ani_object &object) +{ + std::shared_ptr extendData = request->GetExtendInfo(); + if (extendData == nullptr) { + ANS_LOGD("extendInfo is Undefine"); + return true; + } + ani_ref extendInfo = OHOS::AppExecFwk::WrapWantParams(env, *extendData); + if (extendInfo == nullptr || !SetPropertyByRef(env, object, "extendInfo", extendInfo)) { + ANS_LOGD("SetNotificationRequestByCustom: set extendInfo failed"); + } + return true; +} + bool SetRequestActionButtons(ani_env *env, const OHOS::Notification::NotificationRequest *request, ani_object &object) { std::vector> actionButtons = request->GetActionButtons(); diff --git a/frameworks/ets/ani/src/sts_subscribe.cpp b/frameworks/ets/ani/src/sts_subscribe.cpp index 083542849c967b13382e771b9452195a1c14ef1d..a80411ea7cbd47e6280514d5cd13448428f483e5 100644 --- a/frameworks/ets/ani/src/sts_subscribe.cpp +++ b/frameworks/ets/ani/src/sts_subscribe.cpp @@ -795,6 +795,18 @@ bool UnwarpOperationInfo(ani_env *env, const ani_object obj, StsNotificationOper return false; } outObj.SetUserInput(GetResizeStr(userInput, LONG_STR_MAX_SIZE)); + int32_t operationType; + if (GetPropertyInt(env, obj, "operationType", isUndefined, operationType) != ANI_OK || isUndefined == ANI_TRUE) { + ANS_LOGD("ConvertOperationInfoToNative GetIntOrUndefined operationType fail"); + return false; + } + outObj.SetOperationType(static_cast(operationType)); + int32_t btnIndex; + if (GetPropertyInt(env, obj, "buttonIndex", isUndefined, btnIndex) != ANI_OK || isUndefined == ANI_TRUE) { + ANS_LOGD("ConvertOperationInfoToNative GetIntOrUndefined buttonIndex fail"); + return false; + } + outObj.SetBtnIndex(btnIndex); return true; } diff --git a/frameworks/ets/ani/src/sts_subscribe_info.cpp b/frameworks/ets/ani/src/sts_subscribe_info.cpp index 98f4ff9e2b15299f61558dbd8f07bdc7ffd7637c..6a93210939d901eec6416876b6014560f6b5b5f9 100644 --- a/frameworks/ets/ani/src/sts_subscribe_info.cpp +++ b/frameworks/ets/ani/src/sts_subscribe_info.cpp @@ -16,6 +16,7 @@ #include "sts_common.h" #include "ans_log_wrapper.h" +#include "notification_constant.h" // for NotificationConstant::SlotType namespace OHOS { namespace NotificationSts { @@ -55,8 +56,45 @@ bool UnwarpNotificationSubscribeInfo(ani_env *env, ani_object value, Notificatio info.AddDeviceType(GetResizeStr(deviceType, STR_MAX_SIZE)); ANS_LOGD("userId %{public}d deviceType %{public}s filterLimit %{public}d", info.GetAppUserId(), info.GetDeviceType().c_str(), info.GetFilterType()); + UnwarpNotificationSoltType(env, value, info); return true; } +void UnwarpNotificationSoltType(ani_env *env, ani_object value, NotificationSubscribeInfo &info) +{ + ANS_LOGD("UnwarpNotificationSoltType in"); + ani_ref arrayObj = nullptr; + ani_status status; + ani_double length; + ani_boolean isUndefined = ANI_TRUE; + if ((status = GetPropertyRef(env, value, "slotTypes", isUndefined, arrayObj)) != ANI_OK + || isUndefined == ANI_TRUE) { + ANS_LOGE("GetPropertyRef failed"); + return; + } + if ((status = env->Object_GetPropertyByName_Double(static_cast(arrayObj), "length", &length)) + != ANI_OK) { + ANS_LOGE("Object_GetPropertyByName_Double failed"); + return; + } + std::vector slotTypes = {}; + for (int i = 0; i < static_cast(length); i++) { + ani_ref enumItemRef; + if ((status = env->Object_CallMethodByName_Ref(static_cast(arrayObj), "$_get", + "i:C{std.core.Object}", &enumItemRef, (ani_int)i)) != ANI_OK) { + ANS_LOGE("Object_CallMethodByName_Ref failed"); + return; + } + auto slotType = Notification::NotificationConstant::SlotType::ILLEGAL_TYPE; + if (!EnumConvertAniToNative(env, static_cast(enumItemRef), slotType)) { + ANS_LOGE("EnumConvertAniToNative failed"); + return; + } + slotTypes.emplace_back(slotType); + } + info.SetSlotTypes(slotTypes); + ANS_LOGD("UnwarpNotificationSoltType end, slotTypes size:%{public}d", slotTypes.size()); +} + } // namespace NotificationSts } // OHOS diff --git a/frameworks/ets/ets/@ohos.notificationSubscribe.ets b/frameworks/ets/ets/@ohos.notificationSubscribe.ets index 7e5e27d16ebdef630d88a120938d575884a4cd19..2b7435a3efe735a2b83684bece39e52d04532eaf 100644 --- a/frameworks/ets/ets/@ohos.notificationSubscribe.ets +++ b/frameworks/ets/ets/@ohos.notificationSubscribe.ets @@ -316,11 +316,15 @@ export default namespace notificationSubscribe { export interface OperationInfo { actionName?: string; userInput?: string; + operationType?: int; + buttonIndex?: int; } class OperationInfoInner implements OperationInfo { public actionName?: string; public userInput?: string; + public operationType?: int; + public buttonIndex?: int; } export function subscribeSelf(subscriber: NotificationSubscriber): Promise { diff --git a/frameworks/ets/ets/notification/notificationRequest.ets b/frameworks/ets/ets/notification/notificationRequest.ets index 7ef87e11355c9e3e5772286f1a44c69b988f553a..2cfb62aad69fc4d7900a1696bc28c01d48125df9 100644 --- a/frameworks/ets/ets/notification/notificationRequest.ets +++ b/frameworks/ets/ets/notification/notificationRequest.ets @@ -89,6 +89,7 @@ export interface NotificationRequest { tapDismissed?: boolean; autoDeletedTime?: long; wantAgent?: WantAgent; + extraInfo?: Record; extendInfo?: Record; color?: long; colorEnabled?: boolean; @@ -140,6 +141,7 @@ class NotificationRequestInner implements NotificationRequest { public tapDismissed?: boolean | undefined; public autoDeletedTime?: long | undefined; public wantAgent?: WantAgent | undefined; + public extraInfo?: Record | undefined; public extendInfo?: Record | undefined; public color?: long | undefined; public colorEnabled?: boolean | undefined; diff --git a/frameworks/ets/ets/notification/notificationSubscribeInfo.ets b/frameworks/ets/ets/notification/notificationSubscribeInfo.ets index 5011aeb7c7d7e5713a0b35b5f308d764fa566cad..025fcf49f79710c9afc2e1f2f74abfeb4ccd991b 100644 --- a/frameworks/ets/ets/notification/notificationSubscribeInfo.ets +++ b/frameworks/ets/ets/notification/notificationSubscribeInfo.ets @@ -13,11 +13,14 @@ * limitations under the License. */ + import type notificationManager from '@ohos.notificationManager'; + export interface NotificationSubscribeInfo { bundleNames?: Array; userId?: int; deviceType?: string; filterLimit?: long; + slotTypes?: Array; } class NotificationSubscribeInfoInner implements NotificationSubscribeInfo { @@ -25,4 +28,5 @@ class NotificationSubscribeInfoInner implements NotificationSubscribeInfo { public userId?: int; public deviceType?: string; public filterLimit?: long; + public slotTypes?: Array; } \ No newline at end of file