From e8b8e978b1d4bf8dc6405edb8d81950ba7effa31 Mon Sep 17 00:00:00 2001 From: cheerful_ricky Date: Tue, 10 Jun 2025 15:10:27 +0800 Subject: [PATCH] remove unused refactor: disturb_manager stub code Signed-off-by: cheerful_ricky --- services/ans/BUILD.gn | 9 - .../include/disturb_manager/disturb_manager.h | 78 ---- .../ans/include/slot_manager/slot_manager.h | 74 ---- .../add_do_not_disturb_profiles.cpp | 65 --- .../src/disturb_manager/disturb_manager.cpp | 116 ------ .../does_support_do_not_disturb_mode.cpp | 57 --- .../get_do_not_disturb_date.cpp | 136 ------ .../get_do_not_disturb_profile.cpp | 65 --- .../remove_do_not_disturb_profiles.cpp | 67 --- .../set_do_not_disturb_date.cpp | 202 --------- services/ans/test/unittest/BUILD.gn | 65 --- .../disturb_manager/disturb_manager_test.cpp | 391 ------------------ services/test/moduletest/BUILD.gn | 1 - services/test/moduletest/ans_module_test.cpp | 12 +- 14 files changed, 4 insertions(+), 1334 deletions(-) delete mode 100644 services/ans/include/disturb_manager/disturb_manager.h delete mode 100644 services/ans/include/slot_manager/slot_manager.h delete mode 100644 services/ans/src/disturb_manager/add_do_not_disturb_profiles.cpp delete mode 100644 services/ans/src/disturb_manager/disturb_manager.cpp delete mode 100644 services/ans/src/disturb_manager/does_support_do_not_disturb_mode.cpp delete mode 100644 services/ans/src/disturb_manager/get_do_not_disturb_date.cpp delete mode 100644 services/ans/src/disturb_manager/get_do_not_disturb_profile.cpp delete mode 100644 services/ans/src/disturb_manager/remove_do_not_disturb_profiles.cpp delete mode 100644 services/ans/src/disturb_manager/set_do_not_disturb_date.cpp delete mode 100644 services/ans/test/unittest/disturb_manager/disturb_manager_test.cpp diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index 87945431e..5ca9d3463 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -52,10 +52,8 @@ ohos_source_set("ans_service_sources") { include_dirs = [ "${services_path}/ans/include", - "${services_path}/ans/include/disturb_manager", "${services_path}/ans/include/notification_extension", "${services_path}/ans/include/utils", - "${services_path}/ans/include/slot_manager", "${services_path}/ans/src", ] @@ -102,13 +100,6 @@ ohos_source_set("ans_service_sources") { "src/distributed_device_status.cpp", "src/distributed_manager/advanced_notification_distributed_manager_service.cpp", "src/disturb_manager/advanced_notification_disturb_manager_service.cpp", - "src/disturb_manager/add_do_not_disturb_profiles.cpp", - "src/disturb_manager/disturb_manager.cpp", - "src/disturb_manager/does_support_do_not_disturb_mode.cpp", - "src/disturb_manager/get_do_not_disturb_date.cpp", - "src/disturb_manager/get_do_not_disturb_profile.cpp", - "src/disturb_manager/remove_do_not_disturb_profiles.cpp", - "src/disturb_manager/set_do_not_disturb_date.cpp", "src/enable_manager/enable_manager.cpp", "src/event_report.cpp", "src/liveview_all_scenarios_extension_wrapper.cpp", diff --git a/services/ans/include/disturb_manager/disturb_manager.h b/services/ans/include/disturb_manager/disturb_manager.h deleted file mode 100644 index 481932fe9..000000000 --- a/services/ans/include/disturb_manager/disturb_manager.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2024-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_ANS_SERVICES_ANS_INCLUDE_DISTURB_MANAGER_H -#define BASE_NOTIFICATION_ANS_SERVICES_ANS_INCLUDE_DISTURB_MANAGER_H - -#include -#include - -#include "ians_manager.h" -#include "base_manager.h" -#include "distributed_notification_service_ipc_interface_code.h" -#include "ians_subscriber_local_live_view.h" -#include "iremote_stub.h" -#include "singleton.h" - -namespace OHOS { -namespace Notification { -class DisturbManager final : protected BaseManager, public DelayedSingleton { -public: - DisturbManager(); - ~DisturbManager() = default; - using ExecutionType = std::function; -public: - /** - * @brief Handle remote request. - * - * @param data Indicates the input parcel. - * @param reply Indicates the output parcel. - * @param option Indicates the message option. - * @return Returns ERR_OK on success, others on failure. - */ - int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); -private: - ErrCode HandleRemoveDoNotDisturbProfiles(MessageParcel &data, MessageParcel &reply); - ErrCode HandleSetDoNotDisturbDate(MessageParcel &data, MessageParcel &reply); - ErrCode HandleSetDoNotDisturbDateByUser(MessageParcel &data, MessageParcel &reply); - ErrCode HandleGetDoNotDisturbDate(MessageParcel &data, MessageParcel &reply); - ErrCode HandleGetDoNotDisturbDateByUser(MessageParcel &data, MessageParcel &reply); - ErrCode HandleAddDoNotDisturbProfiles(MessageParcel &data, MessageParcel &reply); - ErrCode HandleGetDoNotDisturbProfile(MessageParcel &data, MessageParcel &reply); - ErrCode HandleDoesSupportDoNotDisturbMode(MessageParcel &data, MessageParcel &reply); - -private: - int32_t CheckSystemAndControllerPermission(); - void AdjustDateForDndTypeOnce(int64_t &beginDate, int64_t &endDate); - ErrCode SetDoNotDisturbDate(const sptr &date); - - ErrCode RemoveDoNotDisturbProfilesSyncQueue(const std::vector> &profiles); - ErrCode GetDoNotDisturbDateSyncQueue(sptr &date); - ErrCode GetDoNotDisturbDateByUserSyncQueue(const int32_t &userId, sptr &date); - ErrCode SetDoNotDisturbDateByUserSyncQueue(const int32_t &userId, const sptr &date); - ErrCode AddDoNotDisturbProfilesSyncQueue(const std::vector> &profiles); - - ErrCode SetDoNotDisturbDateByUserInner(const int32_t &userId, const sptr &date); - ErrCode GetDoNotDisturbDateByUserInner(const int32_t &userId, sptr &date); - ErrCode GetDoNotDisturbProfileInner(int64_t id, sptr &profile); - ErrCode DoesSupportDoNotDisturbModeInner(bool &doesSupport); -private: - std::map codeAndExecuteFuncMap_; - std::map> codeAndPermissionFuncMap_; -}; -} // namespace Notification -} // namespace OHOS - -#endif // BASE_NOTIFICATION_ANS_SERVICES_ANS_INCLUDE_DISTURB_MANAGER_H diff --git a/services/ans/include/slot_manager/slot_manager.h b/services/ans/include/slot_manager/slot_manager.h deleted file mode 100644 index 36e34e646..000000000 --- a/services/ans/include/slot_manager/slot_manager.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2021-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_ANS_SERVICES_ANS_INCLUDE_SLOT_MANAGER_H -#define BASE_NOTIFICATION_ANS_SERVICES_ANS_INCLUDE_SLOT_MANAGER_H - -#include -#include - -#include "ians_manager.h" -#include "base_manager.h" -#include "distributed_notification_service_ipc_interface_code.h" -#include "ians_subscriber_local_live_view.h" -#include "iremote_stub.h" -#include "singleton.h" - -namespace OHOS { -namespace Notification { -class SlotManager final : protected BaseManager { -public: - DECLARE_DELAYED_SINGLETON(SlotManager); -public: - static const uint32_t DEFAULT_SLOT_FLAGS = 59; // 0b111011 - /** - * @brief Handle remote request. - * - * @param data Indicates the input parcel. - * @param reply Indicates the output parcel. - * @param option Indicates the message option. - * @return Returns ERR_OK on success, others on failure. - */ - int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); -private: - ErrCode AddSlots(MessageParcel &data, MessageParcel &reply); - ErrCode AddSlotsSyncQue(const std::vector> &slots); - ErrCode AddSlotsInner( - const std::vector> &slots, sptr bundleOption); - - ErrCode SetEnabledForBundleSlot(MessageParcel &data, MessageParcel &reply); - ErrCode SetEnabledForBundleSlotSyncQue( - const sptr &bundleOption, - const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl); - ErrCode SetEnabledForBundleSlotInner( - const sptr &bundleOption, - const sptr &bundle, - const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl); -private: - int32_t CheckInterfacePermission(uint32_t code); - void GenerateSlotReminderMode(const sptr &slot, const sptr &bundle, - bool isSpecifiedSlot = false, uint32_t defaultSlotFlags = DEFAULT_SLOT_FLAGS); - void SendEnableNotificationSlotHiSysEvent( - const sptr &bundleOption, const NotificationConstant::SlotType &slotType, - bool enabled, ErrCode errCode); - ErrCode AddSlotThenPublishEvent( - const sptr &slot, - const sptr &bundle, - bool enabled, bool isForceControl); -}; -} // namespace Notification -} // namespace OHOS - -#endif // BASE_NOTIFICATION_ANS_SERVICES_ANS_INCLUDE_SLOT_MANAGER_H diff --git a/services/ans/src/disturb_manager/add_do_not_disturb_profiles.cpp b/services/ans/src/disturb_manager/add_do_not_disturb_profiles.cpp deleted file mode 100644 index 004da946b..000000000 --- a/services/ans/src/disturb_manager/add_do_not_disturb_profiles.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2024-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 "disturb_manager.h" - -#include -#include -#include - -#include "advanced_notification_service.h" -#include "notification_preferences.h" -#include "os_account_manager_helper.h" - -#include "advanced_notification_inline.h" -namespace OHOS { -namespace Notification { -ErrCode DisturbManager::HandleAddDoNotDisturbProfiles(MessageParcel &data, MessageParcel &reply) -{ - std::vector> profiles; - if (!ReadParcelableVector(profiles, data)) { - ANS_LOGE("Read profiles failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - if (profiles.size() > MAX_STATUS_VECTOR_NUM) { - ANS_LOGE("The profiles is exceeds limit."); - return ERR_ANS_INVALID_PARAM; - } - - ErrCode result = AddDoNotDisturbProfilesSyncQueue(profiles); - if (!reply.WriteInt32(result)) { - ANS_LOGE("Write result failed, ErrCode is %{public}d", result); - return ERR_ANS_PARCELABLE_FAILED; - } - return ERR_OK; -} - -ErrCode DisturbManager::AddDoNotDisturbProfilesSyncQueue( - const std::vector> &profiles) -{ - int32_t userId = SUBSCRIBE_USER_INIT; - if (OsAccountManagerHelper::GetInstance().GetCurrentActiveUserId(userId) != ERR_OK) { - ANS_LOGE("No active user found."); - return ERR_ANS_GET_ACTIVE_USER_FAILED; - } - AdvancedNotificationService::GetInstance()->SubmitSyncTask( - std::bind([copyUserId = userId, copyProfiles = profiles]() { - NotificationPreferences::GetInstance()->AddDoNotDisturbProfiles(copyUserId, copyProfiles); - })); - return ERR_OK; -} -} // namespace Notification -} // namespace OHOS diff --git a/services/ans/src/disturb_manager/disturb_manager.cpp b/services/ans/src/disturb_manager/disturb_manager.cpp deleted file mode 100644 index 87a6b1ba9..000000000 --- a/services/ans/src/disturb_manager/disturb_manager.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2024-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 "disturb_manager.h" -#include -#include -#include -#include - -#include "access_token_helper.h" -#include "ans_inner_errors.h" -#include "ans_log_wrapper.h" -#include "ans_permission_def.h" -#include "errors.h" -#include "os_account_manager_helper.h" -#include "ipc_skeleton.h" - -namespace OHOS { -namespace Notification { -DisturbManager::DisturbManager() -{ - codeAndExecuteFuncMap_ = { - {static_cast(NotificationInterfaceCode::REMOVE_DO_NOT_DISTURB_PROFILES), - std::bind(&DisturbManager::HandleRemoveDoNotDisturbProfiles, this, std::placeholders::_1, - std::placeholders::_2)}, - {static_cast(NotificationInterfaceCode::SET_DO_NOT_DISTURB_DATE), - std::bind(&DisturbManager::HandleSetDoNotDisturbDate, this, std::placeholders::_1, - std::placeholders::_2)}, - {static_cast(NotificationInterfaceCode::GET_DO_NOT_DISTURB_DATE), - std::bind(&DisturbManager::HandleGetDoNotDisturbDate, this, std::placeholders::_1, - std::placeholders::_2)}, - {static_cast(NotificationInterfaceCode::SET_DO_NOT_DISTURB_DATE_BY_USER), - std::bind(&DisturbManager::HandleSetDoNotDisturbDateByUser, this, std::placeholders::_1, - std::placeholders::_2)}, - {static_cast(NotificationInterfaceCode::GET_DO_NOT_DISTURB_DATE_BY_USER), - std::bind(&DisturbManager::HandleGetDoNotDisturbDateByUser, this, std::placeholders::_1, - std::placeholders::_2)}, - {static_cast(NotificationInterfaceCode::ADD_DO_NOTDISTURB_PROFILES), - std::bind(&DisturbManager::HandleAddDoNotDisturbProfiles, this, std::placeholders::_1, - std::placeholders::_2)}, - {static_cast(NotificationInterfaceCode::GET_DONOTDISTURB_PROFILE), - std::bind(&DisturbManager::HandleGetDoNotDisturbProfile, this, std::placeholders::_1, - std::placeholders::_2)}, - {static_cast(NotificationInterfaceCode::DOES_SUPPORT_DO_NOT_DISTURB_MODE), - std::bind(&DisturbManager::HandleDoesSupportDoNotDisturbMode, this, std::placeholders::_1, - std::placeholders::_2)}, - }; - codeAndPermissionFuncMap_ = { - {static_cast(NotificationInterfaceCode::REMOVE_DO_NOT_DISTURB_PROFILES), - std::bind(&DisturbManager::CheckSystemAndControllerPermission, this)}, - {static_cast(NotificationInterfaceCode::SET_DO_NOT_DISTURB_DATE), - std::bind(&DisturbManager::CheckSystemAndControllerPermission, this)}, - {static_cast(NotificationInterfaceCode::GET_DO_NOT_DISTURB_DATE), - std::bind(&DisturbManager::CheckSystemAndControllerPermission, this)}, - {static_cast(NotificationInterfaceCode::SET_DO_NOT_DISTURB_DATE_BY_USER), - std::bind(&DisturbManager::CheckSystemAndControllerPermission, this)}, - {static_cast(NotificationInterfaceCode::GET_DO_NOT_DISTURB_DATE_BY_USER), - std::bind(&DisturbManager::CheckSystemAndControllerPermission, this)}, - {static_cast(NotificationInterfaceCode::ADD_DO_NOTDISTURB_PROFILES), - std::bind(&DisturbManager::CheckSystemAndControllerPermission, this)}, - {static_cast(NotificationInterfaceCode::GET_DONOTDISTURB_PROFILE), - std::bind(&DisturbManager::CheckSystemAndControllerPermission, this)}, - }; -} - -int32_t DisturbManager::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) -{ - ANS_LOGD("[DisturbManager] called."); - auto permissionChecker = codeAndPermissionFuncMap_.find(code); - if (permissionChecker != codeAndPermissionFuncMap_.end()) { - ErrCode result = permissionChecker->second(); - if (result != ERR_OK) { - if (!reply.WriteInt32(result)) { - return ERR_ANS_PARCELABLE_FAILED; - } - return ERR_OK; - } - } - auto execution = codeAndExecuteFuncMap_.find(code); - if (execution == codeAndExecuteFuncMap_.end()) { - ANS_LOGE("[OnRemoteRequest] fail: unknown code!"); - return ERR_ANS_INVALID_PARAM; - } - ErrCode result = execution->second(data, reply); - if (SUCCEEDED(result)) { - return NO_ERROR; - } - return result; -} - -int32_t DisturbManager::CheckSystemAndControllerPermission() -{ - bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); - if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) { - return ERR_ANS_NON_SYSTEM_APP; - } - - if (!AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) { - return ERR_ANS_PERMISSION_DENIED; - } - return ERR_OK; -} -} // namespace Notification -} // namespace OHOS diff --git a/services/ans/src/disturb_manager/does_support_do_not_disturb_mode.cpp b/services/ans/src/disturb_manager/does_support_do_not_disturb_mode.cpp deleted file mode 100644 index 0b2619dde..000000000 --- a/services/ans/src/disturb_manager/does_support_do_not_disturb_mode.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2024-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 "disturb_manager.h" - -#include "access_token_helper.h" -#include "ans_inner_errors.h" -#include "ans_permission_def.h" -#include "ipc_skeleton.h" - -namespace OHOS { -namespace Notification { -ErrCode DisturbManager::HandleDoesSupportDoNotDisturbMode(MessageParcel &data, MessageParcel &reply) -{ - bool support = false; - - ErrCode result = DoesSupportDoNotDisturbModeInner(support); - if (!reply.WriteInt32(result)) { - ANS_LOGE("[HandleDoesSupportDoNotDisturbMode] fail: write result failed, ErrCode=%{public}d", result); - return ERR_ANS_PARCELABLE_FAILED; - } - - if (!reply.WriteBool(support)) { - ANS_LOGE("[HandleDoesSupportDoNotDisturbMode] fail: write doesSupport failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - return ERR_OK; -} - -ErrCode DisturbManager::DoesSupportDoNotDisturbModeInner(bool &doesSupport) -{ - bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); - if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) { - return ERR_ANS_NON_SYSTEM_APP; - } - - if (!AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) { - return ERR_ANS_PERMISSION_DENIED; - } - doesSupport = SUPPORT_DO_NOT_DISTRUB; - return ERR_OK; -} -} // namespace Notification -} // namespace OHOS diff --git a/services/ans/src/disturb_manager/get_do_not_disturb_date.cpp b/services/ans/src/disturb_manager/get_do_not_disturb_date.cpp deleted file mode 100644 index e09a3a637..000000000 --- a/services/ans/src/disturb_manager/get_do_not_disturb_date.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2024-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 "disturb_manager.h" - -#include -#include -#include - -#include "advanced_notification_service.h" -#include "notification_preferences.h" -#include "os_account_manager_helper.h" - -#include "advanced_notification_inline.h" -namespace OHOS { -namespace Notification { -ErrCode DisturbManager::HandleGetDoNotDisturbDate(MessageParcel &data, MessageParcel &reply) -{ - sptr date = nullptr; - - ErrCode result = GetDoNotDisturbDateSyncQueue(date); - if (!reply.WriteInt32(result)) { - ANS_LOGE("[HandleSetDoNotDisturbDate] fail: write result failed, ErrCode=%{public}d", result); - return ERR_ANS_PARCELABLE_FAILED; - } - - if (result == ERR_OK) { - if (!reply.WriteParcelable(date)) { - ANS_LOGE("[HandleSetDoNotDisturbDate] fail: write date failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - } - - return ERR_OK; -} - -ErrCode DisturbManager::HandleGetDoNotDisturbDateByUser(MessageParcel &data, MessageParcel &reply) -{ - int32_t userId = SUBSCRIBE_USER_INIT; - if (!data.ReadInt32(userId)) { - ANS_LOGE("[HandleGetDoNotDisturbDateByUser] fail: read userId failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - sptr date = nullptr; - ErrCode result = GetDoNotDisturbDateByUserSyncQueue(userId, date); - if (!reply.WriteInt32(result)) { - ANS_LOGE("[HandleGetDoNotDisturbDateByUser] fail: write result failed, ErrCode=%{public}d", result); - return ERR_ANS_PARCELABLE_FAILED; - } - - if (result == ERR_OK) { - if (!reply.WriteParcelable(date)) { - ANS_LOGE("[HandleGetDoNotDisturbDateByUser] fail: write date failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - } - - return ERR_OK; -} - -ErrCode DisturbManager::GetDoNotDisturbDateSyncQueue(sptr &date) -{ - ANS_LOGD("%{public}s", __FUNCTION__); - - int32_t userId = SUBSCRIBE_USER_INIT; - if (OsAccountManagerHelper::GetInstance().GetCurrentActiveUserId(userId) != ERR_OK) { - return ERR_ANS_GET_ACTIVE_USER_FAILED; - } - ErrCode result = ERR_OK; - AdvancedNotificationService::GetInstance()->SubmitSyncTask(std::bind([&]() { - result = GetDoNotDisturbDateByUserInner(userId, date); - })); - return result; -} - -ErrCode DisturbManager::GetDoNotDisturbDateByUserSyncQueue(const int32_t &userId, - sptr &date) -{ - ANS_LOGD("%{public}s", __FUNCTION__); - - if (userId <= SUBSCRIBE_USER_INIT) { - ANS_LOGE("Input userId is invalid."); - return ERR_ANS_INVALID_PARAM; - } - ErrCode result = ERR_OK; - AdvancedNotificationService::GetInstance()->SubmitSyncTask(std::bind([&]() { - ANS_LOGD("ffrt enter!"); - result = GetDoNotDisturbDateByUserInner(userId, date); - })); - return result; -} - -ErrCode DisturbManager::GetDoNotDisturbDateByUserInner(const int32_t &userId, sptr &date) -{ - sptr currentConfig = nullptr; - ErrCode result = NotificationPreferences::GetInstance()->GetDoNotDisturbDate(userId, currentConfig); - if (result != ERR_OK) { - return result; - } - int64_t now = GetCurrentTime(); - switch (currentConfig->GetDoNotDisturbType()) { - case NotificationConstant::DoNotDisturbType::CLEARLY: - case NotificationConstant::DoNotDisturbType::ONCE: - if (now >= currentConfig->GetEndDate()) { - date = new (std::nothrow) NotificationDoNotDisturbDate( - NotificationConstant::DoNotDisturbType::NONE, 0, 0); - if (date == nullptr) { - ANS_LOGE("Failed to create NotificationDoNotDisturbDate instance"); - return result; - } - NotificationPreferences::GetInstance()->SetDoNotDisturbDate(userId, date); - } else { - date = currentConfig; - } - break; - default: - date = currentConfig; - break; - } - return result; -} -} // namespace Notification -} // namespace OHOS diff --git a/services/ans/src/disturb_manager/get_do_not_disturb_profile.cpp b/services/ans/src/disturb_manager/get_do_not_disturb_profile.cpp deleted file mode 100644 index 9f1db29c7..000000000 --- a/services/ans/src/disturb_manager/get_do_not_disturb_profile.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2024-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 "disturb_manager.h" - -#include -#include -#include - -#include "advanced_notification_service.h" -#include "notification_preferences.h" -#include "os_account_manager_helper.h" - -#include "advanced_notification_inline.h" -namespace OHOS { -namespace Notification { -ErrCode DisturbManager::HandleGetDoNotDisturbProfile(MessageParcel &data, MessageParcel &reply) -{ - int64_t profileId = data.ReadInt64(); - sptr profile = nullptr; - ErrCode result = GetDoNotDisturbProfileInner(profileId, profile); - if (!reply.WriteInt32(result)) { - ANS_LOGE("HandleGetDoNotDisturbProfile write result failed, ErrCode=%{public}d", result); - return ERR_ANS_PARCELABLE_FAILED; - } - - if (result == ERR_OK) { - if (!reply.WriteParcelable(profile)) { - ANS_LOGE("HandleGetDoNotDisturbProfile write profile failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - } - return ERR_OK; -} - -ErrCode DisturbManager::GetDoNotDisturbProfileInner(int64_t id, sptr &profile) -{ - int32_t userId = SUBSCRIBE_USER_INIT; - if (OsAccountManagerHelper::GetInstance().GetCurrentActiveUserId(userId) != ERR_OK) { - ANS_LOGE("No active user found."); - return ERR_ANS_GET_ACTIVE_USER_FAILED; - } - - profile = new (std::nothrow) NotificationDoNotDisturbProfile(); - ErrCode result = NotificationPreferences::GetInstance()->GetDoNotDisturbProfile(id, userId, profile); - if (result != ERR_OK) { - ANS_LOGE("profile failed id: %{public}s, userid: %{public}d", std::to_string(id).c_str(), userId); - } - return result; -} - -} // namespace Notification -} // namespace OHOS diff --git a/services/ans/src/disturb_manager/remove_do_not_disturb_profiles.cpp b/services/ans/src/disturb_manager/remove_do_not_disturb_profiles.cpp deleted file mode 100644 index 5ea8a9035..000000000 --- a/services/ans/src/disturb_manager/remove_do_not_disturb_profiles.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2024-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 "disturb_manager.h" - -#include -#include -#include - -#include "advanced_notification_service.h" -#include "notification_preferences.h" -#include "os_account_manager_helper.h" - -namespace OHOS { -namespace Notification { -ErrCode DisturbManager::HandleRemoveDoNotDisturbProfiles(MessageParcel &data, MessageParcel &reply) -{ - std::vector> profiles; - if (!ReadParcelableVector(profiles, data)) { - ANS_LOGE("Read profiles failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - if (profiles.size() > MAX_STATUS_VECTOR_NUM) { - ANS_LOGE("The profiles is exceeds limit."); - return ERR_ANS_INVALID_PARAM; - } - - ErrCode result = RemoveDoNotDisturbProfilesSyncQueue(profiles); - if (!reply.WriteInt32(result)) { - ANS_LOGE("Write result failed, ErrCode is %{public}d", result); - return ERR_ANS_PARCELABLE_FAILED; - } - return ERR_OK; -} - -ErrCode DisturbManager::RemoveDoNotDisturbProfilesSyncQueue( - const std::vector> &profiles) -{ - ANS_LOGD("Called."); - - int32_t userId = SUBSCRIBE_USER_INIT; - if (OsAccountManagerHelper::GetInstance().GetCurrentActiveUserId(userId) != ERR_OK) { - ANS_LOGE("No active user found."); - return ERR_ANS_GET_ACTIVE_USER_FAILED; - } - AdvancedNotificationService::GetInstance()->SubmitSyncTask( - std::bind([copyUserId = userId, copyProfiles = profiles]() { - ANS_LOGD("The ffrt enter."); - NotificationPreferences::GetInstance()->RemoveDoNotDisturbProfiles(copyUserId, copyProfiles); - })); - return ERR_OK; -} -} // namespace Notification -} // namespace OHOS diff --git a/services/ans/src/disturb_manager/set_do_not_disturb_date.cpp b/services/ans/src/disturb_manager/set_do_not_disturb_date.cpp deleted file mode 100644 index fb6a198f5..000000000 --- a/services/ans/src/disturb_manager/set_do_not_disturb_date.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (c) 2024-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 "disturb_manager.h" - -#include -#include -#include - -#include "advanced_notification_service.h" -#include "notification_preferences.h" -#include "os_account_manager_helper.h" - -#include "advanced_notification_inline.h" - -namespace OHOS { -namespace Notification { -constexpr int32_t HOURS_IN_ONE_DAY = 24; - -ErrCode DisturbManager::HandleSetDoNotDisturbDate(MessageParcel &data, MessageParcel &reply) -{ - sptr date = data.ReadParcelable(); - if (date == nullptr) { - ANS_LOGE("[HandleSetDoNotDisturbDate] fail: read date failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - ErrCode result = SetDoNotDisturbDate(date); - if (!reply.WriteInt32(result)) { - ANS_LOGE("[HandleSetDoNotDisturbDate] fail: write result failed, ErrCode=%{public}d", result); - return ERR_ANS_PARCELABLE_FAILED; - } - - return ERR_OK; -} -ErrCode DisturbManager::HandleSetDoNotDisturbDateByUser(MessageParcel &data, MessageParcel &reply) -{ - int32_t userId = SUBSCRIBE_USER_INIT; - if (!data.ReadInt32(userId)) { - ANS_LOGE("[HandleSetDoNotDisturbDateByUser] fail: read userId failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - sptr date = data.ReadParcelable(); - if (date == nullptr) { - ANS_LOGE("[HandleSetDoNotDisturbDateByUser] fail: read date failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - ErrCode result = SetDoNotDisturbDateByUserSyncQueue(userId, date); - if (!reply.WriteInt32(result)) { - ANS_LOGE("[HandleSetDoNotDisturbDateByUser] fail: write result failed, ErrCode=%{public}d", result); - return ERR_ANS_PARCELABLE_FAILED; - } - - return ERR_OK; -} - -ErrCode DisturbManager::SetDoNotDisturbDate(const sptr &date) -{ - ANS_LOGD("%{public}s", __FUNCTION__); - - int32_t userId = SUBSCRIBE_USER_INIT; - if (OsAccountManagerHelper::GetInstance().GetCurrentActiveUserId(userId) != ERR_OK) { - ANS_LOGE("No active user found!"); - return ERR_ANS_GET_ACTIVE_USER_FAILED; - } - - return SetDoNotDisturbDateByUserSyncQueue(userId, date); -} - -ErrCode DisturbManager::SetDoNotDisturbDateByUserSyncQueue(const int32_t &userId, - const sptr &date) -{ - ANS_LOGD("%{public}s enter, userId = %{public}d", __FUNCTION__, userId); - if (userId <= SUBSCRIBE_USER_INIT) { - ANS_LOGE("Input userId is invalidity."); - return ERR_ANS_INVALID_PARAM; - } - - if (date == nullptr) { - ANS_LOGE("Invalid date param"); - return ERR_ANS_INVALID_PARAM; - } - int64_t beginDate = ResetSeconds(date->GetBeginDate()); - int64_t endDate = ResetSeconds(date->GetEndDate()); - switch (date->GetDoNotDisturbType()) { - case NotificationConstant::DoNotDisturbType::NONE: - beginDate = 0; - endDate = 0; - break; - case NotificationConstant::DoNotDisturbType::ONCE: - AdjustDateForDndTypeOnce(beginDate, endDate); - break; - case NotificationConstant::DoNotDisturbType::CLEARLY: - if (beginDate >= endDate) { - return ERR_ANS_INVALID_PARAM; - } - break; - default: - break; - } - ANS_LOGD("Before set SetDoNotDisturbDate beginDate = %{public}" PRId64 ", endDate = %{public}" PRId64, - beginDate, endDate); - const sptr newConfig = new (std::nothrow) NotificationDoNotDisturbDate( - date->GetDoNotDisturbType(), beginDate, endDate); - if (newConfig == nullptr) { - ANS_LOGE("Failed to create NotificationDoNotDisturbDate instance"); - return ERR_NO_MEMORY; - } - - sptr bundleOption = AdvancedNotificationService::GenerateBundleOption(); - if (bundleOption == nullptr) { - ANS_LOGE("Generate invalid bundle option!"); - return ERR_ANS_INVALID_BUNDLE; - } - AdvancedNotificationService::GetInstance()->SubmitSyncTask(std::bind([&]() { - SetDoNotDisturbDateByUserInner(userId, newConfig); - })); - return ERR_OK; -} - -ErrCode DisturbManager::SetDoNotDisturbDateByUserInner(const int32_t &userId, - const sptr &date) -{ - ANS_LOGD("ffrt enter!"); - ErrCode result = NotificationPreferences::GetInstance()->SetDoNotDisturbDate(userId, date); - if (result == ERR_OK) { - NotificationSubscriberManager::GetInstance()->NotifyDoNotDisturbDateChanged(userId, date); - } - return result; -} - -void DisturbManager::AdjustDateForDndTypeOnce(int64_t &beginDate, int64_t &endDate) -{ - std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); - time_t nowT = std::chrono::system_clock::to_time_t(now); - tm nowTm = GetLocalTime(nowT); - - auto beginDateMilliseconds = std::chrono::milliseconds(beginDate); - auto beginDateTimePoint = - std::chrono::time_point(beginDateMilliseconds); - time_t beginDateT = std::chrono::system_clock::to_time_t(beginDateTimePoint); - tm beginDateTm = GetLocalTime(beginDateT); - - auto endDateMilliseconds = std::chrono::milliseconds(endDate); - auto endDateTimePoint = - std::chrono::time_point(endDateMilliseconds); - time_t endDateT = std::chrono::system_clock::to_time_t(endDateTimePoint); - tm endDateTm = GetLocalTime(endDateT); - - tm todayBeginTm = nowTm; - todayBeginTm.tm_sec = 0; - todayBeginTm.tm_min = beginDateTm.tm_min; - todayBeginTm.tm_hour = beginDateTm.tm_hour; - - tm todayEndTm = nowTm; - todayEndTm.tm_sec = 0; - todayEndTm.tm_min = endDateTm.tm_min; - todayEndTm.tm_hour = endDateTm.tm_hour; - - time_t todayBeginT = mktime(&todayBeginTm); - if (todayBeginT == -1) { - return; - } - time_t todayEndT = mktime(&todayEndTm); - if (todayEndT == -1) { - return; - } - - auto newBeginTimePoint = std::chrono::system_clock::from_time_t(todayBeginT); - auto newEndTimePoint = std::chrono::system_clock::from_time_t(todayEndT); - if (newBeginTimePoint >= newEndTimePoint) { - newEndTimePoint += std::chrono::hours(HOURS_IN_ONE_DAY); - } - - if (newEndTimePoint < now) { - newBeginTimePoint += std::chrono::hours(HOURS_IN_ONE_DAY); - newEndTimePoint += std::chrono::hours(HOURS_IN_ONE_DAY); - } - - auto newBeginDuration = std::chrono::duration_cast(newBeginTimePoint.time_since_epoch()); - beginDate = newBeginDuration.count(); - - auto newEndDuration = std::chrono::duration_cast(newEndTimePoint.time_since_epoch()); - endDate = newEndDuration.count(); -} - -} // namespace Notification -} // namespace OHOS diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 14d418a50..204ae80d2 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -1246,70 +1246,6 @@ ohos_unittest("os_account_manager_helper_test") { part_name = "${component_name}" } -ohos_unittest("disturb_manager_unit_test") { - module_out_path = module_output_path - include_dirs = [ - ".", - "${services_path}/ans/include", - "${services_path}/ans/include/disturb_manager", - "${services_path}/ans/test/unittest/mock/include", - "${frameworks_module_ans_path}/core/include", - ] - - defines = [] - - sources = [ - "${test_path}/mock/mock_tokenid_kit.cpp", - "disturb_manager/disturb_manager_test.cpp", - "mock/mock_accesstoken_kit.cpp", - "notification_dialog_test/mock_os_account_manager_annex.cpp", - "notification_subscriber_manager_branch_test/mock_access_token_helper.cpp", - ] - - deps = [ - "${frameworks_module_ans_path}:ans_innerkits", - "${services_path}/ans:libans", - ] - - if (distributed_notification_supported) { - defines += [ "DISTRIBUTED_NOTIFICATION_SUPPORTED" ] - deps += [ "${services_path}/distributed:libans_distributed" ] - include_dirs += [ "${services_path}/distributed/include" ] - } - - external_deps = [ - "ability_base:want", - "ability_base:zuri", - "ability_runtime:abilitykit_native", - "ability_runtime:app_manager", - "ability_runtime:wantagent_innerkits", - "access_token:libaccesstoken_sdk", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "common_event_service:cesfwk_innerkits", - "device_manager:devicemanagersdk", - "eventhandler:libeventhandler", - "ffrt:libffrt", - "googletest:gmock_main", - "googletest:gtest_main", - "hilog:libhilog", - "hitrace:hitrace_meter", - "hitrace:libhitracechain", - "image_framework:image_native", - "ipc:ipc_core", - "kv_store:distributeddata_inner", - "os_account:os_account_innerkits", - "relational_store:native_rdb", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - "time_service:time_client", - ] - - subsystem_name = "${subsystem_name}" - part_name = "${component_name}" -} - ohos_unittest("advanced_datashare_observer_unit_test") { module_out_path = module_output_path include_dirs = [ @@ -1508,7 +1444,6 @@ group("unittest") { ":ans_unit_test", ":bundle_manager_helper_branch_test", ":common_utils_test", - ":disturb_manager_unit_test", ":notification_config_parse_test", ":notification_dialog_test", ":notification_extension_wrapper_unit_test", diff --git a/services/ans/test/unittest/disturb_manager/disturb_manager_test.cpp b/services/ans/test/unittest/disturb_manager/disturb_manager_test.cpp deleted file mode 100644 index 2edfb9877..000000000 --- a/services/ans/test/unittest/disturb_manager/disturb_manager_test.cpp +++ /dev/null @@ -1,391 +0,0 @@ -/* - * Copyright (c) 2024-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 "errors.h" -#include "notification_content.h" -#include "notification_record.h" -#include "notification_request.h" -#include -#include -#include -#include -#include - -#include - -#define private public - -#include "accesstoken_kit.h" -#include "ans_const_define.h" -#include "ans_inner_errors.h" -#include "ans_log_wrapper.h" -#include "ans_notification.h" -#include "common_event_manager.h" -#include "common_event_support.h" -#include "disturb_manager.h" -#include "iremote_object.h" -#include "notification_preferences.h" -#include "notification_subscriber.h" -#include "notification_subscriber_manager.h" -#include "system_event_observer.h" -#include "notification_constant.h" -#include "want_agent_info.h" -#include "want_agent_helper.h" -#include "want_params.h" -#include "bundle_manager_helper.h" - -using namespace testing; -using namespace testing::ext; -using namespace OHOS::Security::AccessToken; -using namespace OHOS::Media; - -extern void MockVerifyNativeToken(bool mockRet); -extern void MockQueryForgroundOsAccountId(bool mockRet, uint8_t mockCase); -namespace OHOS { -namespace Notification { -extern void MockGetTokenTypeFlag(ATokenTypeEnum mockRet); -extern void MockIsSystemApp(bool isSystemApp); -extern void MockIsVerfyPermisson(bool isVerify); - -class DisturbManagerTest : public testing::Test { -public: - static void SetUpTestCase() {}; - static void TearDownTestCase() {}; - void SetUp(); - void TearDown(); - -private: - std::shared_ptr disturbManager_; -}; - -void DisturbManagerTest::SetUp() -{ - disturbManager_ = std::make_shared(); -} - -void DisturbManagerTest::TearDown() -{ - disturbManager_ = nullptr; -} - -/** - * @tc.number : DisturbManagerTest_20000 - * @tc.name : DisturbManagerTest_20000 - * @tc.desc : Test invalid userId return ERR_ANS_INVALID_PARAM - * @tc.require : #I61RF2 - */ -HWTEST_F(DisturbManagerTest, DisturbManagerTest_20000, Function | SmallTest | Level1) -{ - int32_t userId = -2; - - sptr date = nullptr; - ASSERT_EQ(disturbManager_->GetDoNotDisturbDateByUserSyncQueue(userId, date), ERR_ANS_INVALID_PARAM); - ASSERT_EQ(disturbManager_->SetDoNotDisturbDateByUserSyncQueue(userId, date), ERR_ANS_INVALID_PARAM); -} - -/** - * @tc.number : DisturbManagerTest - * @tc.name : CheckSystemAndControllerPermission_0100 - * @tc.desc : Test CheckSystemAndControllerPermission return ERR_ANS_NON_SYSTEM_APP. - * @tc.require : #I6P8UI - */ -HWTEST_F(DisturbManagerTest, CheckSystemAndControllerPermission_0100, Function | SmallTest | Level1) -{ - MockVerifyNativeToken(false); - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - MockIsSystemApp(false); - - ASSERT_EQ(disturbManager_->CheckSystemAndControllerPermission(), ERR_ANS_NON_SYSTEM_APP); -} - -/** - * @tc.number : DisturbManagerTest - * @tc.name : CheckSystemAndControllerPermission_0200 - * @tc.desc : Test CheckSystemAndControllerPermission return ERR_ANS_PERMISSION_DENIED. - * @tc.require : #I6P8UI - */ -HWTEST_F(DisturbManagerTest, CheckSystemAndControllerPermission_0200, Function | SmallTest | Level1) -{ - MockVerifyNativeToken(false); - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - MockIsVerfyPermisson(false); - - ASSERT_EQ(disturbManager_->CheckSystemAndControllerPermission(), ERR_ANS_NON_SYSTEM_APP); -} - -/** - * @tc.number : DisturbManagerTest_21000 - * @tc.name : DisturbManagerTest_21000 - * @tc.desc : Test SetDoNotDisturbDate function and GetActiveUserId is false - */ -HWTEST_F(DisturbManagerTest, DisturbManagerTest_21000, Function | SmallTest | Level1) -{ - sptr date = nullptr; - MockQueryForgroundOsAccountId(false, 1); - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE); - - ASSERT_EQ(disturbManager_->SetDoNotDisturbDate(date), ERR_ANS_GET_ACTIVE_USER_FAILED); -} - -/** - * @tc.number : DisturbManagerTest_22000 - * @tc.name : DisturbManagerTest_22000 - * @tc.desc : Test GetDoNotDisturbDateSyncQueue function and GetActiveUserId is false - */ -HWTEST_F(DisturbManagerTest, DisturbManagerTest_22000, Function | SmallTest | Level1) -{ - sptr date = nullptr; - MockQueryForgroundOsAccountId(false, 1); - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE); - - ASSERT_EQ(disturbManager_->GetDoNotDisturbDateSyncQueue(date), ERR_ANS_GET_ACTIVE_USER_FAILED); -} - -/** - * @tc.number : DisturbManagerTest_03600 - * @tc.name : ANS_AddDoNotDisturbProfiles_0100 - * @tc.desc : Test AddDoNotDisturbProfiles function - */ -HWTEST_F(DisturbManagerTest, DisturbManagerTest_03600, Function | SmallTest | Level1) -{ - MockQueryForgroundOsAccountId(true, 1); - sptr date = nullptr; - std::vector> profiles = { date }; - auto ret = disturbManager_->AddDoNotDisturbProfilesSyncQueue(profiles); - ASSERT_EQ(ret, (int)ERR_OK); -} - - -/** - * @tc.number : DisturbManagerTest_04200 - * @tc.name : ANS_AddDoNotDisturbProfiles_0100 - * @tc.desc : Test AddDoNotDisturbProfiles function - */ -HWTEST_F(DisturbManagerTest, DisturbManagerTest_04200, Function | SmallTest | Level1) -{ - MockQueryForgroundOsAccountId(true, 1); - sptr date = nullptr; - std::vector> profiles = { date }; - auto ret = disturbManager_->RemoveDoNotDisturbProfilesSyncQueue(profiles); - ASSERT_EQ(ret, (int)ERR_OK); -} - -/** - * @tc.number : DisturbManagerTest_10500 - * @tc.name : ANS_SetDisturbMode_10500 - * @tc.desc : Test SetDisturbMode function - */ -HWTEST_F(DisturbManagerTest, DisturbManagerTest_10500, Function | SmallTest | Level1) -{ - MockQueryForgroundOsAccountId(true, 1); - sptr date = - new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0); - ASSERT_EQ((int)disturbManager_->SetDoNotDisturbDate(date), (int)ERR_OK); - - std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); - auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); - int64_t beginDate = beginDuration.count(); - timePoint += std::chrono::hours(1); - auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); - int64_t endDate = endDuration.count(); - date = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate); - ASSERT_EQ((int)disturbManager_->SetDoNotDisturbDate(date), (int)ERR_OK); - - timePoint = std::chrono::system_clock::now(); - beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); - beginDate = beginDuration.count(); - timePoint += std::chrono::hours(1); - endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); - endDate = endDuration.count(); - date = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::DAILY, beginDate, endDate); - ASSERT_EQ((int)disturbManager_->SetDoNotDisturbDate(date), (int)ERR_OK); - - timePoint = std::chrono::system_clock::now(); - beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); - beginDate = beginDuration.count(); - timePoint += std::chrono::hours(1); - endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); - endDate = endDuration.count(); - date = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::CLEARLY, beginDate, endDate); - ASSERT_EQ((int)disturbManager_->SetDoNotDisturbDate(date), (int)ERR_OK); -} - - -/** - * @tc.number : DisturbManagerTest_10600 - * @tc.name : ANS_GetDisturbMode_10600 - * @tc.desc : Test GetDisturbMode function - */ -HWTEST_F(DisturbManagerTest, DisturbManagerTest_10600, Function | SmallTest | Level1) -{ - MockQueryForgroundOsAccountId(true, 1); - sptr date = - new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0); - - ASSERT_EQ((int)disturbManager_->SetDoNotDisturbDate(date), (int)ERR_OK); - - sptr result = nullptr; - ASSERT_EQ((int)disturbManager_->GetDoNotDisturbDateSyncQueue(result), (int)ERR_OK); - ASSERT_NE(result, nullptr); - ASSERT_EQ(result->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::NONE); - ASSERT_EQ(result->GetBeginDate(), 0); - ASSERT_EQ(result->GetEndDate(), 0); -} - -/** - * @tc.number : DisturbManagerTest_10700 - * @tc.name : ANS_GetDisturbMode_10700 - * @tc.desc : Test GetDisturbMode function - */ -HWTEST_F(DisturbManagerTest, DisturbManagerTest_10700, Function | SmallTest | Level1) -{ - MockQueryForgroundOsAccountId(true, 1); - std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); - timePoint = std::chrono::time_point_cast(timePoint); - timePoint += std::chrono::hours(1); - auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); - int64_t beginDate = beginDuration.count(); - timePoint += std::chrono::hours(1); - auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); - int64_t endDate = endDuration.count(); - - sptr date = - new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate); - ASSERT_EQ((int)disturbManager_->SetDoNotDisturbDate(date), (int)ERR_OK); - - sptr result = nullptr; - ASSERT_EQ((int)disturbManager_->GetDoNotDisturbDateSyncQueue(result), (int)ERR_OK); - ASSERT_NE(result, nullptr); - ASSERT_EQ(result->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::ONCE); - ASSERT_EQ(result->GetBeginDate(), beginDate); - ASSERT_EQ(result->GetEndDate(), endDate); -} - -/** - * @tc.number : DisturbManagerTest_10800 - * @tc.name : ANS_GetDisturbMode_10800 - * @tc.desc : Test GetDisturbMode function - */ -HWTEST_F(DisturbManagerTest, DisturbManagerTest_10800, Function | SmallTest | Level1) -{ - MockQueryForgroundOsAccountId(true, 1); - std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); - timePoint = std::chrono::time_point_cast(timePoint); - timePoint += std::chrono::hours(1); - auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); - int64_t beginDate = beginDuration.count(); - timePoint += std::chrono::hours(1); - auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); - int64_t endDate = endDuration.count(); - - sptr date = - new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::DAILY, beginDate, endDate); - - ASSERT_EQ((int)disturbManager_->SetDoNotDisturbDate(date), (int)ERR_OK); - sptr result = nullptr; - ASSERT_EQ((int)disturbManager_->GetDoNotDisturbDateSyncQueue(result), (int)ERR_OK); - ASSERT_NE(result, nullptr); - ASSERT_EQ(result->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::DAILY); - ASSERT_EQ(result->GetBeginDate(), beginDate); - ASSERT_EQ(result->GetEndDate(), endDate); -} - -/** - * @tc.number : DisturbManagerTest_10900 - * @tc.name : ANS_GetDisturbMode_10900 - * @tc.desc : Test GetDisturbMode function - */ -HWTEST_F(DisturbManagerTest, DisturbManagerTest_10900, Function | SmallTest | Level1) -{ - MockQueryForgroundOsAccountId(true, 1); - std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); - timePoint = std::chrono::time_point_cast(timePoint); - timePoint += std::chrono::hours(1); - auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); - int64_t beginDate = beginDuration.count(); - timePoint += std::chrono::hours(1); - auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); - int64_t endDate = endDuration.count(); - - sptr date = - new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::CLEARLY, beginDate, endDate); - ASSERT_EQ((int)disturbManager_->SetDoNotDisturbDate(date), (int)ERR_OK); - - sptr result = nullptr; - ASSERT_EQ((int)disturbManager_->GetDoNotDisturbDateSyncQueue(result), (int)ERR_OK); - ASSERT_NE(result, nullptr); - ASSERT_EQ(result->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::CLEARLY); - ASSERT_EQ(result->GetBeginDate(), beginDate); - ASSERT_EQ(result->GetEndDate(), endDate); -} - -/** - * @tc.number : DisturbManagerTest_14200 - * @tc.name : ANS_DoesSupportDoNotDisturbMode_0100 - * @tc.desc : Test DoesSupportDoNotDisturbMode function when the result is ERR_OK - * @tc.require : issueI5S4VP - */ -HWTEST_F(DisturbManagerTest, DisturbManagerTest_14200, Function | SmallTest | Level1) -{ - MockVerifyNativeToken(true); - MockIsVerfyPermisson(true); - sptr req = new NotificationRequest(); - EXPECT_NE(req, nullptr); - bool doesSupport = true; - ASSERT_EQ(disturbManager_->DoesSupportDoNotDisturbModeInner(doesSupport), (int)ERR_OK); -} - -/** - * @tc.number : DisturbManagerTest_15000 - * @tc.name : ANS_GetDoNotDisturbDateByUserSyncQueue_0100 - * @tc.desc : Test GetDoNotDisturbDateByUserSyncQueue function when the result is ERR_OK - * @tc.require : issueI5S4VP - */ -HWTEST_F(DisturbManagerTest, DisturbManagerTest_15000, Function | SmallTest | Level1) -{ - int32_t userId = 100; - sptr date = nullptr; - ASSERT_EQ(disturbManager_->GetDoNotDisturbDateByUserSyncQueue(userId, date), (int)ERR_OK); -} - -/** - * @tc.name: HandleRemoveDoNotDisturbProfiles_0100 - * @tc.desc: test HandleRemoveDoNotDisturbProfiles when ReadParcelableVector return false. - * @tc.type: FUNC - */ - HWTEST_F(DisturbManagerTest, HandleRemoveDoNotDisturbProfiles_0100, TestSize.Level1) - { - MessageParcel data; - MessageParcel reply; - ErrCode ret = disturbManager_->HandleRemoveDoNotDisturbProfiles(data, reply); - EXPECT_EQ(ret, ERR_ANS_PARCELABLE_FAILED); - } - - -/** - * @tc.name: HandleAddDoNotDisturbProfiles_0100 - * @tc.desc: test HandleAddDoNotDisturbProfiles when ReadParcelableVector return false. - * @tc.type: FUNC - */ -HWTEST_F(DisturbManagerTest, HandleAddDoNotDisturbProfiles_0100, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - ErrCode ret = disturbManager_->HandleAddDoNotDisturbProfiles(data, reply); - EXPECT_EQ(ret, ERR_ANS_PARCELABLE_FAILED); -} - -} -} \ No newline at end of file diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index 53738ae40..3a8b6faf5 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -23,7 +23,6 @@ ohos_moduletest("ans_module_test") { include_dirs = [ "include", "${services_path}/ans/include", - "${services_path}/ans/include/disturb_manager", "${services_path}/ans/test/unittest", "${services_path}/ans/test/unittest/mock/include", "${services_path}/test/moduletest/mock/include", diff --git a/services/test/moduletest/ans_module_test.cpp b/services/test/moduletest/ans_module_test.cpp index 9abc4a1e6..087ea8d48 100644 --- a/services/test/moduletest/ans_module_test.cpp +++ b/services/test/moduletest/ans_module_test.cpp @@ -21,7 +21,6 @@ #include "accesstoken_kit.h" #include "advanced_notification_service.h" #include "ans_subscriber_listener.h" -#include "disturb_manager.h" #include "notification_subscriber.h" using namespace testing::ext; @@ -97,17 +96,14 @@ public: void TestAddSlots(); static sptr g_advancedNotificationService; - static std::shared_ptr g_disturbManager; }; sptr AnsModuleTest::g_advancedNotificationService; -std::shared_ptr AnsModuleTest::g_disturbManager; void AnsModuleTest::SetUpTestCase() { passed = false; NotificationPreferences::GetInstance()->ClearNotificationInRestoreFactorySettings(); g_advancedNotificationService = OHOS::Notification::AdvancedNotificationService::GetInstance(); - g_disturbManager = DelayedSingleton::GetInstance(); } void AnsModuleTest::TearDownTestCase() @@ -2816,7 +2812,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0132, Function | SmallTest | Level1) sptr date = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0); - EXPECT_EQ(g_disturbManager->SetDoNotDisturbDateByUserSyncQueue(100, date), ERR_OK); + EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(100, date), ERR_OK); EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK); std::this_thread::sleep_for(std::chrono::milliseconds(200)); @@ -2867,7 +2863,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0133, Function | SmallTest | Level1) int64_t endDate = endDuration.count(); sptr date = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate); - EXPECT_EQ(g_disturbManager->SetDoNotDisturbDateByUserSyncQueue(100, date), ERR_OK); + EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(100, date), ERR_OK); EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK); std::this_thread::sleep_for(std::chrono::milliseconds(200)); @@ -2918,7 +2914,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0134, Function | SmallTest | Level1) int64_t endDate = endDuration.count(); sptr date = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::DAILY, beginDate, endDate); - EXPECT_EQ(g_disturbManager->SetDoNotDisturbDateByUserSyncQueue(100, date), ERR_OK); + EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(100, date), ERR_OK); EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK); std::this_thread::sleep_for(std::chrono::milliseconds(200)); @@ -2969,7 +2965,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0135, Function | SmallTest | Level1) int64_t endDate = endDuration.count(); sptr date = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::CLEARLY, beginDate, endDate); - EXPECT_EQ(g_disturbManager->SetDoNotDisturbDateByUserSyncQueue(100, date), ERR_OK); + EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(100, date), ERR_OK); EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK); std::this_thread::sleep_for(std::chrono::milliseconds(200)); -- Gitee