From 664f4a072e9ff5e526efaa211774cd4332739a7c Mon Sep 17 00:00:00 2001 From: zouheng <18179045811@163.com> Date: Fri, 29 Aug 2025 16:40:00 +0800 Subject: [PATCH] =?UTF-8?q?401=E9=94=99=E8=AF=AF=E7=A0=81=E5=AF=B9?= =?UTF-8?q?=E6=AF=94NAPI=E9=80=BB=E8=BE=91=EF=BC=8C=E5=9C=A8ETS=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=BF=9B=E8=A1=8C=E5=85=A5=E5=8F=82=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouheng <18179045811@163.com> --- .../ets/ets/@ohos.notificationManager.ets | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/frameworks/ets/ets/@ohos.notificationManager.ets b/frameworks/ets/ets/@ohos.notificationManager.ets index e6f76234f..1a1b40398 100644 --- a/frameworks/ets/ets/@ohos.notificationManager.ets +++ b/frameworks/ets/ets/@ohos.notificationManager.ets @@ -324,6 +324,19 @@ export default namespace notificationManager { } return error; } + function isInvalidParameter(slotType: SlotType): BusinessError + { + let error: BusinessError = successCallbackError; + if (slotType == null) { + error = errorParamInvalid + return error; + } + if (typeof slotType !== 'number') { + error = errorParamInvalid + return error; + } + return error; + } function isInvalidContent(normal?: NotificationBasicContent): boolean { if (normal === null) { @@ -759,6 +772,10 @@ export default namespace notificationManager { } export function removeSlot(slotType: SlotType, callback: AsyncCallback): void { + let error: BusinessError = isInvalidParameter(slotType); + if (error.code !== ERROR_OK) { + throw error; + } if (callback == null) { throw errorParamInvalid; } @@ -772,6 +789,10 @@ export default namespace notificationManager { } export function removeSlot(slotType: SlotType): Promise { + let error: BusinessError = isInvalidParameter(slotType); + if (error.code !== ERROR_OK) { + throw error; + } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { let p = taskpool.execute((): void => { return nativeRemoveSlot(slotType); }); p.then((data: NullishType): void => { @@ -811,6 +832,10 @@ export default namespace notificationManager { } export function getSlot(slotType: SlotType): Promise { + let error: BusinessError = isInvalidParameter(slotType); + if (error.code !== ERROR_OK) { + throw error; + } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { let p = taskpool.execute((): NotificationSlot => { return nativeGetSlot(slotType); }); p.then((data: NullishType): void => { @@ -824,6 +849,10 @@ export default namespace notificationManager { } export function getSlot(slotType: SlotType, callback: AsyncCallback): void { + let error: BusinessError = isInvalidParameter(slotType); + if (error.code !== ERROR_OK) { + throw error; + } if (callback == null) { throw errorParamInvalid; } @@ -842,6 +871,10 @@ export default namespace notificationManager { if (error.code !== ERROR_OK) { throw error; } + error = isInvalidParameter(slotType); + if (error.code !== ERROR_OK) { + throw error; + } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { let p = taskpool.execute((): NotificationSlot => { return nativeGetSlotByBundle(bundle, slotType); }); p.then((data: NullishType): void => { @@ -919,6 +952,10 @@ export default namespace notificationManager { } export function addSlot(type: SlotType, callback: AsyncCallback): void { + let error: BusinessError = isInvalidParameter(type); + if (error.code !== ERROR_OK) { + throw error; + } if (callback == null) { throw errorParamInvalid; } @@ -932,6 +969,10 @@ export default namespace notificationManager { } export function addSlot(type: SlotType): Promise { + let error: BusinessError = isInvalidParameter(type); + if (error.code !== ERROR_OK) { + throw error; + } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { let p = taskpool.execute((): void => { return nativeAddSlotBySlotType(type); }); p.then((data: NullishType): void => { @@ -1086,6 +1127,10 @@ export default namespace notificationManager { if (error.code !== ERROR_OK) { throw error; } + error = isInvalidParameter(type); + if (error.code !== ERROR_OK) { + throw error; + } if (callback == null) { throw errorParamInvalid; } @@ -1107,6 +1152,10 @@ export default namespace notificationManager { if (error.code !== ERROR_OK) { throw error; } + error = isInvalidParameter(type); + if (error.code !== ERROR_OK) { + throw error; + } let forceControl: boolean = false; if (isForceControl != undefined) { forceControl = isForceControl; @@ -1131,6 +1180,10 @@ export default namespace notificationManager { if (error.code !== ERROR_OK) { throw error; } + error = isInvalidParameter(type); + if (error.code !== ERROR_OK) { + throw error; + } if (callback == null) { throw errorParamInvalid; } @@ -1149,6 +1202,10 @@ export default namespace notificationManager { if (error.code !== ERROR_OK) { throw error; } + error = isInvalidParameter(type); + if (error.code !== ERROR_OK) { + throw error; + } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { let p = taskpool.execute((): boolean => { return nativeIsNotificationSlotEnabled(bundle, type); }); p.then((data: NullishType): void => { @@ -1167,6 +1224,10 @@ export default namespace notificationManager { if (error.code !== ERROR_OK) { throw error; } + error = isInvalidParameter(type); + if (error.code !== ERROR_OK) { + throw error; + } if (callback == null) { throw errorParamInvalid; } @@ -2354,6 +2415,10 @@ export default namespace notificationManager { export function setDistributedEnabledBySlot(slot: SlotType, deviceType: string, enabled: boolean): Promise { + let error: BusinessError = isInvalidParameter(slot); + if (error.code !== ERROR_OK) { + throw error; + } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { let p = taskpool.execute((): void => { return nativesetDistributedEnabledBySlot(slot, deviceType, enabled); @@ -2369,6 +2434,10 @@ export default namespace notificationManager { export function isDistributedEnabledBySlot(slot: SlotType, deviceType: string): Promise { + let error: BusinessError = isInvalidParameter(slot); + if (error.code !== ERROR_OK) { + throw error; + } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { let p = taskpool.execute((): boolean => { return nativeisDistributedEnabledBySlot(slot, deviceType); }); p.then((data: NullishType): void => { -- Gitee