From 733a326e4b5e430890d79671c1a5ecd0979baf35 Mon Sep 17 00:00:00 2001 From: chenyuyan Date: Sat, 7 Jan 2023 23:26:49 +0800 Subject: [PATCH] =?UTF-8?q?monthly=E5=BC=B9=E7=AA=97=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E9=80=82=E9=85=8Dgettopability=E6=9D=83=E9=99=90=E7=AE=A1?= =?UTF-8?q?=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenyuyan Change-Id: I9d59f425df002b7d83e478b2d20164443b265ca0 --- frameworks/ans/src/notification_helper.cpp | 4 +- .../unittest/notification_helper_test.cpp | 3 +- frameworks/core/BUILD.gn | 1 - .../core/include/ans_callback_interface.h | 40 ------ .../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 | 10 +- 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 | 59 +-------- .../ans_manager_stub_test.cpp | 4 +- .../ans_notification_unit_test.cpp | 3 +- .../js/napi/include/enable_notification.h | 17 --- .../js/napi/src/enable_notification.cpp | 109 +--------------- .../src/manager/napi_enable_notification.cpp | 15 +-- interfaces/inner_api/notification_helper.h | 3 +- services/ans/BUILD.gn | 3 + .../include/advanced_notification_service.h | 3 +- .../ans/include/notification_dialog.h | 32 +++-- .../ans/src/advanced_notification_service.cpp | 16 ++- services/ans/src/notification_dialog.cpp | 60 +++++++++ services/ans/test/unittest/BUILD.gn | 2 + .../advanced_notification_service_test.cpp | 5 +- .../NotificationServiceExtAbility.ts | 1 - .../src/main/ets/pages/notificationDialog.ets | 26 +--- services/test/moduletest/BUILD.gn | 1 + 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 +- 40 files changed, 129 insertions(+), 712 deletions(-) delete mode 100644 frameworks/core/include/ans_callback_interface.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 rename frameworks/core/include/ans_callback_stub.h => services/ans/include/notification_dialog.h (51%) create mode 100644 services/ans/src/notification_dialog.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 1f8fb1710..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, bool &popFlag) +ErrCode NotificationHelper::RequestEnableNotification(std::string &deviceId) { - return DelayedSingleton::GetInstance()->RequestEnableNotification(deviceId, popFlag); + 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 800e197e0..a3a18929b 100644 --- a/frameworks/ans/test/unittest/notification_helper_test.cpp +++ b/frameworks/ans/test/unittest/notification_helper_test.cpp @@ -417,8 +417,7 @@ HWTEST_F(NotificationHelperTest, RequestEnableNotification_00001, Function | Sma { std::string deviceId = "DeviceId"; NotificationHelper notificationHelper; - bool needPop = true; - ErrCode ret = notificationHelper.RequestEnableNotification(deviceId, needPop); + 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 35b830b1b..4f9ef97a8 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_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index a2a918268..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 popFlag Indicates the flag that allows dialog to be popped. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode RequestEnableNotification(const std::string &deviceId, bool &popFlag) = 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 4d736b1a2..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 popFlag Indicates the flag that allows dialog to be popped. * @return Returns ERR_OK on success, others on failure. */ - ErrCode RequestEnableNotification(const std::string &deviceId, bool &popFlag) 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 a770d5553..57a16e8ba 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -347,10 +347,9 @@ public: * @brief Allow notifications to be sent based on the deviceId. * * @param deviceId Indicates the device Id. - * @param popFlag Indicates the flag that allows dialog to be popped. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode RequestEnableNotification(const std::string &deviceId, bool &popFlag) 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_notification.h b/frameworks/core/include/ans_notification.h index 59faa1011..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 popFlag Indicates the flag that allows dialog to be popped. * @return Returns set notifications enabled for default bundle result. */ - ErrCode RequestEnableNotification(std::string &deviceId, bool &popFlag); + 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 195a3f443..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, bool &popFlag) +ErrCode AnsManagerProxy::RequestEnableNotification(const std::string &deviceId) { ANS_LOGI("enter"); MessageParcel data; @@ -1129,11 +1129,6 @@ ErrCode AnsManagerProxy::RequestEnableNotification(const std::string &deviceId, ANS_LOGE("[RequestEnableNotification] fail: read result failed."); return ERR_ANS_PARCELABLE_FAILED; } - - if (!reply.ReadBool(popFlag)) { - ANS_LOGE("[RequestEnableNotification] fail: read popFlag failed."); - return ERR_ANS_PARCELABLE_FAILED; - } return result; } diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index 3b39d6b93..b660dab92 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -938,21 +938,15 @@ ErrCode AnsManagerStub::HandleRequestEnableNotification(MessageParcel &data, Mes { ANS_LOGI("enter"); std::string deviceId; - bool popFlag = false; if (!data.ReadString(deviceId)) { ANS_LOGE("[HandleRequestEnableNotification] fail: read deviceId failed."); return ERR_ANS_PARCELABLE_FAILED; } - ErrCode result = RequestEnableNotification(deviceId, popFlag); + ErrCode result = RequestEnableNotification(deviceId); if (!reply.WriteInt32(result)) { ANS_LOGE("[HandleRequestEnableNotification] fail: write result failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; } - if (!reply.WriteBool(popFlag)) { - ANS_LOGE("[HandleRequestEnableNotification] fail: write popFlag failed, ErrCode=%{public}d", popFlag); - return ERR_ANS_PARCELABLE_FAILED; - } - ANS_LOGD("Write popFlag into reply. popFlag = %{public}d", popFlag); return ERR_OK; } @@ -1998,7 +1992,7 @@ ErrCode AnsManagerStub::UpdateSlots( return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::RequestEnableNotification(const std::string &deviceId, bool &popFlag) +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 67371739d..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, bool &popFlag) +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, popFlag); + 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 dc68a67b3..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"; - bool popFlag = false; - int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); + 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 = ""; - bool popFlag = false; - int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); + int32_t result = proxy->RequestEnableNotification(deviceId); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } @@ -1079,10 +1077,8 @@ HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0300, Function | std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); std::string deviceId = "Device"; - bool popFlag = false; - int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); + int32_t result = proxy->RequestEnableNotification(deviceId); EXPECT_EQ(ERR_OK, result); - EXPECT_EQ(true, popFlag); } /* @@ -1102,57 +1098,10 @@ HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0400, Function | std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); std::string deviceId = "Device"; - bool popFlag = false; - int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); + int32_t result = proxy->RequestEnableNotification(deviceId); EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); } -/* - * @tc.name: RequestEnableNotificationTest_0500 - * @tc.desc: test RequestEnableNotification function - * @tc.type: FUNC - * @tc.require: #I5XO2O - */ -HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0500, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, RequestEnableNotificationTest_0500, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) - .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, - ERR_OK, false, true, true)), Return(NO_ERROR))); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - std::string deviceId = "Device"; - bool popFlag = false; - int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); - EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); -} - -/* - * @tc.name: RequestEnableNotificationTest_0600 - * @tc.desc: test RequestEnableNotification function - * @tc.type: FUNC - * @tc.require: #I5XO2O - */ -HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0600, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, RequestEnableNotificationTest_0600, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) - .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, - ERR_OK, true, true, false)), Return(NO_ERROR))); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - std::string deviceId = "Device"; - bool popFlag = false; - int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); - EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); -} - /* * @tc.name: RemoveSlotByTypeTest_0100 * @tc.desc: test RemoveSlotByType function 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 d3f6cc428..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 @@ -3786,9 +3786,7 @@ HWTEST_F(AnsManagerStubTest, UpdateSlots01, Function | SmallTest | Level1) HWTEST_F(AnsManagerStubTest, RequestEnableNotification01, Function | SmallTest | Level1) { std::string deviceId = "this is deviceId"; - bool popFlag = true; - - ErrCode result = ansManagerStub_->RequestEnableNotification(deviceId, popFlag); + 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 8d7d2fcc7..b73cb5f5a 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 @@ -334,8 +334,7 @@ HWTEST_F(AnsNotificationUnitTest, RequestEnableNotification_0100, Function | Med ASSERT_NE(nullptr, proxy); ans_->GetAnsManagerProxy(); std::string deviceId = "this is deviceId"; - bool popFlag = true; - ErrCode ret1 = ans_->RequestEnableNotification(deviceId, popFlag); + 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 70c2fb23d..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,9 +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(); -void StartNotificationDialog(AsyncCallbackInfoIsEnable *callbackInfo); } // 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 0666cc548..d870bae7b 100644 --- a/frameworks/js/napi/src/enable_notification.cpp +++ b/frameworks/js/napi/src/enable_notification.cpp @@ -344,24 +344,14 @@ napi_value RequestEnableNotification(napi_env env, napi_callback_info info) AsyncCallbackInfoIsEnable *asynccallbackinfo = static_cast(data); if (asynccallbackinfo) { std::string deviceId {""}; - bool popFlag = false; - asynccallbackinfo->info.errorCode = NotificationHelper::RequestEnableNotification(deviceId, popFlag); - asynccallbackinfo->params.allowToPop = popFlag; - ANS_LOGI("errorCode = %{public}d, allowToPop = %{public}d", - asynccallbackinfo->info.errorCode, asynccallbackinfo->params.allowToPop); - if (asynccallbackinfo->info.errorCode == ERR_OK && asynccallbackinfo->params.allowToPop) { - ANS_LOGI("Begin to start notification dialog"); - auto *callbackInfo = static_cast(data); - StartNotificationDialog(callbackInfo); - } + 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 && asynccallbackinfo->params.allowToPop)) { - AsyncCompleteCallbackIsNotificationEnabled(env, status, data); - } + AsyncCompleteCallbackIsNotificationEnabled(env, status, data); } }, (void *)asynccallbackinfo, @@ -375,98 +365,5 @@ napi_value RequestEnableNotification(napi_env env, napi_callback_info info) return promise; } } - -void StartNotificationDialog(AsyncCallbackInfoIsEnable *callbackInfo) -{ - ANS_LOGD("%{public}s, Begin Calling StartNotificationDialog.", __func__); - if (CreateCallbackStubImpl(callbackInfo)) { - sptr token; - auto result = AAFwk::AbilityManagerClient::GetInstance()->GetTopAbility(token); - if (result == ERR_OK) { - AAFwk::Want want; - want.SetElementName("com.ohos.notificationdialog", "EnableNotificationDialog"); - want.SetParam("callbackStubImpl_", callbackStubImpl_); - want.SetParam("tokenId", token); - want.SetParam("from", AAFwk::AbilityManagerClient::GetInstance()->GetTopAbility().GetBundleName()); - ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, token, -1); - ANS_LOGD("%{public}s, End Calling StartNotificationDialog. ret=%{public}d", __func__, err); - } else { - ANS_LOGE("%{public}s, show notification dialog failed", __func__); - ResetCallbackStubImpl(); - } - } -} - -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); - } - 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 \ No newline at end of file diff --git a/frameworks/js/napi/src/manager/napi_enable_notification.cpp b/frameworks/js/napi/src/manager/napi_enable_notification.cpp index 2d29ba374..07a609928 100644 --- a/frameworks/js/napi/src/manager/napi_enable_notification.cpp +++ b/frameworks/js/napi/src/manager/napi_enable_notification.cpp @@ -237,22 +237,13 @@ napi_value NapiRequestEnableNotification(napi_env env, napi_callback_info info) AsyncCallbackInfoIsEnable *asynccallbackinfo = static_cast(data); if (asynccallbackinfo) { std::string deviceId {""}; - bool popFlag = false; - asynccallbackinfo->info.errorCode = NotificationHelper::RequestEnableNotification(deviceId, popFlag); - asynccallbackinfo->params.allowToPop = popFlag; - ANS_LOGI("asynccallbackinfo->info.errorCode = %{public}d, allowToPop = %{public}d", - asynccallbackinfo->info.errorCode, asynccallbackinfo->params.allowToPop); - if (asynccallbackinfo->info.errorCode == ERR_OK && asynccallbackinfo->params.allowToPop) { - ANS_LOGI("Begin to start notification dialog"); - auto *callbackInfo = static_cast(data); - StartNotificationDialog(callbackInfo); - } + 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 e153cc4e0..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 popFlag Indicates the flag that allows dialog to be popped. * @return Returns set notifications enabled for default bundle result. */ - static ErrCode RequestEnableNotification(std::string &deviceId, bool &popFlag); + 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/BUILD.gn b/services/ans/BUILD.gn index ec8fdfebf..161d24c39 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -31,6 +31,7 @@ ohos_shared_library("libans") { "src/advanced_notification_service_ability.cpp", "src/bundle_manager_helper.cpp", "src/event_report.cpp", + "src/notification_dialog.cpp", "src/notification_preferences.cpp", "src/notification_preferences_database.cpp", "src/notification_preferences_info.cpp", @@ -52,6 +53,7 @@ ohos_shared_library("libans") { cflags = [] deps = [ + "${ability_runtime_services_path}/abilitymgr:abilityms", "${core_path}:ans_core", "//foundation/arkui/ace_engine/interfaces/inner_api/ui_service_manager:ui_service_mgr", ] @@ -67,6 +69,7 @@ ohos_shared_library("libans") { } external_deps = [ + "ability_runtime:ability_manager", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", "c_utils:utils", diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 958a4331a..0b82dffee 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -343,10 +343,9 @@ public: * @brief Allow notifications to be sent based on the deviceId. * * @param deviceId Indicates the device Id. - * @param popFlag Indicates the flag that allows dialog to be popped. * @return Returns ERR_OK on success, others on failure. */ - ErrCode RequestEnableNotification(const std::string &deviceId, bool &popFlag) 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_callback_stub.h b/services/ans/include/notification_dialog.h similarity index 51% rename from frameworks/core/include/ans_callback_stub.h rename to services/ans/include/notification_dialog.h index c7e3c46cd..dfff565a6 100644 --- a/frameworks/core/include/ans_callback_stub.h +++ b/services/ans/include/notification_dialog.h @@ -13,23 +13,31 @@ * 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" +#include "ability_record.h" +#include "iremote_object.h" namespace OHOS { namespace Notification { -class AnsCallbackStub : public IRemoteStub { +class NotificationDialog { public: - AnsCallbackStub() = default; - virtual ~AnsCallbackStub() override = default; - DISALLOW_COPY_AND_MOVE(AnsCallbackStub); + NotificationDialog() = default; + ~NotificationDialog() = default; + + /** + * @brief To judge whether the caller is current application. + * + * @param abilityRecord The abilityRecord of comparison. + * @return true if it is selfcalled, else not. + */ + bool JudgeSelfCalled(const std::shared_ptr &abilityRecord); - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + /** + * @brief To start the enableNotificationDialog ability. + * + * @param callbackInfo The callbackInfo. + * @return ERR_OK if success, else not. + */ + ErrCode StartEnableNotificationDialogAbility(); }; } // namespace Notification } // namespace OHOS - -#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_CALLBACK_STUB_H diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index a22918bd6..a46571c00 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -39,6 +39,7 @@ #include "hitrace_meter.h" #include "ipc_skeleton.h" #include "notification_constant.h" +#include "notification_dialog.h" #include "notification_filter.h" #include "notification_preferences.h" #include "notification_slot.h" @@ -1438,7 +1439,7 @@ ErrCode AdvancedNotificationService::GetSpecialActiveNotifications( return result; } -ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string &deviceId, bool &popFlag) +ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string &deviceId) { ANS_LOGD("%{public}s", __FUNCTION__); @@ -1455,7 +1456,6 @@ ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string ANS_LOGI("result = %{public}d, allowedNotify = %{public}d", result, allowedNotify); if (result != ERR_OK || allowedNotify) { ANS_LOGD("Already granted permission"); - popFlag = false; return result; } @@ -1464,11 +1464,19 @@ ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string result = GetHasPoppedDialog(bundleOption, hasPopped); if (result != ERR_OK || hasPopped) { ANS_LOGD("Already shown dialog"); - popFlag = false; return result; } + + ANS_LOGI("hasPopped = %{public}d, allowedNotify = %{public}d", hasPopped, allowedNotify); + if (!hasPopped && !allowedNotify) { + auto notificationDialog = std::make_shared(); + result = notificationDialog->StartEnableNotificationDialogAbility(); + if (result != ERR_OK) { + ANS_LOGD("StartEnableNotificationDialogAbility failed, result = %{public}d", result); + return result; + } + } SetHasPoppedDialog(bundleOption, true); - popFlag = true; return result; } diff --git a/services/ans/src/notification_dialog.cpp b/services/ans/src/notification_dialog.cpp new file mode 100644 index 000000000..a26053896 --- /dev/null +++ b/services/ans/src/notification_dialog.cpp @@ -0,0 +1,60 @@ +/* + * 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 "notification_dialog.h" + +#include "ability_manager_client.h" +#include "advanced_notification_service.h" +#include "in_process_call_wrapper.h" +#include "ipc_skeleton.h" + +namespace OHOS { +namespace Notification { +bool NotificationDialog::JudgeSelfCalled(const std::shared_ptr &abilityRecord) +{ + auto callingTokenId = IPCSkeleton::GetCallingTokenID(); + auto tokenID = abilityRecord->GetApplicationInfo().accessTokenId; + if (callingTokenId != tokenID) { + ANS_LOGE("Is not self, not enabled"); + return false; + } + return true; +} + +ErrCode NotificationDialog::StartEnableNotificationDialogAbility() +{ + ANS_LOGD("%{public}s, Enter.", __func__); + sptr token; + int result = IN_PROCESS_CALL(AAFwk::AbilityManagerClient::GetInstance()->GetTopAbility(token)); + std::shared_ptr ability = AAFwk::Token::GetAbilityRecordByToken(token); + if (result != ERR_OK) { + ANS_LOGD("%{public}s, GetTopAbility failed. result=%{public}d", __func__, result); + return result; + } + if (!JudgeSelfCalled(ability)) { + ANS_LOGD("%{public}s, if it is not selfcalled.", __func__); + return result; + } + AAFwk::Want want; + std::string bundleName = IN_PROCESS_CALL(AAFwk::AbilityManagerClient::GetInstance()->GetTopAbility().GetBundleName()); + want.SetElementName("com.ohos.notificationdialog", "EnableNotificationDialog"); + want.SetParam("tokenId", token); + want.SetParam("from", bundleName); + result = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, token, -1); + ANS_LOGD("%{public}s, End Calling StartNotificationDialog. result=%{public}d", __func__, result); + return result; +} +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index b6e5e6c1e..e884afdb1 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -59,6 +59,7 @@ ohos_unittest("reminder_unit_test") { deps = [ "${core_path}:ans_core", "${frameworks_module_ans_path}:ans_innerkits", + "${services_path}/ans:libans", "//foundation/arkui/ace_engine/interfaces/inner_api/ui_service_manager:ui_service_mgr", "//third_party/googletest:gtest_main", ] @@ -162,6 +163,7 @@ ohos_unittest("ans_unit_test") { deps = [ "${core_path}:ans_core", "${frameworks_module_ans_path}:ans_innerkits", + "${services_path}/ans:libans", "//foundation/arkui/ace_engine/interfaces/inner_api/ui_service_manager:ui_service_mgr", "//third_party/googletest:gtest_main", ] diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index c3e504374..62361bc21 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -1762,8 +1762,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13100, sptr req = new NotificationRequest(); EXPECT_NE(req, nullptr); std::string deviceId = "DeviceId"; - bool needPop = false; - EXPECT_EQ(advancedNotificationService_->RequestEnableNotification(deviceId, needPop), (int)ERR_ANS_INVALID_PARAM); + EXPECT_EQ(advancedNotificationService_->RequestEnableNotification(deviceId), (int)ERR_ANS_INVALID_PARAM); } /** @@ -2343,7 +2342,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16900, std::string deviceId = "DeviceId"; bool needPop = false; - EXPECT_EQ(advancedNotificationService_->RequestEnableNotification(deviceId, needPop), 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 122ae5293..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 a64eb2948..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/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index f61ff5073..119b12825 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -60,6 +60,7 @@ ohos_moduletest("ans_module_test") { deps = [ "${core_path}:ans_core", "${frameworks_module_ans_path}:ans_innerkits", + "${services_path}/ans:libans", "//foundation/arkui/ace_engine/interfaces/inner_api/ui_service_manager:ui_service_mgr", ] 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 5e2ce9698..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); - bool popFlag = true; - ansManagerStub.RequestEnableNotification(deviceId, popFlag); + 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 74d4ad5bc..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); - bool needPop = true; - Notification::NotificationHelper::RequestEnableNotification(deviceId, needPop); + Notification::NotificationHelper::RequestEnableNotification(deviceId); // test AreNotificationsSuspended function bool suspended = true; Notification::NotificationHelper::AreNotificationsSuspended(suspended); -- Gitee