From a59bfc922810390a75cfc0fa426f03a27c88767c Mon Sep 17 00:00:00 2001 From: chenyuyan Date: Fri, 6 Jan 2023 13:38:37 +0800 Subject: [PATCH] =?UTF-8?q?xts=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenyuyan Change-Id: I830ffefeb7c9d14037eca2feb031d93d25711d40 --- frameworks/ans/src/notification_helper.cpp | 4 +- .../unittest/notification_helper_test.cpp | 5 +- frameworks/core/BUILD.gn | 1 - .../core/include/ans_callback_interface.h | 40 ------ frameworks/core/include/ans_callback_stub.h | 35 ------ .../core/include/ans_manager_interface.h | 3 +- frameworks/core/include/ans_manager_proxy.h | 3 +- frameworks/core/include/ans_manager_stub.h | 3 +- frameworks/core/include/ans_notification.h | 3 +- frameworks/core/src/ans_callback_stub.cpp | 52 -------- frameworks/core/src/ans_manager_proxy.cpp | 7 +- frameworks/core/src/ans_manager_stub.cpp | 9 +- frameworks/core/src/ans_notification.cpp | 4 +- frameworks/core/test/unittest/BUILD.gn | 1 - .../unittest/ans_callback_stub_test/BUILD.gn | 50 -------- .../ans_callback_stub_test.cpp | 116 ------------------ .../ans_manager_proxy_unit_test.cpp | 12 +- .../ans_manager_stub_test.cpp | 7 +- .../ans_notification_unit_test.cpp | 3 +- .../js/napi/include/enable_notification.h | 16 --- .../js/napi/src/enable_notification.cpp | 85 +------------ .../src/manager/napi_enable_notification.cpp | 10 +- interfaces/inner_api/notification_helper.h | 3 +- .../include/advanced_notification_service.h | 4 +- services/ans/include/notification_dialog.h | 2 +- .../ans/src/advanced_notification_service.cpp | 4 +- services/ans/src/notification_dialog.cpp | 4 +- .../advanced_notification_service_test.cpp | 4 +- .../NotificationServiceExtAbility.ts | 1 - .../src/main/ets/pages/notificationDialog.ets | 26 +--- test/fuzztest/BUILD.gn | 1 - test/fuzztest/anscallbackstub_fuzzer/BUILD.gn | 55 --------- .../anscallbackstub_fuzzer.cpp | 59 --------- .../anscallbackstub_fuzzer.h | 23 ---- .../anscallbackstub_fuzzer/corpus/init | 13 -- .../anscallbackstub_fuzzer/project.xml | 25 ---- .../ansmanagerstub_fuzzer.cpp | 3 +- .../setnotificationbadgenum_fuzzer.cpp | 3 +- 38 files changed, 37 insertions(+), 662 deletions(-) delete mode 100644 frameworks/core/include/ans_callback_interface.h delete mode 100644 frameworks/core/include/ans_callback_stub.h delete mode 100644 frameworks/core/src/ans_callback_stub.cpp delete mode 100644 frameworks/core/test/unittest/ans_callback_stub_test/BUILD.gn delete mode 100644 frameworks/core/test/unittest/ans_callback_stub_test/ans_callback_stub_test.cpp delete mode 100644 test/fuzztest/anscallbackstub_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.cpp delete mode 100644 test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.h delete mode 100644 test/fuzztest/anscallbackstub_fuzzer/corpus/init delete mode 100644 test/fuzztest/anscallbackstub_fuzzer/project.xml diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index 15f7f0c44..823d8a89c 100644 --- a/frameworks/ans/src/notification_helper.cpp +++ b/frameworks/ans/src/notification_helper.cpp @@ -154,9 +154,9 @@ ErrCode NotificationHelper::IsAllowedNotifySelf(bool &allowed) return DelayedSingleton::GetInstance()->IsAllowedNotifySelf(allowed); } -ErrCode NotificationHelper::RequestEnableNotification(std::string &deviceId, const sptr &callbackInfo) +ErrCode NotificationHelper::RequestEnableNotification(std::string &deviceId) { - return DelayedSingleton::GetInstance()->RequestEnableNotification(deviceId, callbackInfo); + return DelayedSingleton::GetInstance()->RequestEnableNotification(deviceId); } ErrCode NotificationHelper::AreNotificationsSuspended(bool &suspended) diff --git a/frameworks/ans/test/unittest/notification_helper_test.cpp b/frameworks/ans/test/unittest/notification_helper_test.cpp index 8d1718553..1237f160c 100644 --- a/frameworks/ans/test/unittest/notification_helper_test.cpp +++ b/frameworks/ans/test/unittest/notification_helper_test.cpp @@ -417,9 +417,8 @@ HWTEST_F(NotificationHelperTest, RequestEnableNotification_00001, Function | Sma { std::string deviceId = "DeviceId"; NotificationHelper notificationHelper; - sptr callbackInfo; - ErrCode ret = notificationHelper.RequestEnableNotification(deviceId, callbackInfo); - EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); + ErrCode ret = notificationHelper.RequestEnableNotification(deviceId); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); } /** diff --git a/frameworks/core/BUILD.gn b/frameworks/core/BUILD.gn index 606ba3b08..e40380960 100644 --- a/frameworks/core/BUILD.gn +++ b/frameworks/core/BUILD.gn @@ -32,7 +32,6 @@ ohos_shared_library("ans_core") { sources = [ "${core_path}/common/src/ans_log_wrapper.cpp", "${core_path}/common/src/ans_watchdog.cpp", - "${core_path}/src/ans_callback_stub.cpp", "${core_path}/src/ans_image_util.cpp", "${core_path}/src/ans_manager_death_recipient.cpp", "${core_path}/src/ans_manager_proxy.cpp", diff --git a/frameworks/core/include/ans_callback_interface.h b/frameworks/core/include/ans_callback_interface.h deleted file mode 100644 index 6670acfc8..000000000 --- a/frameworks/core/include/ans_callback_interface.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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. - */ - -#ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_CALLBACK_INTERFACE_H -#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_CALLBACK_INTERFACE_H - -#include "iremote_broker.h" - -namespace OHOS { -namespace Notification { -class AnsCallbackInterface : public IRemoteBroker { -public: - AnsCallbackInterface() = default; - virtual ~AnsCallbackInterface() = default; - DISALLOW_COPY_AND_MOVE(AnsCallbackInterface); - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Notification.AnsCallbackInterface"); - - virtual bool OnEnableNotification(bool isAllow) = 0; - -protected: - enum InterfaceCode : uint32_t { - ON_ENABLE_NOTIFICATION_CALLBACK = 0, - }; -}; -} // namespace Notification -} // namespace OHOS - -#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_CALLBACK_INTERFACE_H diff --git a/frameworks/core/include/ans_callback_stub.h b/frameworks/core/include/ans_callback_stub.h deleted file mode 100644 index c7e3c46cd..000000000 --- a/frameworks/core/include/ans_callback_stub.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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. - */ - -#ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_CALLBACK_STUB_H -#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_CALLBACK_STUB_H - -#include "ans_callback_interface.h" -#include "iremote_stub.h" - -namespace OHOS { -namespace Notification { -class AnsCallbackStub : public IRemoteStub { -public: - AnsCallbackStub() = default; - virtual ~AnsCallbackStub() override = default; - DISALLOW_COPY_AND_MOVE(AnsCallbackStub); - - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; -}; -} // namespace Notification -} // namespace OHOS - -#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_CALLBACK_STUB_H diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index 599042a39..472582a1c 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -343,10 +343,9 @@ public: * @brief Allow notifications to be sent based on the deviceId. * * @param deviceId Indicates the device Id. - * @param callbackInfo Indicates the callbackinfo. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode RequestEnableNotification(const std::string &deviceId, const sptr &callbackInfo) = 0; + virtual ErrCode RequestEnableNotification(const std::string &deviceId) = 0; /** * @brief Set whether to allow the specified deviceId to send notifications for current bundle. diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index a72c96229..0cc02ac0d 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -331,10 +331,9 @@ public: * @brief Allow notifications to be sent based on the deviceId. * * @param deviceId Indicates the device Id. - * @param callbackInfo Indicates the callbackinfo. * @return Returns ERR_OK on success, others on failure. */ - ErrCode RequestEnableNotification(const std::string &deviceId, const sptr &callbackInfo) override; + ErrCode RequestEnableNotification(const std::string &deviceId) override; /** * @brief Set whether to allow the specified deviceId to send notifications for current bundle. diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index 6d28330a4..f7d4370b3 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -347,11 +347,10 @@ public: * @brief Allow notifications to be sent based on the deviceId. * * @param deviceId Indicates the device Id. - * @param callbackInfo Indicates the callbackInfo. * @return Returns ERR_OK on success, others on failure. */ ErrCode RequestEnableNotification( - const std::string &deviceId, const sptr &callbackInfo) override; + const std::string &deviceId) override; /** * @brief Set whether to allow the specified deviceId to send notifications for current bundle. diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index 5dcd6a55f..6c5e718d0 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -281,10 +281,9 @@ public: * * @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. - * @param callbackInfo Indicates the callbackInfo. * @return Returns set notifications enabled for default bundle result. */ - ErrCode RequestEnableNotification(std::string &deviceId, const sptr &callbackInfo); + ErrCode RequestEnableNotification(std::string &deviceId); /** * @brief Checks whether this application is in the suspended state.Applications in this state cannot publish diff --git a/frameworks/core/src/ans_callback_stub.cpp b/frameworks/core/src/ans_callback_stub.cpp deleted file mode 100644 index ecf76a676..000000000 --- a/frameworks/core/src/ans_callback_stub.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2021 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 "ans_callback_stub.h" - -#include "ans_const_define.h" -#include "ans_inner_errors.h" -#include "ans_log_wrapper.h" -#include "message_option.h" -#include "message_parcel.h" -#include "parcel.h" - -namespace OHOS { -namespace Notification { -int32_t AnsCallbackStub::OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &flags) -{ - ANS_LOGI("enter"); - std::u16string descriptor = data.ReadInterfaceToken(); - if (descriptor != AnsCallbackStub::GetDescriptor()) { - ANS_LOGW("[OnRemoteRequest] fail: invalid interface token!"); - return OBJECT_NULL; - } - - if (InterfaceCode::ON_ENABLE_NOTIFICATION_CALLBACK == code) { - bool result = false; - if (!data.ReadBool(result)) { - ANS_LOGE("read notification enabled result failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - ANS_LOGD("result = %{public}d", result); - OnEnableNotification(result); - } else { - ANS_LOGW("[OnRemoteRequest] fail: unknown code! %{public}d", code); - return IRemoteStub::OnRemoteRequest(code, data, reply, flags); - } - return NO_ERROR; -} -} // namespace Notification -} // namespace OHOS diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index 01851d24b..9303fb6c4 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -1103,7 +1103,7 @@ ErrCode AnsManagerProxy::UpdateSlots( return result; } -ErrCode AnsManagerProxy::RequestEnableNotification(const std::string &deviceId, const sptr &callbackInfo) +ErrCode AnsManagerProxy::RequestEnableNotification(const std::string &deviceId) { ANS_LOGI("enter"); MessageParcel data; @@ -1117,11 +1117,6 @@ ErrCode AnsManagerProxy::RequestEnableNotification(const std::string &deviceId, return ERR_ANS_PARCELABLE_FAILED; } - if (!data.WriteRemoteObject(callbackInfo)) { - ANS_LOGE("[RequestEnableNotification] fail: write callbackInfo failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - MessageParcel reply; MessageOption option = {MessageOption::TF_SYNC}; ErrCode result = InnerTransact(REQUEST_ENABLE_NOTIFICATION, option, data, reply); diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index 8ffc32c44..b660dab92 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -942,12 +942,7 @@ ErrCode AnsManagerStub::HandleRequestEnableNotification(MessageParcel &data, Mes ANS_LOGE("[HandleRequestEnableNotification] fail: read deviceId failed."); return ERR_ANS_PARCELABLE_FAILED; } - sptr callbackInfo = data.ReadRemoteObject(); - if (callbackInfo == nullptr) { - ANS_LOGE("[HandleRequestEnableNotification] fail: read callbackInfo failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - ErrCode result = RequestEnableNotification(deviceId, callbackInfo); + ErrCode result = RequestEnableNotification(deviceId); if (!reply.WriteInt32(result)) { ANS_LOGE("[HandleRequestEnableNotification] fail: write result failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; @@ -1997,7 +1992,7 @@ ErrCode AnsManagerStub::UpdateSlots( return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::RequestEnableNotification(const std::string &deviceId, const sptr &callbackInfo) +ErrCode AnsManagerStub::RequestEnableNotification(const std::string &deviceId) { ANS_LOGE("AnsManagerStub::RequestEnableNotification called!"); return ERR_INVALID_OPERATION; diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index b2b064fd6..a78070892 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -373,14 +373,14 @@ ErrCode AnsNotification::IsAllowedNotifySelf(bool &allowed) return ansManagerProxy_->IsAllowedNotifySelf(allowed); } -ErrCode AnsNotification::RequestEnableNotification(std::string &deviceId, const sptr &callbackInfo) +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, callbackInfo); + return ansManagerProxy_->RequestEnableNotification(deviceId); } ErrCode AnsNotification::AreNotificationsSuspended(bool &suspended) diff --git a/frameworks/core/test/unittest/BUILD.gn b/frameworks/core/test/unittest/BUILD.gn index e2f15f875..e02a47dbc 100644 --- a/frameworks/core/test/unittest/BUILD.gn +++ b/frameworks/core/test/unittest/BUILD.gn @@ -16,7 +16,6 @@ group("unittest") { deps = [] deps += [ - "ans_callback_stub_test:unittest", "ans_image_util_test:unittest", "ans_manager_death_recipient_test:unittest", "ans_manager_proxy_test:unittest", diff --git a/frameworks/core/test/unittest/ans_callback_stub_test/BUILD.gn b/frameworks/core/test/unittest/ans_callback_stub_test/BUILD.gn deleted file mode 100644 index 78c8bad85..000000000 --- a/frameworks/core/test/unittest/ans_callback_stub_test/BUILD.gn +++ /dev/null @@ -1,50 +0,0 @@ -# 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. - -import("//base/notification/distributed_notification_service/notification.gni") -import("//build/ohos.gni") -import("//build/test.gni") - -module_output_path = "${component_name}/unittest" - -ohos_unittest("ans_callback_stub_test") { - module_out_path = module_output_path - include_dirs = [ - "${core_path}/include", - "//commonlibrary/c_utils/base/include", - ] - - sources = [ "ans_callback_stub_test.cpp" ] - - deps = [ "${core_path}:ans_core" ] - - external_deps = [ - "ability_base:want", - "ability_base:zuri", - "ability_runtime:wantagent_innerkits", - "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", - "multimedia_image_framework:image_native", - "relational_store:native_rdb", - ] - - subsystem_name = "${subsystem_name}" - part_name = "${component_name}" -} - -group("unittest") { - testonly = true - deps = [] - - deps += [ ":ans_callback_stub_test" ] -} diff --git a/frameworks/core/test/unittest/ans_callback_stub_test/ans_callback_stub_test.cpp b/frameworks/core/test/unittest/ans_callback_stub_test/ans_callback_stub_test.cpp deleted file mode 100644 index 4e507a144..000000000 --- a/frameworks/core/test/unittest/ans_callback_stub_test/ans_callback_stub_test.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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; -using namespace OHOS; -using namespace OHOS::Notification; - -class AnsCallbackStubImpl : public AnsCallbackStub { - bool OnEnableNotification(bool isAllow) override - { - return false; - } -}; - -class AnsCallbackStubTest : public testing::Test { -public: - static void SetUpTestCase() {} - static void TearDownTestCase() {} - - void SetUp() - { - ansCallbackStub_ = new AnsCallbackStubImpl(); - } - void TearDown() {} - sptr ansCallbackStub_; -}; - -/** - * @tc.name: OnRemoteRequest01 - * @tc.desc: Test if the descriptor is wrong. - * @tc.type: FUNC - * @tc.require: issueI5XO2O - */ -HWTEST_F(AnsCallbackStubTest, OnRemoteRequest01, Function | SmallTest | Level1) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - - data.WriteInterfaceToken(u"error.GetDescriptor"); - - int32_t ret = ansCallbackStub_->OnRemoteRequest(0, data, reply, option); - EXPECT_EQ(ret, (int)OBJECT_NULL); -} - -/** - * @tc.name: OnRemoteRequest02 - * @tc.desc: Test if can not read a bool from data failed. - * @tc.type: FUNC - * @tc.require: issueI5XO2O - */ -HWTEST_F(AnsCallbackStubTest, OnRemoteRequest02, Function | SmallTest | Level1) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - - data.WriteInterfaceToken(AnsCallbackStub::GetDescriptor()); - - int32_t ret = ansCallbackStub_->OnRemoteRequest(0, data, reply, option); - EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); -} - -/** - * @tc.name: OnRemoteRequest03 - * @tc.desc: Test unknow code failed. - * @tc.type: FUNC - * @tc.require: issueI5XO2O - */ -HWTEST_F(AnsCallbackStubTest, OnRemoteRequest03, Function | SmallTest | Level1) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - - data.WriteInterfaceToken(AnsCallbackStub::GetDescriptor()); - - int32_t ret = ansCallbackStub_->OnRemoteRequest(1, data, reply, option); - EXPECT_EQ(ret, (int)IPC_STUB_UNKNOW_TRANS_ERR); -} - -/** - * @tc.name: OnRemoteRequest04 - * @tc.desc: Test OnRemoteRequest success. - * @tc.type: FUNC - * @tc.require: issueI5XO2O - */ -HWTEST_F(AnsCallbackStubTest, OnRemoteRequest04, Function | SmallTest | Level1) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - - data.WriteInterfaceToken(AnsCallbackStub::GetDescriptor()); - data.WriteBool(true); - - int32_t ret = ansCallbackStub_->OnRemoteRequest(0, data, reply, option); - EXPECT_EQ(ret, (int)NO_ERROR); -} diff --git a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp index 98b95bffd..60675f79e 100644 --- a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp @@ -1035,8 +1035,7 @@ HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0100, Function | std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); std::string deviceId = "Device"; - sptr callbackInfo; - int32_t result = proxy->RequestEnableNotification(deviceId, callbackInfo); + int32_t result = proxy->RequestEnableNotification(deviceId); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } @@ -1056,8 +1055,7 @@ HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0200, Function | std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); std::string deviceId = ""; - sptr callbackInfo; - int32_t result = proxy->RequestEnableNotification(deviceId, callbackInfo); + int32_t result = proxy->RequestEnableNotification(deviceId); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } @@ -1079,8 +1077,7 @@ HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0300, Function | std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); std::string deviceId = "Device"; - sptr callbackInfo; - int32_t result = proxy->RequestEnableNotification(deviceId, callbackInfo); + int32_t result = proxy->RequestEnableNotification(deviceId); EXPECT_EQ(ERR_OK, result); } @@ -1101,8 +1098,7 @@ HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0400, Function | std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); std::string deviceId = "Device"; - sptr callbackInfo; - int32_t result = proxy->RequestEnableNotification(deviceId, callbackInfo); + int32_t result = proxy->RequestEnableNotification(deviceId); EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); } diff --git a/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp b/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp index 73cd26065..197fca0c2 100644 --- a/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp +++ b/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp @@ -1468,14 +1468,12 @@ HWTEST_F(AnsManagerStubTest, HandleRequestEnableNotification01, Function | Small MessageOption option = {MessageOption::TF_SYNC}; std::string deviceId = "this is a deviceId"; - sptr callbackInfo; data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); data.WriteString(deviceId); - data.WriteRemoteObject(callbackInfo); ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); + EXPECT_EQ(ret, (int)ERR_OK); } /** @@ -3788,8 +3786,7 @@ HWTEST_F(AnsManagerStubTest, UpdateSlots01, Function | SmallTest | Level1) HWTEST_F(AnsManagerStubTest, RequestEnableNotification01, Function | SmallTest | Level1) { std::string deviceId = "this is deviceId"; - sptr callbackInfo; - ErrCode result = ansManagerStub_->RequestEnableNotification(deviceId, callbackInfo); + ErrCode result = ansManagerStub_->RequestEnableNotification(deviceId); EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); } diff --git a/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp b/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp index f8d2dee9f..fdfa5dcca 100644 --- a/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp @@ -363,8 +363,7 @@ HWTEST_F(AnsNotificationUnitTest, RequestEnableNotification_0100, Function | Med ASSERT_NE(nullptr, proxy); ans_->GetAnsManagerProxy(); std::string deviceId = "this is deviceId"; - sptr callbackInfo; - ErrCode ret1 = ans_->RequestEnableNotification(deviceId, callbackInfo); + ErrCode ret1 = ans_->RequestEnableNotification(deviceId); EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); bool suspended = true; ErrCode ret2 = ans_->AreNotificationsSuspended(suspended); diff --git a/frameworks/js/napi/include/enable_notification.h b/frameworks/js/napi/include/enable_notification.h index 6a8a65d35..9c76362c5 100644 --- a/frameworks/js/napi/include/enable_notification.h +++ b/frameworks/js/napi/include/enable_notification.h @@ -17,7 +17,6 @@ #include -#include "ans_callback_stub.h" #include "common.h" namespace OHOS { @@ -43,19 +42,6 @@ struct AsyncCallbackInfoIsEnable { bool allowed = false; }; -class CallbackStubImpl : public AnsCallbackStub { -public: - explicit CallbackStubImpl(AsyncCallbackInfoIsEnable *task) : task_(task) {}; - ~CallbackStubImpl() override = default; - bool OnEnableNotification(bool isAllow) override; - -private: - AsyncCallbackInfoIsEnable *task_; -}; - -static std::mutex callbackMutex_; -static sptr callbackStubImpl_; - struct EnableParams { NotificationBundleOption option; bool enable = false; @@ -76,8 +62,6 @@ napi_value RequestEnableNotification(napi_env env, napi_callback_info info); napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, EnableParams ¶ms); napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, IsEnableParams ¶ms); -bool CreateCallbackStubImpl(AsyncCallbackInfoIsEnable *callbackInfo); -void ResetCallbackStubImpl(); } // namespace NotificationNapi } // namespace OHOS #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_INCLUDE_ENABLE_NOTIFICATION_H \ No newline at end of file diff --git a/frameworks/js/napi/src/enable_notification.cpp b/frameworks/js/napi/src/enable_notification.cpp index 9c144dc03..262437707 100644 --- a/frameworks/js/napi/src/enable_notification.cpp +++ b/frameworks/js/napi/src/enable_notification.cpp @@ -342,20 +342,14 @@ napi_value RequestEnableNotification(napi_env env, napi_callback_info info) AsyncCallbackInfoIsEnable *asynccallbackinfo = static_cast(data); if (asynccallbackinfo) { std::string deviceId {""}; - auto *callbackInfo = static_cast(data); - if (CreateCallbackStubImpl(callbackInfo)) { - asynccallbackinfo->info.errorCode = - NotificationHelper::RequestEnableNotification(deviceId, callbackStubImpl_); - } + asynccallbackinfo->info.errorCode = + NotificationHelper::RequestEnableNotification(deviceId); } }, [](napi_env env, napi_status status, void *data) { AsyncCallbackInfoIsEnable *asynccallbackinfo = static_cast(data); if (asynccallbackinfo) { - if (asynccallbackinfo->info.errorCode != ERR_OK) { - AsyncCompleteCallbackIsNotificationEnabled(env, status, data); - ResetCallbackStubImpl(); - } + AsyncCompleteCallbackIsNotificationEnabled(env, status, data); } }, (void *)asynccallbackinfo, @@ -370,78 +364,5 @@ napi_value RequestEnableNotification(napi_env env, napi_callback_info info) } } -bool CreateCallbackStubImpl(AsyncCallbackInfoIsEnable *callbackInfo) -{ - std::lock_guard lock(callbackMutex_); - if (callbackStubImpl_ != nullptr) { - return false; - } - callbackStubImpl_ = new (std::nothrow) CallbackStubImpl(callbackInfo); - return true; -} - -void ResetCallbackStubImpl() -{ - std::lock_guard lock(callbackMutex_); - callbackStubImpl_ = nullptr; -} - -bool CallbackStubImpl::OnEnableNotification(bool isAllow) -{ - ANS_LOGI("isAllow: %{public}d", isAllow); - if (!task_ || !task_->env) { - ANS_LOGW("invalid task."); - return false; - } - - uv_loop_s *loop = nullptr; - napi_get_uv_event_loop(task_->env, &loop); - if (!loop) { - ANS_LOGW("failed to get loop from env."); - delete task_; - task_ = nullptr; - return false; - } - - uv_work_t *work = new (std::nothrow) uv_work_t; - if (work == nullptr) { - ANS_LOGW("uv_work_t instance is nullptr"); - delete task_; - task_ = nullptr; - return false; - } - - task_->allowed = isAllow; - work->data = reinterpret_cast(task_); - int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, - [](uv_work_t *work, int status) { - auto task_ = static_cast(work->data); - napi_value result = nullptr; - napi_get_boolean(task_->env, task_->allowed, &result); - if (task_->newInterface) { - Common::CreateReturnValue(task_->env, task_->info, result); - } else { - Common::ReturnCallbackPromise(task_->env, task_->info, result); - } - if (task_->info.callback != nullptr) { - napi_delete_reference(task_->env, task_->info.callback); - } - napi_delete_async_work(task_->env, task_->asyncWork); - delete task_; - task_ = nullptr; - delete work; - work = nullptr; - }); - if (ret != 0) { - ANS_LOGW("failed to insert work into queue"); - delete task_; - task_ = nullptr; - delete work; - work = nullptr; - return false; - } - return true; -} - } // namespace NotificationNapi } // namespace OHOS diff --git a/frameworks/js/napi/src/manager/napi_enable_notification.cpp b/frameworks/js/napi/src/manager/napi_enable_notification.cpp index 9046be8bd..5ada940fc 100644 --- a/frameworks/js/napi/src/manager/napi_enable_notification.cpp +++ b/frameworks/js/napi/src/manager/napi_enable_notification.cpp @@ -235,17 +235,13 @@ napi_value NapiRequestEnableNotification(napi_env env, napi_callback_info info) AsyncCallbackInfoIsEnable *asynccallbackinfo = static_cast(data); if (asynccallbackinfo) { std::string deviceId {""}; - auto *callbackInfo = static_cast(data); - if (CreateCallbackStubImpl(callbackInfo)) { - asynccallbackinfo->info.errorCode = - NotificationHelper::RequestEnableNotification(deviceId, callbackStubImpl_); - } + asynccallbackinfo->info.errorCode = + NotificationHelper::RequestEnableNotification(deviceId); } }, [](napi_env env, napi_status status, void *data) { AsyncCallbackInfoIsEnable *asynccallbackinfo = static_cast(data); - if (asynccallbackinfo != nullptr && !(asynccallbackinfo->info.errorCode == ERR_OK && - asynccallbackinfo->params.allowToPop)) { + if (asynccallbackinfo) { AsyncCompleteCallbackNapiIsNotificationEnabled(env, status, data); } }, diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index 7c15d7c7c..2c7855390 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -283,10 +283,9 @@ public: * * @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. - * @param callbackInfo Indicates the callbackInfo. * @return Returns set notifications enabled for default bundle result. */ - static ErrCode RequestEnableNotification(std::string &deviceId, const sptr &callbackInfo); + static ErrCode RequestEnableNotification(std::string &deviceId); /** * @brief Checks whether this application is in the suspended state.Applications in this state cannot publish diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index d1526a75f..0b82dffee 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -343,11 +343,9 @@ public: * @brief Allow notifications to be sent based on the deviceId. * * @param deviceId Indicates the device Id. - * @param callbackInfo Indicates the callbackInfo. * @return Returns ERR_OK on success, others on failure. */ - ErrCode RequestEnableNotification(const std::string &deviceId, const sptr &callbackInfo -) override; + ErrCode RequestEnableNotification(const std::string &deviceId) override; /** * @brief Set whether to allow the specified deviceId to send notifications for current bundle. diff --git a/services/ans/include/notification_dialog.h b/services/ans/include/notification_dialog.h index 0e924ec5b..dfff565a6 100644 --- a/services/ans/include/notification_dialog.h +++ b/services/ans/include/notification_dialog.h @@ -37,7 +37,7 @@ public: * @param callbackInfo The callbackInfo. * @return ERR_OK if success, else not. */ - ErrCode StartEnableNotificationDialogAbility(const sptr &callbackInfo); + ErrCode StartEnableNotificationDialogAbility(); }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index a2e51342f..d7907e69a 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1440,7 +1440,7 @@ ErrCode AdvancedNotificationService::GetSpecialActiveNotifications( } ErrCode AdvancedNotificationService::RequestEnableNotification( - const std::string &deviceId, const sptr &callbackInfo) + const std::string &deviceId) { ANS_LOGD("%{public}s", __FUNCTION__); @@ -1471,7 +1471,7 @@ ErrCode AdvancedNotificationService::RequestEnableNotification( ANS_LOGI("hasPopped = %{public}d, allowedNotify = %{public}d", hasPopped, allowedNotify); if (!hasPopped && !allowedNotify) { auto notificationDialog = std::make_shared(); - result = notificationDialog->StartEnableNotificationDialogAbility(callbackInfo); + result = notificationDialog->StartEnableNotificationDialogAbility(); if (result != ERR_OK) { ANS_LOGD("StartEnableNotificationDialogAbility failed, result = %{public}d", result); return result; diff --git a/services/ans/src/notification_dialog.cpp b/services/ans/src/notification_dialog.cpp index df25bf47d..a26053896 100644 --- a/services/ans/src/notification_dialog.cpp +++ b/services/ans/src/notification_dialog.cpp @@ -17,7 +17,6 @@ #include "ability_manager_client.h" #include "advanced_notification_service.h" -#include "ans_callback_stub.h" #include "in_process_call_wrapper.h" #include "ipc_skeleton.h" @@ -34,7 +33,7 @@ bool NotificationDialog::JudgeSelfCalled(const std::shared_ptr &callbackInfo) +ErrCode NotificationDialog::StartEnableNotificationDialogAbility() { ANS_LOGD("%{public}s, Enter.", __func__); sptr token; @@ -51,7 +50,6 @@ ErrCode NotificationDialog::StartEnableNotificationDialogAbility(const sptrGetTopAbility().GetBundleName()); want.SetElementName("com.ohos.notificationdialog", "EnableNotificationDialog"); - want.SetParam("callbackStubImpl", callbackInfo); want.SetParam("tokenId", token); want.SetParam("from", bundleName); result = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, token, -1); diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index bb72d85c2..a00b51060 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -1763,7 +1763,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13100, sptr req = new NotificationRequest(); EXPECT_NE(req, nullptr); std::string deviceId = "DeviceId"; - EXPECT_EQ(advancedNotificationService_->RequestEnableNotification(deviceId, nullptr), (int)ERR_ANS_INVALID_PARAM); + EXPECT_EQ(advancedNotificationService_->RequestEnableNotification(deviceId), (int)ERR_ANS_INVALID_PARAM); } /** @@ -2343,7 +2343,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16900, std::string deviceId = "DeviceId"; bool needPop = false; - EXPECT_EQ(advancedNotificationService_->RequestEnableNotification(deviceId, nullptr), ERR_ANS_INVALID_BUNDLE); + EXPECT_EQ(advancedNotificationService_->RequestEnableNotification(deviceId), ERR_ANS_INVALID_BUNDLE); EXPECT_EQ(advancedNotificationService_->IsAllowedNotifySelf(needPop), ERR_ANS_INVALID_BUNDLE); sptr bundleOption; EXPECT_EQ(advancedNotificationService_->IsAllowedNotifySelf(bundleOption, needPop), ERR_ANS_INVALID_BUNDLE); diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/ServiceExtAbility/NotificationServiceExtAbility.ts b/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/ServiceExtAbility/NotificationServiceExtAbility.ts index d15fa92d5..ee4a619ec 100644 --- a/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/ServiceExtAbility/NotificationServiceExtAbility.ts +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/ServiceExtAbility/NotificationServiceExtAbility.ts @@ -22,7 +22,6 @@ export default class NotificationDialogServiceExtensionAbility extends extension onCreate(want) { console.debug(TAG, "onCreate, want: " + JSON.stringify(want)); globalThis.notificationExtensionContext = this.context; - globalThis.callbackImp = want.parameters.callbackStubImpl; globalThis.closeDialog = () => { console.info(TAG, 'click waiting for a response'); globalThis.notificationExtensionContext.terminateSelf(); diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/pages/notificationDialog.ets b/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/pages/notificationDialog.ets index 6d116e96a..58cdfa42f 100644 --- a/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/pages/notificationDialog.ets +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/pages/notificationDialog.ets @@ -25,7 +25,6 @@ struct NotificationDialog { @State private want: any = undefined @State private uid: any = undefined @State private style: any = {} - @State callBackImp_: any = {} @State token_: any = undefined @State popWidth: any = undefined @State popHeight: any = undefined @@ -114,37 +113,14 @@ struct NotificationDialog { console.error('Start enableNotification failed. ErrCode: ' + JSON.stringify(err.code)); return } - let option = new rpc.MessageOption() - let data = rpc.MessageParcel.create() - let reply = rpc.MessageParcel.create() - data.writeInterfaceToken("OHOS.Notification.AnsCallbackInterface") - data.writeBoolean(flag) - console.info("before send request") - this.callBackImp_.sendRequest(0, data, reply, option) - .then(function (result) { - console.info("start to send request") - if (result.errCode != 0) { - console.error("send request failed, errCode: " + result.errCode) - return - } - }) - .catch(function (err) { - console.error(this.TAG + "send request got exception: " + err) - }) - .finally(() => { - data.reclaim() - reply.reclaim() - globalThis.closeDialog() - }) }) - console.info("after send request") + globalThis.closeDialog() } aboutToAppear() { console.log(this.TAG, "dialog page appears") this.want = globalThis.abilityWant this.style = globalThis.style - this.callBackImp_ = globalThis.abilityWant.parameters['callbackStubImpl'].value this.token_ = globalThis.abilityWant.parameters['tokenId'].value globalThis.bundleName = globalThis.abilityWant.parameters['from'] } diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 2871d134d..4f5b2f36c 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -18,7 +18,6 @@ group("fuzztest") { "addnotificationslot_fuzzer:AddNotificationSlotFuzzTest", "addnotificationslots_fuzzer:AddNotificationSlotsFuzzTest", "addslotbytype_fuzzer:AddSlotByTypeFuzzTest", - "anscallbackstub_fuzzer:AnsCallbackStubFuzzTest", "ansmanagerstub_fuzzer:AnsManagerStubFuzzTest", "ansmanagerstubannex_fuzzer:AnsManagerStubAnnexFuzzTest", "ansmanagerstubannexthree_fuzzer:AnsManagerStubAnnexThreeFuzzTest", diff --git a/test/fuzztest/anscallbackstub_fuzzer/BUILD.gn b/test/fuzztest/anscallbackstub_fuzzer/BUILD.gn deleted file mode 100644 index f83638039..000000000 --- a/test/fuzztest/anscallbackstub_fuzzer/BUILD.gn +++ /dev/null @@ -1,55 +0,0 @@ -# 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. - -#####################hydra-fuzz################### -import("//base/notification/distributed_notification_service/notification.gni") -import("//build/config/features.gni") -import("//build/test.gni") -module_output_path = "${component_name}/fuzztest" - -##############################fuzztest########################################## -ohos_fuzztest("AnsCallbackStubFuzzTest") { - module_out_path = module_output_path - fuzz_config_file = "${component_path}/test/fuzztest/anscallbackstub_fuzzer" - - include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "anscallbackstub_fuzzer.cpp" ] - - deps = [ - "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", - "${frameworks_module_ans_path}:ans_innerkits", - "//base\notification\distributed_notification_service\frameworks\core:ans_core", - ] - - external_deps = [ - "ability_base:want", - "ability_base:zuri", - "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", - "multimedia_image_framework:image_native", - "relational_store:native_rdb", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":AnsCallbackStubFuzzTest" ] -} -############################################################################### diff --git a/test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.cpp b/test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.cpp deleted file mode 100644 index cbbaac756..000000000 --- a/test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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. - */ - -#define private public -#define protected public -#include "ans_callback_stub.h" -#undef private -#undef protected -#include "anscallbackstub_fuzzer.h" -#include "notification_request.h" - -using namespace OHOS::Notification; - -namespace OHOS { -class AnsCallbackStubImpl : public AnsCallbackStub { - bool OnEnableNotification(bool isAllow) override - { - return false; - } -}; - -bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) -{ - std::shared_ptr ansCallbackStub = - std::make_shared(); - uint32_t code = GetU32Data(data); - MessageParcel datas; - MessageParcel reply; - MessageOption flags; - // test OnRemoteRequest function - ansCallbackStub->OnRemoteRequest(code, datas, reply, flags); - return true; -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - char *ch = ParseData(data, size); - if (ch != nullptr && size >= GetU32Size()) { - OHOS::DoSomethingInterestingWithMyAPI(ch, size); - free(ch); - ch = nullptr; - } - return 0; -} diff --git a/test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.h b/test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.h deleted file mode 100644 index 1acf06ab4..000000000 --- a/test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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. - */ - -#ifndef TEST_FUZZTEST_ANSCALLBACKSTUB_FUZZER_ANSCALLBACKSTUB_FUZZER_H -#define TEST_FUZZTEST_ANSCALLBACKSTUB_FUZZER_ANSCALLBACKSTUB_FUZZER_H - -#include "fuzz_common_base.h" - -#define FUZZ_PROJECT_NAME "anscallbackstub_fuzzer" - -#endif // TEST_FUZZTEST_ANSCALLBACKSTUB_FUZZER_ANSCALLBACKSTUB_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/anscallbackstub_fuzzer/corpus/init b/test/fuzztest/anscallbackstub_fuzzer/corpus/init deleted file mode 100644 index 1b910144f..000000000 --- a/test/fuzztest/anscallbackstub_fuzzer/corpus/init +++ /dev/null @@ -1,13 +0,0 @@ -# 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. -FUZZ \ No newline at end of file diff --git a/test/fuzztest/anscallbackstub_fuzzer/project.xml b/test/fuzztest/anscallbackstub_fuzzer/project.xml deleted file mode 100644 index 6e8ad2cfd..000000000 --- a/test/fuzztest/anscallbackstub_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp index 8ead6cb8f..2c57ed626 100644 --- a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp @@ -160,8 +160,7 @@ namespace OHOS { ansManagerStub.DeleteAll(); ansManagerStub.GetSlotsByBundle(bundleOption, slots); ansManagerStub.UpdateSlots(bundleOption, slots); - sptr callbackInfo; - ansManagerStub.RequestEnableNotification(deviceId, callbackInfo); + ansManagerStub.RequestEnableNotification(deviceId); const std::string bundle = "this is a notification bundle"; bool enabled = true; ansManagerStub.SetNotificationsEnabledForBundle(bundle, enabled); diff --git a/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp b/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp index 25769a27c..2ba0e8a3c 100644 --- a/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp +++ b/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp @@ -21,8 +21,7 @@ namespace OHOS { { // test RequestEnableNotification function std::string deviceId(data); - sptr callbackInfo; - Notification::NotificationHelper::RequestEnableNotification(deviceId, callbackInfo); + Notification::NotificationHelper::RequestEnableNotification(deviceId); // test AreNotificationsSuspended function bool suspended = true; Notification::NotificationHelper::AreNotificationsSuspended(suspended); -- Gitee