From 6a55b0142df11b2ff5f6614f1bef3887cf1e7f89 Mon Sep 17 00:00:00 2001 From: xdongs Date: Mon, 3 Mar 2025 15:45:55 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E4=B8=9C=E6=B9=96=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xdongs --- frameworks/ans/src/notification_helper.cpp | 6 ++++ .../core/include/ans_manager_interface.h | 9 +++++ frameworks/core/include/ans_manager_proxy.h | 9 +++++ frameworks/core/include/ans_manager_stub.h | 10 ++++++ frameworks/core/include/ans_notification.h | 9 +++++ ..._notification_service_ipc_interface_code.h | 2 ++ frameworks/core/src/ans_manager_stub.cpp | 27 ++++++++++++++ .../core/src/ans_manager_stub_invalid.cpp | 6 ++++ frameworks/core/src/ans_notification.cpp | 11 ++++++ .../src/manager/ans_manager_proxy_bundle.cpp | 35 +++++++++++++++++++ .../ans_notification_branch_test.cpp | 5 +++ .../include/advanced_notification_service.h | 21 +++++++++++ services/ans/include/notification_dialog.h | 3 +- .../ans/include/notification_dialog_manager.h | 3 +- .../advanced_notification_publish_service.cpp | 31 ++++++++++++---- .../ans/src/advanced_notification_service.cpp | 10 ++++++ services/ans/src/notification_dialog.cpp | 21 +++++++++-- .../ans/src/notification_dialog_manager.cpp | 9 +++-- .../notification_dialog_test.cpp | 6 ++-- .../AppScope/app.json | 4 +-- .../NotificationServiceExtAbility.ts | 10 ++++-- .../src/main/ets/pages/notificationDialog.ets | 6 +++- .../main/resources/base/element/string.json | 4 +++ .../main/resources/bo_CN/element/string.json | 4 +++ .../src/main/resources/ug/element/string.json | 4 +++ .../main/resources/zh_CN/element/string.json | 4 +++ .../main/resources/zh_HK/element/string.json | 4 +++ .../main/resources/zh_TW/element/string.json | 4 +++ 28 files changed, 254 insertions(+), 23 deletions(-) diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index 0722b0a91..b91a05e38 100644 --- a/frameworks/ans/src/notification_helper.cpp +++ b/frameworks/ans/src/notification_helper.cpp @@ -189,6 +189,12 @@ ErrCode NotificationHelper::RequestEnableNotification(std::string &deviceId, deviceId, hostClient, callerToken); } +ErrCode NotificationHelper::RequestEnableNotification(const std::string bundleName, const int32_t uid) +{ + return DelayedSingleton::GetInstance()->RequestEnableNotification( + bundleName, uid); +} + ErrCode NotificationHelper::HasNotificationPolicyAccessPermission(bool &hasPermission) { return DelayedSingleton::GetInstance()->HasNotificationPolicyAccessPermission(hasPermission); diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index 384c34820..9af40693f 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -403,6 +403,15 @@ public: const sptr &callback, const sptr &callerToken) = 0; + /** + * @brief Allow application to publish notifications. + * + * @param bundleName bundle name. + * @param uid uid. + * @return Returns set notifications enabled for the bundle result. + */ + virtual ErrCode RequestEnableNotification(const std::string bundleName, const int32_t uid) = 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 0a906f4eb..d36f5903f 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -390,6 +390,15 @@ public: ErrCode RequestEnableNotification(const std::string &deviceId, const sptr &callback, const sptr &callerToken) override; + + /** + * @brief Allow application to publish notifications. + * + * @param bundleName bundle name. + * @param uid uid. + * @return Returns set notifications enabled for the bundle result. + */ + ErrCode RequestEnableNotification(const std::string bundleName, const int32_t uid) 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 72a6b8616..00d0877a6 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -394,6 +394,15 @@ public: const sptr &callback, const sptr &callerToken) override; + /** + * @brief Allow application to publish notifications. + * + * @param bundleName bundle name. + * @param uid uid. + * @return Returns set notifications enabled for the bundle result. + */ + ErrCode RequestEnableNotification(const std::string bundleName, const int32_t uid) override; + /** * @brief Set whether to allow the specified deviceId to send notifications for current bundle. * @@ -1021,6 +1030,7 @@ private: ErrCode HandleGetSlotByBundle(MessageParcel &data, MessageParcel &reply); ErrCode HandleUpdateSlots(MessageParcel &data, MessageParcel &reply); ErrCode HandleRequestEnableNotification(MessageParcel &data, MessageParcel &reply); + ErrCode HandleRequestEnableNotificationByBundle(MessageParcel &data, MessageParcel &reply); ErrCode HandleSetNotificationsEnabledForBundle(MessageParcel &data, MessageParcel &reply); ErrCode HandleSetNotificationsEnabledForAllBundles(MessageParcel &data, MessageParcel &reply); ErrCode HandleSetNotificationsEnabledForSpecialBundle(MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index be1d52d0b..e5622cbdc 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -330,6 +330,15 @@ public: sptr &hostClient, sptr &callerToken); + /** + * @brief Allow application to publish notifications. + * + * @param bundleName bundle name. + * @param uid uid. + * @return Returns set notifications enabled for the bundle result. + */ + ErrCode RequestEnableNotification(const std::string bundleName, const int32_t uid); + /** * @brief Checks whether this application has permission to modify the Do Not Disturb (DND) notification policy. * diff --git a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h index 2e2e68cbf..301c49318 100644 --- a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h +++ b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h @@ -153,6 +153,8 @@ namespace Notification { GET_DONOTDISTURB_PROFILE, UPDATE_NOTIFICATION_TIMER, Set_HASH_CODE_RULE, + GET_ALL_NOTIFICATIONS_BY_SLOTTYPE, + REQUEST_ENABLE_NOTIFICATION_BY_BUNDLE, }; } } diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index a350e8f9a..e5a0c0e47 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -183,6 +183,10 @@ int32_t AnsManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Mess result = HandleRequestEnableNotification(data, reply); break; } + case static_cast(NotificationInterfaceCode::REQUEST_ENABLE_NOTIFICATION_BY_BUNDLE): { + result = HandleRequestEnableNotificationByBundle(data, reply); + break; + } case static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_BUNDLE): { result = HandleSetNotificationsEnabledForBundle(data, reply); break; @@ -1386,6 +1390,29 @@ ErrCode AnsManagerStub::HandleRequestEnableNotification(MessageParcel &data, Mes return ERR_OK; } +ErrCode AnsManagerStub::HandleRequestEnableNotificationByBundle(MessageParcel &data, MessageParcel &reply) +{ + ANS_LOGD("enter"); + std::string bundleName; + if (!data.ReadString(bundleName)) { + ANS_LOGE("[HandleRequestEnableNotificationByBundle] fail: read bundleName failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t uid = 0; + if (!data.ReadInt32(uid)) { + ANS_LOGE("[HandleRequestEnableNotificationByBundle] fail: read uid failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = RequestEnableNotification(bundleName, uid); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleRequestEnableNotificationByBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + ErrCode AnsManagerStub::HandleSetNotificationsEnabledForBundle(MessageParcel &data, MessageParcel &reply) { std::string deviceId; diff --git a/frameworks/core/src/ans_manager_stub_invalid.cpp b/frameworks/core/src/ans_manager_stub_invalid.cpp index db13e6eb8..3a5a6c524 100644 --- a/frameworks/core/src/ans_manager_stub_invalid.cpp +++ b/frameworks/core/src/ans_manager_stub_invalid.cpp @@ -274,6 +274,12 @@ ErrCode AnsManagerStub::RequestEnableNotification(const std::string &deviceId, return ERR_INVALID_OPERATION; } +ErrCode AnsManagerStub::RequestEnableNotification(const std::string bundleName, const int32_t uid) +{ + ANS_LOGE("AnsManagerStub::RequestEnableNotification called!"); + return ERR_INVALID_OPERATION; +} + ErrCode AnsManagerStub::SetNotificationsEnabledForBundle(const std::string &bundle, bool enabled) { ANS_LOGE("AnsManagerStub::SetNotificationsEnabledForBundle called!"); diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index dfb2da388..0d9e81108 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -527,6 +527,17 @@ ErrCode AnsNotification::RequestEnableNotification(std::string &deviceId, return proxy->RequestEnableNotification(deviceId, hostClient, callerToken); } +ErrCode AnsNotification::RequestEnableNotification(const std::string bundleName, const int32_t uid) +{ + ANS_LOGD("enter"); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->RequestEnableNotification(bundleName, uid); +} + ErrCode AnsNotification::HasNotificationPolicyAccessPermission(bool &hasPermission) { sptr proxy = GetAnsManagerProxy(); diff --git a/frameworks/core/src/manager/ans_manager_proxy_bundle.cpp b/frameworks/core/src/manager/ans_manager_proxy_bundle.cpp index 8d2c39b92..21c00b4b2 100644 --- a/frameworks/core/src/manager/ans_manager_proxy_bundle.cpp +++ b/frameworks/core/src/manager/ans_manager_proxy_bundle.cpp @@ -162,6 +162,41 @@ ErrCode AnsManagerProxy::RequestEnableNotification(const std::string &deviceId, return result; } +ErrCode AnsManagerProxy::RequestEnableNotification(const std::string bundleName, const int32_t uid) +{ + ANS_LOGD("enter"); + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGE("[RequestEnableNotification] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteString(bundleName)) { + ANS_LOGE("[RequestEnableNotification] fail: write bundleName failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteInt32(uid)) { + ANS_LOGE("[RequestEnableNotification] fail: write uid failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::REQUEST_ENABLE_NOTIFICATION_BY_BUNDLE, + option, data, reply); + if (result != ERR_OK) { + ANS_LOGE("[RequestEnableNotification] fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + + if (!reply.ReadInt32(result)) { + ANS_LOGE("[RequestEnableNotification] fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + ErrCode AnsManagerProxy::SetNotificationsEnabledForBundle(const std::string &deviceId, bool enabled) { MessageParcel data; diff --git a/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp b/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp index 92bfd457a..96efb0e48 100644 --- a/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp +++ b/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp @@ -238,6 +238,11 @@ public: return ERR_ANS_INVALID_PARAM; } + ErrCode RequestEnableNotification(const std::string bundleName, const int32_t uid) override + { + return ERR_ANS_INVALID_PARAM; + } + ErrCode SetNotificationsEnabledForBundle(const std::string &deviceId, bool enabled) override { return ERR_ANS_INVALID_PARAM; diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index fbfded21e..c437502e5 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -447,6 +447,15 @@ public: const sptr &callback, const sptr &callerToken) override; + /** + * @brief Allow application to publish notifications. + * + * @param bundleName bundle name. + * @param uid uid. + * @return Returns set notifications enabled for the bundle result. + */ + ErrCode RequestEnableNotification(const std::string bundleName, const int32_t uid) override; + /** * @brief Set whether to allow the specified deviceId to send notifications for current bundle. * @@ -1464,6 +1473,18 @@ private: const sptr &slot, const sptr &bundle, bool enabled, bool isForceControl); + ErrCode OnRecoverLiveView(const std::vector &keys); + void HandleUpdateLiveViewNotificationTimer(const int32_t uid, const bool isPaused); + void CancelWantAgent(const sptr ¬ification); + void CancelOnceWantAgent(const std::shared_ptr &wantAgent); + void PublishSubscriberExistFlagEvent(bool headsetExistFlag, bool wearableExistFlag); + void SetClassificationWithVoip(const sptr &request); + void UpdateCollaborateTimerInfo(const std::shared_ptr &record); + ErrCode CommonRequestEnableNotification(const std::string &deviceId, + const sptr &callback, + const sptr &callerToken, + const sptr bundleOption, + const bool innerLake); private: static sptr instance_; static std::mutex instanceMutex_; diff --git a/services/ans/include/notification_dialog.h b/services/ans/include/notification_dialog.h index 941e7f47f..0703496de 100644 --- a/services/ans/include/notification_dialog.h +++ b/services/ans/include/notification_dialog.h @@ -34,7 +34,8 @@ public: const std::string &serviceAbilityName, int32_t uid, std::string appBundleName, - const sptr &callerToken); + const sptr &callerToken, + const bool innerLake); static int32_t GetUidByBundleName(const std::string &bundleName); }; diff --git a/services/ans/include/notification_dialog_manager.h b/services/ans/include/notification_dialog_manager.h index 2d8b63877..dc5f848cd 100644 --- a/services/ans/include/notification_dialog_manager.h +++ b/services/ans/include/notification_dialog_manager.h @@ -84,7 +84,8 @@ public: ErrCode RequestEnableNotificationDailog( const sptr& bundle, const sptr& callback, - const sptr& callerToken + const sptr& callerToken, + const bool innerLake ); /* diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index a0cffd382..563176104 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -67,6 +67,7 @@ constexpr int32_t TYPE_CODE_DOWNLOAD = 8; constexpr const char *FOCUS_MODE_REPEAT_CALLERS_ENABLE = "1"; constexpr const char *CONTACT_DATA = "datashare:///com.ohos.contactsdataability/contacts/contact_data?Proxy=true"; constexpr int32_t OPERATION_TYPE_COMMON_EVENT = 4; +const static std::string BUNDLE_NAME_ZYT = "com.zhuoyi.appstore.lite"; ErrCode AdvancedNotificationService::SetDefaultNotificationEnabled( const sptr &bundleOption, bool enabled) @@ -874,13 +875,31 @@ ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string ANS_LOGE("callback == nullptr"); return ERR_ANS_INVALID_PARAM; } - - ErrCode result = ERR_OK; sptr bundleOption = GenerateBundleOption(); - if (bundleOption == nullptr) { - ANS_LOGE("bundleOption is nullptr."); - return ERR_ANS_INVALID_BUNDLE; + return CommonRequestEnableNotification(deviceId, callback, callerToken, bundleOption, false); +} + +ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string bundleName, const int32_t uid) +{ + ANS_LOGI("RequestEnableNotification bundleName = %{public}s uid = %{public}d", bundleName.c_str(), uid); + if (!AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) { + return ERR_ANS_PERMISSION_DENIED; + } + if (bundleName == BUNDLE_NAME_ZYT) { + return ERR_ANS_NOT_ALLOWED; } + sptr bundleOption = new (std::nothrow) NotificationBundleOption(bundleName, uid); + return CommonRequestEnableNotification("", nullptr, nullptr, bundleOption, true); +} + +ErrCode AdvancedNotificationService::CommonRequestEnableNotification(const std::string &deviceId, + const sptr &callback, + const sptr &callerToken, + const sptr bundleOption, + const bool innerLake) +{ + ANS_LOGI("%{public}s", __FUNCTION__); + ErrCode result = ERR_OK; // To get the permission bool allowedNotify = false; HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_8, EventBranchId::BRANCH_5); @@ -923,7 +942,7 @@ ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string return ERROR_INTERNAL_ERROR; } - result = dialogManager_->RequestEnableNotificationDailog(bundleOption, callback, callerToken); + result = dialogManager_->RequestEnableNotificationDailog(bundleOption, callback, callerToken, innerLake); if (result == ERR_OK) { result = ERR_ANS_DIALOG_POP_SUCCEEDED; } diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index bdf5f4921..ea34b9e5b 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -240,6 +240,16 @@ ErrCode AdvancedNotificationService::PrepareNotificationRequest(const sptrGetOwnerUid(), ownerUserId); request->SetOwnerUserId(ownerUserId); + std::shared_ptr additionalData = request->GetAdditionalData(); + if (AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER) && + AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER) && + additionalData && additionalData->HasParam("is_ancoNotification")) { + AAFwk::IBoolean *bo = AAFwk::IBoolean::Query(additionalData->GetParam("is_ancoNotification")); + if (AAFwk::Boolean::Unbox(bo)) { + ANS_LOGI("push publish notification"); + request->SetOwnerUserId(DEFAULT_USER_ID); + } + } } ErrCode result = CheckPictureSize(request); diff --git a/services/ans/src/notification_dialog.cpp b/services/ans/src/notification_dialog.cpp index 8b635cf9f..ac53a9545 100644 --- a/services/ans/src/notification_dialog.cpp +++ b/services/ans/src/notification_dialog.cpp @@ -24,10 +24,13 @@ #include "os_account_manager_helper.h" #include "system_dialog_connect_stb.h" #include "extension_manager_client.h" +#include +#include namespace OHOS { namespace Notification { constexpr int32_t DEFAULT_VALUE = -1; +const int32_t SLEEP_TIME = 200; int32_t NotificationDialog::GetUidByBundleName(const std::string &bundleName) { @@ -41,15 +44,26 @@ ErrCode NotificationDialog::StartEnableNotificationDialogAbility( const std::string &serviceAbilityName, int32_t uid, std::string appBundleName, - const sptr &callerToken) + const sptr &callerToken, + const bool innerLake) { ANS_LOGD("%{public}s, Enter.", __func__); auto topBundleName = IN_PROCESS_CALL(AAFwk::AbilityManagerClient::GetInstance()->GetTopAbility().GetBundleName()); - auto topUid = NotificationDialog::GetUidByBundleName(topBundleName); if (topBundleName != appBundleName) { ANS_LOGE("Current application isn't in foreground, top is %{public}s.", topBundleName.c_str()); - return ERR_ANS_INVALID_BUNDLE; + if (!innerLake) { + return ERR_ANS_INVALID_BUNDLE; + } else { + ANS_LOGE("get top ability again"); + std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME)); + topBundleName = IN_PROCESS_CALL( + AAFwk::AbilityManagerClient::GetInstance()->GetTopAbility().GetBundleName()); + if (topBundleName != appBundleName) { + ANS_LOGE("get top ability again failed"); + return ERR_ANS_INVALID_BUNDLE; + } + } } AAFwk::Want want; @@ -63,6 +77,7 @@ ErrCode NotificationDialog::StartEnableNotificationDialogAbility( root["bundleName"] = appBundleName; root["bundleUid"] = uid; root["ability.want.params.uiExtensionType"] = uiExtensionType; + root["innerLake"] = innerLake; std::string command = root.dump(); auto connection_ = sptr(new (std::nothrow) SystemDialogConnectStb(command)); diff --git a/services/ans/src/notification_dialog_manager.cpp b/services/ans/src/notification_dialog_manager.cpp index 29e4bde4f..e7d40a91d 100644 --- a/services/ans/src/notification_dialog_manager.cpp +++ b/services/ans/src/notification_dialog_manager.cpp @@ -88,11 +88,9 @@ bool NotificationDialogManager::Init() ErrCode NotificationDialogManager::RequestEnableNotificationDailog( const sptr& bundle, const sptr& callback, - const sptr& callerToken) + const sptr& callerToken, + const bool innerLake) { - if (bundle == nullptr || callback == nullptr) { - return ERROR_INTERNAL_ERROR; - } if (!AddDialogInfoIfNotExist(bundle, callback)) { ANS_LOGE("AddDialogIfNotExist failed. Dialog already exists."); return ERR_ANS_DIALOG_IS_POPPING; @@ -102,7 +100,8 @@ ErrCode NotificationDialogManager::RequestEnableNotificationDailog( NotificationDialogManager::NOTIFICATION_DIALOG_SERVICE_ABILITY, bundle->GetUid(), bundle->GetBundleName(), - callerToken); + callerToken, + innerLake); if (result != ERR_OK) { ANS_LOGE("StartEnableNotificationDialogAbility failed, result = %{public}d", result); std::unique_ptr dialogInfoRemoved = nullptr; diff --git a/services/ans/test/unittest/notification_dialog_test/notification_dialog_test.cpp b/services/ans/test/unittest/notification_dialog_test/notification_dialog_test.cpp index a43ffabdb..b7f5b3e98 100644 --- a/services/ans/test/unittest/notification_dialog_test/notification_dialog_test.cpp +++ b/services/ans/test/unittest/notification_dialog_test/notification_dialog_test.cpp @@ -74,7 +74,8 @@ HWTEST_F(NotificationDialogTest, NotificationDialog_00300, Function | SmallTest NotificationDialogManager::NOTIFICATION_DIALOG_SERVICE_ABILITY, uid, bundleName, - callerToken); + callerToken, + false); ASSERT_EQ(result3, ERR_ANS_INVALID_BUNDLE); } @@ -99,7 +100,8 @@ HWTEST_F(NotificationDialogTest, NotificationDialog_00400, Function | SmallTest NotificationDialogManager::NOTIFICATION_DIALOG_SERVICE_ABILITY, uid, bundleName, - callerToken); + callerToken, + false); ASSERT_EQ(result3, ERR_ANS_INVALID_BUNDLE); } } // namespace Notification diff --git a/services/dialog_ui/enable_notification_dialog/AppScope/app.json b/services/dialog_ui/enable_notification_dialog/AppScope/app.json index 1d926fa0a..edeaa9dba 100644 --- a/services/dialog_ui/enable_notification_dialog/AppScope/app.json +++ b/services/dialog_ui/enable_notification_dialog/AppScope/app.json @@ -2,8 +2,8 @@ "app": { "bundleName": "com.ohos.notificationdialog", "vendor": "example", - "versionCode": 1000017, - "versionName": "1.1.7", + "versionCode": 1000018, + "versionName": "1.1.8", "icon": "$media:app_icon", "label": "$string:app_name", "distributedNotificationEnabled": true, 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 fc1d03530..088f568a0 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 @@ -91,14 +91,16 @@ export class EnableNotificationDialog { stageModel: boolean; subWindow: window.Window; initSubWindowSize: boolean; + innerLake: boolean; - constructor(id: number, want: Want, stageModel: boolean) { + constructor(id: number, want: Want, stageModel: boolean, innerLake: boolean) { this.id = id; this.want = want; this.stageModel = stageModel; this.window = undefined; this.extensionWindow = undefined; this.initSubWindowSize = false; + this.innerLake = innerLake; } @@ -266,17 +268,21 @@ class NotificationDialogServiceExtensionAbility extends UIExtensionAbility { let stageModel = false; let bundleName = want.parameters['ohos.aafwk.param.callerBundleName']; let bundleUid = want.parameters['ohos.aafwk.param.callerUid']; + let innerLake = false; if (bundleName !== EnableNotificationDialog.SCENEBOARD_BUNDLE && bundleName !== EnableNotificationDialog.SYSTEMUI_BUNDLE) { want.parameters.bundleName = bundleName; want.parameters.bundleUid = bundleUid; stageModel = true; + console.log(TAG, `stage model`); } else { stageModel = false; + innerLake = Boolean(want.parameters.innerLake); + console.log(TAG, ` un stage model innerLake = , ${innerLake}`); } console.log(TAG, `UIExtAbility onSessionCreate bundleName ${want.parameters.bundleName}` + `uid ${want.parameters.bundleUid}`); - let dialog = new EnableNotificationDialog(1, want, stageModel); + let dialog = new EnableNotificationDialog(1, want, stageModel, innerLake); await dialog.createUiExtensionWindow(session, stageModel); AppStorage.setOrCreate('dialog', dialog); } catch (err) { 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 86d5bc184..42d222214 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 @@ -150,7 +150,11 @@ struct PermissionDialog { Row() { Flex({ justifyContent: FlexAlign.Center }) { Text() { - Span(permission.reason) + if (!this.dialog.innerLake) { + Span(permission.reason) + } else { + Span($r('app.string.reason_zyt')) + } } .fontSize(Constants.DIALOG_DESP_FONT_SIZE) .fontWeight(FontWeight.Regular) diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/element/string.json b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/element/string.json index da8c2f069..02d98f4cd 100644 --- a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/element/string.json +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/element/string.json @@ -16,6 +16,10 @@ "name": "reason", "value": "These may include lock screen notifications, banners, sounds, vibrations, and more. You can change this in Settings." }, + { + "name":"reason_zyt", + "value":"These may include lock screen and banner notifications as well as sounds and vibration. You can modify these settings in EasyAbroad > App management." + }, { "name": "ALLOW", "value": "Allow" diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/bo_CN/element/string.json b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/bo_CN/element/string.json index 1ca84808c..f17a3a238 100644 --- a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/bo_CN/element/string.json +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/bo_CN/element/string.json @@ -16,6 +16,10 @@ "name": "reason", "value": "བརྡ་ཐོ་དྲན་སྐུལ་གྱི་ཐབས་ལམ་ལ་སྒོ་ལྕགས་བརྙན་ཡོལ་དང་། འཕྲེད་བྱང་། དྲིལ་སྒྲ། སྦིར་བརྡ་སོགས་ཚུད་སྲིད། ༼སྒྲིག་འགོད་༽ལ་བསྐྱོད་ནས་བཅོས་ཆོག" }, + { + "name":"reason_zyt", + "value":"བརྡ་ཐོའི་དྲན་སྐུལ་གྱི་ཐབས་ལམ་ལ་སྒོ་ལྕགས་བརྙན་ཡོལ་དང་། འཕྲེད་བྱང་། དྲིལ་སྒྲ། སྦིར་བརྡ་སོགས་ཚུད་སྲིད། ༼ཀྲུའོ་དབྱི་ཐུང་༽>༼ ཉེར་སྤྱོད་དོ་དམ་༽ལ་བསྐྱོད་ནས་བཅོས་ཆོག" + }, { "name": "ALLOW", "value": "ཆོག་པ།" diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/ug/element/string.json b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/ug/element/string.json index 2bc9b3ed1..488d6204a 100644 --- a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/ug/element/string.json +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/ug/element/string.json @@ -16,6 +16,10 @@ "name": "reason", "value": "قۇلۇپ ئېكرانى، بالداق، ئاۋاز ۋە تىترەش شۇلارنىڭ ئىچىدە. تەڭشەكتىن ئۆزگەرتەلەيسىز." }, + { + "name":"reason_zyt", + "value":"قۇلۇپ ئېكرانى، بالداق، ئاۋاز ۋە تىترەش قاتارلىقلار شۇنىڭ ئىچىدە. DroiTong > ئەپ باشقۇرۇش دېگەن ئورۇندىن ئۆزگەرتەلەيسىز." + }, { "name": "ALLOW", "value": "رۇخسەت" diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/zh_CN/element/string.json b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/zh_CN/element/string.json index 9b9b9b5ea..3627f2a36 100644 --- a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/zh_CN/element/string.json +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/zh_CN/element/string.json @@ -16,6 +16,10 @@ "name": "reason", "value": "通知提醒方式可能包括锁屏、横幅、响铃、振动等。可前往“设置” 更改。" }, + { + "name":"reason_zyt", + "value":"通知提醒方式可能包括锁屏、横幅、响铃、振动等。可前往“卓易通”>“应用管理”更改。" + }, { "name": "ALLOW", "value": "允许" diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/zh_HK/element/string.json b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/zh_HK/element/string.json index 1b3ddf6bc..c8a3e11ec 100644 --- a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/zh_HK/element/string.json +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/zh_HK/element/string.json @@ -16,6 +16,10 @@ "name": "reason", "value": "通知提醒方式可能包括鎖屏、橫幅、響鬧、震動等。可前往「設定」更改。" }, + { + "name":"reason_zyt", + "value":"通知提醒方式可能包括鎖屏、橫幅、響鬧和震動等。可前往「卓易通」>「應用程式管理」更改。" + }, { "name": "ALLOW", "value": "允許" diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/zh_TW/element/string.json b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/zh_TW/element/string.json index c15a58719..55b69a738 100644 --- a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/zh_TW/element/string.json +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/zh_TW/element/string.json @@ -16,6 +16,10 @@ "name": "reason", "value": "通知提醒方式可能包括鎖定螢幕、橫幅、響鈴、振動等。可前往「設定」變更。" }, + { + "name":"reason_zyt", + "value":"通知提醒方式可能包括鎖定螢幕、橫幅、響鈴、振動等。您可以前往「卓易通」>「應用程式管理」變更。" + }, { "name": "ALLOW", "value": "允許" -- Gitee From cb225c97c743fd81498dfc1132b347432d178689 Mon Sep 17 00:00:00 2001 From: xdongs Date: Mon, 17 Mar 2025 20:31:48 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E4=B8=9C=E6=B9=96=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xdongs --- .vscode/settings.json | 61 ++++++++++++++++++++++ interfaces/inner_api/notification_helper.h | 11 +++- 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..cd2284a7e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,61 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "codecvt": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "list": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "map": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "ratio": "cpp", + "regex": "cpp", + "set": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "typeinfo": "cpp" + } +} \ No newline at end of file diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index 3625c2d79..547b0aed4 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -329,7 +329,16 @@ public: static ErrCode RequestEnableNotification(std::string &deviceId, sptr &hostClient, sptr &callerToken); - + + /** + * @brief Allow application to publish notifications. + * + * @param bundleName bundle name. + * @param uid uid. + * @return Returns set notifications enabled for the bundle result. + */ + static ErrCode RequestEnableNotification(const std::string bundleName, const int32_t uid); + /** * @brief Checks whether this application has permission to modify the Do Not Disturb (DND) notification policy. * -- Gitee From 6ebe651667b67573a5317b4e60b8d75d95410127 Mon Sep 17 00:00:00 2001 From: xdongs Date: Mon, 17 Mar 2025 20:33:23 +0800 Subject: [PATCH 3/8] delete Signed-off-by: xdongs --- .vscode/settings.json | 61 ------------------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index cd2284a7e..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "files.associations": { - "array": "cpp", - "atomic": "cpp", - "*.tcc": "cpp", - "bitset": "cpp", - "cctype": "cpp", - "chrono": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "codecvt": "cpp", - "condition_variable": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "list": "cpp", - "unordered_map": "cpp", - "unordered_set": "cpp", - "vector": "cpp", - "exception": "cpp", - "algorithm": "cpp", - "functional": "cpp", - "iterator": "cpp", - "map": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "ratio": "cpp", - "regex": "cpp", - "set": "cpp", - "string": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "fstream": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "mutex": "cpp", - "new": "cpp", - "ostream": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "thread": "cpp", - "typeinfo": "cpp" - } -} \ No newline at end of file -- Gitee From 4086d65d62c4b9c60ddeb5b93dc2a61d93d06a44 Mon Sep 17 00:00:00 2001 From: xdongs2009 Date: Tue, 18 Mar 2025 00:02:03 +0000 Subject: [PATCH 4/8] update services/ans/include/advanced_notification_service.h. Signed-off-by: xdongs2009 --- services/ans/include/advanced_notification_service.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index c437502e5..365a299bd 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1473,13 +1473,6 @@ private: const sptr &slot, const sptr &bundle, bool enabled, bool isForceControl); - ErrCode OnRecoverLiveView(const std::vector &keys); - void HandleUpdateLiveViewNotificationTimer(const int32_t uid, const bool isPaused); - void CancelWantAgent(const sptr ¬ification); - void CancelOnceWantAgent(const std::shared_ptr &wantAgent); - void PublishSubscriberExistFlagEvent(bool headsetExistFlag, bool wearableExistFlag); - void SetClassificationWithVoip(const sptr &request); - void UpdateCollaborateTimerInfo(const std::shared_ptr &record); ErrCode CommonRequestEnableNotification(const std::string &deviceId, const sptr &callback, const sptr &callerToken, -- Gitee From 6477366b94c5a3b863eb664d660595a5b8dc5f81 Mon Sep 17 00:00:00 2001 From: xdongs2009 Date: Tue, 18 Mar 2025 00:03:15 +0000 Subject: [PATCH 5/8] update frameworks/core/include/distributed_notification_service_ipc_interface_code.h. Signed-off-by: xdongs2009 --- .../distributed_notification_service_ipc_interface_code.h | 1 - 1 file changed, 1 deletion(-) diff --git a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h index 301c49318..efe213c5c 100644 --- a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h +++ b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h @@ -153,7 +153,6 @@ namespace Notification { GET_DONOTDISTURB_PROFILE, UPDATE_NOTIFICATION_TIMER, Set_HASH_CODE_RULE, - GET_ALL_NOTIFICATIONS_BY_SLOTTYPE, REQUEST_ENABLE_NOTIFICATION_BY_BUNDLE, }; } -- Gitee From 5d3dfa4f3d266db62d7cb8b48358f3fe72e0ea16 Mon Sep 17 00:00:00 2001 From: xdongs Date: Tue, 18 Mar 2025 09:43:57 +0800 Subject: [PATCH 6/8] proxy Signed-off-by: xdongs --- frameworks/core/src/ans_manager_proxy.cpp | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index c922ac1ee..c182dd7d9 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -1039,6 +1039,41 @@ ErrCode AnsManagerProxy::RequestEnableNotification(const std::string &deviceId, return result; } +ErrCode AnsManagerProxy::RequestEnableNotification(const std::string bundleName, const int32_t uid) +{ + ANS_LOGD("enter"); + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGE("[RequestEnableNotification] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteString(bundleName)) { + ANS_LOGE("[RequestEnableNotification] fail: write bundleName failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteInt32(uid)) { + ANS_LOGE("[RequestEnableNotification] fail: write uid failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::REQUEST_ENABLE_NOTIFICATION_BY_BUNDLE, + option, data, reply); + if (result != ERR_OK) { + ANS_LOGE("[RequestEnableNotification] fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + + if (!reply.ReadInt32(result)) { + ANS_LOGE("[RequestEnableNotification] fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + ErrCode AnsManagerProxy::SetNotificationsEnabledForBundle(const std::string &deviceId, bool enabled) { MessageParcel data; -- Gitee From d20f480fed8f7ae69816c56cffe135610458c874 Mon Sep 17 00:00:00 2001 From: xdongs2009 Date: Tue, 18 Mar 2025 06:25:15 +0000 Subject: [PATCH 7/8] update services/ans/src/advanced_notification_publish_service.cpp. Signed-off-by: xdongs2009 --- .../ans/src/advanced_notification_publish_service.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 563176104..5d1210f71 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -889,6 +889,10 @@ ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string return ERR_ANS_NOT_ALLOWED; } sptr bundleOption = new (std::nothrow) NotificationBundleOption(bundleName, uid); + if (bundleOption == nullptr) { + ANS_LOGE("bundleOption is nullptr."); + return ERR_ANS_INVALID_BUNDLE; + } return CommonRequestEnableNotification("", nullptr, nullptr, bundleOption, true); } @@ -899,6 +903,10 @@ ErrCode AdvancedNotificationService::CommonRequestEnableNotification(const std:: const bool innerLake) { ANS_LOGI("%{public}s", __FUNCTION__); + if (bundleOption == nullptr) { + ANS_LOGE("bundleOption is nullptr."); + return ERR_ANS_INVALID_BUNDLE; + } ErrCode result = ERR_OK; // To get the permission bool allowedNotify = false; -- Gitee From 8807223b2d153b1457683e56b8535bba78f8dd45 Mon Sep 17 00:00:00 2001 From: xdongs2009 Date: Wed, 26 Mar 2025 03:55:30 +0000 Subject: [PATCH 8/8] update services/ans/include/advanced_notification_service.h. Signed-off-by: xdongs2009 --- services/ans/include/advanced_notification_service.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 6157713d3..d277446c0 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1473,7 +1473,7 @@ private: const sptr &slot, const sptr &bundle, bool enabled, bool isForceControl); - + void ClearSlotTypeData(const sptr &request, int32_t callingUid); ErrCode CommonRequestEnableNotification(const std::string &deviceId, const sptr &callback, const sptr &callerToken, -- Gitee