diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index 15f7f0c44c6924b681a1b692e8253f36c226017a..823d8a89c3f34e426611fd3d2bd37a38b7832f38 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 8d1718553d79481cd318bc5ccfa21c34d7386fbe..1237f160cdd8e7120b3ffbccd4dd3dbcc3048ae3 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 606ba3b08cdd1cd144174bd9747209a0a3814d75..e40380960c09649ea9c382a37e24e44420344236 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 6670acfc8375f870aec68dc73bd5c34dc9c92f61..0000000000000000000000000000000000000000 --- 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 c7e3c46cdf483d93d3278197f41e4c980a128e5b..0000000000000000000000000000000000000000 --- 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 599042a3908dabbfc673cf4e7314249909431eaf..472582a1ca13116902cfda59d3b28ec17475ee48 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 a72c962297b4c266d33d61a09df5fa86286893bc..0cc02ac0d640eae3b6cda986ae83474dc819cfe9 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 6d28330a43bc2e2fab3dd3294c8e011c535e1dcf..f7d4370b3cf1d0dd031057922b8580b0f1af615c 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 5dcd6a55fe6fd36fa6cec5c1391b2eddedd670f3..6c5e718d01d886b90fc706b5bab32ba84077f647 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 ecf76a676387dffa10374969e913fb2ba91858fc..0000000000000000000000000000000000000000 --- 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 01851d24bef6fae147f024b7cb47a83693000bc1..9303fb6c45f05e682f6d4c6f473a38da48232766 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 8ffc32c44d7fc47db6ecf890cc04d5eeaa8b1f62..b660dab928de4dce96f68e9ea767fb4bc8ce4031 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 b2b064fd667a60c499f34ca84158da0ac4b74c75..a78070892b79deefc123ca876a19f7923a2d283d 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 e2f15f87538221e7251fa1b31ba989936945d951..e02a47dbc5714755fe0317ff36f1af3f2799d84d 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 78c8bad857396478e2b9d1f96b95e28a03bd2148..0000000000000000000000000000000000000000 --- 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 4e507a144a3f1131045339f92def385f2133d8b2..0000000000000000000000000000000000000000 --- 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 98b95bffd64adbe71663959c966f46df7684a980..60675f79ef866d2ae8dbef12e20a1352dc9828d1 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 73cd2606585c8c9fe5276a6ffa64ae94b16f3bb6..197fca0c29cdcd90544489721d44d1560f363985 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 f8d2dee9fa72adf91f057b163b85f2d70394796a..fdfa5dcca64467e183358dd75f98470240e51215 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 6a8a65d353dc410c04ff76155a0d6bedad9640fd..9c76362c55414a2406758b5718bacdfd6a5b9016 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 9c144dc030c0c5a02dc6b266d624832ff03a317c..2624377078e4560bbe29dd5c9e1b2aa4edee41af 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 9046be8bd0a75238347bf95b02130e7d7c3bc46a..5ada940fc4186f038f261d6eb63491c85cce1e16 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 7c15d7c7ce99b69c2252d24fc5255cf4932ebdb1..2c78553908df5440a8b7392946c5dc2f60eafe96 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 d1526a75fa1184e91fffaf9c8e9dff392324703c..0b82dffee2cc69a40987da8c5d8b38f3505245b7 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 0e924ec5b2c21c1b3fa2143bbb166ef3a1267709..dfff565a6d5b7e15c7886c0a297212a46c8f785d 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 a2e51342fbac301aed91ac9649636f5e6b7cc94d..d7907e69ad8edff975e169cbcddbb7a37fd17496 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 df25bf47d1ae1ccc1098071d19082a4f5a16b79f..a2605389677f4010ce4fd05469d2bfa3d401d0e3 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 bb72d85c2aea8c8869d5b6ea51b584b42248c9fe..a00b5106003ebb9107e493b21ccc6a180235965e 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 d15fa92d58a0edce49f704729268f8ff4e25da7c..ee4a619ece59de0fb0558853db51c38eeb3f63a8 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 6d116e96ace80d6414a75cf8e1a6a120f53e0ba1..58cdfa42fb9a1638479ab960624b561777368aef 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 2871d134dc9f04596590ee32247be655e09451db..4f5b2f36cff5893e5a4d87aa2175f27b68ff6b60 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 f83638039abd45dc17c81d3e5a9e910fedf405ed..0000000000000000000000000000000000000000 --- 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 cbbaac7561ad1fed1cc3759d69c060b007e90305..0000000000000000000000000000000000000000 --- 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 1acf06ab4814bc17581da53b813716d0d778fa5c..0000000000000000000000000000000000000000 --- 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 1b910144fb1ff33a40a44b1d2a491b1ab05b598b..0000000000000000000000000000000000000000 --- 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 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..0000000000000000000000000000000000000000 --- 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 8ead6cb8f6b471f6c27932b959743e190b118217..2c57ed626087e742e660fd5f1cc3f4981fa40af4 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 25769a27c87fa70e4f8331cad887eed0d2f1f701..2ba0e8a3cc28649a675dd68ca6c72ed5fdbf0785 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);