diff --git a/frameworks/ets/ani/include/sts_notification_manager.h b/frameworks/ets/ani/include/sts_notification_manager.h index ecabcb048b4878981081c1f6da509b0249b4e1a6..a3ed873fe0e05f28696ecf8d5e655703d29c41ba 100644 --- a/frameworks/ets/ani/include/sts_notification_manager.h +++ b/frameworks/ets/ani/include/sts_notification_manager.h @@ -34,6 +34,7 @@ using ContentType = OHOS::Notification::NotificationContent::Type; using ButtonOption = OHOS::Notification::NotificationButtonOption; using NotificationDoNotDisturbDate = OHOS::Notification::NotificationDoNotDisturbDate; using RemindType = OHOS::Notification::NotificationConstant::RemindType; +using SourceType = OHOS::Notification::NotificationConstant::SourceType; using NotificationConstant = OHOS::Notification::NotificationConstant; enum STSDoNotDisturbType { @@ -79,6 +80,12 @@ enum class STSRemindType { ACTIVE_REMIND }; +enum class STSSourceType { + TYPE_NORMAL, + TYPE_CONTINUOUS, + TYPE_TIMER +}; + class StsDoNotDisturbTypeUtils { public: static bool StsToC(const STSDoNotDisturbType inType, @@ -109,6 +116,12 @@ static bool StsToC(const STSRemindType inType, RemindType &outType); static bool CToSts(const RemindType inType, STSRemindType &outType); }; +class StsSourceTypeUtils { +public: +static bool StsToC(const STSSourceType inType, SourceType &outType); +static bool CToSts(const SourceType inType, STSSourceType &outType); +}; + class StsNotificationLocalLiveViewSubscriber : public NotificationLocalLiveViewSubscriber { public: StsNotificationLocalLiveViewSubscriber(); @@ -166,6 +179,9 @@ bool ContentTypeCToEts(ani_env *env, ContentType contentType, ani_enum_item &enu bool DeviceRemindTypeCToEts(ani_env *env, RemindType remindType, ani_enum_item &enumItem); bool DeviceRemindTypeEtsToC(ani_env *env, ani_enum_item enumItem, RemindType &remindType); +bool SourceTypeCToEts(ani_env *env, SourceType sourceType, ani_enum_item &enumItem); +bool SourceTypeEtsToC(ani_env *env, ani_enum_item enumItem, SourceType &sourceType); + ani_status UnWarpNotificationButtonOption(ani_env *env, const ani_object buttonOptionObj, ButtonOption &buttonOption); ani_object WarpNotificationButtonOption(ani_env *env, sptr buttonOption); diff --git a/frameworks/ets/ani/include/sts_request.h b/frameworks/ets/ani/include/sts_request.h index c35fee773d5eed331e3e3d0efdf19ade94d5345e..5a1416d3b7e497ec62837f2148eda58a4c8ee65c 100644 --- a/frameworks/ets/ani/include/sts_request.h +++ b/frameworks/ets/ani/include/sts_request.h @@ -31,7 +31,7 @@ struct StsDistributedOptions { int32_t remindType = -1; }; -void UnWarpDistributedOptions(ani_env *env, ani_object obj, StsDistributedOptions distributedOptions); +void UnWarpDistributedOptions(ani_env *env, ani_object obj, StsDistributedOptions &distributedOptions); bool WarpNotificationUnifiedGroupInfo(ani_env* env, const std::shared_ptr &groupInfo, ani_object &groupInfoObject); @@ -39,6 +39,7 @@ ani_status UnWarpNotificationRequest( ani_env *env, ani_object obj, std::shared_ptr ¬ificationRequest); bool WarpNotificationRequest( ani_env *env, const NotificationRequest *notificationRequest, ani_class &cls, ani_object &outAniObj); +bool WarpNotification(ani_env *env, const sptr notification, ani_class &cls, ani_object &outAniObj); ani_object GetAniNotificationRequestArray(ani_env *env, std::vector> requests); ani_object GetAniNotificationRequestArrayByNotifocations(ani_env *env, std::vector> requests); diff --git a/frameworks/ets/ani/src/sts_action_button.cpp b/frameworks/ets/ani/src/sts_action_button.cpp index 24012799e73951205976680916c185ec0a5d9376..950d6d39a84f8fc2bfa112d6d21dc3a1090d1f35 100644 --- a/frameworks/ets/ani/src/sts_action_button.cpp +++ b/frameworks/ets/ani/src/sts_action_button.cpp @@ -239,7 +239,7 @@ ani_status GetNotificationActionButtonArray(ani_env *env, ani_object param, ANS_LOGE("GetActionButtonArray: GetPropertyRef name = %{public}s, status = %{public}d", name, status); return ANI_INVALID_ARGS; } - if (ANI_OK!= (status = GetPropertyInt(env, static_cast(arrayObj), "length", isUndefined, length))) { + if (ANI_OK!= (status = env->Object_GetPropertyByName_Int(static_cast(arrayObj), "length", &length))) { ANS_LOGE("GetActionButtonArray: GetPropertyDouble name = %{public}s, status = %{public}d", name, status); return status; } diff --git a/frameworks/ets/ani/src/sts_notification_manager.cpp b/frameworks/ets/ani/src/sts_notification_manager.cpp index 3987646738ecb00080f3cf3692a7aa2e118d8f67..6ed5f922a7625954c002a97724aa440cf3670def 100644 --- a/frameworks/ets/ani/src/sts_notification_manager.cpp +++ b/frameworks/ets/ani/src/sts_notification_manager.cpp @@ -286,6 +286,44 @@ bool StsRemindTypeUtils::CToSts(const RemindType inType, STSRemindType &outType) return true; } +bool StsSourceTypeUtils::StsToC(const STSSourceType inType, SourceType &outType) +{ + switch (inType) { + case STSSourceType::TYPE_NORMAL: + outType = SourceType::TYPE_NORMAL; + break; + case STSSourceType::TYPE_CONTINUOUS: + outType = SourceType::TYPE_CONTINUOUS; + break; + case STSSourceType::TYPE_TIMER: + outType = SourceType::TYPE_TIMER; + break; + default: + ANS_LOGE("SourceType %{public}d is an invalid value", inType); + return false; + } + return true; +} + +bool StsSourceTypeUtils::CToSts(const SourceType inType, STSSourceType &outType) +{ + switch (inType) { + case SourceType::TYPE_NORMAL: + outType = STSSourceType::TYPE_NORMAL; + break; + case SourceType::TYPE_CONTINUOUS: + outType = STSSourceType::TYPE_CONTINUOUS; + break; + case SourceType::TYPE_TIMER: + outType = STSSourceType::TYPE_TIMER; + break; + default: + ANS_LOGE("SourceType %{public}d is an invalid value", inType); + return false; + } + return true; +} + StsNotificationLocalLiveViewSubscriber::StsNotificationLocalLiveViewSubscriber() {} @@ -483,6 +521,25 @@ bool DeviceRemindTypeEtsToC(ani_env *env, ani_enum_item enumItem, RemindType &re return false; } +bool SourceTypeCToEts(ani_env *env, SourceType sourceType, ani_enum_item &enumItem) +{ + STSSourceType stsSourceType = STSSourceType::TYPE_NORMAL; + StsSourceTypeUtils::CToSts(sourceType, stsSourceType); + EnumConvertNativeToAni(env, + "@ohos.notificationManager.notificationManager.SourceType", stsSourceType, enumItem); + return true; +} + +bool SourceTypeEtsToC(ani_env *env, ani_enum_item enumItem, SourceType &sourceType) +{ + STSSourceType stsSourceType = STSSourceType::TYPE_NORMAL; + if (EnumConvertAniToNative(env, enumItem, stsSourceType)) { + StsSourceTypeUtils::StsToC(stsSourceType, sourceType); + return true; + } + return false; +} + ani_status UnWarpNotificationButtonOption(ani_env *env, const ani_object buttonOptionObj, ButtonOption &buttonOption) { diff --git a/frameworks/ets/ani/src/sts_request.cpp b/frameworks/ets/ani/src/sts_request.cpp index 7db7d2f3514f427781b7200fef163e303f69c4e0..60b68101290f25493051cbd8c570cecf80a7d8ff 100644 --- a/frameworks/ets/ani/src/sts_request.cpp +++ b/frameworks/ets/ani/src/sts_request.cpp @@ -33,7 +33,7 @@ namespace NotificationSts { using namespace OHOS::AAFwk; using namespace OHOS::AppExecFwk; -void UnWarpDistributedOptions(ani_env *env, ani_object obj, StsDistributedOptions distributedOptions) +void UnWarpDistributedOptions(ani_env *env, ani_object obj, StsDistributedOptions &distributedOptions) { ANS_LOGD("UnWarpDistributedOptions start"); if (env == nullptr || obj == nullptr) { @@ -883,8 +883,6 @@ bool SetNotificationRequestByNumber(ani_env* env, ani_class cls, const OHOS::Not SetPropertyOptionalByInt(env, object, "creatorPid", request->GetCreatorPid()); // badgeNumber?: long SetPropertyOptionalByLong(env, object, "badgeNumber", request->GetBadgeNumber()); - //notificationControlFlags?: long - SetPropertyOptionalByLong(env, object, "notificationControlFlags", request->GetNotificationControlFlags()); return true; } @@ -1178,6 +1176,116 @@ bool WarpNotificationRequest(ani_env *env, const OHOS::Notification::Notificatio return true; } +bool SetNotificationRequestDistributedOptions(ani_env *env, + const sptr notification, ani_object &object) +{ + ANS_LOGD("SetNotificationRequestDistributedOptions call"); + ani_object optionsObj; + ani_class ncCls; + if (!CreateClassObjByClassName(env, "notification.notificationRequest.DistributedOptionsInner", + ncCls, optionsObj) || optionsObj == nullptr) { + ANS_LOGE("create distributedOption class failed"); + return false; + } + NotificationDistributedOptions options = notification->GetNotificationRequest().GetNotificationDistributedOptions(); + // isDistributed?: boolean + if (!SetPropertyOptionalByBoolean(env, optionsObj, "isDistributed", options.IsDistributed())) { + ANS_LOGE("set isDistributed failed"); + } + // supportDisplayDevices?: Array + ani_object displayDevices = GetAniStringArrayByVectorString(env, options.GetDevicesSupportDisplay()); + if (displayDevices == nullptr || !SetPropertyByRef(env, optionsObj, "supportDisplayDevices", displayDevices)) { + ANS_LOGE("set supportDisplayDevices failed"); + } + // supportOperateDevices?: Array + ani_object supportOperateDevices = GetAniStringArrayByVectorString(env, options.GetDevicesSupportOperate()); + if (supportOperateDevices == nullptr || + !SetPropertyByRef(env, optionsObj, "supportOperateDevices", supportOperateDevices)) { + ANS_LOGE("set supportOperateDevices failed"); + } + // readonly remindType?: number + ani_enum_item remindTypeItem {}; + if (DeviceRemindTypeCToEts(env, notification->GetRemindType(), remindTypeItem)) { + CallSetter(env, ncCls, optionsObj, "remindType", remindTypeItem); + } + if (!SetPropertyByRef(env, object, "distributedOption", optionsObj)) { + ANS_LOGE("set distributedOption faild"); + } + ANS_LOGD("SetNotificationRequestDistributedOptions end"); + return true; +} + +bool WarpNotificationOther(ani_env *env, ani_class &cls, + const sptr notification, ani_object &outAniObj) +{ + // hashCode?: string + if (!SetPropertyOptionalByString(env, outAniObj, "hashCode", notification->GetKey().c_str())) { + ANS_LOGD("set hashCode faild"); + } + // isFloatingIcon ?: boolean + if (!SetPropertyOptionalByBoolean(env, outAniObj, "isFloatingIcon", notification->IsFloatingIcon())) { + ANS_LOGD("set isFloatingIcon faild"); + } + // readonly creatorBundleName?: string + if (!SetPropertyOptionalByString(env, outAniObj, "creatorBundleName", notification->GetBundleName().c_str())) { + ANS_LOGD("set creatorBundleName faild"); + } + // readonly creatorUid?: number + if (!SetPropertyOptionalByInt(env, outAniObj, "creatorUid", notification->GetNotificationRequest().GetOwnerUid())) { + ANS_LOGD("set creatorUid faild"); + } + // readonly creatorUserId?: number + if (!SetPropertyOptionalByInt(env, outAniObj, "creatorUserId", notification->GetRecvUserId())) { + ANS_LOGD("set creatorUserId faild"); + } + // readonly creatorPid?: number + if (!SetPropertyOptionalByInt(env, outAniObj, "creatorPid", notification->GetPid())) { + ANS_LOGD("set creatorPid faild"); + } + // distributedOption?:DistributedOptions + if (!SetNotificationRequestDistributedOptions(env, notification, outAniObj)) { + ANS_LOGD("set distributedOption faild"); + return false; + } + // readonly isRemoveAllowed?: boolean + if (!SetPropertyOptionalByBoolean(env, outAniObj, "isRemoveAllowed", notification->IsRemoveAllowed())) { + ANS_LOGD("set isRemoveAllowed faild"); + } + // readonly source?: number + ani_enum_item sourceTypeItem {}; + if (SourceTypeCToEts(env, notification->GetSourceType(), sourceTypeItem)) { + CallSetter(env, cls, outAniObj, "source", sourceTypeItem); + } + // readonly deviceId?: string + if (!SetPropertyOptionalByString(env, outAniObj, "deviceId", notification->GetDeviceId().c_str())) { + ANS_LOGD("set deviceId faild"); + } + // notificationControlFlags?: number + if (!SetPropertyOptionalByLong(env, outAniObj, "notificationControlFlags", + static_cast(notification->GetNotificationRequest().GetNotificationControlFlags()))) { + ANS_LOGD("set notificationControlFlags faild"); + } + return true; +} + +bool WarpNotification(ani_env *env, const sptr notification, ani_class &cls, ani_object &outAniObj) +{ + ANS_LOGD("WarpNotification called"); + if (notification == nullptr) { + ANS_LOGE("null notification"); + return false; + } + NotificationRequest request = notification->GetNotificationRequest(); + if (!WarpNotificationRequest(env, &request, cls, outAniObj)) { + return false; + } + if (!WarpNotificationOther(env, cls, notification, outAniObj)) { + return false; + } + ANS_LOGD("WarpNotification end"); + return true; +} + ani_object GetAniNotificationRequestArray(ani_env *env, std::vector> requests) { ani_object arrayObj = newArrayClass(env, requests.size()); diff --git a/frameworks/ets/ani/src/sts_subscriber.cpp b/frameworks/ets/ani/src/sts_subscriber.cpp index 934e4b772762dc34c6ed5df8ef4ad012495e3b53..60d749f07e25aee2c93615558521a9d3579b3f95 100644 --- a/frameworks/ets/ani/src/sts_subscriber.cpp +++ b/frameworks/ets/ani/src/sts_subscriber.cpp @@ -28,9 +28,13 @@ bool SetNotificationRequest(ani_env *env, const std::shared_ptr ani_status status = ANI_OK; ani_object requestObj; ani_class requestCls; - if (!WarpNotificationRequest(env, request->GetNotificationRequestPoint().GetRefPtr(), requestCls, requestObj) - || requestObj == nullptr) { - ANS_LOGE("WarpNotificationRequest faild"); + sptr notification = new (std::nothrow)NotificationSts(request->GetNotificationRequestPoint()); + if (!notification) { + ANS_LOGE("new notification faild"); + return false; + } + if (!WarpNotification(env, notification, requestCls, requestObj) || requestObj == nullptr) { + ANS_LOGE("WarpNotification faild"); return false; } if (ANI_OK != (status = env->Object_SetPropertyByName_Ref(outObj, "request", requestObj))) { diff --git a/frameworks/ets/ets/@ohos.notificationManager.ets b/frameworks/ets/ets/@ohos.notificationManager.ets index 82c069c6751d85f9774760a8d2b2de558828b08e..5a6010a170f3bed588d256070b3eb7189d436261 100644 --- a/frameworks/ets/ets/@ohos.notificationManager.ets +++ b/frameworks/ets/ets/@ohos.notificationManager.ets @@ -140,6 +140,12 @@ export default namespace notificationManager { ACTIVE_REMIND = 3, } + export enum SourceType { + TYPE_NORMAL = 0, + TYPE_CONTINUOUS = 1, + TYPE_TIMER = 2 + } + export native function nativeCancelAll(): void; export native function nativeCancelWithId(id: int): void; export native function nativeCancelWithIdLabel(id: int, label: string): void;