diff options
author | Jusung Son <jusung07.son@samsung.com> | 2019-08-23 10:44:32 +0900 |
---|---|---|
committer | Jusung Son <jusung07.son@samsung.com> | 2019-10-08 15:55:42 +0900 |
commit | f59841497ce72aaa068ab248033efa9142948485 (patch) | |
tree | a4b18872066b05a99765dadd624bbf731de0b60e | |
parent | c74f15730cd40d853e3a54561a789634da6ad00e (diff) | |
download | notification-sandbox/noti_ex_porting.tar.gz notification-sandbox/noti_ex_porting.tar.bz2 notification-sandbox/noti_ex_porting.zip |
Apply API versionsandbox/noti_ex_porting
Change-Id: I98a5fa33fc1772f868da91bc4c0ac3ef20f4e170
Signed-off-by: Jusung Son <jusung07.son@samsung.com>
-rw-r--r-- | notification-ex/abstract_item.cc | 4 | ||||
-rw-r--r-- | notification-ex/abstract_item.h | 6 | ||||
-rw-r--r-- | notification-ex/abstract_item_implementation.h | 2 | ||||
-rw-r--r-- | notification-ex/api/notification_ex_internal.h | 10 | ||||
-rw-r--r-- | notification-ex/db_manager.cc | 57 | ||||
-rw-r--r-- | notification-ex/db_manager.h | 14 | ||||
-rw-r--r-- | notification-ex/event_info.cc | 12 | ||||
-rw-r--r-- | notification-ex/event_info_implementation.h | 2 | ||||
-rw-r--r-- | notification-ex/event_info_internal.h | 2 | ||||
-rw-r--r-- | notification-ex/ievent_info.h | 2 | ||||
-rw-r--r-- | notification-ex/ievent_info_internal.h | 2 | ||||
-rw-r--r-- | notification-ex/iitem_info_internal.h | 6 | ||||
-rw-r--r-- | notification-ex/item_info.cc | 9 | ||||
-rw-r--r-- | notification-ex/item_info_internal.h | 6 | ||||
-rw-r--r-- | notification-ex/manager.cc | 25 | ||||
-rw-r--r-- | notification-ex/manager.h | 2 | ||||
-rw-r--r-- | notification-ex/manager_implementation.h | 1 | ||||
-rw-r--r-- | notification-ex/stub.cc | 47 | ||||
-rw-r--r-- | notification/src/notification_convert.c | 14 | ||||
-rw-r--r-- | unittest/src/test_abstract_item.cc | 10 |
20 files changed, 181 insertions, 52 deletions
diff --git a/notification-ex/abstract_item.cc b/notification-ex/abstract_item.cc index f39331e..91d256f 100644 --- a/notification-ex/abstract_item.cc +++ b/notification-ex/abstract_item.cc @@ -141,7 +141,7 @@ Bundle AbstractItem::Serialize() const { b.Add(ABSTRACT_ITEM_ID_KEY, impl_->id_); b.Add(ABSTRACT_ITEM_SENDER_APPID_KEY, GetSenderAppId().c_str()); b.Add(ABSTRACT_ITEM_TYPE_KEY, to_string(GetType())); - b.Add(ABSTRACT_ITEM_VERSION_KEY, to_string(impl_->version_)); + b.Add(ABSTRACT_ITEM_VERSION_KEY, to_string(static_cast<int>(impl_->version_))); b.Add(ABSTRACT_ITEM_HIDE_TIME_KEY, to_string(impl_->hide_time_)); b.Add(ABSTRACT_ITEM_DELETE_TIME_KEY, to_string(impl_->delete_time_)); b.Add(ABSTRACT_ITEM_UID_KEY, to_string(impl_->uid_)); @@ -246,7 +246,7 @@ void AbstractItem::Deserialize(Bundle b) { impl_->id_ = b.GetString(ABSTRACT_ITEM_ID_KEY); impl_->sender_appid_ = b.GetString(ABSTRACT_ITEM_SENDER_APPID_KEY); impl_->channel_ = b.GetString(ABSTRACT_ITEM_CHANNEL_KEY); - impl_->version_ = stoi(b.GetString(ABSTRACT_ITEM_VERSION_KEY)); + impl_->version_ = static_cast<AbstractItem::Version>(stoi(b.GetString(ABSTRACT_ITEM_VERSION_KEY))); impl_->hide_time_ = stoi(b.GetString(ABSTRACT_ITEM_HIDE_TIME_KEY)); impl_->delete_time_ = stoi(b.GetString(ABSTRACT_ITEM_DELETE_TIME_KEY)); impl_->can_receive_ = b.GetString(ABSTRACT_ITEM_CAN_RECEIVE_KEY); diff --git a/notification-ex/abstract_item.h b/notification-ex/abstract_item.h index e9961a7..e2af2e8 100644 --- a/notification-ex/abstract_item.h +++ b/notification-ex/abstract_item.h @@ -375,6 +375,12 @@ class EXPORT_API AbstractItem { SimMode = 1 << 1, }; + enum Version { + Legacy = 1 << 0, + Extension = 1 << 1, + ALL = Legacy | Extension + }; + public: /** * @brief Constructor diff --git a/notification-ex/abstract_item_implementation.h b/notification-ex/abstract_item_implementation.h index 24a434b..92d851f 100644 --- a/notification-ex/abstract_item_implementation.h +++ b/notification-ex/abstract_item_implementation.h @@ -48,7 +48,7 @@ class AbstractItem::Impl { std::shared_ptr<Style> style_ = nullptr; bool visible_ = true; bool enable_ = true; - int version_ = 1; + AbstractItem::Version version_ = AbstractItem::Version::Extension; int hide_time_ = 0; int delete_time_ = 0; std::list<std::string> receiver_group_list_; diff --git a/notification-ex/api/notification_ex_internal.h b/notification-ex/api/notification_ex_internal.h index da7ea5d..39dfa22 100644 --- a/notification-ex/api/notification_ex_internal.h +++ b/notification-ex/api/notification_ex_internal.h @@ -18,11 +18,19 @@ #define __TIZEN_APPFW_NOTIFICATION_EX_INTERNAL_H__ #include <notification_ex_item.h> +#include <notification_ex_manager.h> #ifdef __cplusplus extern "C" { #endif +typedef enum _noti_ex_item_version { + NOTI_EX_ITEM_VERSION_LEGACY = 1 << 0, + NOTI_EX_ITEM_VERSION_EXTENSION = 1 << 1, + NOTI_EX_ITEM_VERSION_ALL = NOTI_EX_ITEM_VERSION_LEGACY + | NOTI_EX_ITEM_VERSION_EXTENSION +} noti_ex_item_version_e; + int noti_ex_item_get_version(noti_ex_item_h item, int *version); int noti_ex_item_set_version(noti_ex_item_h item, int version); int noti_ex_item_get_uid(noti_ex_item_h item, int *uid); @@ -36,6 +44,8 @@ int noti_ex_item_get_hide_viewer_list(noti_ex_item_h item, int noti_ex_ptr_get(noti_ex_item_h item, void** ptr); int noti_ex_ptr_destroy(void* ptr); int noti_ex_item_create(noti_ex_item_h *handle, void* item); +int noti_ex_manager_set_unified_mode(noti_ex_manager_h handle, bool mode); +int noti_ex_manager_get_unified_mode(noti_ex_manager_h handle, bool* mode); #ifdef __cplusplus } diff --git a/notification-ex/db_manager.cc b/notification-ex/db_manager.cc index 734d5b4..aafcadf 100644 --- a/notification-ex/db_manager.cc +++ b/notification-ex/db_manager.cc @@ -48,6 +48,7 @@ " priv_id INTEGER PRIMARY KEY,\n" \ " pkg_id TEXT,\n" \ " policy INTEGER,\n" \ + " version INTEGER,\n" \ " data TEXT NOT NULL,\n" \ " insert_time INTEGER,\n" \ " hide_list TEXT,\n" \ @@ -438,14 +439,15 @@ int DBManager::InsertNotification(list<shared_ptr<item::AbstractItem>> addedItem static_pointer_cast<IItemInfoInternal>(i->GetInfo())->SetPrivateId(seq); Bundle b = i->Serialize(); query = sqlite3_mprintf("INSERT INTO noti_ex_list" - " (root_id, app_id, uid, priv_id, pkg_id, policy, data, insert_time)" - " VALUES (%Q, %Q, %d, %" PRId64 ", %Q, %d, %Q, %d)", + " (root_id, app_id, uid, priv_id, pkg_id, policy, version, data, insert_time)" + " VALUES (%Q, %Q, %d, %" PRId64 ", %Q, %d, %d, %Q, %d)", i->GetId().c_str(), i->GetSenderAppId().c_str(), uid, static_pointer_cast<IItemInfoInternal>(i->GetInfo())->GetPrivateId(), GetPkgId(i->GetSenderAppId(),uid).c_str(), static_cast<int>(i->GetPolicy()), + static_cast<int>(static_pointer_cast<IItemInfoInternal>(i->GetInfo())->GetVersion()), reinterpret_cast<char*>(b.ToRaw().first.get()), static_pointer_cast<IItemInfo>(i->GetInfo())->GetTime()); @@ -701,13 +703,15 @@ list<shared_ptr<item::AbstractItem>> DBManager::ExecuteGetList(char* query) { return item_list; } -list<shared_ptr<item::AbstractItem>> DBManager::GetNotificationList(string app_id, int uid) { +list<shared_ptr<item::AbstractItem>> DBManager::GetNotificationList(string app_id, + int uid, item::AbstractItem::Version version) { char* query; list<shared_ptr<item::AbstractItem>> item_list; query = sqlite3_mprintf("SELECT data FROM noti_ex_list" - " WHERE uid = %d AND app_id = %Q ORDER BY insert_time DESC", - uid, app_id.c_str()); + " WHERE uid = %d AND app_id = %Q AND (version & %d) != 0" + " ORDER BY insert_time DESC", + uid, app_id.c_str(), static_cast<int>(version)); if (!query) { LOGE("OOM - sql query"); return item_list; @@ -744,7 +748,12 @@ list<shared_ptr<item::AbstractItem>> DBManager::GetNotificationList char* query; list<shared_ptr<item::AbstractItem>> item_list; - query = sqlite3_mprintf("SELECT data FROM noti_ex_list" + if (app_id.empty()) + query = sqlite3_mprintf("SELECT data FROM noti_ex_list" + " WHERE uid = %d AND priv_id = %" PRId64 "", + uid, priv_id); + else + query = sqlite3_mprintf("SELECT data FROM noti_ex_list" " WHERE uid = %d AND app_id = %Q AND priv_id = %" PRId64 "", uid, app_id.c_str(), priv_id); @@ -759,27 +768,35 @@ list<shared_ptr<item::AbstractItem>> DBManager::GetNotificationList return item_list; } -list<shared_ptr<item::AbstractItem>> DBManager::GetNotificationList(int uid) { - int ret, sim_mode; +list<shared_ptr<item::AbstractItem>> DBManager::GetNotificationList(int uid, + item::AbstractItem::Version version, item::AbstractItem::Policy policy, bool sim_check_mode) { + int ret, sim_status; char* query; list<shared_ptr<item::AbstractItem>> item_list; + string policy_query, sim_query; + if (sim_check_mode) { /* Check current sim status */ - ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &sim_mode); - if (ret < 0) { - sim_mode = VCONFKEY_TELEPHONY_SIM_INSERTED; - LOGI("vconf_get_int"); - } + ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &sim_status); + if (ret < 0) { + sim_status = VCONFKEY_TELEPHONY_SIM_INSERTED; + LOGI("vconf_get_int"); + } - if (sim_mode == VCONFKEY_TELEPHONY_SIM_INSERTED) { - query = sqlite3_mprintf("SELECT data FROM noti_ex_list WHERE uid = %d" - " ORDER BY insert_time DESC", uid); - } else { - query = sqlite3_mprintf("SELECT data FROM noti_ex_list" - " WHERE uid = %d AND (policy & %d) == 0 ORDER BY insert_time DESC", - uid, static_cast<int>(item::AbstractItem::Policy::SimMode)); + if (sim_status != VCONFKEY_TELEPHONY_SIM_INSERTED) + sim_query = " AND (policy & " + + to_string(static_cast<int>(item::AbstractItem::Policy::SimMode)) + + ") == 0"; } + if (policy != item::AbstractItem::Policy::None) + policy_query = " AND (policy & " + to_string(static_cast<int>(policy)) + ") != 0"; + + string query_str = "SELECT data FROM noti_ex_list WHERE uid == %d AND (version & %d) != 0 " + + policy_query + sim_query; + + query = sqlite3_mprintf(query_str.c_str(), uid, static_cast<int>(version)); + if (!query) { LOGE("OOM - sql query"); return item_list; diff --git a/notification-ex/db_manager.h b/notification-ex/db_manager.h index 0817dfa..48878db 100644 --- a/notification-ex/db_manager.h +++ b/notification-ex/db_manager.h @@ -43,10 +43,16 @@ class EXPORT_API DBManager { static int GetCount(int64_t priv_id, const std::string& root_id, const std::string& app_id, int uid, int* count); static int GetCount(const std::string& app_id, int uid, int* count); static int DeleteNotification(std::shared_ptr<item::AbstractItem> deletedItem); - static std::list<std::shared_ptr<item::AbstractItem>> GetNotificationList(int uid); - static std::list<std::shared_ptr<item::AbstractItem>> GetNotificationList(std::string app_id, int uid); - static std::list<std::shared_ptr<item::AbstractItem>> GetNotificationList(std::string app_id, std::string root_id, int uid); - static std::list<std::shared_ptr<item::AbstractItem>> GetNotificationList(std::string app_id, int64_t private_id, int uid); + static std::list<std::shared_ptr<item::AbstractItem>> GetNotificationList( + int uid, item::AbstractItem::Version version, + item::AbstractItem::Policy policy, bool sim_check_mode); + static std::list<std::shared_ptr<item::AbstractItem>> GetNotificationList( + std::string app_id, int uid, + item::AbstractItem::Version version); + static std::list<std::shared_ptr<item::AbstractItem>> GetNotificationList( + std::string app_id, std::string root_id, int uid); + static std::list<std::shared_ptr<item::AbstractItem>> GetNotificationList( + std::string app_id, int64_t private_id, int uid); private: DBManager(); /* LCOV_EXCL_LINE */ diff --git a/notification-ex/event_info.cc b/notification-ex/event_info.cc index fda2de5..9eaeb18 100644 --- a/notification-ex/event_info.cc +++ b/notification-ex/event_info.cc @@ -35,6 +35,7 @@ #define NOTIFICATION_EX_EVENT_UID_KEY "__NOTIFICATION_EX_EVENT_UID_KEY__" #define NOTIFICATION_EX_EVENT_REQUEST_ID_KEY "__NOTIFICATION_EX_EVENT_REQUEST_ID_KEY__" #define NOTIFICATION_EX_EVENT_ERROR_KEY "__NOTIFICATION_EX_EVENT_ERROR_KEY__" +#define NOTIFICATION_EX_EVENT_REQUEST_VERSION_KEY "__NOTIFICATION_EX_EVENT_REQUEST_VERSION_KEY__" using namespace std; namespace notification { @@ -71,6 +72,8 @@ EventInfo::EventInfo(Bundle serialized) string error_str = serialized.GetString(NOTIFICATION_EX_EVENT_ERROR_KEY); impl_->error_ = (NotificationError)strtol(error_str.c_str(), NULL, 10); + impl_->request_version_ = static_cast<item::AbstractItem::Version> + (stoi(serialized.GetString(NOTIFICATION_EX_EVENT_REQUEST_VERSION_KEY))); } string EventInfo::GetString(int type) { @@ -105,6 +108,8 @@ Bundle EventInfo::Serialize() const { NOTIFICATION_EX_EVENT_REQUEST_ID_KEY, to_string(impl_->request_id_)); serialized.Add( NOTIFICATION_EX_EVENT_ERROR_KEY, to_string(impl_->error_)); + serialized.Add(NOTIFICATION_EX_EVENT_REQUEST_VERSION_KEY, + to_string(static_cast<int>(impl_->request_version_))); return serialized; } @@ -149,4 +154,11 @@ void EventInfo::SetError(NotificationError error) { impl_->error_ = error; } +void EventInfo::SetRequestVersion(item::AbstractItem::Version version) { + impl_->request_version_ = version; +} + +item::AbstractItem::Version EventInfo::GetRequestVersion() const { + return impl_->request_version_; +} } // namespace notification diff --git a/notification-ex/event_info_implementation.h b/notification-ex/event_info_implementation.h index 41ef31f..b1a8cde 100644 --- a/notification-ex/event_info_implementation.h +++ b/notification-ex/event_info_implementation.h @@ -23,6 +23,7 @@ #include <sys/types.h> +#include "notification-ex/abstract_item.h" #include "notification-ex/dbus_sender.h" #include "notification-ex/ievent_info.h" #include "notification-ex/common.h" @@ -47,6 +48,7 @@ class EventInfo::Impl { int request_id_; NotificationError error_; EventInfo* parent_; + item::AbstractItem::Version request_version_ = item::AbstractItem::Version::Extension; }; } // namespace notification diff --git a/notification-ex/event_info_internal.h b/notification-ex/event_info_internal.h index c13f4a9..622f79c 100644 --- a/notification-ex/event_info_internal.h +++ b/notification-ex/event_info_internal.h @@ -47,6 +47,8 @@ class EXPORT_API EventInfo : public IEventInfoInternal { std::string GetItemId() const override; int GetRequestId() const override; Bundle Serialize() const override; + void SetRequestVersion(item::AbstractItem::Version) override; + item::AbstractItem::Version GetRequestVersion() const override; static std::string GetString(int type); private: diff --git a/notification-ex/ievent_info.h b/notification-ex/ievent_info.h index c4e13e6..f0f5176 100644 --- a/notification-ex/ievent_info.h +++ b/notification-ex/ievent_info.h @@ -18,6 +18,7 @@ #define NOTIFICATION_EX_IEVENT_INFO_H_ #include "notification-ex/ex_bundle.h" +#include "notification-ex/abstract_item.h" namespace notification { @@ -44,6 +45,7 @@ class EXPORT_API IEventInfo { virtual std::string GetItemId() const = 0; virtual int GetRequestId() const = 0; virtual Bundle Serialize() const = 0; + virtual item::AbstractItem::Version GetRequestVersion() const = 0; }; } // namespace notification diff --git a/notification-ex/ievent_info_internal.h b/notification-ex/ievent_info_internal.h index d5ef3a6..3febc07 100644 --- a/notification-ex/ievent_info_internal.h +++ b/notification-ex/ievent_info_internal.h @@ -19,6 +19,7 @@ #include "notification-ex/common.h" #include "notification-ex/ievent_info.h" +#include "notification-ex/abstract_item.h" namespace notification { @@ -30,6 +31,7 @@ class IEventInfoInternal : public IEventInfo { virtual NotificationError GetError() const = 0; virtual void SetError(NotificationError error) = 0; virtual void SetEventType(int type) = 0; + virtual void SetRequestVersion(item::AbstractItem::Version version) = 0; }; } // namespace notification diff --git a/notification-ex/iitem_info_internal.h b/notification-ex/iitem_info_internal.h index 597debc..e2facd5 100644 --- a/notification-ex/iitem_info_internal.h +++ b/notification-ex/iitem_info_internal.h @@ -33,12 +33,12 @@ class EXPORT_API IItemInfoInternal : public IItemInfo { virtual void SetUid(int uid) = 0; virtual int64_t GetPrivateId() const = 0; virtual void SetPrivateId(int64_t private_id) = 0; - virtual int GetVersion() const = 0; - virtual void SetVersion(int ver) = 0; + virtual AbstractItem::Version GetVersion() const = 0; + virtual void SetVersion(AbstractItem::Version ver) = 0; virtual void AddHideViewer(std::string appid) = 0; virtual std::list<std::string> GetHideViewerList() const = 0; virtual void SetTime(time_t time) = 0; - virtual bool CanReceive(std::string receiver_group) const = 0; + virtual bool CanReceive(std::string receiver_group, bool unified_mode) const = 0; }; } // namespace item diff --git a/notification-ex/item_info.cc b/notification-ex/item_info.cc index 60da396..0f64c05 100644 --- a/notification-ex/item_info.cc +++ b/notification-ex/item_info.cc @@ -59,11 +59,11 @@ void AbstractItem::Impl::ItemInfo::SetTime(time_t time) { impl_->time_ = time; } -int AbstractItem::Impl::ItemInfo::GetVersion() const { +AbstractItem::Version AbstractItem::Impl::ItemInfo::GetVersion() const { return impl_->version_; } -void AbstractItem::Impl::ItemInfo::SetVersion(int ver) { +void AbstractItem::Impl::ItemInfo::SetVersion(AbstractItem::Version ver) { impl_->version_ = ver; } @@ -92,7 +92,10 @@ void AbstractItem::Impl::ItemInfo::AddHideViewer(std::string appid) { impl_->hide_viewer_list_.push_back(appid); } -bool AbstractItem::Impl::ItemInfo::CanReceive(std::string receiver_group) const { +bool AbstractItem::Impl::ItemInfo::CanReceive(std::string receiver_group, bool unified_mode) const { + if (unified_mode == false && impl_->version_ < AbstractItem::Version::Extension) + return false; + if (impl_->receiver_group_list_.size() != 0 && !receiver_group.empty()) { list<string>::iterator iter = std::find(impl_->receiver_group_list_.begin(), diff --git a/notification-ex/item_info_internal.h b/notification-ex/item_info_internal.h index c40af75..4bc2bf1 100644 --- a/notification-ex/item_info_internal.h +++ b/notification-ex/item_info_internal.h @@ -33,15 +33,15 @@ class AbstractItem::Impl::ItemInfo : public IItemInfoInternal { void SetUid(int uid) override; time_t GetTime() const override; void SetTime(time_t time) override; - int GetVersion() const override; - void SetVersion(int ver) override; + AbstractItem::Version GetVersion() const override; + void SetVersion(AbstractItem::Version ver) override; void SetHideTime(int hide_time) override; int GetHideTime() const override; void SetDeleteTime(int delete_time) override; int GetDeleteTime() const override; void AddHideViewer(std::string appid) override; std::list<std::string> GetHideViewerList() const override; - bool CanReceive(std::string receiver_group) const override; + bool CanReceive(std::string receiver_group, bool unified_mode) const override; private: AbstractItem::Impl* impl_; diff --git a/notification-ex/manager.cc b/notification-ex/manager.cc index 8067aa6..2f18563 100644 --- a/notification-ex/manager.cc +++ b/notification-ex/manager.cc @@ -64,6 +64,9 @@ int Manager::Impl::SendNotify(shared_ptr<item::AbstractItem> noti, IEventInfo::EventType type) { Bundle serialized = noti->Serialize(); EventInfo info(type, util::GetAppId(), noti->GetChannel(), noti->GetId()); + if (unified_mode_) + info.SetRequestVersion(AbstractItem::Version::ALL); + list<Bundle> serialized_list {serialized}; /* Reply to Sender */ @@ -97,10 +100,21 @@ int Manager::DeleteAll() { int Manager::GetCount() const { EventInfo info(EventInfo::Count, util::GetAppId(), ""); + if (GetUnifiedMode()) + info.SetRequestVersion(AbstractItem::Version::ALL); + int num = impl_->sender_->RequestNumber(info); return num; } +void Manager::SetUnifiedMode(bool mode) { + impl_->unified_mode_ = mode; +} + +bool Manager::GetUnifiedMode() const { + return impl_->unified_mode_; +} + int Manager::Hide(shared_ptr<item::AbstractItem> noti) { (reinterpret_cast<IItemInfoInternal*>(noti->GetInfo().get()))->AddHideViewer(util::GetAppId()); return impl_->SendNotify(noti, EventInfo::Update); @@ -120,6 +134,9 @@ unique_ptr<item::AbstractItem> Manager::FindByRootID(string id) { list<unique_ptr<item::AbstractItem>> Manager::Get() { EventInfo info(EventInfo::Get, util::GetAppId(), ""); + if (GetUnifiedMode()) + info.SetRequestVersion(AbstractItem::Version::ALL); + list<Bundle> result = impl_->sender_->Request(info); list<unique_ptr<item::AbstractItem>> gen_list; for (auto& i : result) { @@ -143,7 +160,7 @@ list<Bundle> Manager::OnRequest(const IEventInfo& info) { list<Bundle> serialized_list; for (auto& i : item_list) { if (std::static_pointer_cast<IItemInfoInternal>(i->GetInfo()) - ->CanReceive(impl_->receiver_group_)) + ->CanReceive(impl_->receiver_group_, GetUnifiedMode())) serialized_list.push_back(i->Serialize()); } return serialized_list; @@ -170,7 +187,7 @@ void Manager::OnEvent(const IEventInfo& info, list<Bundle> serialized) { for (auto& i : serialized) { gen_item = ItemInflator::Create(i); if (std::static_pointer_cast<IItemInfoInternal>(gen_item->GetInfo()) - ->CanReceive(impl_->receiver_group_)) + ->CanReceive(impl_->receiver_group_, GetUnifiedMode())) added.emplace_back(gen_item); } if (added.size() > 0) @@ -181,7 +198,7 @@ void Manager::OnEvent(const IEventInfo& info, list<Bundle> serialized) { for (auto& i : serialized) { gen_item = ItemInflator::Create(i); if (std::static_pointer_cast<IItemInfoInternal>(gen_item->GetInfo()) - ->CanReceive(impl_->receiver_group_)) + ->CanReceive(impl_->receiver_group_, GetUnifiedMode())) OnUpdate(info, gen_item); } break; @@ -190,7 +207,7 @@ void Manager::OnEvent(const IEventInfo& info, list<Bundle> serialized) { for (auto& i : serialized) { gen_item = ItemInflator::Create(i); if (std::static_pointer_cast<IItemInfoInternal>(gen_item->GetInfo()) - ->CanReceive(impl_->receiver_group_)) + ->CanReceive(impl_->receiver_group_, GetUnifiedMode())) OnDelete(info, gen_item); } break; diff --git a/notification-ex/manager.h b/notification-ex/manager.h index 9fd69a3..68bf2f3 100644 --- a/notification-ex/manager.h +++ b/notification-ex/manager.h @@ -51,6 +51,8 @@ class EXPORT_API Manager : public IEventObserver { int OnRequestNumber(const IEventInfo& info) override; void SendError(const IEventInfo& info, NotificationError error); int GetCount() const; + void SetUnifiedMode(bool mode); + bool GetUnifiedMode() const; static std::string GetPath(); protected: diff --git a/notification-ex/manager_implementation.h b/notification-ex/manager_implementation.h index 5502822..b2af8d6 100644 --- a/notification-ex/manager_implementation.h +++ b/notification-ex/manager_implementation.h @@ -41,6 +41,7 @@ class Manager::Impl { std::unique_ptr<IEventListener> listener_; std::string receiver_group_; Manager* parent_; + bool unified_mode_ = false; }; } // namespace notification diff --git a/notification-ex/stub.cc b/notification-ex/stub.cc index 81aa458..1f3eca4 100644 --- a/notification-ex/stub.cc +++ b/notification-ex/stub.cc @@ -2641,8 +2641,9 @@ extern "C" EXPORT_API int noti_ex_item_get_version( } Handle* h = static_cast<Handle*>(item); - *version = - static_pointer_cast<IItemInfoInternal>(h->Get()->GetInfo())->GetVersion(); + *version = static_cast<int>( + static_pointer_cast<IItemInfoInternal>(h->Get()->GetInfo()) + ->GetVersion()); return NOTI_EX_ERROR_NONE; } @@ -2655,7 +2656,8 @@ extern "C" EXPORT_API int noti_ex_item_set_version( } Handle* h = static_cast<Handle*>(item); - static_pointer_cast<IItemInfoInternal>(h->Get()->GetInfo())->SetVersion(version); + static_pointer_cast<IItemInfoInternal>(h->Get()->GetInfo()) + ->SetVersion(static_cast<AbstractItem::Version>(version)); return NOTI_EX_ERROR_NONE; } @@ -2813,3 +2815,42 @@ extern "C" EXPORT_API int noti_ex_item_create( return NOTI_EX_ERROR_NONE; } + +extern "C" EXPORT_API int noti_ex_manager_set_unified_mode( + noti_ex_manager_h handle, bool mode) +{ + if (handle == nullptr) { + LOGE("Invalid parameter"); + return NOTI_EX_ERROR_INVALID_PARAMETER; + } + + try { + ManagerStub* stub = static_cast<ManagerStub*>(handle); + stub->SetUnifiedMode(mode); + } catch (Exception &ex) { + LOGE("%s %d", ex.what(), ex.GetErrorCode()); + return NOTI_EX_ERROR_IO_ERROR; + } + + return NOTI_EX_ERROR_NONE; +} + +extern "C" EXPORT_API int noti_ex_manager_get_unified_mode( + noti_ex_manager_h handle, bool* mode) +{ + if (handle == nullptr || mode == nullptr) { + LOGE("Invalid parameter"); + return NOTI_EX_ERROR_INVALID_PARAMETER; + } + + try { + ManagerStub* stub = static_cast<ManagerStub*>(handle); + *mode = stub->GetUnifiedMode(); + } catch (Exception &ex) { + LOGE("%s %d", ex.what(), ex.GetErrorCode()); + return NOTI_EX_ERROR_IO_ERROR; + } + + return NOTI_EX_ERROR_NONE; +} + diff --git a/notification/src/notification_convert.c b/notification/src/notification_convert.c index c110cab..7a23e0e 100644 --- a/notification/src/notification_convert.c +++ b/notification/src/notification_convert.c @@ -494,7 +494,7 @@ int _convert_to_ex_text(notification_h noti, noti_ex_item_h group) return notification_convert_to_ex_error(ret); } - if (text == NULL) + if (text == NULL || strlen(text) == 0) continue; ret = noti_ex_item_text_create(&item, text_type_arr[i], text, NULL); @@ -964,7 +964,7 @@ int _make_legacy_action(noti_ex_item_h group, int index, return ret; ret = noti_ex_item_get_action(item, &appcontrol_action); - if (ret != NOTI_EX_ERROR_NONE) { + if (ret != NOTI_EX_ERROR_NONE || appcontrol_action == NULL) { ERR("failed to convert(%d)", ret); return ret; } @@ -1370,7 +1370,7 @@ int _convert_to_ex_receiver(notification_h noti, noti_ex_item_h group) return notification_convert_to_ex_error(ret); } - if (display_applist & NOTIFICATION_DISPLAY_APP_ALL + if ((display_applist & NOTIFICATION_DISPLAY_APP_ALL) != NOTIFICATION_DISPLAY_APP_ALL) { for (i = 0; i < sizeof(display_arr) / sizeof(display_arr[0]); i++) { if (display_applist & display_arr[i]) { @@ -1492,7 +1492,7 @@ EXPORT_API int notification_convert_to_legacy( } noti_ex_item_get_private_id(item, &priv_id); - ret = notification_set_priv_id(notification, priv_id); + ret = notification_set_priv_id(notification, (int)priv_id); if (ret != NOTI_EX_ERROR_NONE) { ERR("failed to convert(%d)", ret); goto out; @@ -1560,6 +1560,12 @@ EXPORT_API int notification_convert_to_ex( return ret; } + ret = noti_ex_item_set_version(group_item, NOTI_EX_ITEM_VERSION_LEGACY); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + notification_get_pkgname(noti, (char **)&id); ret = noti_ex_item_set_sender_app_id(group_item, id); if (ret != NOTI_EX_ERROR_NONE) { diff --git a/unittest/src/test_abstract_item.cc b/unittest/src/test_abstract_item.cc index 0a7ed6f..2cdb01d 100644 --- a/unittest/src/test_abstract_item.cc +++ b/unittest/src/test_abstract_item.cc @@ -110,7 +110,7 @@ TEST_F(AbstractItemTest, SerializeDeserialize) { std::static_pointer_cast<IItemInfoInternal>(item.GetInfo())->AddHideViewer("hide_1"); std::static_pointer_cast<IItemInfoInternal>(item.GetInfo())->AddHideViewer("hide_2"); item.SetPolicy(AbstractItem::Policy::OnBootClear); - std::static_pointer_cast<IItemInfoInternal>(item.GetInfo())->SetVersion(3); + std::static_pointer_cast<IItemInfoInternal>(item.GetInfo())->SetVersion(AbstractItem::Version::ALL); item.GetInfo()->SetHideTime(5); item.GetInfo()->SetDeleteTime(9); item.SetChannel("channel99"); @@ -143,7 +143,7 @@ TEST_F(AbstractItemTest, SerializeDeserialize) { ASSERT_EQ(gen_test->GetEnable(), false); ASSERT_EQ(gen_test->GetVisible(),false); ASSERT_EQ(gen_test->GetPolicy(), AbstractItem::Policy::OnBootClear); - ASSERT_EQ(std::static_pointer_cast<IItemInfoInternal>(gen_test->GetInfo())->GetVersion(), 3); + ASSERT_EQ(std::static_pointer_cast<IItemInfoInternal>(gen_test->GetInfo())->GetVersion(), AbstractItem::Version::ALL); ASSERT_EQ(gen_test->GetInfo()->GetHideTime(), 5); ASSERT_EQ(gen_test->GetInfo()->GetDeleteTime(), 9); ASSERT_EQ(gen_test->GetChannel(), "channel99"); @@ -225,9 +225,9 @@ TEST_F(AbstractItemTest, ItemInfoCanReceive) { item.AddReceiver(ReceiverGroup::Panel); item.AddReceiver(ReceiverGroup::LockScreen); - ASSERT_TRUE(std::static_pointer_cast<IItemInfoInternal>(item.GetInfo())->CanReceive(ReceiverGroup::Panel)); - ASSERT_TRUE(std::static_pointer_cast<IItemInfoInternal>(item.GetInfo())->CanReceive(ReceiverGroup::LockScreen)); - ASSERT_FALSE(std::static_pointer_cast<IItemInfoInternal>(item.GetInfo())->CanReceive(ReceiverGroup::Popup)); + ASSERT_TRUE(std::static_pointer_cast<IItemInfoInternal>(item.GetInfo())->CanReceive(ReceiverGroup::Panel, true)); + ASSERT_TRUE(std::static_pointer_cast<IItemInfoInternal>(item.GetInfo())->CanReceive(ReceiverGroup::LockScreen, true)); + ASSERT_FALSE(std::static_pointer_cast<IItemInfoInternal>(item.GetInfo())->CanReceive(ReceiverGroup::Popup, true)); } } // namespace
\ No newline at end of file |