From 77db6cd0074ca0621135be93005c03e828507553 Mon Sep 17 00:00:00 2001 From: liwang <965027894@qq.com> Date: Tue, 2 Sep 2025 10:09:50 +0800 Subject: [PATCH] =?UTF-8?q?4=E9=98=B6=E6=AE=B5=E6=8E=A5=E5=8F=A3=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liwang <965027894@qq.com> --- frameworks/ets/ani/BUILD.gn | 1 + .../include/manager/ani_distributed_enable.h | 3 + .../include/manager/ani_notification_enable.h | 1 + .../manager/ani_silent_reminder_enable.h | 26 ++++ .../ets/ani/include/sts_bundle_option.h | 4 + .../ani/include/sts_notification_manager.h | 17 +++ .../src/manager/ani_distributed_enable.cpp | 72 +++++++++ .../ets/ani/src/manager/ani_manager.cpp | 13 ++ .../src/manager/ani_notification_enable.cpp | 22 +++ .../manager/ani_silent_reminder_enable.cpp | 75 +++++++++ frameworks/ets/ani/src/sts_bundle_option.cpp | 72 +++++++++ .../ets/ani/src/sts_notification_manager.cpp | 67 ++++++++ .../ets/ets/@ohos.notificationManager.ets | 143 ++++++++++++++++++ 13 files changed, 516 insertions(+) create mode 100644 frameworks/ets/ani/include/manager/ani_silent_reminder_enable.h create mode 100644 frameworks/ets/ani/src/manager/ani_silent_reminder_enable.cpp diff --git a/frameworks/ets/ani/BUILD.gn b/frameworks/ets/ani/BUILD.gn index a322f9fc9..5061ffc76 100644 --- a/frameworks/ets/ani/BUILD.gn +++ b/frameworks/ets/ani/BUILD.gn @@ -49,6 +49,7 @@ ohos_shared_library("notification_manager_ani") { "./src/manager/ani_push_callback.cpp", "./src/manager/ani_remove_group.cpp", "./src/manager/ani_request_enable.cpp", + "./src/manager/ani_silent_reminder_enable.cpp", "./src/manager/ani_slot.cpp", "./src/manager/ani_support_template.cpp", "./src/manager/ani_sync_config.cpp", diff --git a/frameworks/ets/ani/include/manager/ani_distributed_enable.h b/frameworks/ets/ani/include/manager/ani_distributed_enable.h index 385c801ac..12e4a0a3a 100755 --- a/frameworks/ets/ani/include/manager/ani_distributed_enable.h +++ b/frameworks/ets/ani/include/manager/ani_distributed_enable.h @@ -31,6 +31,9 @@ ani_boolean AniIsSmartReminderEnabled(ani_env *env, ani_string deviceType); void AniSetSmartReminderEnable(ani_env *env, ani_string deviceType, ani_boolean enable); void AniSetDistributedEnableBySlot(ani_env *env, ani_enum_item slot, ani_string deviceType, ani_boolean enable); ani_boolean AniIsDistributedEnabledBySlot(ani_env *env, ani_enum_item slot, ani_string deviceType); +void AniSetDistributedEnabled(ani_env *env, ani_boolean enable, ani_string deviceType); +void AniSetDistributedEnableByBundles(ani_env *env, ani_object obj, ani_string deviceType); +ani_object AniGetDistributedDeviceList(ani_env *env); } // namespace NotificationManagerSts } // namespace OHOS #endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/manager/ani_notification_enable.h b/frameworks/ets/ani/include/manager/ani_notification_enable.h index bb657a6e2..ed88d6c18 100644 --- a/frameworks/ets/ani/include/manager/ani_notification_enable.h +++ b/frameworks/ets/ani/include/manager/ani_notification_enable.h @@ -28,6 +28,7 @@ ani_boolean AniIsNotificationEnabledSync(ani_env *env); ani_boolean AniGetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double userId); ani_object AniGetAllNotificationEnabledBundles(ani_env *env); void AniDisableNotificationFeature(ani_env *env, ani_boolean disabled, ani_object bundleList); +void AniDisableNotificationFeatureWithId(ani_env *env, ani_boolean disabled, ani_object bundleList, ani_double userId); } // namespace NotificationManagerSts } // namespace OHOS #endif diff --git a/frameworks/ets/ani/include/manager/ani_silent_reminder_enable.h b/frameworks/ets/ani/include/manager/ani_silent_reminder_enable.h new file mode 100644 index 000000000..db6d17c36 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_silent_reminder_enable.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SILENT_REMINDER_ENABLE_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SILENT_REMINDER_ENABLE_H +#include "ani.h" + +namespace OHOS { +namespace NotificationManagerSts { +void AniSetSilentReminderEnabled(ani_env *env, ani_object bundleOption, ani_boolean enable); +ani_object AniIsSilentReminderEnabled(ani_env *env, ani_object bundleOption); +} // namespace NotificationManagerSts +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/sts_bundle_option.h b/frameworks/ets/ani/include/sts_bundle_option.h index 5bda338dd..dc323d1f1 100644 --- a/frameworks/ets/ani/include/sts_bundle_option.h +++ b/frameworks/ets/ani/include/sts_bundle_option.h @@ -16,9 +16,11 @@ #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_STS_BUNDLE_OPTION_H #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_STS_BUNDLE_OPTION_H #include "ani.h" +#include "distributed_bundle_option.h" #include "notification_bundle_option.h" using BundleOption = OHOS::Notification::NotificationBundleOption; +using DistributedBundleOption = OHOS::Notification::DistributedBundleOption; namespace OHOS { namespace NotificationSts { bool UnwrapBundleOption(ani_env *env, ani_object param, BundleOption& option); @@ -27,6 +29,8 @@ bool WrapBundleOption(ani_env* env, bool UnwrapArrayBundleOption(ani_env *env, ani_ref arrayObj, std::vector& options); ani_object GetAniArrayBundleOption(ani_env* env, const std::vector &bundleOptions); +bool UnwrapArrayDistributedBundleOption(ani_env *env, ani_object arrayObj, + std::vector &options); } } diff --git a/frameworks/ets/ani/include/sts_notification_manager.h b/frameworks/ets/ani/include/sts_notification_manager.h index bc454c994..04cddfd42 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 SwitchState = OHOS::Notification::NotificationConstant::SWITCH_STATE; using NotificationConstant = OHOS::Notification::NotificationConstant; enum STSDoNotDisturbType { @@ -79,6 +80,13 @@ enum class STSRemindType { ACTIVE_REMIND }; +enum class STSSwitchState { + USER_MODIFIED_OFF, + USER_MODIFIED_ON, + SYSTEM_DEFAULT_OFF, + SYSTEM_DEFAULT_ON +}; + class StsDoNotDisturbTypeUtils { public: static bool StsToC(const STSDoNotDisturbType inType, @@ -109,6 +117,12 @@ static bool StsToC(const STSRemindType inType, RemindType &outType); static bool CToSts(const RemindType inType, STSRemindType &outType); }; +class StsSwitchStateUtils { +public: +static bool StsToC(const STSSwitchState inType, SwitchState &outType); +static bool CToSts(const SwitchState inType, STSSwitchState &outType); +}; + class StsNotificationLocalLiveViewSubscriber : public NotificationLocalLiveViewSubscriber { public: StsNotificationLocalLiveViewSubscriber(); @@ -166,6 +180,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 SwitchStateCToEts(ani_env *env, SwitchState switchState, ani_enum_item &enumItem); +bool SwitchStateEtsToC(ani_env *env, ani_enum_item enumItem, SwitchState &switchState); + 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/src/manager/ani_distributed_enable.cpp b/frameworks/ets/ani/src/manager/ani_distributed_enable.cpp index d31676f6f..79b0697b8 100755 --- a/frameworks/ets/ani/src/manager/ani_distributed_enable.cpp +++ b/frameworks/ets/ani/src/manager/ani_distributed_enable.cpp @@ -286,5 +286,77 @@ ani_boolean AniIsDistributedEnabledBySlot(ani_env *env, ani_enum_item slot, ani_ } return isEnable ? ANI_TRUE : ANI_FALSE; } + +void AniSetDistributedEnableByBundles(ani_env *env, ani_object obj, ani_string deviceType) +{ + ANS_LOGD("AniSetDistributedEnableByBundles call"); + std::string deviceTypeStr; + if (env == nullptr || deviceType == nullptr) { + ANS_LOGE("Invalid env or deviceType is null"); + return; + } + if (NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr) != ANI_OK) { + ANS_LOGE("GetStringByAniString fail"); + OHOS::NotificationSts::ThrowErrorWithInvalidParam(env); + return; + } + std::vector bundles; + if (!NotificationSts::UnwrapArrayDistributedBundleOption(env, obj, bundles)) { + ANS_LOGE("UnwrapArrayDistributedBundleOption fail"); + OHOS::NotificationSts::ThrowErrorWithInvalidParam(env); + return; + } + int returncode = Notification::NotificationHelper::SetDistributedBundleOption(bundles, deviceTypeStr); + if (returncode != ERR_OK) { + int externalCode = NotificationSts::GetExternalCode(returncode); + ANS_LOGE("AniSetDistributedEnableByBundles error, errorCode: %{public}d", externalCode); + NotificationSts::ThrowError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("AniSetDistributedEnableByBundles end"); +} + +void AniSetDistributedEnabled(ani_env *env, ani_boolean enable, ani_string deviceType) +{ + ANS_LOGD("AniSetDistributedEnabled call"); + std::string deviceTypeStr; + if (env == nullptr || deviceType == nullptr) { + ANS_LOGE("Invalid env or deviceType is null"); + return; + } + if (NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr) != ANI_OK) { + ANS_LOGE("GetStringByAniString fail"); + OHOS::NotificationSts::ThrowErrorWithInvalidParam(env); + return; + } + int returncode = Notification::NotificationHelper::SetDistributedEnabled(deviceTypeStr, + NotificationSts::AniBooleanToBool(enable)); + if (returncode != ERR_OK) { + int externalCode = NotificationSts::GetExternalCode(returncode); + ANS_LOGE("AniSetDistributedEnabled error, errorCode: %{public}d", externalCode); + NotificationSts::ThrowError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("AniSetDistributedEnabled end"); +} + +ani_object AniGetDistributedDeviceList(ani_env *env) +{ + ANS_LOGD("AniGetDistributedDeviceList call"); + std::vector deviceList; + int returncode = Notification::NotificationHelper::GetDistributedDevicelist(deviceList); + if (returncode != ERR_OK) { + int externalCode = NotificationSts::GetExternalCode(returncode); + ANS_LOGE("AniGetDistributedDeviceList error, errorCode: %{public}d", externalCode); + NotificationSts::ThrowError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("GetDistributedDevicelist deviceList size: %{public}d", deviceList.size()); + ani_object deviceListArray = NotificationSts::GetAniStringArrayByVectorString(env, deviceList); + if (deviceListArray == nullptr) { + ANS_LOGE("deviceListArray nullptr"); + OHOS::NotificationSts::ThrowErrorWithCode(env, OHOS::Notification::ERROR_INTERNAL_ERROR); + return nullptr; + } + ANS_LOGD("AniGetDistributedDeviceList end"); + return deviceListArray; +} } } \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_manager.cpp b/frameworks/ets/ani/src/manager/ani_manager.cpp index e78a804c1..d18373da8 100644 --- a/frameworks/ets/ani/src/manager/ani_manager.cpp +++ b/frameworks/ets/ani/src/manager/ani_manager.cpp @@ -25,6 +25,7 @@ #include "ani_publish.h" #include "ani_local_live_view.h" #include "ani_request_enable.h" +#include "ani_silent_reminder_enable.h" #include "ani_on.h" #include "ani_support_template.h" #include "ani_distributed_enable.h" @@ -167,6 +168,18 @@ static std::array kitManagerFunctions = { reinterpret_cast(AniGetSyncNotificationEnabledWithoutApp)}, ani_native_function {"nativeSetSyncNotificationEnabledWithoutApp", nullptr, reinterpret_cast(AniSetSyncNotificationEnabledWithoutApp)}, + ani_native_function {"nativeDisableNotificationFeatureWithId", nullptr, + reinterpret_cast(AniDisableNotificationFeatureWithId)}, + ani_native_function {"nativeSetDistributedEnabled", nullptr, reinterpret_cast(AniSetDistributedEnabled)}, + ani_native_function {"nativeSetDistributedEnableByBundles", nullptr, + reinterpret_cast(AniSetDistributedEnableByBundles)}, + ani_native_function {"nativeGetDistributedDeviceList", nullptr, + reinterpret_cast(AniGetDistributedDeviceList)}, + + ani_native_function {"nativeSetSilentReminderEnabled", nullptr, + reinterpret_cast(AniSetSilentReminderEnabled)}, + ani_native_function {"nativeIsSilentReminderEnabled", nullptr, + reinterpret_cast(AniIsSilentReminderEnabled)}, }; void AniNotificationManagerRegistryInit(ani_env *env) diff --git a/frameworks/ets/ani/src/manager/ani_notification_enable.cpp b/frameworks/ets/ani/src/manager/ani_notification_enable.cpp index 934e4f58a..8b5dabec0 100644 --- a/frameworks/ets/ani/src/manager/ani_notification_enable.cpp +++ b/frameworks/ets/ani/src/manager/ani_notification_enable.cpp @@ -178,5 +178,27 @@ void AniDisableNotificationFeature(ani_env *env, ani_boolean disabled, ani_objec NotificationSts::ThrowError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } } + +void AniDisableNotificationFeatureWithId(ani_env *env, ani_boolean disabled, ani_object bundleList, ani_double userId) +{ + ANS_LOGD("AniDisableNotificationFeatureWithId enter"); + std::vector bundleListStd; + if (!NotificationSts::GetStringArrayByAniObj(env, bundleList, bundleListStd)) { + ANS_LOGE("GetStringArrayByAniObj fail"); + OHOS::NotificationSts::ThrowErrorWithInvalidParam(env); + return; + } + Notification::NotificationDisable param; + param.SetDisabled(NotificationSts::AniBooleanToBool(disabled)); + param.SetBundleList(bundleListStd); + param.SetUserId(static_cast(userId)); + int returncode = ERR_OK; + returncode = Notification::NotificationHelper::DisableNotificationFeature(param); + if (returncode != ERR_OK) { + int externalCode = NotificationSts::GetExternalCode(returncode); + ANS_LOGE("AniDisableNotificationFeatureWithId error, errorCode: %{public}d", externalCode); + OHOS::NotificationSts::ThrowError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } +} } // namespace NotificationManagerSts } // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_silent_reminder_enable.cpp b/frameworks/ets/ani/src/manager/ani_silent_reminder_enable.cpp new file mode 100644 index 000000000..1c8cf9c31 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_silent_reminder_enable.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ani_silent_reminder_enable.h" + +#include "ans_log_wrapper.h" +#include "notification_helper.h" +#include "sts_bundle_option.h" +#include "sts_common.h" +#include "sts_notification_manager.h" +#include "sts_throw_erro.h" + +namespace OHOS { +namespace NotificationManagerSts { +void AniSetSilentReminderEnabled(ani_env *env, ani_object bundleOption, ani_boolean enable) +{ + ANS_LOGD("AniSetSilentReminderEnabled call"); + int returncode = ERR_OK; + BundleOption option; + if (!NotificationSts::UnwrapBundleOption(env, bundleOption, option)) { + ANS_LOGE("UnwrapBundleOption fail"); + OHOS::NotificationSts::ThrowErrorWithInvalidParam(env); + return; + } + returncode = Notification::NotificationHelper::SetSilentReminderEnabled(option, enable); + if (returncode != ERR_OK) { + int externalCode = NotificationSts::GetExternalCode(returncode); + ANS_LOGE("GetExternalCode failed, errorCode: %{public}d", externalCode); + OHOS::NotificationSts::ThrowError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("AniSetSilentReminderEnabled end"); +} + +ani_object AniIsSilentReminderEnabled(ani_env *env, ani_object bundleOption) +{ + ANS_LOGD("AniIsSilentReminderEnabled call"); + int returncode = ERR_OK; + BundleOption option; + int32_t enableStatus = 0; + if (!NotificationSts::UnwrapBundleOption(env, bundleOption, option)) { + ANS_LOGE("UnwrapBundleOption fail"); + OHOS::NotificationSts::ThrowErrorWithInvalidParam(env); + return nullptr; + } + returncode = Notification::NotificationHelper::IsSilentReminderEnabled(option, enableStatus); + if (returncode != ERR_OK) { + int externalCode = NotificationSts::GetExternalCode(returncode); + ANS_LOGE("GetExternalCode failed, errorCode: %{public}d", externalCode); + OHOS::NotificationSts::ThrowError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return nullptr; + } + ani_enum_item switchStateItem {}; + Notification::NotificationConstant::SWITCH_STATE switchState = + static_cast(enableStatus); + if (!NotificationSts::SwitchStateCToEts(env, switchState, switchStateItem)) { + ANS_LOGE("SwitchStateCToEts failed"); + OHOS::NotificationSts::ThrowErrorWithCode(env, OHOS::Notification::ERROR_INTERNAL_ERROR); + return nullptr; + } + ANS_LOGD("AniIsSilentReminderEnabled end"); + return switchStateItem; +} +} // namespace NotificationManagerSts +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/sts_bundle_option.cpp b/frameworks/ets/ani/src/sts_bundle_option.cpp index edcf16454..3c80d1f77 100644 --- a/frameworks/ets/ani/src/sts_bundle_option.cpp +++ b/frameworks/ets/ani/src/sts_bundle_option.cpp @@ -138,5 +138,77 @@ bool WrapBundleOption(ani_env* env, ANS_LOGD("WrapBundleOption end"); return true; } + +bool UnwrapDistributedBundleOption(ani_env *env, ani_object obj, DistributedBundleOption &distributedOption) +{ + ANS_LOGD("UnwrapDistributedBundleOption call"); + if (env == nullptr || obj == nullptr) { + ANS_LOGE("UnwrapDistributedBundleOption failed, has nullptr"); + return false; + } + ani_status status = ANI_ERROR; + ani_boolean isUndefined = ANI_TRUE; + std::string tempStr; + status = GetPropertyString(env, obj, "bundleName", isUndefined, tempStr); + if (status != ANI_OK || isUndefined == ANI_TRUE) { + ANS_LOGE("GetPropertyString 'bundleName' fail. status:%{public}d", status); + return false; + } + std::shared_ptr optionValue = std::make_shared(); + if (optionValue == nullptr) { + ANS_LOGE("new BundleOption fail."); + return false; + } + std::string bundleName = GetResizeStr(tempStr, STR_MAX_SIZE); + optionValue->SetBundleName(bundleName); + ani_double result = 0.0; + if ((status = env->Object_GetPropertyByName_Double(obj, "uid", &result)) != ANI_OK) { + ANS_LOGE("Object_GetPropertyByName_Double 'uid' fail. status:%{public}d", status); + return false; + } + int32_t uid = static_cast(result); + optionValue->SetUid(uid); + distributedOption.SetBundle(optionValue); + bool enable = true; + status = GetPropertyBool(env, obj, "enable", isUndefined, enable); + if (status == ANI_OK && isUndefined == ANI_FALSE) { + distributedOption.SetEnable(enable); + } + ANS_LOGD("UnwrapDistributedBundleOption end"); + return true; +} + +bool UnwrapArrayDistributedBundleOption(ani_env *env, ani_object arrayObj, + std::vector &options) +{ + ANS_LOGD("UnwrapArrayDistributedBundleOption call"); + if (env == nullptr || arrayObj == nullptr) { + ANS_LOGE("UnwrapArrayDistributedBundleOption failed, has nullptr"); + return false; + } + ani_status status; + ani_double length; + if (ANI_OK!= (status = env->Object_GetPropertyByName_Double(static_cast(arrayObj), + "length", &length))) { + ANS_LOGE("get length failed, status = %{public}d", status); + return false; + } + Notification::DistributedBundleOption option; + for (int32_t i = 0; i < static_cast(length); i++) { + ani_ref optionRef; + status = env->Object_CallMethodByName_Ref(arrayObj, "$_get", "I:Lstd/core/Object;", &optionRef, i); + if (status != ANI_OK) { + ANS_LOGE("get optionRef failed, status = %{public}d", status); + return false; + } + if (!UnwrapDistributedBundleOption(env, static_cast(optionRef), option)) { + ANS_LOGE("get option status = %{public}d, index = %{public}d", status, i); + return false; + } + options.push_back(option); + } + ANS_LOGD("UnwrapArrayDistributedBundleOption end"); + return true; +} } } \ No newline at end of file diff --git a/frameworks/ets/ani/src/sts_notification_manager.cpp b/frameworks/ets/ani/src/sts_notification_manager.cpp index 85dc54085..52afdaa2f 100644 --- a/frameworks/ets/ani/src/sts_notification_manager.cpp +++ b/frameworks/ets/ani/src/sts_notification_manager.cpp @@ -286,6 +286,50 @@ bool StsRemindTypeUtils::CToSts(const RemindType inType, STSRemindType &outType) return true; } +bool StsSwitchStateUtils::StsToC(const STSSwitchState inType, SwitchState &outType) +{ + switch (inType) { + case STSSwitchState::USER_MODIFIED_OFF: + outType = SwitchState::USER_MODIFIED_OFF; + break; + case STSSwitchState::USER_MODIFIED_ON: + outType = SwitchState::USER_MODIFIED_ON; + break; + case STSSwitchState::SYSTEM_DEFAULT_OFF: + outType = SwitchState::SYSTEM_DEFAULT_OFF; + break; + case STSSwitchState::SYSTEM_DEFAULT_ON: + outType = SwitchState::SYSTEM_DEFAULT_ON; + break; + default: + ANS_LOGE("STSSwitchState %{public}d is an invalid value", inType); + return false; + } + return true; +} + +bool StsSwitchStateUtils::CToSts(const SwitchState inType, STSSwitchState &outType) +{ + switch (inType) { + case SwitchState::USER_MODIFIED_OFF: + outType = STSSwitchState::USER_MODIFIED_OFF; + break; + case SwitchState::USER_MODIFIED_ON: + outType = STSSwitchState::USER_MODIFIED_ON; + break; + case SwitchState::SYSTEM_DEFAULT_OFF: + outType = STSSwitchState::SYSTEM_DEFAULT_OFF; + break; + case SwitchState::SYSTEM_DEFAULT_ON: + outType = STSSwitchState::SYSTEM_DEFAULT_ON; + break; + default: + ANS_LOGE("SwitchState %{public}d is an invalid value", inType); + return false; + } + return true; +} + StsNotificationLocalLiveViewSubscriber::StsNotificationLocalLiveViewSubscriber() {} @@ -483,6 +527,29 @@ bool DeviceRemindTypeEtsToC(ani_env *env, ani_enum_item enumItem, RemindType &re return false; } +bool SwitchStateCToEts(ani_env *env, SwitchState switchState, ani_enum_item &enumItem) +{ + STSSwitchState stsSwitchState = STSSwitchState::USER_MODIFIED_OFF; + if (!EnumConvertNativeToAni(env, + "L@ohos/notificationManager/notificationManager/SwitchState;", stsSwitchState, enumItem) + || !StsSwitchStateUtils::CToSts(switchState, stsSwitchState)) { + ANS_LOGE("SwitchStateCToEts failed"); + return false; + } + return true; +} + +bool SwitchStateEtsToC(ani_env *env, ani_enum_item enumItem, SwitchState &switchState) +{ + STSSwitchState stsSwitchState = STSSwitchState::USER_MODIFIED_OFF; + if (!EnumConvertAniToNative(env, enumItem, stsSwitchState) + || !StsSwitchStateUtils::StsToC(stsSwitchState, switchState)) { + ANS_LOGE("SwitchStateEtsToC failed"); + return false; + } + return true; +} + ani_status UnWarpNotificationButtonOption(ani_env *env, const ani_object buttonOptionObj, ButtonOption &buttonOption) { diff --git a/frameworks/ets/ets/@ohos.notificationManager.ets b/frameworks/ets/ets/@ohos.notificationManager.ets index a2e06ea12..b49cdc03d 100644 --- a/frameworks/ets/ets/@ohos.notificationManager.ets +++ b/frameworks/ets/ets/@ohos.notificationManager.ets @@ -38,6 +38,7 @@ type CallbackForCheckInfo = const ERROR_OK = 0; const ERROR_PARAM_INVALID = 401; const ERROR_INTERNAL_ERROR = 160001; +const MAX_USER_ID = 10736; const rejectInternalError: BusinessError = {code: ERROR_INTERNAL_ERROR, data: "Internal error."}; const callbackInternalError: BusinessError = {code: ERROR_INTERNAL_ERROR, data: undefined}; @@ -130,6 +131,25 @@ export default namespace notificationManager { ACTIVE_REMIND = 3, } + export interface DistributedBundleEnableInfo { + bundleName: string; + uid: number; + enable?: boolean; + } + + class DistributedBundleEnableInfoInner implements DistributedBundleEnableInfo { + bundleName: string = ""; + uid: number = -1; + enable?: boolean | undefined; + } + + export enum SwitchState { + USER_MODIFIED_OFF = 0, + USER_MODIFIED_ON = 1, + SYSTEM_DEFAULT_OFF = 2, + SYSTEM_DEFAULT_ON = 3, + } + export native function nativeCancelAll(): void; export native function nativeCancelWithId(id: number): void; export native function nativeCancelWithIdLabel(id: number, label: string): void; @@ -191,6 +211,9 @@ export default namespace notificationManager { export native function nativeIsDistributedEnabled(): boolean; export native function nativeIsDistributedEnabledByBundle(bundle: BundleOption): boolean; export native function nativeIsDistributedEnabledByBundleType(bundle: BundleOption, deviceType: string): boolean; + export native function nativeSetDistributedEnabled(enable: boolean, deviceType: string): void; + export native function nativeSetDistributedEnableByBundles(bundleEnableInfos: Array, deviceType: string): void; + export native function nativeGetDistributedDeviceList(): Array; export native function nativeGetDeviceRemindType(): DeviceRemindType; export native function nativeSetSyncNotificationEnabledWithoutApp(userId: number, enable: boolean): void; export native function nativeGetSyncNotificationEnabledWithoutApp(userId: number): boolean; @@ -218,6 +241,10 @@ export default namespace notificationManager { export native function nativesetAdditionalConfig(key: string, value: string): int; export native function nativesetDistributedEnableByBundle(bundle: BundleOption, enable: boolean):void; export native function nativedisableNotificationFeature(disabled:boolean, bundleList: Array):void; + export native function nativeDisableNotificationFeatureWithId(disabled:boolean, bundleList: Array, userId: number): void; + + export native function nativeSetSilentReminderEnabled(bundle: BundleOption, enable: boolean): void; + export native function nativeIsSilentReminderEnabled(bundle: BundleOption): SwitchState; function isInvalidParameter(doNotDisturbDate: DoNotDisturbDate): BusinessError { @@ -1465,4 +1492,120 @@ export default namespace notificationManager { }); return pPromise; } + + export function disableNotificationFeature(disabled: boolean, bundleList: Array, userId: number): Promise + { + if (bundleList.length == 0) { + throw errorParamInvalid; + } + bundleList.forEach((value, index, bundleList) => { + if (value.trim().isEmpty()) { + throw errorParamInvalid; + } + }); + if (userId < 0 || userId > MAX_USER_ID) { + throw errorParamInvalid; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { + nativeDisableNotificationFeatureWithId(disabled, bundleList, userId); + }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Error): void => { + reject(error); + }); + }); + return pPromise; + } + + export function setDistributedEnabled(enabled: boolean, deviceType: string): Promise + { + if (deviceType.trim().isEmpty()) { + throw errorParamInvalid; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { + return nativeSetDistributedEnabled(enabled, deviceType); + }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Error): void => { + reject(error); + }); + }); + return pPromise; + } + + export function setDistributedEnableByBundles(bundleEnableInfos: Array, deviceType: string): Promise + { + if (bundleEnableInfos.length == 0 || deviceType.trim().isEmpty()) { + throw errorParamInvalid; + } + bundleEnableInfos.forEach((value, index, bundleEnableInfos) => { + if (value.bundleName.trim().isEmpty()) { + throw errorParamInvalid; + } + }); + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { + return nativeSetDistributedEnableByBundles(bundleEnableInfos, deviceType); + }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Error): void => { + reject(error); + }); + }); + return pPromise; + } + + export function getDistributedDeviceList(): Promise> + { + let pPromise = new Promise>((resolve: ResolveCallback>, reject: RejectCallback): void => { + let p = taskpool.execute((): Array => { return nativeGetDistributedDeviceList(); }); + p.then((data: NullishType): void => { + let ret : Array = data as Array; + resolve(ret); + }, (error: Error): void => { + reject(error); + }); + }); + return pPromise; + } + + export function setSilentReminderEnabled(bundle: BundleOption, enabled: boolean): Promise + { + if (bundle.bundle.trim().isEmpty()) { + throw errorParamInvalid; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { + return nativeSetSilentReminderEnabled(bundle, enabled); + }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Error): void => { + reject(error); + }); + }); + return pPromise; + } + + export function isSilentReminderEnabled(bundle: BundleOption): Promise + { + if (bundle.bundle.trim().isEmpty()) { + throw errorParamInvalid; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): SwitchState => { return nativeIsSilentReminderEnabled(bundle); }); + p.then((data: NullishType): void => { + let ret : SwitchState = data as SwitchState; + resolve(ret); + }, (error: Error): void => { + reject(error); + }); + }); + return pPromise; + } } \ No newline at end of file -- Gitee