From 98ad667ff14fa95a839d6b775f30c9e34d18cbd0 Mon Sep 17 00:00:00 2001 From: markYao Date: Sun, 22 Oct 2023 18:03:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E5=AE=9E=E5=86=B5=E7=AA=97?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A4=B4=E6=96=87=E4=BB=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: markYao --- ...ans_subscriber_local_live_view_interface.h | 55 ++++++++ .../ans_subscriber_local_live_view_proxy.h | 69 ++++++++++ .../ans_subscriber_local_live_view_stub.h | 67 ++++++++++ .../napi/include/local_live_view_subscribe.h | 106 +++++++++++++++ .../include/manager/napi_local_live_view.h | 30 +++++ .../inner_api/notification_button_option.h | 98 ++++++++++++++ interfaces/inner_api/notification_capsule.h | 117 +++++++++++++++++ .../notification_local_live_view_button.h | 106 +++++++++++++++ .../notification_local_live_view_content.h | 121 ++++++++++++++++++ .../notification_local_live_view_subscriber.h | 96 ++++++++++++++ interfaces/inner_api/notification_progress.h | 113 ++++++++++++++++ ...ation_local_live_view_subscriber_manager.h | 116 +++++++++++++++++ 12 files changed, 1094 insertions(+) create mode 100644 frameworks/core/include/ans_subscriber_local_live_view_interface.h create mode 100644 frameworks/core/include/ans_subscriber_local_live_view_proxy.h create mode 100644 frameworks/core/include/ans_subscriber_local_live_view_stub.h create mode 100644 frameworks/js/napi/include/local_live_view_subscribe.h create mode 100644 frameworks/js/napi/include/manager/napi_local_live_view.h create mode 100644 interfaces/inner_api/notification_button_option.h create mode 100644 interfaces/inner_api/notification_capsule.h create mode 100644 interfaces/inner_api/notification_local_live_view_button.h create mode 100644 interfaces/inner_api/notification_local_live_view_content.h create mode 100644 interfaces/inner_api/notification_local_live_view_subscriber.h create mode 100644 interfaces/inner_api/notification_progress.h create mode 100644 services/ans/include/notification_local_live_view_subscriber_manager.h diff --git a/frameworks/core/include/ans_subscriber_local_live_view_interface.h b/frameworks/core/include/ans_subscriber_local_live_view_interface.h new file mode 100644 index 000000000..3cd6acbd7 --- /dev/null +++ b/frameworks/core/include/ans_subscriber_local_live_view_interface.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2021-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_LOCAL_LIVE_VIEW_SUBSCRIBER_INTERFACE_H +#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_LOCAL_LIVE_VIEW_SUBSCRIBER_INTERFACE_H + +#include "iremote_broker.h" + +#include "badge_number_callback_data.h" +#include "enabled_notification_callback_data.h" +#include "notification.h" +#include "notification_constant.h" +#include "notification_do_not_disturb_date.h" +#include "notification_request.h" +#include "notification_sorting.h" +#include "notification_sorting_map.h" + +namespace OHOS { +namespace Notification { +class AnsSubscriberLocalLiveViewInterface : public IRemoteBroker { +public: + AnsSubscriberLocalLiveViewInterface() = default; + virtual ~AnsSubscriberLocalLiveViewInterface() override = default; + DISALLOW_COPY_AND_MOVE(AnsSubscriberLocalLiveViewInterface); + + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Notification.AnsSubscriberLocalLiveViewInterface"); + + /** + * @brief The callback function for the subscriber to establish a connection. + */ + virtual void OnConnected() = 0; + + /** + * @brief The callback function for subscriber disconnected. + */ + virtual void OnDisconnected() = 0; + + virtual void OnResponse(int32_t notificationId, sptr buttonOption) = 0; +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_LOCAL_LIVE_VIEW_SUBSCRIBER_INTERFACE_H diff --git a/frameworks/core/include/ans_subscriber_local_live_view_proxy.h b/frameworks/core/include/ans_subscriber_local_live_view_proxy.h new file mode 100644 index 000000000..b7d3fbdcf --- /dev/null +++ b/frameworks/core/include/ans_subscriber_local_live_view_proxy.h @@ -0,0 +1,69 @@ +/* + * 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. + */ + +#ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_LIVE_VIEW_PROXY_H +#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_LIVE_VIEW_PROXY_H + +#include "ans_subscriber_local_live_view_interface.h" +#include "distributed_notification_service_ipc_interface_code.h" +#include "iremote_proxy.h" + +namespace OHOS { +namespace Notification { +class AnsSubscriberLocalLiveViewProxy : public IRemoteProxy { +public: + AnsSubscriberLocalLiveViewProxy() = delete; + explicit AnsSubscriberLocalLiveViewProxy(const sptr &impl); + ~AnsSubscriberLocalLiveViewProxy() override; + DISALLOW_COPY_AND_MOVE(AnsSubscriberLocalLiveViewProxy); + + /** + * @brief The callback function for the subscriber to establish a connection. + */ + void OnConnected() override; + + /** + * @brief The callback function for subscriber disconnected. + */ + void OnDisconnected() override; + + void OnResponse(int32_t notificationId, sptr buttonOption) override; + +private: + ErrCode InnerTransact(NotificationInterfaceCode code, + MessageOption &flags, MessageParcel &data, MessageParcel &reply); + static inline BrokerDelegator delegator_; + + template + bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &data) + { + if (!data.WriteInt32(parcelableVector.size())) { + ANS_LOGE("write ParcelableVector size failed"); + return false; + } + + for (auto &parcelable : parcelableVector) { + if (!data.WriteStrongParcelable(parcelable)) { + ANS_LOGE("write ParcelableVector failed"); + return false; + } + } + return true; + } +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_LIVE_VIEW_PROXY_H diff --git a/frameworks/core/include/ans_subscriber_local_live_view_stub.h b/frameworks/core/include/ans_subscriber_local_live_view_stub.h new file mode 100644 index 000000000..63e9080ca --- /dev/null +++ b/frameworks/core/include/ans_subscriber_local_live_view_stub.h @@ -0,0 +1,67 @@ +/* + * 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. + */ + +#ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_LIVE_VIEW_STUB_H +#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_LIVE_VIEW_STUB_H + +#include "ans_subscriber_local_live_view_interface.h" +#include "distributed_notification_service_ipc_interface_code.h" +#include "iremote_stub.h" + +namespace OHOS { +namespace Notification { +class AnsSubscriberLocalLiveViewStub : public IRemoteStub { +public: + AnsSubscriberLocalLiveViewStub(); + ~AnsSubscriberLocalLiveViewStub() override; + DISALLOW_COPY_AND_MOVE(AnsSubscriberLocalLiveViewStub); + + /** + * @brief Handle remote request. + * + * @param data Indicates the input parcel. + * @param reply Indicates the output parcel. + * @param option Indicates the message option. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + + /** + * @brief The callback function for the subscriber to establish a connection. + */ + void OnConnected() override; + + /** + * @brief The callback function for subscriber disconnected. + */ + void OnDisconnected() override; + + void OnResponse(int32_t notificationId, sptr buttonOption) override; + +private: + std::map> interfaces_; + + ErrCode HandleOnConnected(MessageParcel &data, MessageParcel &reply); + ErrCode HandleOnDisconnected(MessageParcel &data, MessageParcel &reply); + ErrCode HandleOnResponse(MessageParcel &data, MessageParcel &reply); + + template + bool ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &data); +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_LIVE_VIEW_STUB_H diff --git a/frameworks/js/napi/include/local_live_view_subscribe.h b/frameworks/js/napi/include/local_live_view_subscribe.h new file mode 100644 index 000000000..42d5928d8 --- /dev/null +++ b/frameworks/js/napi/include/local_live_view_subscribe.h @@ -0,0 +1,106 @@ +/* + * 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. + */ +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_INCLUDE_SUBSCRIBE_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_INCLUDE_SUBSCRIBE_H + +#include "common.h" +#include "notification_bundle_option.h" + +namespace OHOS { +namespace NotificationNapi { +using namespace OHOS::Notification; + +class LocalLiveViewSubscriberInstance : public NotificationLocalLiveViewSubscriber { +public: + LocalLiveViewSubscriberInstance(); + virtual ~LocalLiveViewSubscriberInstance(); + + /** + * @brief Called back when a notification is canceled. + * + */ + virtual void OnConnected() override; + + /** + * @brief Called back when the subscriber is disconnected from the ANS. + * + */ + virtual void OnDisconnected() override; + + virtual void OnResponse(int32_t notificationId, sptr buttonOption) override; + + /** + * @brief Called back when connection to the ANS has died. + * + */ + virtual void OnDied() override; + + /** + * @brief Sets the callback information by type. + * + * @param env Indicates the environment that the API is invoked under. + * @param type Indicates the type of callback. + * @param ref Indicates the napi_ref of callback. + */ + void SetCallbackInfo(const napi_env &env, const std::string &type, const napi_ref &ref); + +private: + void SetResponseCallbackInfo(const napi_env &env, const napi_ref &ref); + +private: + struct CallbackInfo { + napi_env env = nullptr; + napi_ref ref = nullptr; + }; + + CallbackInfo responseCallbackInfo_; +}; + +struct LocalLiveViewSubscriberInstancesInfo { + napi_ref ref = nullptr; + LocalLiveViewSubscriberInstance *subscriber = nullptr; +}; + +struct AsyncCallbackInfoSubscribeLocalLiveView { + napi_env env = nullptr; + napi_async_work asyncWork = nullptr; + LocalLiveViewSubscriberInstance *objectInfo = nullptr; + NotificationBundleOption bundleOption; + NotificationButtonOption buttonOption; + int32_t notificationId; + CallbackPromiseInfo info; +}; + +static std::mutex mutex_; +static thread_local std::vector subscriberInstances_; + +static std::mutex delMutex_; +static std::vector DeletingSubscriber; + +bool HasNotificationSubscriber(const napi_env &env, + const napi_value &value, LocalLiveViewSubscriberInstancesInfo &subscriberInfo); +bool AddSubscriberInstancesInfo(const napi_env &env, const LocalLiveViewSubscriberInstancesInfo &subscriberInfo); +bool DelSubscriberInstancesInfo(const napi_env &env, const LocalLiveViewSubscriberInstance *subscriber); + +bool AddDeletingSubscriber(LocalLiveViewSubscriberInstance *subscriber); +void DelDeletingSubscriber(LocalLiveViewSubscriberInstance *subscriber); + +napi_value Subscribe(napi_env env, napi_callback_info info); + +napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, + LocalLiveViewSubscriberInstance *&subscriber, napi_ref &callback); +} // namespace NotificationNapi +} // namespace OHOS +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_INCLUDE_SUBSCRIBE_H diff --git a/frameworks/js/napi/include/manager/napi_local_live_view.h b/frameworks/js/napi/include/manager/napi_local_live_view.h new file mode 100644 index 000000000..5e11c62b0 --- /dev/null +++ b/frameworks/js/napi/include/manager/napi_local_live_view.h @@ -0,0 +1,30 @@ +/* + * 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_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_LOCAL_LIVE_VIEW_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_LOCAL_LIVE_VIEW_H + +#include "common.h" + +namespace OHOS { +namespace NotificationNapi { +using namespace OHOS::Notification; + +napi_value NapiSubscriteLocalAcitvity(napi_env env, napi_callback_info info); +napi_value NapiUnsubscriteLocalLiveView(napi_env env, napi_callback_info info); +napi_value NapiTriggerLocalLiveView(napi_env env, napi_callback_info info); + +} // namespace NotificationNapi +} // namespace OHOS +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_LOCAL_LIVE_VIEW_H diff --git a/interfaces/inner_api/notification_button_option.h b/interfaces/inner_api/notification_button_option.h new file mode 100644 index 000000000..7bdc1e660 --- /dev/null +++ b/interfaces/inner_api/notification_button_option.h @@ -0,0 +1,98 @@ +/* + * 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_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_BUTTON_OPTION_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_BUTTON_OPTION_H + +#include "notification_json_convert.h" +#include "parcel.h" + +namespace OHOS { +namespace Notification { +class NotificationButtonOption : public Parcelable, public NotificationJsonConvertionBase { +public: + NotificationButtonOption() = default; + + ~NotificationButtonOption() = default; + + /** + * @brief Sets devices that support display. + * + * @param devices Indicates the devices that support display. + */ + void SetButtonName(const std::string &buttonName); + + /** + * @brief Obtains the devices that support display. + * + * @return Returns the devices that support display. + */ + std::string GetButtonName() const; + + /** + * @brief Returns a string representation of the object. + * + * @return Returns a string representation of the object. + */ + std::string Dump(); + + /** + * @brief Converts a NotificationButtonOptions object into a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ToJson(nlohmann::json &jsonObject) const override; + + /** + * @brief Creates a NotificationButtonOptions object from a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns the NotificationButtonOptions. + */ + static NotificationButtonOption *FromJson(const nlohmann::json &jsonObject); + + /** + * @brief Marshal a object into a Parcel. + * + * @param parcel Indicates the object into the parcel. + * @return Returns true if succeed; returns false otherwise. + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Unmarshal object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns the NotificationButtonOptions object. + */ + static NotificationButtonOption *Unmarshalling(Parcel &parcel); + +private: + /** + * @brief Read a NotificationButtonOptions object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ReadFromParcel(Parcel &parcel); + +private: + std::string buttonName_ {}; +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_BUTTON_OPTION_H \ No newline at end of file diff --git a/interfaces/inner_api/notification_capsule.h b/interfaces/inner_api/notification_capsule.h new file mode 100644 index 000000000..3d77ff434 --- /dev/null +++ b/interfaces/inner_api/notification_capsule.h @@ -0,0 +1,117 @@ +/* + * 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. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_CAPSULE_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_CAPSULE_H + +#include "foundation/multimedia/image_framework/interfaces/innerkits/include/pixel_map.h" +#include "notification_json_convert.h" +#include "parcel.h" +#include + +namespace OHOS { +namespace Notification { +class NotificationCapsule : public Parcelable, public NotificationJsonConvertionBase { +public: + NotificationCapsule() = default; + + ~NotificationCapsule() = default; + + /** + * @brief Obtains the text to be displayed as the content of this message. + * + * @return Returns the message content. + */ + std::string GetTitle() const; + + void SetTitle(const std::string &title); + + /** + * @brief Obtains the time when this message arrived. + * + * @return Returns the time when this message arrived. + */ + const std::shared_ptr GetIcon() const; + + void SetIcon(const std::shared_ptr &icon); + + /** + * @brief Obtains the sender of this message. + * + * @return Returns the message sender. + */ + std::string GetBackgroundColor() const; + + void SetBackgroundColor(const std::string &color); + + + /** + * @brief Returns a string representation of the object. + * + * @return Returns a string representation of the object. + */ + std::string Dump(); + + /** + * @brief Converts a NotificationConversationalMessage object into a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ToJson(nlohmann::json &jsonObject) const override; + + /** + * @brief Creates a NotificationConversationalMessage object from a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns the NotificationConversationalMessage. + */ + static NotificationCapsule *FromJson(const nlohmann::json &jsonObject); + + /** + * @brief Marshal a object into a Parcel. + * + * @param parcel Indicates the object into the parcel. + * @return Returns true if succeed; returns false otherwise. + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Unmarshal object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns the NotificationConversationalMessage. + */ + static NotificationCapsule *Unmarshalling(Parcel &parcel); + +private: + + /** + * @brief Read a NotificationConversationalMessage object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ReadFromParcel(Parcel &parcel); + +private: + std::string title_ {}; + std::shared_ptr icon_ {}; + std::string backgroundColor_ {}; +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_CAPSULE_H \ No newline at end of file diff --git a/interfaces/inner_api/notification_local_live_view_button.h b/interfaces/inner_api/notification_local_live_view_button.h new file mode 100644 index 000000000..1fddaa952 --- /dev/null +++ b/interfaces/inner_api/notification_local_live_view_button.h @@ -0,0 +1,106 @@ +/* + * 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. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_LIVE_VIEW_BUTTON_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_LIVE_VIEW_BUTTON_H + +#include "base/notification/distributed_notification_service/interfaces/inner_api/notification_button_option.h" +#include "foundation/multimedia/image_framework/interfaces/innerkits/include/pixel_map.h" +#include "message_user.h" +#include "notification_json_convert.h" +#include "parcel.h" +#include "uri.h" +#include + +namespace OHOS { +namespace Notification { +class NotificationLocalLiveViewButton : public Parcelable, public NotificationJsonConvertionBase { +public: + NotificationLocalLiveViewButton() = default; + ~NotificationLocalLiveViewButton() = default; + + /** + * @brief Obtains the text to be displayed as the content of this message. + * + * @return Returns the message content. + */ + std::vector GetAllButtonNames() const; + + void addSingleButtonName(const std::string &buttonName); + + /** + * @brief Obtains the time when this message arrived. + * + * @return Returns the time when this message arrived. + */ + std::vector> GetAllButtonIcon() const; + + void addSingleButtonIcon(std::shared_ptr &icon); + + /** + * @brief Returns a string representation of the object. + * + * @return Returns a string representation of the object. + */ + std::string Dump(); + + /** + * @brief Converts a NotificationConversationalMessage object into a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ToJson(nlohmann::json &jsonObject) const override; + + /** + * @brief Creates a NotificationConversationalMessage object from a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns the NotificationConversationalMessage. + */ + static NotificationLocalLiveViewButton *FromJson(const nlohmann::json &jsonObject); + + /** + * @brief Marshal a object into a Parcel. + * + * @param parcel Indicates the object into the parcel. + * @return Returns true if succeed; returns false otherwise. + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Unmarshal object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns the NotificationConversationalMessage. + */ + static NotificationLocalLiveViewButton *Unmarshalling(Parcel &parcel); + +private: + /** + * @brief Read a NotificationConversationalMessage object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ReadFromParcel(Parcel &parcel); + + std::vector buttonNames_ {}; + std::vector> buttonIcons_ {}; +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_LIVE_VIEW_BUTTON_H \ No newline at end of file diff --git a/interfaces/inner_api/notification_local_live_view_content.h b/interfaces/inner_api/notification_local_live_view_content.h new file mode 100644 index 000000000..06c1eb868 --- /dev/null +++ b/interfaces/inner_api/notification_local_live_view_content.h @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2021-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_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_LIVE_VIEW_CONTENT_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_LIVE_VIEW_CONTENT_H + +#include "base/notification/distributed_notification_service/interfaces/inner_api/notification_capsule.h" +#include "base/notification/distributed_notification_service/interfaces/inner_api/notification_progress.h" +#include "base/notification/distributed_notification_service/interfaces/inner_api/notification_local_live_view_button.h" +#include "message_user.h" +#include "notification_basic_content.h" +#include "notification_conversational_message.h" +#include "notification_json_convert.h" +#include "parcel.h" + +namespace OHOS { +namespace Notification { +class NotificationLocalLiveViewContent : public NotificationBasicContent { +public: + NotificationLocalLiveViewContent() = default; + ~NotificationLocalLiveViewContent() = default; + + /* + * @brief Sets the type to be included in a local live view notification. + * + * @param type Indicates the type to be included. + */ + void SetType(int32_t type); + + /* + * @brief Sets the capsule to be included in a local live view notification. + * + * @param capsule Indicates the type to be included. + */ + void SetCapsule(NotificationCapsule capsule); + + /* + * @brief Sets the button to be included in a local live view notification. + * + * @param button Indicates the type to be included. + */ + void SetButton(NotificationLocalLiveViewButton button); + + /* + * @brief Sets the progress to be included in a local live view notification. + * + * @param progress Indicates the type to be included. + + */ + void SetProgress(NotificationProgress progress); + + /** + * @brief Returns a string representation of the object. + * + * @return Returns a string representation of the object. + */ + std::string Dump() override; + + /** + * @brief Converts a NotificationConversationalContent object into a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns true if succeed; returns false otherwise. + */ + virtual bool ToJson(nlohmann::json &jsonObject) const override; + + /** + * @brief Creates a NotificationConversationalContent object from a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns the NotificationConversationalContent. + */ + static NotificationLocalLiveViewContent *FromJson(const nlohmann::json &jsonObject); + + /** + * @brief Marshal a object into a Parcel. + * + * @param parcel Indicates the object into the parcel. + * @return Returns true if succeed; returns false otherwise. + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Unmarshal object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns the NotificationConversationalContent. + */ + static NotificationLocalLiveViewContent *Unmarshalling(Parcel &parcel); + +protected: + /** + * @brief Read a NotificationConversationalContent object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ReadFromParcel(Parcel &parcel) override; + +private: + int32_t type_ {0}; + NotificationCapsule capsule_ {}; + NotificationLocalLiveViewButton button_ {}; + NotificationProgress progress_ {}; +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_CONVERSATIONAL_CONTENT_H \ No newline at end of file diff --git a/interfaces/inner_api/notification_local_live_view_subscriber.h b/interfaces/inner_api/notification_local_live_view_subscriber.h new file mode 100644 index 000000000..900b3eff8 --- /dev/null +++ b/interfaces/inner_api/notification_local_live_view_subscriber.h @@ -0,0 +1,96 @@ +/* + * 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. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_LOCAL_LIVE_VIEW_SUBSCRIBER_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_LOCAL_LIVE_VIEW_SUBSCRIBER_H + +#include "ans_manager_interface.h" +#include "ans_subscriber_stub.h" +#include "ans_subscriber_local_live_view_stub.h" +#include "notification_request.h" +#include "notification_sorting.h" +#include "notification_sorting_map.h" + +namespace OHOS { +namespace Notification { +class NotificationLocalLiveViewSubscriber { +public: + NotificationLocalLiveViewSubscriber(); + + virtual ~NotificationLocalLiveViewSubscriber(); + + /** + * @brief Called back when the subscriber is connected to the Advanced Notification Service (ANS). + **/ + virtual void OnConnected() = 0; + + /** + * @brief Called back when the subscriber is disconnected from the ANS. + **/ + virtual void OnDisconnected() = 0; + + virtual void OnResponse(int32_t notificationId, sptr buttonOption) = 0; + + /** + * @brief Called back when connection to the ANS has died. + **/ + virtual void OnDied() = 0; + +private: + class SubscriberLocalLiveViewImpl final : public AnsSubscriberLocalLiveViewStub { + public: + class DeathRecipient final : public IRemoteObject::DeathRecipient { + public: + DeathRecipient(SubscriberLocalLiveViewImpl &subscriberImpl); + + ~DeathRecipient(); + + void OnRemoteDied(const wptr &object) override; + + private: + SubscriberLocalLiveViewImpl &subscriberImpl_; + }; + + public: + SubscriberLocalLiveViewImpl(NotificationLocalLiveViewSubscriber &subscriber); + ~SubscriberLocalLiveViewImpl() {}; + + void OnConnected() override; + + void OnDisconnected() override; + + void OnResponse(int32_t notificationId, sptr buttonOption) override; + + bool GetAnsManagerProxy(); + + public: + NotificationLocalLiveViewSubscriber &subscriber_; + sptr recipient_ {nullptr}; + sptr proxy_ {nullptr}; + std::mutex mutex_ {}; + }; + +private: + const sptr GetImpl() const; + +private: + sptr impl_ = nullptr; + + friend class AnsNotification; +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_LOCAL_LIVE_VIEW_SUBSCRIBER_H \ No newline at end of file diff --git a/interfaces/inner_api/notification_progress.h b/interfaces/inner_api/notification_progress.h new file mode 100644 index 000000000..ef2e179ff --- /dev/null +++ b/interfaces/inner_api/notification_progress.h @@ -0,0 +1,113 @@ +/* + * 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. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_PROGRESS_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_PROGRESS_H + +#include "notification_json_convert.h" +#include "parcel.h" +#include + +namespace OHOS { +namespace Notification { +class NotificationProgress : public Parcelable, public NotificationJsonConvertionBase { +public: + NotificationProgress() = default; + ~NotificationProgress() = default; + + /** + * @brief Obtains the text to be displayed as the content of this message. + * + * @return Returns the message content. + */ + int32_t GetMaxValue() const; + + void SetMaxValue(int32_t maxValue); + + /** + * @brief Obtains the time when this message arrived. + * + * @return Returns the time when this message arrived. + */ + int32_t GetCurrentValue() const; + + void SetCurrentValue(int32_t curValue); + + /** + * @brief Obtains the sender of this message. + * + * @return Returns the message sender. + */ + int32_t GetIsPercentage() const; + + void SetIsPercentage(int32_t isPercentage); + + /** + * @brief Returns a string representation of the object. + * + * @return Returns a string representation of the object. + */ + std::string Dump(); + + /** + * @brief Converts a NotificationConversationalMessage object into a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ToJson(nlohmann::json &jsonObject) const override; + + /** + * @brief Creates a NotificationConversationalMessage object from a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns the NotificationConversationalMessage. + */ + static NotificationProgress *FromJson(const nlohmann::json &jsonObject); + + /** + * @brief Marshal a object into a Parcel. + * + * @param parcel Indicates the object into the parcel. + * @return Returns true if succeed; returns false otherwise. + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Unmarshal object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns the NotificationConversationalMessage. + */ + static NotificationProgress *Unmarshalling(Parcel &parcel); + +private: + /** + * @brief Read a NotificationConversationalMessage object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ReadFromParcel(Parcel &parcel); + +private: + int32_t maxValue_ {0}; + int32_t currentValue_ {0}; + int32_t isPercentage_ {0}; +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_PROGRESS_H \ No newline at end of file diff --git a/services/ans/include/notification_local_live_view_subscriber_manager.h b/services/ans/include/notification_local_live_view_subscriber_manager.h new file mode 100644 index 000000000..a492f858c --- /dev/null +++ b/services/ans/include/notification_local_live_view_subscriber_manager.h @@ -0,0 +1,116 @@ +/* + * 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. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_LOCAL_LIVE_VIEW_SUBSCRIBER_LOCAL_LIVE_VIEW_MANAGER_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_LOCAL_LIVE_VIEW_SUBSCRIBER_LOCAL_LIVE_VIEW_MANAGER_H + +#include +#include +#include + +#include "errors.h" +#include "event_handler.h" +#include "event_runner.h" +#include "ffrt.h" +#include "nocopyable.h" +#include "refbase.h" +#include "singleton.h" + +#include "ans_subscriber_local_live_view_interface.h" +#include "notification_bundle_option.h" +#include "notification_constant.h" +#include "notification_request.h" +#include "notification_sorting_map.h" +#include "notification_subscribe_info.h" + +namespace OHOS { +namespace Notification { +class NotificationLocalLiveViewSubscriberManager : public DelayedSingleton { +public: + /** + * @brief Add a subscriber. + * + * @param subscriber Indicates the AnsSubscriberInterface object. + * @param subscribeInfo Indicates the NotificationSubscribeInfo object. + * @return Indicates the result code. + */ + ErrCode AddLocalLiveViewSubscriber(const sptr &subscriber, + const sptr &subscribeInfo); + + /** + * @brief Remove a subscriber. + * + * @param subscriber Indicates the AnsSubscriberInterface object. + * @param subscribeInfo Indicates the NotificationSubscribeInfo object. + * @return Indicates the result code. + */ + ErrCode RemoveLocalLiveViewSubscriber(const sptr &subscriber, + const sptr &subscribeInfo); + + /** + * @brief Notify all subscribers on canceled. + * + * @param notification Indicates the Notification object. + * @param buttonOption Indicates the buttonOption object. + */ + void NotifyTriggerResponse(const sptr ¬ification, + const sptr &buttonOption); + + /** + * @brief Obtains the death event. + * + * @param object Indicates the death object. + */ + void OnRemoteDied(const wptr &object); + + /** + * @brief Reset ffrt queue + */ + void ResetFfrtQueue(); + +private: + struct LocalLiveViewSubscriberRecord; + + std::shared_ptr FindSubscriberRecord(const wptr &object); + std::shared_ptr FindSubscriberRecord( + const sptr &subscriber); + std::shared_ptr CreateSubscriberRecord( + const sptr &subscriber, + const sptr &bundleOption); + + ErrCode AddSubscriberInner(const sptr &subscriber, + const sptr &bundleOption); + ErrCode RemoveSubscriberInner(const sptr &subscriber, + const sptr &subscribeInfo); + + void NotifyTriggerResponseInner(const sptr ¬ification, + sptr buttonOption); + bool IsSystemUser(int32_t userId); + +private: + std::list> buttonRecordList_ {}; + std::shared_ptr runner_ {}; + std::shared_ptr handler_ {}; + sptr ansSubscriberProxy_ {}; + sptr recipient_ {}; + std::shared_ptr notificationButtonQueue_ = nullptr; + + DECLARE_DELAYED_SINGLETON(NotificationLocalLiveViewSubscriberManager); + DISALLOW_COPY_AND_MOVE(NotificationLocalLiveViewSubscriberManager); +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_LOCAL_LIVE_VIEW_SUBSCRIBER_LOCAL_LIVE_VIEW_MANAGER_H \ No newline at end of file -- Gitee