diff --git a/frameworks/ets/ani/include/manager/ani_slot.h b/frameworks/ets/ani/include/manager/ani_slot.h index 7fc0c605339880700ee725d3d6062acacfc8b79f..596786a3dc303c32f90d5a037a024374e867dad6 100644 --- a/frameworks/ets/ani/include/manager/ani_slot.h +++ b/frameworks/ets/ani/include/manager/ani_slot.h @@ -37,6 +37,7 @@ void AniRemoveSlot(ani_env *env, ani_enum_item enumObj); void AniRemoveAllSlots(ani_env *env); void AniSetSlotByBundle(ani_env *env, ani_object bundleOptionObj, ani_object slotObj); ani_long AniGetSlotNumByBundle(ani_env *env, ani_object bundleOption); +ani_object AniGetNotificationSetting(ani_env *env); } // namespace NotificationManagerSts } // namespace OHOS #endif diff --git a/frameworks/ets/ani/include/sts_slot.h b/frameworks/ets/ani/include/sts_slot.h index 12a8eeef03949db61c3b991a09023d8e017de7bf..87ee56b9fda506cb4e2a35723b63dcca9998e02f 100644 --- a/frameworks/ets/ani/include/sts_slot.h +++ b/frameworks/ets/ani/include/sts_slot.h @@ -38,6 +38,7 @@ bool ParseNotificationSlotByBasicType(ani_env *env, ani_object notificationSlotO bool UnwrapNotificationSlot(ani_env *env, ani_object notificationSlotObj, NotificationSlot &slot); bool UnwrapNotificationSlotArrayByAniObj(ani_env *env, ani_object notificationSlotArrayObj, std::vector &slots); +bool WrapGetNotificationSetting(ani_env *env, uint32_t slotFlags, ani_object &outAniObj); } // namespace NotificationSts } // OHOS #endif diff --git a/frameworks/ets/ani/src/manager/ani_manager.cpp b/frameworks/ets/ani/src/manager/ani_manager.cpp index 7b024fa20f90e6e22b6b445c0150419c35bc0467..9dba1b422bfce320a903c50983b7dbf9fa0505ff 100644 --- a/frameworks/ets/ani/src/manager/ani_manager.cpp +++ b/frameworks/ets/ani/src/manager/ani_manager.cpp @@ -95,6 +95,7 @@ static std::array kitManagerFunctions = { ani_native_function {"nativeRequestEnableNotification", "Lapplication/UIAbilityContext/UIAbilityContext;:Lstd/core/Promise;", reinterpret_cast(AniRequestEnableNotification)}, + ani_native_function {"nativeGetNotificationSetting", nullptr, reinterpret_cast(AniGetNotificationSetting)}, #ifdef ANS_FEATURE_BADGE_MANAGER ani_native_function {"nativeDisplayBadge", nullptr, reinterpret_cast(AniDisplayBadge)}, diff --git a/frameworks/ets/ani/src/manager/ani_slot.cpp b/frameworks/ets/ani/src/manager/ani_slot.cpp index bcd6fc42f14c7b5cd27e427b992a3fa1462097aa..2c899e8993463c11915d1687dd47abf514ced924 100644 --- a/frameworks/ets/ani/src/manager/ani_slot.cpp +++ b/frameworks/ets/ani/src/manager/ani_slot.cpp @@ -382,5 +382,26 @@ ani_object AniGetSlotByBundle(ani_env *env, ani_object bundleOption, ani_enum_it } return infoObj; } + +ani_object AniGetNotificationSetting(ani_env *env) +{ + ANS_LOGD("AniGetNotificationSetting enter"); + uint32_t slotFlags = 0; + int returncode = Notification::NotificationHelper::GetNotificationSettings(slotFlags); + ANS_LOGD("AniGetNotificationSetting slotFlags: %{public}d", slotFlags); + if (returncode != ERR_OK) { + int externalCode = NotificationSts::GetExternalCode(returncode); + ANS_LOGE("GetNotificationSetting -> error, errorCode: %{public}d", externalCode); + NotificationSts::ThrowError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return nullptr; + } + ani_object infoObj; + if (!NotificationSts::WrapGetNotificationSetting(env, slotFlags, infoObj) || infoObj == nullptr) { + NotificationSts::ThrowStsErroWithMsg(env, "WrapGetNotificationSetting Failed"); + return nullptr; + } + + return infoObj; +} } } \ No newline at end of file diff --git a/frameworks/ets/ani/src/sts_slot.cpp b/frameworks/ets/ani/src/sts_slot.cpp index 0167a798b051442a9260668e5c70d317fcc0f643..6f249d273c8bc7394528fa964a460cbdf431a000 100644 --- a/frameworks/ets/ani/src/sts_slot.cpp +++ b/frameworks/ets/ani/src/sts_slot.cpp @@ -142,6 +142,35 @@ bool WrapNotificationSlotByInt(ani_env *env, sptrObject_SetPropertyByName_Boolean( + outAniObj, "vibrationEnabled", BoolToAniBoolean(vibrationEnabled)))) { + ANS_LOGE("Set vibrationEnabled fail, status %{public}d", status); + return false; + } + if (ANI_OK != (status = env->Object_SetPropertyByName_Boolean( + outAniObj, "soundEnabled", BoolToAniBoolean(soundEnabled)))) { + ANS_LOGE("Set soundEnabled fail, status %{public}d", status); + return false; + } + return true; +} + bool WrapNotificationSlot(ani_env *env, sptr slot, ani_object &outAniObj) { ANS_LOGD("WrapNotificationSlot call"); diff --git a/frameworks/ets/ets/@ohos.notificationManager.ets b/frameworks/ets/ets/@ohos.notificationManager.ets index 3bd9e4e93d82719c713c7ce8b8434ef3bb2b0cce..33516006d16ae4e5e875341992863aa0aa517d62 100644 --- a/frameworks/ets/ets/@ohos.notificationManager.ets +++ b/frameworks/ets/ets/@ohos.notificationManager.ets @@ -95,6 +95,16 @@ export default namespace notificationManager { end: Date; } + export interface NotificationSetting { + vibrationEnabled: boolean; + soundEnabled: boolean; + } + + class NotificationSettingInner implements NotificationSetting { + vibrationEnabled: boolean = false; + soundEnabled: boolean = false; + } + export interface DoNotDisturbProfile { id: long; name: string; @@ -222,7 +232,8 @@ export default namespace notificationManager { type: 'checkNotification', callback: CallbackForCheckInfo, checkRequest?: NotificationCheckRequest): int; export native function nativeOff( type: 'checkNotification', callback?: CallbackForCheckInfo): int; - + export native function nativeGetNotificationSetting(): NotificationSetting; + function isInvalidParameter(doNotDisturbDate: DoNotDisturbDate): BusinessError { let error: BusinessError = successCallbackError @@ -2609,4 +2620,19 @@ export default namespace notificationManager { callback(err, undefined); }) } + + export function getNotificationSetting(): Promise { + let pPromise = new Promise( + (resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): NotificationSetting => + { return nativeGetNotificationSetting(); }); + p.then((data: NullishType): void => { + let ret : NotificationSetting = data as NotificationSetting; + resolve(ret); + }, (error: Error): void => { + reject(error); + }); + }); + return pPromise; + } }