diff --git a/frameworks/ets/ets/@ohos.notificationManager.ets b/frameworks/ets/ets/@ohos.notificationManager.ets index 5a6010a170f3bed588d256070b3eb7189d436261..832ee49fc64b0a23cef423ec9a3766f036bd4d43 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 => { 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 => { 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 => { 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 => {