diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index ec6963f02244d732372d493faed76b07d923160a..1f8fb171066cc695f99f9068cf7e750a817030b2 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 ff5eedb5ef0a72ff303ebd0f8580b7dfef2bba11..a4086147b9bd4174924eda5dba4bfcc1b1d1a8a5 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 3b40c55fe1b4a7373aadafe99a0dfa4ec086736f..a2a91826869321f8f5329ce35dd80659dbda8774 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 89c5129ff4af667afd1618b426bab049f4321a18..4d736b1a23cfb13c2937ba8c6367df6beb024e4f 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 55207f7d31e70c8392daa630fbe8d8bd4f974d7b..a770d555391faa3ef72ac1641030f45354169bdc 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 0afd8a3b4876bd7482ac5f41a3fa5c9e83bc9680..59faa10115491f1a5f047e3e1be55e30a359eb0d 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 466eeb00ba6ba8fa51690300f97c5f74bfe5631a..195a3f443b7360bc8dcff1b7e278d5ee25750105 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 64eaa72e99a316774e4e9d30838386093f61de0d..3b39d6b93e793bf0e7cd5d5eb46ea57d65d46d30 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 2860aa3dbd6fa45eecf5291d4a0aeb1a555c2096..67371739decf88f299ace83565aefb7c94df601f 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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 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 0000000000000000000000000000000000000000..20736a968e86c641eb00bf2267988f8884ca091c --- /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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index c982bac66f53f61528f7da49a7af7b8cc98887cc..e153cc4e02f4aa3117ee32a55c6ca91c67fc236f 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 27f7a86632a48ac7252a73509e26ab76d36f0e9f..958a4331aace703deefab906745494f334a0f760 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 971858661da736fa8bde337374847055f6a451f8..05481b8e720fd04bb2aec3fa680071243ec01504 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 2ba0e8a3cc28649a675dd68ca6c72ed5fdbf0785..abee5f38813e60eee7b51a981d478b7e46abf94f 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);