From 5e1d8c339764f9c426c0568ae60ee3a18ed65eb5 Mon Sep 17 00:00:00 2001 From: chenyuyan Date: Wed, 26 Oct 2022 09:51:32 +0800 Subject: [PATCH] =?UTF-8?q?fixed=2095fc262=20from=20https://gitee.com/oran?= =?UTF-8?q?geeeechen/notification=5Fdistributed=5Fnotification=5Fservice/p?= =?UTF-8?q?ulls/683=20RequestEnableNotification=E6=8E=A5=E5=8F=A3=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=8F=82=E6=95=B0=E9=80=82=E9=85=8D=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenyuyan Change-Id: Ic657729976f941db9fc1f8c86a467bd807c09199 --- frameworks/ans/src/notification_helper.cpp | 5 - .../unittest/notification_helper_test.cpp | 3 +- .../core/include/ans_manager_interface.h | 8 -- frameworks/core/include/ans_manager_proxy.h | 8 -- frameworks/core/include/ans_manager_stub.h | 8 -- frameworks/core/include/ans_notification.h | 9 -- frameworks/core/src/ans_manager_proxy.cpp | 6 - frameworks/core/src/ans_manager_stub.cpp | 6 - frameworks/core/src/ans_notification.cpp | 10 -- frameworks/test/unittest/BUILD.gn | 0 .../test/unittest/ans_callback_stub_test.cpp | 111 ++++++++++++++++++ .../test/unittest/ans_manager_stub_test.cpp | 0 interfaces/inner_api/notification_helper.h | 9 -- .../include/advanced_notification_service.h | 8 -- .../ans/src/advanced_notification_service.cpp | 6 - .../setnotificationbadgenum_fuzzer.cpp | 3 +- 16 files changed, 115 insertions(+), 85 deletions(-) create mode 100644 frameworks/test/unittest/BUILD.gn create mode 100644 frameworks/test/unittest/ans_callback_stub_test.cpp create mode 100644 frameworks/test/unittest/ans_manager_stub_test.cpp diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index ec6963f02..1f8fb1710 100644 --- a/frameworks/ans/src/notification_helper.cpp +++ b/frameworks/ans/src/notification_helper.cpp @@ -154,11 +154,6 @@ ErrCode NotificationHelper::IsAllowedNotifySelf(bool &allowed) return DelayedSingleton::GetInstance()->IsAllowedNotifySelf(allowed); } -ErrCode NotificationHelper::RequestEnableNotification(std::string &deviceId) -{ - return DelayedSingleton::GetInstance()->RequestEnableNotification(deviceId); -} - ErrCode NotificationHelper::RequestEnableNotification(std::string &deviceId, bool &popFlag) { return DelayedSingleton::GetInstance()->RequestEnableNotification(deviceId, popFlag); diff --git a/frameworks/ans/test/unittest/notification_helper_test.cpp b/frameworks/ans/test/unittest/notification_helper_test.cpp index ff5eedb5e..a4086147b 100644 --- a/frameworks/ans/test/unittest/notification_helper_test.cpp +++ b/frameworks/ans/test/unittest/notification_helper_test.cpp @@ -416,8 +416,9 @@ HWTEST_F(NotificationHelperTest, IsAllowedNotifySelf_00001, Function | SmallTest HWTEST_F(NotificationHelperTest, RequestEnableNotification_00001, Function | SmallTest | Level1) { std::string deviceId = "DeviceId"; + bool needPop = true; NotificationHelper notificationHelper; - ErrCode ret = notificationHelper.RequestEnableNotification(deviceId); + ErrCode ret = notificationHelper.RequestEnableNotification(deviceId, needPop); EXPECT_EQ(ret, (int)ERR_ANS_NOT_ALLOWED); } diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index 3b40c55fe..a2a918268 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -339,14 +339,6 @@ public: virtual ErrCode UpdateSlots( const sptr &bundleOption, const std::vector> &slots) = 0; - /** - * @brief Allow notifications to be sent based on the deviceId. - * - * @param deviceId Indicates the device Id. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode RequestEnableNotification(const std::string &deviceId) = 0; - /** * @brief Allow notifications to be sent based on the deviceId. * diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index 89c5129ff..4d736b1a2 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -327,14 +327,6 @@ public: ErrCode UpdateSlots( const sptr &bundleOption, const std::vector> &slots) override; - /** - * @brief Allow notifications to be sent based on the deviceId. - * - * @param deviceId Indicates the device Id. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode RequestEnableNotification(const std::string &deviceId) override; - /** * @brief Allow notifications to be sent based on the deviceId. * diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index 55207f7d3..a770d5553 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -343,14 +343,6 @@ public: virtual ErrCode UpdateSlots( const sptr &bundleOption, const std::vector> &slots) override; - /** - * @brief Allow notifications to be sent based on the deviceId. - * - * @param deviceId Indicates the device Id. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode RequestEnableNotification(const std::string &deviceId) override; - /** * @brief Allow notifications to be sent based on the deviceId. * diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index 0afd8a3b4..59faa1011 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -276,15 +276,6 @@ public: */ ErrCode IsAllowedNotifySelf(bool &allowed); - /** - * @brief Allows the current application to publish notifications on a specified device. - * - * @param deviceId Indicates the ID of the device running the application. At present, this parameter can - * only be null or an empty string, indicating the current device. - * @return Returns set notifications enabled for default bundle result. - */ - ErrCode RequestEnableNotification(std::string &deviceId); - /** * @brief Allows the current application to publish notifications on a specified device. * diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index 466eeb00b..195a3f443 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -1103,12 +1103,6 @@ ErrCode AnsManagerProxy::UpdateSlots( return result; } -ErrCode AnsManagerProxy::RequestEnableNotification(const std::string &deviceId) -{ - ANS_LOGE("[RequestEnableNotification] fail: deprecated."); - return ERR_ANS_NOT_ALLOWED; -} - ErrCode AnsManagerProxy::RequestEnableNotification(const std::string &deviceId, bool &popFlag) { ANS_LOGI("enter"); diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index 64eaa72e9..3b39d6b93 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -1998,12 +1998,6 @@ ErrCode AnsManagerStub::UpdateSlots( return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::RequestEnableNotification(const std::string &deviceId) -{ - ANS_LOGE("AnsManagerStub::RequestEnableNotification called!"); - return ERR_INVALID_OPERATION; -} - ErrCode AnsManagerStub::RequestEnableNotification(const std::string &deviceId, bool &popFlag) { ANS_LOGE("AnsManagerStub::RequestEnableNotification called!"); diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index 2860aa3db..67371739d 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -373,16 +373,6 @@ ErrCode AnsNotification::IsAllowedNotifySelf(bool &allowed) return ansManagerProxy_->IsAllowedNotifySelf(allowed); } -ErrCode AnsNotification::RequestEnableNotification(std::string &deviceId) -{ - ANS_LOGD("enter"); - if (!GetAnsManagerProxy()) { - ANS_LOGE("GetAnsManagerProxy fail."); - return ERR_ANS_SERVICE_NOT_CONNECTED; - } - return ansManagerProxy_->RequestEnableNotification(deviceId); -} - ErrCode AnsNotification::RequestEnableNotification(std::string &deviceId, bool &popFlag) { ANS_LOGD("enter"); diff --git a/frameworks/test/unittest/BUILD.gn b/frameworks/test/unittest/BUILD.gn new file mode 100644 index 000000000..e69de29bb diff --git a/frameworks/test/unittest/ans_callback_stub_test.cpp b/frameworks/test/unittest/ans_callback_stub_test.cpp new file mode 100644 index 000000000..20736a968 --- /dev/null +++ b/frameworks/test/unittest/ans_callback_stub_test.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2022 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 + +#include "ans_callback_stub.h" +#include "ans_inner_errors.h" + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationHelperTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: AnsCallbackStub_00001 + * @tc.desc: Test OBJECT_NULL failed. + * @tc.type: FUNC + * @tc.require: issueI5XO2O + */ +//权限校验分支 +HWTEST_F(AnsCallbackStub, OnRemoteRequest0001, Function | SmallTest | Level1) +{ + //InterfaceCode这是个protect啊 这咋引啊 要不就写死写成0 + // uint32_t code = static_cast(InterfaceCode::ON_ENABLE_NOTIFICATION_CALLBACK); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(u"error.GetDescriptor"); + + ErrCode ret = AnsCallbackStub->OnRemoteRequest(0, data, reply, option); + EXPECT_EQ(ret, (int)OBJECT_NULL); +} + +/** + * @tc.name: AnsCallbackStub_00002 + * @tc.desc: Test ERR_ANS_PERMISSION_DENIED failed. + * @tc.type: FUNC + * @tc.require: issueI5XO2O + */ +//读data值的分支 +HWTEST_F(AnsCallbackStub, OnRemoteRequest0002, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsCallbackStub::GetDescriptor()); + data.WriteBool(false); + + ErrCode ret = AnsCallbackStub->OnRemoteRequest(0, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PERMISSION_DENIED); +} + +/** + * @tc.name: AnsCallbackStub_00003 + * @tc.desc: Test 这个错误码不知道是啥. + * @tc.type: FUNC + * @tc.require: issueI5XO2O + */ +//未知code的分支 +HWTEST_F(AnsCallbackStub, OnRemoteRequest0003, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsCallbackStub::GetDescriptor()); + data.WriteBool(false); + + ErrCode ret = AnsCallbackStub->OnRemoteRequest(1, data, reply, option); + EXPECT_EQ(ret, (int)); +} + +/** + * @tc.name: AnsCallbackStub_00004 + * @tc.desc: Test OnRemoteRequest success. + * @tc.type: FUNC + * @tc.require: issueI5XO2O + */ +//正常返回noerror的分支 +HWTEST_F(AnsCallbackStub, OnRemoteRequest0004, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsCallbackStub::GetDescriptor()); + data.WriteBool(true); + + ErrCode ret = AnsCallbackStub->OnRemoteRequest(0, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} diff --git a/frameworks/test/unittest/ans_manager_stub_test.cpp b/frameworks/test/unittest/ans_manager_stub_test.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index c982bac66..e153cc4e0 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -278,15 +278,6 @@ public: */ static ErrCode IsAllowedNotifySelf(bool &allowed); - /** - * @brief Allow the current application to publish notifications on a specified device. - * - * @param deviceId Indicates the ID of the device running the application. At present, this parameter can - * only be null or an empty string, indicating the current device. - * @return Returns set notifications enabled for default bundle result. - */ - static ErrCode RequestEnableNotification(std::string &deviceId); - /** * @brief Allow the current application to publish notifications on a specified device. * diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 27f7a8663..958a4331a 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -339,14 +339,6 @@ public: ErrCode UpdateSlots( const sptr &bundleOption, const std::vector> &slots) override; - /** - * @brief Allow notifications to be sent based on the deviceId. - * - * @param deviceId Indicates the device Id. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode RequestEnableNotification(const std::string &deviceId) override; - /** * @brief Allow notifications to be sent based on the deviceId. * diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 971858661..05481b8e7 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1434,12 +1434,6 @@ ErrCode AdvancedNotificationService::GetSpecialActiveNotifications( return result; } -ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string &deviceId) -{ - ANS_LOGE("[RequestEnableNotification] fail: deprecated."); - return ERR_ANS_NOT_ALLOWED; -} - ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string &deviceId, bool &popFlag) { ANS_LOGD("%{public}s", __FUNCTION__); diff --git a/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp b/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp index 2ba0e8a3c..abee5f388 100644 --- a/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp +++ b/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp @@ -21,7 +21,8 @@ namespace OHOS { { // test RequestEnableNotification function std::string deviceId(data); - Notification::NotificationHelper::RequestEnableNotification(deviceId); + bool needFlag = true; + Notification::NotificationHelper::RequestEnableNotification(deviceId, needFlag); // test AreNotificationsSuspended function bool suspended = true; Notification::NotificationHelper::AreNotificationsSuspended(suspended); -- Gitee