diff --git a/frameworks/ans/BUILD.gn b/frameworks/ans/BUILD.gn index 92524efdd91bf18d073632e82d23ec4e3ff55ade..20eb039f1d7bb04d74c7f54a313489696a70ae9d 100644 --- a/frameworks/ans/BUILD.gn +++ b/frameworks/ans/BUILD.gn @@ -54,6 +54,8 @@ ohos_shared_library("ans_innerkits") { "${core_path}/src/ans_manager_proxy.cpp", "${core_path}/src/ans_manager_stub.cpp", "${core_path}/src/ans_notification.cpp", + "${core_path}/src/ans_subscriber_local_activity_proxy.cpp", + "${core_path}/src/ans_subscriber_local_activity_stub.cpp", "${core_path}/src/ans_subscriber_proxy.cpp", "${core_path}/src/ans_subscriber_stub.cpp", "${frameworks_module_ans_path}/src/badge_number_callback_data.cpp", @@ -76,6 +78,7 @@ ohos_shared_library("ans_innerkits") { "${frameworks_module_ans_path}/src/notification_multiline_content.cpp", "${frameworks_module_ans_path}/src/notification_normal_content.cpp", "${frameworks_module_ans_path}/src/notification_picture_content.cpp", + "${frameworks_module_ans_path}/src/notification_progress.cpp", "${frameworks_module_ans_path}/src/notification_request.cpp", "${frameworks_module_ans_path}/src/notification_slot.cpp", "${frameworks_module_ans_path}/src/notification_sorting.cpp", diff --git a/frameworks/ans/src/notification_progress.cpp b/frameworks/ans/src/notification_progress.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2b051c05ea028df52ebc74127a74b8453379db9a --- /dev/null +++ b/frameworks/ans/src/notification_progress.cpp @@ -0,0 +1,148 @@ +/* + * 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 "notification_progress.h" + +#include +#include // for basic_string, operator+, basic_string<>... +#include // for shared_ptr, shared_ptr<>::element_type + + +#include "ans_log_wrapper.h" +#include "nlohmann/json.hpp" // for json, basic_json<>::object_t, basic_json +#include "parcel.h" // for Parcel + +namespace OHOS { +namespace Notification { + +int32_t NotificationProgress::GetMaxValue() const +{ + return maxValue_; +} + +void NotificationProgress::SetMaxValue(int32_t maxValue) +{ + maxValue_ = maxValue; +} + +int32_t NotificationProgress::GetCurrentValue() const +{ + return currentValue_; +} + +void NotificationProgress::SetCurrentValue(int32_t curValue) +{ + currentValue_ = curValue; +} + +int32_t NotificationProgress::GetIsPercentage() const +{ + return isPercentage_; +} + +void NotificationProgress::SetIsPercentage(int32_t isPercentage) +{ + isPercentage_ = isPercentage; +} + + +std::string NotificationProgress::Dump() +{ + return "Progress{ " + "maxValue = " + std::to_string(maxValue_) + + ", currentValue = " + std::to_string(currentValue_) + + ", isPercentage = " + std::to_string(isPercentage_) + + " }"; +} + +bool NotificationProgress::ToJson(nlohmann::json &jsonObject) const +{ + jsonObject["maxValue"] = maxValue_; + jsonObject["currentValue"] = currentValue_; + jsonObject["isPercentage"] = isPercentage_; + + return true; +} + +NotificationProgress *NotificationProgress::FromJson(const nlohmann::json &jsonObject) +{ + if (jsonObject.is_null() or !jsonObject.is_object()) { + ANS_LOGE("Invalid JSON object"); + return nullptr; + } + + NotificationProgress *progress = new (std::nothrow) NotificationProgress(); + if (progress == nullptr) { + ANS_LOGE("Failed to create capsule instance"); + return nullptr; + } + + const auto &jsonEnd = jsonObject.cend(); + if (jsonObject.find("maxValue") != jsonEnd && jsonObject.at("maxValue").is_number_integer()) { + progress->maxValue_ = jsonObject.at("maxValue").get(); + } + + if (jsonObject.find("currentValue") != jsonEnd && jsonObject.at("currentValue").is_number_integer()) { + progress->currentValue_ = jsonObject.at("currentValue").get(); + } + + if (jsonObject.find("isPercentage") != jsonEnd && jsonObject.at("isPercentage").is_number_integer()) { + progress->isPercentage_ = jsonObject.at("isPercentage_").get(); + } + + return progress; +} + +bool NotificationProgress::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteInt32(maxValue_)) { + ANS_LOGE("Failed to write maxValue"); + return false; + } + + if (!parcel.WriteInt32(currentValue_)) { + ANS_LOGE("Failed to write currentValue"); + return false; + } + + if (!parcel.WriteInt32(isPercentage_)) { + ANS_LOGE("Failed to write isPercentage"); + return false; + } + return true; +} + +bool NotificationProgress::ReadFromParcel(Parcel &parcel) +{ + maxValue_ = parcel.ReadInt32(); + currentValue_ = parcel.ReadInt32(); + isPercentage_ = parcel.ReadInt32(); + + return true; +} + +NotificationProgress *NotificationProgress::Unmarshalling(Parcel &parcel) +{ + NotificationProgress *progress = new (std::nothrow) NotificationProgress(); + + if (progress && !progress->ReadFromParcel(parcel)) { + delete progress; + progress = nullptr; + } + + return progress; +} +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/core/include/ans_subscriber_local_activity_interface.h b/frameworks/core/include/ans_subscriber_local_activity_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..16dc610a6d66b4c76dfe6e8bc4d8aabc0173a3f1 --- /dev/null +++ b/frameworks/core/include/ans_subscriber_local_activity_interface.h @@ -0,0 +1,59 @@ +/* + * 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_ACTIVITY_SUBSCRIBER_INTERFACE_H +#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_LOCAL_ACTIVITY_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 AnsSubscriberLocalActivityInterface : public IRemoteBroker { +public: + AnsSubscriberLocalActivityInterface() = default; + virtual ~AnsSubscriberLocalActivityInterface() override = default; + DISALLOW_COPY_AND_MOVE(AnsSubscriberLocalActivityInterface); + + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Notification.AnsSubscriberLocalActivityInterface"); + + /** + * @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; + + /** + * @brief The callback function for subscriber button click. + */ + virtual void OnResponse(int32_t notificationId, const sptr &buttonOption) = 0; + +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_LOCAL_ACTIVITY_SUBSCRIBER_INTERFACE_H diff --git a/frameworks/core/include/ans_subscriber_local_activity_proxy.h b/frameworks/core/include/ans_subscriber_local_activity_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..9eeb28b2c33c54fb7be2a85d8ac51d60a035b1ac --- /dev/null +++ b/frameworks/core/include/ans_subscriber_local_activity_proxy.h @@ -0,0 +1,71 @@ +/* + * 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_SYSTEM_ACTIVITY_PROXY_H +#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_SYSTEM_ACTIVITY_PROXY_H + +#include "ans_subscriber_local_activity_interface.h" +#include "distributed_notification_service_ipc_interface_code.h" +#include "iremote_proxy.h" + +namespace OHOS { +namespace Notification { +class AnsSubscriberLocalActivityProxy : public IRemoteProxy { +public: + AnsSubscriberLocalActivityProxy() = delete; + explicit AnsSubscriberLocalActivityProxy(const sptr &impl); + ~AnsSubscriberLocalActivityProxy() override; + DISALLOW_COPY_AND_MOVE(AnsSubscriberLocalActivityProxy); + + /** + * @brief The callback function for the subscriber to establish a connection. + */ + void OnConnected() override; + + /** + * @brief The callback function for subscriber disconnected. + */ + void OnDisconnected() override; + + /** + * @brief The callback function for subscriber button click. + */ + void OnResponse(int32_t notificationId, const 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_SYSTEM_ACTIVITY_PROXY_H diff --git a/frameworks/core/include/ans_subscriber_local_activity_stub.h b/frameworks/core/include/ans_subscriber_local_activity_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..12d8d140974d8fc02b5d250d8a456f9ca3b37a4c --- /dev/null +++ b/frameworks/core/include/ans_subscriber_local_activity_stub.h @@ -0,0 +1,70 @@ +/* + * 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_ACTIVITY_STUB_H +#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_ACTIVITY_STUB_H + +#include "ans_subscriber_local_activity_interface.h" +#include "distributed_notification_service_ipc_interface_code.h" +#include "iremote_stub.h" + +namespace OHOS { +namespace Notification { +class AnsSubscriberLocalActivityStub : public IRemoteStub { +public: + AnsSubscriberLocalActivityStub(); + ~AnsSubscriberLocalActivityStub() override; + DISALLOW_COPY_AND_MOVE(AnsSubscriberLocalActivityStub); + + /** + * @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; + + /** + * @brief The callback function for subscriber button click. + */ + void OnResponse(int32_t notificationId, const 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_ACTIVITY_STUB_H diff --git a/frameworks/core/src/ans_subscriber_local_activity_proxy.cpp b/frameworks/core/src/ans_subscriber_local_activity_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b3227bb73b7de130d0708fc7ee1a2bf9708aeffb --- /dev/null +++ b/frameworks/core/src/ans_subscriber_local_activity_proxy.cpp @@ -0,0 +1,118 @@ +/* + * 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. + */ + +#include "ans_subscriber_local_activity_proxy.h" + +#include "ans_inner_errors.h" +#include "ans_log_wrapper.h" +#include "message_option.h" +#include "message_parcel.h" + +namespace OHOS { +namespace Notification { +AnsSubscriberLocalActivityProxy::AnsSubscriberLocalActivityProxy(const sptr &impl) : IRemoteProxy(impl) +{} + +AnsSubscriberLocalActivityProxy::~AnsSubscriberLocalActivityProxy() +{} + +ErrCode AnsSubscriberLocalActivityProxy::InnerTransact( + NotificationInterfaceCode code, MessageOption &flags, MessageParcel &data, MessageParcel &reply) +{ + auto remote = Remote(); + if (remote == nullptr) { + ANS_LOGE("[InnerTransact] fail: get Remote fail code %{public}u", code); + return ERR_DEAD_OBJECT; + } + + int32_t err = remote->SendRequest(static_cast(code), data, reply, flags); + switch (err) { + case NO_ERROR: { + return ERR_OK; + } + case DEAD_OBJECT: { + ANS_LOGE("[InnerTransact] fail: ipcErr=%{public}d code %{public}d", err, code); + return ERR_DEAD_OBJECT; + } + default: { + ANS_LOGE("[InnerTransact] fail: ipcErr=%{public}d code %{public}d", err, code); + return ERR_ANS_TRANSACT_FAILED; + } + } +} + +void AnsSubscriberLocalActivityProxy::OnConnected() +{ + MessageParcel data; + if (!data.WriteInterfaceToken(AnsSubscriberLocalActivityProxy::GetDescriptor())) { + ANS_LOGE("[OnConnected] fail: write interface token failed."); + return; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_ASYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::ON_CONNECTED, option, data, reply); + if (result != ERR_OK) { + ANS_LOGE("[OnConnected] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED"); + return; + } +} + +void AnsSubscriberLocalActivityProxy::OnDisconnected() +{ + MessageParcel data; + if (!data.WriteInterfaceToken(AnsSubscriberLocalActivityProxy::GetDescriptor())) { + ANS_LOGE("[OnDisconnected] fail: write interface token failed."); + return; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_ASYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::ON_DISCONNECTED, option, data, reply); + if (result != ERR_OK) { + ANS_LOGE("[OnDisconnected] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED"); + return; + } +} + + +void AnsSubscriberLocalActivityProxy::OnResponse(int32_t notificationId, const sptr &buttonOption) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(AnsSubscriberLocalActivityProxy::GetDescriptor())) { + ANS_LOGE("[OnResponse] fail: write interface token failed."); + return; + } + + if (!data.WriteInt32(notificationId)) { + ANS_LOGE("[OnResponse] fail: write notificationId failed"); + return; + } + + if (!data.WriteParcelable(buttonOption)) { + ANS_LOGE("[OnResponse] fail: write buttonName failed"); + return; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_ASYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::ON_RESPONSE, option, data, reply); + if (result != ERR_OK) { + ANS_LOGE("[OnResponse] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED"); + return; + } +} +} // namespace Notification +} // namespace OHOS diff --git a/frameworks/core/src/ans_subscriber_local_activity_stub.cpp b/frameworks/core/src/ans_subscriber_local_activity_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1db24040bcd39dcd6ba7f1df4715b1f872fabdc8 --- /dev/null +++ b/frameworks/core/src/ans_subscriber_local_activity_stub.cpp @@ -0,0 +1,131 @@ +/* + * 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_subscriber_local_activity_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 "notification_bundle_option.h" +#include "notification_button_option.h" +#include "parcel.h" +#include "refbase.h" +#include + +namespace OHOS { +namespace Notification { +AnsSubscriberLocalActivityStub::AnsSubscriberLocalActivityStub() +{ + interfaces_.emplace(NotificationInterfaceCode::ON_CONNECTED, + std::bind(&AnsSubscriberLocalActivityStub::HandleOnConnected, this, std::placeholders::_1, std::placeholders::_2)); + interfaces_.emplace(NotificationInterfaceCode::ON_DISCONNECTED, + std::bind(&AnsSubscriberLocalActivityStub::HandleOnDisconnected, this, std::placeholders::_1, std::placeholders::_2)); + interfaces_.emplace(NotificationInterfaceCode::ON_RESPONSE, + std::bind(&AnsSubscriberLocalActivityStub::HandleOnResponse, this, std::placeholders::_1, std::placeholders::_2)); +} + +AnsSubscriberLocalActivityStub::~AnsSubscriberLocalActivityStub() +{} + +int32_t AnsSubscriberLocalActivityStub::OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &flags) +{ + std::u16string descriptor = AnsSubscriberLocalActivityStub::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (descriptor != remoteDescriptor) { + ANS_LOGW("[OnRemoteRequest] fail: invalid interface token!"); + return OBJECT_NULL; + } + + auto it = interfaces_.find(static_cast(code)); + if (it == interfaces_.end()) { + ANS_LOGW("[OnRemoteRequest] fail: unknown code!"); + return IPCObjectStub::OnRemoteRequest(code, data, reply, flags); + } + + auto fun = it->second; + if (fun == nullptr) { + ANS_LOGW("[OnRemoteRequest] fail: not find function!"); + return IPCObjectStub::OnRemoteRequest(code, data, reply, flags); + } + + fun(data, reply); + return NO_ERROR; +} + +ErrCode AnsSubscriberLocalActivityStub::HandleOnConnected(MessageParcel &data, MessageParcel &reply) +{ + OnConnected(); + return ERR_OK; +} + +ErrCode AnsSubscriberLocalActivityStub::HandleOnDisconnected(MessageParcel &data, MessageParcel &reply) +{ + OnDisconnected(); + return ERR_OK; +} + +template +bool AnsSubscriberLocalActivityStub::ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &data) +{ + int32_t infoSize = 0; + if (!data.ReadInt32(infoSize)) { + ANS_LOGE("read Parcelable size failed."); + return false; + } + + parcelableInfos.clear(); + infoSize = (infoSize < MAX_PARCELABLE_VECTOR_NUM) ? infoSize : MAX_PARCELABLE_VECTOR_NUM; + for (int32_t index = 0; index < infoSize; index++) { + sptr info = data.ReadStrongParcelable(); + if (info == nullptr) { + ANS_LOGE("read Parcelable infos failed."); + return false; + } + parcelableInfos.emplace_back(info); + } + + return true; +} + +ErrCode AnsSubscriberLocalActivityStub::HandleOnResponse(MessageParcel &data, MessageParcel &reply) +{ + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleOnResponse] fail : read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + sptr buttonOption = nullptr; + buttonOption = data.ReadParcelable(); + if (buttonOption == nullptr) { + ANS_LOGE("[HandleOnResponse] fail : read buttonOption failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + OnResponse(notificationId, buttonOption); + return ERR_OK; +} + +void AnsSubscriberLocalActivityStub::OnConnected() +{} + +void AnsSubscriberLocalActivityStub::OnDisconnected() +{} + +void AnsSubscriberLocalActivityStub::OnResponse(int32_t notificationId, const sptr &buttonOption) +{} +} // namespace Notification +} // namespace OHOS diff --git a/interfaces/inner_api/notification_button_option.h b/interfaces/inner_api/notification_button_option.h new file mode 100644 index 0000000000000000000000000000000000000000..f1ec1e403b9a18a8411ad2998354b0cbf29bb869 --- /dev/null +++ b/interfaces/inner_api/notification_button_option.h @@ -0,0 +1,99 @@ +/* + * 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 the button name. + * + * @param buttonName Indicates the button name. + */ + void SetButtonName(const std::string &buttonName); + + /** + * @brief Obtains the button name. + * + * @return Returns the button name. + */ + 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 0000000000000000000000000000000000000000..1b1ac33fe6c8aa884f65cb6e898781e61bd6499e --- /dev/null +++ b/interfaces/inner_api/notification_capsule.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_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 title of capsule. + * + * @return Returns the title of capsule. + */ + std::string GetTitle() const; + + void SetTitle(const std::string &title); + + /** + * @brief Obtains the buttonIcon of capsule. + * + * @return Returns the buttonIcon of capsule. + */ + const std::shared_ptr GetIcon() const; + + void SetIcon(const std::shared_ptr &icon); + + /** + * @brief Obtains the backgroundColor of capsule. + * + * @return Returns the backgroundColor of capsule. + */ + 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 NotificationCapsule 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 NotificationCapsule object from a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns the NotificationCapsule. + */ + 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 NotificationCapsule. + */ + static NotificationCapsule *Unmarshalling(Parcel &parcel); + +private: + + /** + * @brief Read a NotificationCapsule 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