From: Zofia Abramowska Date: Fri, 23 Jun 2017 18:09:07 +0000 (+0200) Subject: Redo askuser-notification X-Git-Tag: submit/tizen/20170727.154157~1^2~48 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0b458a12846079bd35eca41feb22c98babc90b13;p=platform%2Fcore%2Fsecurity%2Faskuser.git Redo askuser-notification * Remove redundant event/element ids * Move PolicyUpdater to askuser-notification * Implement new logic of askuser-notification Change-Id: I32f104f20bcb640f00e05c6edfc140786e73c2de --- diff --git a/packaging/askuser-notification.spec b/packaging/askuser-notification.spec index e767bb2..6c0e6be 100644 --- a/packaging/askuser-notification.spec +++ b/packaging/askuser-notification.spec @@ -21,6 +21,7 @@ BuildRequires: pkgconfig(libsystemd) BuildRequires: pkgconfig(cynara-plugin) BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(security-privilege-manager) +BuildRequires: pkgconfig(security-manager) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(capi-ui-efl-util) diff --git a/src/agent/main/Policy.cpp b/src/agent/main/Policy.cpp deleted file mode 100644 index e63faa7..0000000 --- a/src/agent/main/Policy.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2016-2017 Samsung Electronics Co. - * - * 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 - */ -/** - * @file src/agent/main/Policy.cpp - * @author Zofia Abramowska - * @brief Implementation of Policy wrappers - */ - -#include - -#include - -#include -#include - -#include -#include "Policy.h" - -namespace { -inline void throwOnSMError(std::string err, int ret) -{ - if (ret != SECURITY_MANAGER_SUCCESS) - throw AskUser::Exception(err + " : " + std::to_string(ret)); -} -} - -namespace AskUser { - -void identifyApp(const std::string &client, const std::string &user, - std::string &appId, std::string &pkgLabel) -{ - char *pkgName = nullptr; - char *appName = nullptr; - - int ret = security_manager_identify_app_from_cynara_client(client.c_str(), &pkgName, &appName); - std::unique_ptr pkg_name_p(pkgName, free); - std::unique_ptr app_name_p(appName, free); - throwOnSMError("security_manager_identify_app_from_cynara_client", ret); - - if (!pkgName) { - ALOGE("Couldn't identify clients package id"); - return; - } - - uid_t uid = std::strtoul(user.c_str(), nullptr, 10); - PkgInfo pkgInfo(pkgName, uid); - if (!appName) - appId = pkgInfo.mainAppId(); - - pkgLabel = pkgInfo.pkgLabel(); -} - -PolicyEntry::PolicyEntry() { - throwOnSMError("security_manager_policy_entry_new", - security_manager_policy_entry_new(&m_entry)); -} - -PolicyEntry::PolicyEntry(PolicyEntry &&other) : m_entry(std::move(other.m_entry)) { - other.m_entry = nullptr; -} - -PolicyEntry::~PolicyEntry() { - security_manager_policy_entry_free(m_entry); -} - -void PolicyEntry::setApp(const std::string &appId) { - throwOnSMError("security_manager_policy_entry_set_application", - security_manager_policy_entry_set_application(m_entry, appId.c_str())); -} - -void PolicyEntry::setUser(const std::string &user) { - throwOnSMError("security_manager_policy_entry_set_user", - security_manager_policy_entry_set_user(m_entry, user.c_str())); -} - -void PolicyEntry::setPrivilege(const std::string &privilege) { - throwOnSMError("security_manager_policy_entry_set_privilege", - security_manager_policy_entry_set_privilege(m_entry, privilege.c_str())); -} - -void PolicyEntry::setLevel(const std::string &level) { - throwOnSMError("security_manager_policy_entry_admin_set_level", - security_manager_policy_entry_set_level(m_entry, level.c_str())); -} - -PolicyRequest::PolicyRequest() { - throwOnSMError("security_manager_policy_update_req_new", - security_manager_policy_update_req_new(&m_req)); -} - -PolicyRequest::~PolicyRequest() { - m_entries.clear(); - security_manager_policy_update_req_free(m_req); -} - -void PolicyRequest::addEntry(PolicyEntry &&entry) { - throwOnSMError("security_manager_policy_update_req_add_entry", - security_manager_policy_update_req_add_entry(m_req, entry.get())); - m_entries.emplace_back(std::move(entry)); -} - -void PolicyRequest::updatePolicy() { - throwOnSMError("security_manager_policy_update_send", - security_manager_policy_update_send(m_req)); -} - -} /* namespace AskUser */ diff --git a/src/agent/main/Policy.h b/src/agent/main/Policy.h deleted file mode 100644 index 66bf8d9..0000000 --- a/src/agent/main/Policy.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2016-2017 Samsung Electronics Co. - * - * 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 - */ -/** - * @file src/agent/main/Policy.h - * @author Zofia Abramowska - * @brief Definition of Policy wrappers - */ - -#pragma once - -#include -#include - -struct policy_entry; -struct policy_update_req; - -namespace AskUser { - -void identifyApp(const std::string &client, const std::string &user, - std::string &appId, std::string &pkgLabel); - -class PolicyEntry { -public: - PolicyEntry(); - PolicyEntry(PolicyEntry &&other); - ~PolicyEntry(); - void setApp(const std::string &appId); - void setUser(const std::string &user); - void setPrivilege(const std::string &privilege); - void setLevel(const std::string &level); - - policy_entry *get() const { return m_entry; } - -private: - policy_entry *m_entry; -}; - -class PolicyRequest { -public: - PolicyRequest(); - ~PolicyRequest(); - void addEntry(PolicyEntry &&entry); - void updatePolicy(); - -private: - policy_update_req *m_req; - std::vector m_entries; -}; - -} /* namespace AskUser */ diff --git a/src/agent/main/PolicyUpdater.cpp b/src/agent/main/PolicyUpdater.cpp deleted file mode 100644 index a9fbd91..0000000 --- a/src/agent/main/PolicyUpdater.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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. - */ -/** - * @file PolicyUpdater.cpp - * @author Zofia Abramowska - * @brief This file implements class of policy updater - */ - -#include -#include - -#include -#include - -#include - -#include "Policy.h" -#include "PolicyUpdater.h" - -namespace AskUser { - -namespace Agent { - -PolicyUpdater::PolicyUpdater() : m_running(false) -{} - -void PolicyUpdater::start() { - m_thread = std::thread(&PolicyUpdater::run, this); - m_running = true; -} - -void PolicyUpdater::stop() { - if (!m_running || !m_thread.joinable()) - return; - m_running = false; - - m_thread.join(); - ALOGD("PolicyUpdater thread finished."); -} - -void PolicyUpdater::run() { - int ret; - sigset_t mask; - sigemptyset(&mask); - sigaddset(&mask, SIGTERM); - if ((ret = pthread_sigmask(SIG_BLOCK, &mask, nullptr)) < 0) { - ALOGE("sigprocmask failed [<<" << ret << "]"); - } - - while (m_running) { - try { - std::unique_lock lock(m_mutex); - m_event.wait(lock, [&](){ return !m_events.empty() || !m_running;}); - - if (m_events.empty()) { - continue; - } - - ALOGD("Got " << m_events.size() << " policies to update"); - m_eventsInternal = std::move(m_events); - lock.unlock(); - - PolicyRequest req; - ALOGD("Updating " << m_eventsInternal.size() << " policies"); - for (auto &policyInfo : m_eventsInternal) { - std::string privacyName = PrivilegeInfo::getPrivacyName(policyInfo.priv); - if (privacyName.empty()) { - ALOGE("Unable to get privacy name for privilege " << policyInfo.priv); - throw Exception("Unable to get privacy name for " + policyInfo.priv); - } - auto privacyPrivs = PrivilegeInfo::getPrivacyPrivileges(privacyName); - if (privacyPrivs.empty()) { - ALOGE("Unable to get privacy privileges for privacy " << privacyName); - throw Exception("Unable to get privacy privileges for privacy " + privacyName); - } - ALOGD("Adding policy entry for : app: " << policyInfo.appId << ", privilege: " - << policyInfo.priv << ", user:" << policyInfo.user << ", level: " - << policyInfo.level); - for (auto &priv : privacyPrivs) { - PolicyEntry entry; - entry.setApp(policyInfo.appId); - entry.setUser(policyInfo.user); - entry.setPrivilege(priv); - entry.setLevel(policyInfo.level); - req.addEntry(std::move(entry)); - } - } - req.updatePolicy(); - ALOGD("Policy update sent"); - - m_eventsInternal.clear(); - } catch (const std::exception &e) { - ALOGC("Unexpected exception: <" << e.what() << ">"); - } catch (...) { - ALOGE("Unexpected unknown exception caught!"); - } - } -} - -void PolicyUpdater::update(const std::string &appId, const std::string &user, - const std::string &privilege, const std::string &level) -{ - ALOGD("Queueing policy update for: app: " << appId << ", privilege: " << privilege - << ", user:" << user << ", level: " << level); - if (!m_running) { - ALOGE("PolicyUpdater not running, cannot update policy for " << appId << " " << user << " " - << privilege << " " << level); - return; - } - { - std::lock_guard lock(m_mutex); - m_events.push_back({appId, user, privilege, level}); - } - m_event.notify_one(); -} - -} // namespace Agent - -} // namespace AskUser diff --git a/src/agent/main/PolicyUpdater.h b/src/agent/main/PolicyUpdater.h deleted file mode 100644 index 1cfff28..0000000 --- a/src/agent/main/PolicyUpdater.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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. - */ -/** - * @file PolicyUpdater.h - * @author Zofia Abramowska - * @brief This file declares class of policy updater - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace AskUser { - -namespace Agent { - -class PolicyUpdater { -public: - PolicyUpdater(); - ~PolicyUpdater() { stop(); } - - void start(); - void stop(); - - void update(const std::string &appId, const std::string &user, const std::string &privilege, - const std::string &level); -private: - struct PolicyInfo { - std::string appId; - std::string user; - std::string priv; - std::string level; - }; - std::atomic m_running; - std::thread m_thread; - - std::mutex m_mutex; - std::condition_variable m_event; - std::vector m_events; - std::vector m_eventsInternal; - - void run(); -}; - -} // namespace Agent - -} // namespace AskUser diff --git a/src/common/policy/PkgInfo.h b/src/common/policy/PkgInfo.h deleted file mode 100644 index e2f9e59..0000000 --- a/src/common/policy/PkgInfo.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co. - * - * 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 - */ -/** - * @file src/common/policy/PkgInfo.h - * @author Zofia Abramowska - * @brief Definition of pkgmgr-info wrappers - */ - -#pragma once - -#include -#include -#include - -#include - -struct PkgInfo { - PkgInfo(const std::string &pkgId, uid_t uid) : m_handle(nullptr) { - int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgId.c_str(), uid, &m_handle); - if (ret != PMINFO_R_OK) { - ALOGE("pkgmgrinfo_pkginfo_get_usr_pkginfo failed for " << pkgId << " with " << ret); - m_handle = nullptr; - } - } - ~PkgInfo() { - if (m_handle) - pkgmgrinfo_pkginfo_destroy_pkginfo(m_handle); - } - const std::string mainAppId(){ - if (!m_handle) { - return ""; - } - char *mainAppId; - int ret = pkgmgrinfo_pkginfo_get_mainappid(m_handle, &mainAppId); - if (ret != PMINFO_R_OK) { - ALOGE("pkgmgrinfo_pkginfo_get_mainappid failed with " << ret); - return ""; - } - return mainAppId ? mainAppId : ""; - } - const std::string pkgLabel() { - if (!m_handle) { - return ""; - } - char *pkgLabel; - int ret = pkgmgrinfo_pkginfo_get_label(m_handle, &pkgLabel); - if (ret != PMINFO_R_OK) { - ALOGE("pkgmgrinfo_pkginfo_get_label failed with " << ret); - return ""; - } - return pkgLabel ? pkgLabel : ""; - } - pkgmgrinfo_pkginfo_h m_handle; -}; diff --git a/src/common/policy/PrivilegeInfo.cpp b/src/common/policy/PrivilegeInfo.cpp deleted file mode 100644 index 06d65b7..0000000 --- a/src/common/policy/PrivilegeInfo.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co. - * - * 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 - */ -/** - * @file src/agent/notification-daemon/Privilege.cpp - * @author Zofia Abramowska - * @brief Implementation of Privilege Info wrappers - */ - -#include -#include - -#include "PrivilegeInfo.h" - -#include -#include - -#include -#include - -namespace AskUser { - -struct GListWrap { - GListWrap(GList *_list) : list(_list) {} - ~GListWrap() { g_list_free_full(list, free);} - GList * get() { return list; } - GList *list; -}; - -namespace PrivilegeInfo { - -std::string getPrivacyDisplayName(const std::string &privilege) { - char *displayName = nullptr; - int ret = privilege_info_get_privacy_display(getPrivacyName(privilege).c_str(), &displayName); - if (ret != PRVMGR_ERR_NONE || !displayName) { - ALOGE("Unable to get privacy display name for <" << privilege << ">, err: <" << ret << ">"); - return privilege; - } - std::unique_ptr displaNamePtr(displayName, free); - return std::string(displayName); -} - -std::string getPrivacyName(const std::string &privilege) { - char* privacyName = nullptr; - int ret = privilege_info_get_privacy_by_privilege(privilege.c_str(), &privacyName); - if (ret != PRVMGR_ERR_NONE || !privacyName) { - ALOGE("Unable to get privacy group for privilege: <" << privilege << ">, err: <" << ret << ">"); - return privilege; - } - - std::unique_ptr privacyNamePtr(privacyName, free); - return std::string(privacyName); -} - -std::vector getPrivacyPrivileges(const std::string &privacy) { - GList *privilegeList = nullptr; - - int ret = privilege_info_get_privilege_list_by_privacy(privacy.c_str(), &privilegeList); - if (ret != PRVMGR_ERR_NONE || !privilegeList) { - ALOGE("Unable to get privacy group list of privileges; err: <" << ret << ">" ); - return {privacy}; - } - - GListWrap privList(privilegeList); - std::vector privVector; - for (GList *l = privList.get(); l != NULL; l = l->next) { - privVector.push_back(static_cast(l->data)); - } - return privVector; -} - -} -} /* namespace AskUser */ diff --git a/src/common/policy/PrivilegeInfo.h b/src/common/policy/PrivilegeInfo.h deleted file mode 100644 index 0249b4f..0000000 --- a/src/common/policy/PrivilegeInfo.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co. - * - * 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 - */ -/** - * @file src/agent/notification-daemon/Privilege.h - * @author Zofia Abramowska - * @brief Definition of Privilege Info wrappers - */ - -#pragma once - -#include -#include - -namespace AskUser { - -namespace PrivilegeInfo { - std::string getPrivacyDisplayName(const std::string &privilege); - std::string getPrivacyName(const std::string &privilege); - std::vector getPrivacyPrivileges(const std::string &privacy); -}; - -} /* namespace AskUser */ - - diff --git a/src/common/protocol/askuser-notification/ask-user-service.h b/src/common/protocol/askuser-notification/ask-user-service.h index 8fb5b93..ca55528 100644 --- a/src/common/protocol/askuser-notification/ask-user-service.h +++ b/src/common/protocol/askuser-notification/ask-user-service.h @@ -34,6 +34,9 @@ namespace Protocol { typedef int ConnectionFd; typedef int RequestId; +const ConnectionFd INVALID_FD = -1; +const RequestId INVALID_ID = -1; + enum FdMask { READ = 1, WRITE = 2, diff --git a/src/notification-daemon/CMakeLists.txt b/src/notification-daemon/CMakeLists.txt index 5986288..80e724c 100644 --- a/src/notification-daemon/CMakeLists.txt +++ b/src/notification-daemon/CMakeLists.txt @@ -15,6 +15,7 @@ PKG_CHECK_MODULES(ASKUSER_NOTIFICATION_DEP capi-ui-efl-util capi-system-info security-privilege-manager + security-manager ) INCLUDE_DIRECTORIES(SYSTEM @@ -30,10 +31,12 @@ INCLUDE_DIRECTORIES( SET(ASKUSER_NOTIFICATION_SOURCES ${NOTIF_PATH}/main.cpp ${NOTIF_PATH}/Logic.cpp + ${NOTIF_PATH}/PolicyUpdater.cpp ${NOTIF_PATH}/ServerCallbacks.cpp + ${NOTIF_PATH}/policy/Policy.cpp + ${NOTIF_PATH}/policy/PrivilegeInfo.cpp ${NOTIF_PATH}/ui/Po.cpp ${ASKUSER_PATH}/common/log/alog.cpp - ${ASKUSER_PATH}/common/policy/PrivilegeInfo.cpp ${NOTIF_PATH}/ui/Popupper.cpp ) diff --git a/src/notification-daemon/Logic.cpp b/src/notification-daemon/Logic.cpp index 7997bdb..c4e4d9d 100644 --- a/src/notification-daemon/Logic.cpp +++ b/src/notification-daemon/Logic.cpp @@ -30,6 +30,8 @@ #include #include +#include +#include "PolicyUpdater.h" #include "ServerCallbacks.h" namespace AskUser { @@ -37,16 +39,16 @@ namespace AskUser { namespace Notification { void Logic::addChannelFd(Protocol::ConnectionFd fd, const Protocol::Credentials &creds) { - // TODO check if doesn't already exist - // TODO translate to appId, pkgId and appIds from package auto it = m_connToInfo.find(fd); if (it != m_connToInfo.end()) { ALOGE("Connection with fd : " << fd << " already exists. Closing connection"); m_clientChannel->process(fd, 0); return; } - (void)creds; - ConnectionInfo connInfo; + + std::string appId, pkgId; + identifyApp(creds.label, appId, pkgId); + ConnectionInfo connInfo{appId, pkgId}; m_connToInfo.insert(it, std::make_pair(fd, connInfo)); } @@ -55,19 +57,22 @@ void Logic::updateChannelFd(Protocol::ConnectionFd fd, Ecore_Fd_Handler_Flags fl if (it != m_fdInfo.end()) { m_fdInfo[fd].status = FdChange::CHANGE; ecore_main_fd_handler_del(m_fdInfo[fd].handler); + } else { + m_fdInfo[fd].status = FdChange::NONE; } auto handler = ecore_main_fd_handler_add(fd, flags, &Logic::clientChHandler, this, nullptr, nullptr); if (handler == nullptr) { ALOGE("Couldn't set fd handler"); + m_fdInfo[fd].status = FdChange::DEL; return; } m_fdInfo[fd].handler = handler; - m_fdInfo[fd].status = FdChange::NONE; } void Logic::removeChannelFd(Protocol::ConnectionFd fd) { m_connToInfo.erase(fd); + auto it = m_fdInfo.find(fd); if (it == m_fdInfo.end()) { return; @@ -93,7 +98,6 @@ Eina_Bool Logic::clientChHandler(void *data, Ecore_Fd_Handler *handler) { } Eina_Bool Logic::processChannel(int fd, int mask) { - m_fdInfo[fd].status = FdChange::NONE; updateChannel(fd, mask); switch (m_fdInfo[fd].status) { @@ -101,15 +105,17 @@ Eina_Bool Logic::processChannel(int fd, int mask) { return ECORE_CALLBACK_RENEW; case FdChange::DEL: { // Remove all pending events from this fd - auto queueIt = std::remove_if(m_pendingEvents.begin(), m_pendingEvents.end(), [fd](const FdEvent &fdEvent) {return fdEvent.fd == fd;}); + auto queueIt = std::remove_if(m_pendingEvents.begin(), m_pendingEvents.end(), + [fd](const FdEvent &fdEvent) {return fdEvent.id.fd == fd;}); m_pendingEvents.erase(queueIt, m_pendingEvents.end()); // Handle next event if removed active fd - if (fd == m_currentFd) { + if (fd == m_currentEvent.fd) { finishCurrentEvent(); processEvents(); } m_fdInfo.erase(fd); + m_clientChannel->process(fd, 0); return ECORE_CALLBACK_CANCEL; } case FdChange::CHANGE: @@ -120,26 +126,31 @@ Eina_Bool Logic::processChannel(int fd, int mask) { } } -void Logic::addEvent(IUIEvent *event) { - FdEvent fdEvent{m_currentFd, std::unique_ptr(event)}; +void Logic::addEvent(EventId id, IUIEvent *event) { + FdEvent fdEvent{id, std::unique_ptr(event)}; m_pendingEvents.emplace_back(std::move(fdEvent)); processEvents(); } -void Logic::popup(Protocol::ConnectionFd fd, Protocol::RequestId id, std::string &&privilege) { - (void)fd; - (void)id; - (void)privilege; +void Logic::popup(Protocol::ConnectionFd fd, Protocol::RequestId id, const std::string &privilege) { + auto it = m_connToInfo.find(fd); + if (it == m_connToInfo.end()) { + ALOGE("Got request to non existing fd " << fd); + return; + } + + auto &pkgId = it->second.pkgId; + addEvent({fd, id}, new EventPopupCheck(&m_popupper, pkgId, privilege)); } bool Logic::isEventProcessed() { - return m_currentEventId != -1; + return m_currentEvent.fd != Protocol::INVALID_FD; } void Logic::finishCurrentEvent() { - m_popupper.popupClose(m_currentEventId); - m_currentEventId = -1; - m_currentFd = -1; + m_popupper.popupClose(); + m_currentEvent = EventId(); + m_pendingEvents.pop_front(); } void Logic::processEvents() { @@ -152,10 +163,6 @@ void Logic::processEvents() { return; FdEvent fdEvent = std::move(m_pendingEvents.front()); - m_currentFd = fdEvent.fd; - m_currentEventId = fdEvent.event->getId(); - m_pendingEvents.pop_front(); - fdEvent.event->process(); } @@ -205,7 +212,7 @@ void Logic::init() { init_agent_log(); m_popupper.setLocale(); m_popupper.initialize(); - m_popupper.registerPopupResponseHandler([&](int popupId, NResponseType response) { popupResponse(popupId, response);}); + m_popupper.registerPopupResponseHandler([&](NResponseType response) { popupResponse(response);}); registerSignalFd(); @@ -218,12 +225,17 @@ void Logic::run() { m_popupper.shutdown(); } -void Logic::popupResponse(int popupId, NResponseType response) { - if (popupId != m_currentEventId) { - ALOGD("Got different popup id than is being processed"); +void Logic::popupResponse(NResponseType response) { + auto it = m_connToInfo.find(m_currentEvent.fd); + if (it == m_connToInfo.end()) { + ALOGE("Got response from inactive fd " << m_currentEvent.fd); return; } + + EventPopupCheck *event = dynamic_cast(m_pendingEvents.front().event.get()); + int clientResponse; + std::string level; // TODO translate ui response to policy result switch (response) { case NResponseType::Deny: @@ -231,12 +243,12 @@ void Logic::popupResponse(int popupId, NResponseType response) { break; case NResponseType::DenyAlways: clientResponse = ASKUSER_DENY_FOREVER; + level = "Deny"; break; case NResponseType::Allow: - clientResponse = ASKUSER_ALLOW_ONCE; - break; case NResponseType::AllowAlways: clientResponse = ASKUSER_ALLOW_FOREVER; + level = "Allow"; break; case NResponseType::None: clientResponse = ASKUSER_NONE; @@ -247,8 +259,15 @@ void Logic::popupResponse(int popupId, NResponseType response) { default: clientResponse = -255; // error } + if (!level.empty()) { + if (!PolicyUpdater::update(it->second.appId, event->getPrivilege(), level)) { + ALOGE("Failed to update policy, returning DENY_ONCE in this case"); + clientResponse = ASKUSER_DENY_ONCE; + } + } + // TODO create popup ids containing fd and request id - m_clientChannel->popupResponse(-1, popupId, clientResponse); + m_clientChannel->popupResponse(m_currentEvent.fd, m_currentEvent.id, clientResponse); finishCurrentEvent(); processEvents(); } diff --git a/src/notification-daemon/Logic.h b/src/notification-daemon/Logic.h index e1bec91..4a50c00 100644 --- a/src/notification-daemon/Logic.h +++ b/src/notification-daemon/Logic.h @@ -41,7 +41,7 @@ public: private: std::string m_msg; }; - Logic() : m_currentFd(-1), m_currentEventId(-1), m_isFdDeleted(false) {} + Logic() : m_currentEvent{-1, -1} {} void init(); void run(); void stop(); @@ -50,11 +50,17 @@ public: void updateChannelFd(Protocol::ConnectionFd fd, Ecore_Fd_Handler_Flags flags); void removeChannelFd(Protocol::ConnectionFd fd); - void addEvent(IUIEvent *event); - void popup(Protocol::ConnectionFd fd, Protocol::RequestId id, std::string &&privilege); + void popup(Protocol::ConnectionFd fd, Protocol::RequestId id, const std::string &privilege); ~Logic() {} private: + struct EventId { + EventId() : fd(Protocol::INVALID_FD), id(Protocol::INVALID_ID) {} + EventId(Protocol::ConnectionFd _fd, Protocol::RequestId _id) : fd(_fd), id(_id) {} + Protocol::ConnectionFd fd; + Protocol::RequestId id; + }; + //Initialization void registerSignalFd(); void prepareChannel(); @@ -65,43 +71,42 @@ private: static Eina_Bool signalHandler(void *data, Ecore_Fd_Handler *handler); //static Eina_Bool signalHandler(void *data, int type, void *event); + void addEvent(EventId id, IUIEvent *event); Eina_Bool processChannel(int fd, int mask); + bool identifyClient(const std::string &label, std::string &appId, std::string &pkgId); void processEvents(); bool isEventProcessed(); void finishCurrentEvent(); - void popupResponse(int popupId, NResponseType response); + void popupResponse(NResponseType response); AskUser::Protocol::ChannelPtr m_clientChannel; Popupper m_popupper; struct FdEvent { - int fd; + EventId id; std::unique_ptr event; }; - // Workaround for no information about to which fd event belongs to - int m_currentFd; - int m_currentEventId; - int m_isFdDeleted; + EventId m_currentEvent; std::deque m_pendingEvents; enum class FdChange { NONE, ADD, CHANGE, - DEL + DEL, }; struct FdInfo { + FdInfo() : handler(nullptr), status(FdChange::NONE) {} Ecore_Fd_Handler* handler; FdChange status; }; - std::map m_fdInfo; + std::map m_fdInfo; struct ConnectionInfo { std::string appId; std::string pkgId; - std::vector apps; }; std::map m_connToInfo; diff --git a/src/notification-daemon/PolicyUpdater.cpp b/src/notification-daemon/PolicyUpdater.cpp new file mode 100644 index 0000000..2319dd3 --- /dev/null +++ b/src/notification-daemon/PolicyUpdater.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ +/** + * @file PolicyUpdater.cpp + * @author Zofia Abramowska + * @brief This file implements class of policy updater + */ + +#include +#include + +#include +#include + +#include "PolicyUpdater.h" +#include +#include + +namespace AskUser { + +namespace Notification { + +bool PolicyUpdater::update(const std::string &appId, + const std::string &privilege, const std::string &level) +{ + try { + ALOGD("Policy update for: app: " << appId << ", privilege: " << privilege + << ", user:" << geteuid() << ", level: " << level); + + static const std::string user = std::to_string(geteuid()); + PolicyRequest req; + + std::string privacyName = PrivilegeInfo::getPrivacyName(privilege); + if (privacyName.empty()) { + ALOGE("Unable to get privacy name for privilege " << privilege); + throw Exception("Unable to get privacy name for " + privilege); + } + auto privacyPrivs = PrivilegeInfo::getPrivacyPrivileges(privacyName); + if (privacyPrivs.empty()) { + ALOGE("Unable to get privacy privileges for privacy " << privacyName); + throw Exception("Unable to get privacy privileges for privacy " + privacyName); + } + ALOGD("Adding policy entry for : app: " << appId << ", privilege: " + << privilege << ", user:" << user << ", level: " + << level); + for (auto &priv : privacyPrivs) { + PolicyEntry entry; + entry.setApp(appId); + entry.setUser(user); + entry.setPrivilege(priv); + entry.setLevel(level); + req.addEntry(std::move(entry)); + } + + req.updatePolicy(); + ALOGD("Policy update sent"); + return true; + } catch (AskUser::Exception &e) { + ALOGE("Failed to update policy in security-manager : " << e.what()); + } catch (std::exception &e) { + ALOGE("Failed to update policy : " << e.what()); + } catch (...) { + ALOGE("Failed to update policy with unknown exception"); + } + return false; +} + +} // namespace Agent + +} // namespace AskUser diff --git a/src/notification-daemon/PolicyUpdater.h b/src/notification-daemon/PolicyUpdater.h new file mode 100644 index 0000000..f91e88f --- /dev/null +++ b/src/notification-daemon/PolicyUpdater.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ +/** + * @file PolicyUpdater.h + * @author Zofia Abramowska + * @brief This file declares class of policy updater + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace AskUser { + +namespace Notification { + +namespace PolicyUpdater { + bool update(const std::string &appId, const std::string &privilege, + const std::string &level); +}; + +} // namespace Agent + +} // namespace AskUser diff --git a/src/notification-daemon/ServerCallbacks.cpp b/src/notification-daemon/ServerCallbacks.cpp index b8c7825..5f438ba 100644 --- a/src/notification-daemon/ServerCallbacks.cpp +++ b/src/notification-daemon/ServerCallbacks.cpp @@ -49,7 +49,7 @@ void ServerCallbacks::updateConnection(ConnectionFd fd, int mask) { } void ServerCallbacks::popup(ConnectionFd fd, RequestId id, std::string &&privilege) { - m_service->popup(fd, id, std::move(privilege)); + m_service->popup(fd, id, privilege); } } /* namespace Notification */ diff --git a/src/notification-daemon/event/Event.h b/src/notification-daemon/event/Event.h index f00cba4..2327569 100644 --- a/src/notification-daemon/event/Event.h +++ b/src/notification-daemon/event/Event.h @@ -31,32 +31,27 @@ namespace Notification { class IUIEvent { public: - IUIEvent(Popupper *popupper) : m_popupper(popupper), m_eventId(-1) {} + IUIEvent(Popupper *popupper) : m_popupper(popupper) {} virtual void process() = 0; - void setId(int id) { m_eventId = id; } - int getId() { return m_eventId; } virtual ~IUIEvent() {} protected: Popupper *m_popupper; - int m_eventId; }; class EventPopupCheck : public IUIEvent { public: - EventPopupCheck(Popupper *popupper, int popupId, const std::string &appName, - const std::string &pkgName, const std::string &privilege) - : IUIEvent(popupper), m_popupId(popupId), m_appName(appName), - m_pkgName(pkgName), m_privilege(privilege) - { - setId(popupId); + EventPopupCheck(Popupper *popupper, const std::string &pkgName, const std::string &privilege) + : IUIEvent(popupper), m_pkgName(pkgName), m_privilege(privilege) + {} + + std::string getPrivilege() { + return m_privilege; } virtual void process() { - m_popupper->popupCheck(m_popupId, m_appName, m_pkgName, m_privilege); + m_popupper->popupCheck(m_pkgName, m_privilege); } private: - int m_popupId; - std::string m_appName; std::string m_pkgName; std::string m_privilege; }; diff --git a/src/notification-daemon/policy/PkgInfo.h b/src/notification-daemon/policy/PkgInfo.h new file mode 100644 index 0000000..e2f9e59 --- /dev/null +++ b/src/notification-daemon/policy/PkgInfo.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co. + * + * 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 + */ +/** + * @file src/common/policy/PkgInfo.h + * @author Zofia Abramowska + * @brief Definition of pkgmgr-info wrappers + */ + +#pragma once + +#include +#include +#include + +#include + +struct PkgInfo { + PkgInfo(const std::string &pkgId, uid_t uid) : m_handle(nullptr) { + int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgId.c_str(), uid, &m_handle); + if (ret != PMINFO_R_OK) { + ALOGE("pkgmgrinfo_pkginfo_get_usr_pkginfo failed for " << pkgId << " with " << ret); + m_handle = nullptr; + } + } + ~PkgInfo() { + if (m_handle) + pkgmgrinfo_pkginfo_destroy_pkginfo(m_handle); + } + const std::string mainAppId(){ + if (!m_handle) { + return ""; + } + char *mainAppId; + int ret = pkgmgrinfo_pkginfo_get_mainappid(m_handle, &mainAppId); + if (ret != PMINFO_R_OK) { + ALOGE("pkgmgrinfo_pkginfo_get_mainappid failed with " << ret); + return ""; + } + return mainAppId ? mainAppId : ""; + } + const std::string pkgLabel() { + if (!m_handle) { + return ""; + } + char *pkgLabel; + int ret = pkgmgrinfo_pkginfo_get_label(m_handle, &pkgLabel); + if (ret != PMINFO_R_OK) { + ALOGE("pkgmgrinfo_pkginfo_get_label failed with " << ret); + return ""; + } + return pkgLabel ? pkgLabel : ""; + } + pkgmgrinfo_pkginfo_h m_handle; +}; diff --git a/src/notification-daemon/policy/Policy.cpp b/src/notification-daemon/policy/Policy.cpp new file mode 100644 index 0000000..5fefb59 --- /dev/null +++ b/src/notification-daemon/policy/Policy.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co. + * + * 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 + */ +/** + * @file src/agent/main/Policy.cpp + * @author Zofia Abramowska + * @brief Implementation of Policy wrappers + */ + +#include + +#include + +#include +#include + +#include "PkgInfo.h" +#include "Policy.h" + +namespace { +inline void throwOnSMError(std::string err, int ret) +{ + if (ret != SECURITY_MANAGER_SUCCESS) + throw AskUser::Exception(err + " : " + std::to_string(ret)); +} +} + +namespace AskUser { + +void identifyApp(const std::string &client, std::string &appId, std::string &pkgLabel) +{ + char *pkgName = nullptr; + char *appName = nullptr; + + int ret = security_manager_identify_app_from_cynara_client(client.c_str(), &pkgName, &appName); + std::unique_ptr pkg_name_p(pkgName, free); + std::unique_ptr app_name_p(appName, free); + throwOnSMError("security_manager_identify_app_from_cynara_client", ret); + + if (!pkgName) { + ALOGE("Couldn't identify clients package id"); + return; + } + + PkgInfo pkgInfo(pkgName, geteuid()); + if (!appName) + appId = pkgInfo.mainAppId(); + + pkgLabel = pkgInfo.pkgLabel(); +} + +PolicyEntry::PolicyEntry() { + throwOnSMError("security_manager_policy_entry_new", + security_manager_policy_entry_new(&m_entry)); +} + +PolicyEntry::PolicyEntry(PolicyEntry &&other) : m_entry(std::move(other.m_entry)) { + other.m_entry = nullptr; +} + +PolicyEntry::~PolicyEntry() { + security_manager_policy_entry_free(m_entry); +} + +void PolicyEntry::setApp(const std::string &appId) { + throwOnSMError("security_manager_policy_entry_set_application", + security_manager_policy_entry_set_application(m_entry, appId.c_str())); +} + +void PolicyEntry::setUser(const std::string &user) { + throwOnSMError("security_manager_policy_entry_set_user", + security_manager_policy_entry_set_user(m_entry, user.c_str())); +} + +void PolicyEntry::setPrivilege(const std::string &privilege) { + throwOnSMError("security_manager_policy_entry_set_privilege", + security_manager_policy_entry_set_privilege(m_entry, privilege.c_str())); +} + +void PolicyEntry::setLevel(const std::string &level) { + throwOnSMError("security_manager_policy_entry_admin_set_level", + security_manager_policy_entry_set_level(m_entry, level.c_str())); +} + +PolicyRequest::PolicyRequest() { + throwOnSMError("security_manager_policy_update_req_new", + security_manager_policy_update_req_new(&m_req)); +} + +PolicyRequest::~PolicyRequest() { + m_entries.clear(); + security_manager_policy_update_req_free(m_req); +} + +void PolicyRequest::addEntry(PolicyEntry &&entry) { + throwOnSMError("security_manager_policy_update_req_add_entry", + security_manager_policy_update_req_add_entry(m_req, entry.get())); + m_entries.emplace_back(std::move(entry)); +} + +void PolicyRequest::updatePolicy() { + throwOnSMError("security_manager_policy_update_send", + security_manager_policy_update_send(m_req)); +} + +} /* namespace AskUser */ diff --git a/src/notification-daemon/policy/Policy.h b/src/notification-daemon/policy/Policy.h new file mode 100644 index 0000000..3c9828b --- /dev/null +++ b/src/notification-daemon/policy/Policy.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co. + * + * 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 + */ +/** + * @file src/agent/main/Policy.h + * @author Zofia Abramowska + * @brief Definition of Policy wrappers + */ + +#pragma once + +#include +#include + +struct policy_entry; +struct policy_update_req; + +namespace AskUser { + +void identifyApp(const std::string &client, std::string &appId, std::string &pkgLabel); + +class PolicyEntry { +public: + PolicyEntry(); + PolicyEntry(PolicyEntry &&other); + ~PolicyEntry(); + void setApp(const std::string &appId); + void setUser(const std::string &user); + void setPrivilege(const std::string &privilege); + void setLevel(const std::string &level); + + policy_entry *get() const { return m_entry; } + +private: + policy_entry *m_entry; +}; + +class PolicyRequest { +public: + PolicyRequest(); + ~PolicyRequest(); + void addEntry(PolicyEntry &&entry); + void updatePolicy(); + +private: + policy_update_req *m_req; + std::vector m_entries; +}; + +} /* namespace AskUser */ diff --git a/src/notification-daemon/policy/PrivilegeInfo.cpp b/src/notification-daemon/policy/PrivilegeInfo.cpp new file mode 100644 index 0000000..06d65b7 --- /dev/null +++ b/src/notification-daemon/policy/PrivilegeInfo.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co. + * + * 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 + */ +/** + * @file src/agent/notification-daemon/Privilege.cpp + * @author Zofia Abramowska + * @brief Implementation of Privilege Info wrappers + */ + +#include +#include + +#include "PrivilegeInfo.h" + +#include +#include + +#include +#include + +namespace AskUser { + +struct GListWrap { + GListWrap(GList *_list) : list(_list) {} + ~GListWrap() { g_list_free_full(list, free);} + GList * get() { return list; } + GList *list; +}; + +namespace PrivilegeInfo { + +std::string getPrivacyDisplayName(const std::string &privilege) { + char *displayName = nullptr; + int ret = privilege_info_get_privacy_display(getPrivacyName(privilege).c_str(), &displayName); + if (ret != PRVMGR_ERR_NONE || !displayName) { + ALOGE("Unable to get privacy display name for <" << privilege << ">, err: <" << ret << ">"); + return privilege; + } + std::unique_ptr displaNamePtr(displayName, free); + return std::string(displayName); +} + +std::string getPrivacyName(const std::string &privilege) { + char* privacyName = nullptr; + int ret = privilege_info_get_privacy_by_privilege(privilege.c_str(), &privacyName); + if (ret != PRVMGR_ERR_NONE || !privacyName) { + ALOGE("Unable to get privacy group for privilege: <" << privilege << ">, err: <" << ret << ">"); + return privilege; + } + + std::unique_ptr privacyNamePtr(privacyName, free); + return std::string(privacyName); +} + +std::vector getPrivacyPrivileges(const std::string &privacy) { + GList *privilegeList = nullptr; + + int ret = privilege_info_get_privilege_list_by_privacy(privacy.c_str(), &privilegeList); + if (ret != PRVMGR_ERR_NONE || !privilegeList) { + ALOGE("Unable to get privacy group list of privileges; err: <" << ret << ">" ); + return {privacy}; + } + + GListWrap privList(privilegeList); + std::vector privVector; + for (GList *l = privList.get(); l != NULL; l = l->next) { + privVector.push_back(static_cast(l->data)); + } + return privVector; +} + +} +} /* namespace AskUser */ diff --git a/src/notification-daemon/policy/PrivilegeInfo.h b/src/notification-daemon/policy/PrivilegeInfo.h new file mode 100644 index 0000000..0249b4f --- /dev/null +++ b/src/notification-daemon/policy/PrivilegeInfo.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co. + * + * 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 + */ +/** + * @file src/agent/notification-daemon/Privilege.h + * @author Zofia Abramowska + * @brief Definition of Privilege Info wrappers + */ + +#pragma once + +#include +#include + +namespace AskUser { + +namespace PrivilegeInfo { + std::string getPrivacyDisplayName(const std::string &privilege); + std::string getPrivacyName(const std::string &privilege); + std::vector getPrivacyPrivileges(const std::string &privacy); +}; + +} /* namespace AskUser */ + + diff --git a/src/notification-daemon/ui/Answerable.h b/src/notification-daemon/ui/Answerable.h index 3a18ed2..114fa2c 100644 --- a/src/notification-daemon/ui/Answerable.h +++ b/src/notification-daemon/ui/Answerable.h @@ -34,7 +34,7 @@ public: ALLOW, DENY }; - typedef std::function AnswerHandler; + typedef std::function AnswerHandler; IAnswerable(AnswerHandler handler) : m_handler(handler) {} virtual void process(enum Button) const = 0; @@ -65,7 +65,7 @@ public: default: answer = NResponseType::Error; } - m_handler(m_popup->getId(), answer); + m_handler( answer); } private: PopupCheck *m_popup; diff --git a/src/notification-daemon/ui/Po.cpp b/src/notification-daemon/ui/Po.cpp index b984fd5..7ee8218 100644 --- a/src/notification-daemon/ui/Po.cpp +++ b/src/notification-daemon/ui/Po.cpp @@ -99,7 +99,7 @@ std::string getPkgLabel(const std::string &pkgName) { namespace Notification { namespace Po { -std::string createPopupCheckMsg(const std::string &, const std::string &pkgName, const std::string &priv) { +std::string createPopupCheckMsg(const std::string &pkgName, const std::string &priv) { return makeFromFormat(getFormat(MsgType::MSG_POPUP_TEXT), getPkgLabel(pkgName).c_str(), PrivilegeInfo::getPrivacyDisplayName(priv).c_str()); } diff --git a/src/notification-daemon/ui/Po.h b/src/notification-daemon/ui/Po.h index 0f7fab4..b702c93 100644 --- a/src/notification-daemon/ui/Po.h +++ b/src/notification-daemon/ui/Po.h @@ -26,7 +26,7 @@ namespace AskUser { namespace Notification { namespace Po { -std::string createPopupCheckMsg(const std::string &appName, const std::string &pkgName, const std::string &priv); +std::string createPopupCheckMsg(const std::string &pkgName, const std::string &priv); std::string createPrivilegeDescr(const std::string &priv); std::string getPopupTitleMsg(); diff --git a/src/notification-daemon/ui/PopupCheckMobile.h b/src/notification-daemon/ui/PopupCheckMobile.h index 5ba7380..3882343 100644 --- a/src/notification-daemon/ui/PopupCheckMobile.h +++ b/src/notification-daemon/ui/PopupCheckMobile.h @@ -32,11 +32,9 @@ namespace Notification { class PopupCheckMobile : public PopupCheck { public: - PopupCheckMobile(Evas_Object *parent, int popupId, const std::string &msg) + PopupCheckMobile(Evas_Object *parent, const std::string &msg) : PopupCheck(parent, msg) - { - setId(popupId); - } + {} virtual void create() { // popup elm_popup_align_set(m_popup, ELM_NOTIFY_ALIGN_FILL, 1.0); diff --git a/src/notification-daemon/ui/PopupCheckWearable.h b/src/notification-daemon/ui/PopupCheckWearable.h index 74fe9ef..a58692c 100644 --- a/src/notification-daemon/ui/PopupCheckWearable.h +++ b/src/notification-daemon/ui/PopupCheckWearable.h @@ -32,11 +32,9 @@ namespace Notification { class PopupCheckWearable : public PopupCheck { public: - PopupCheckWearable(Evas_Object *parent, int popupId, const std::string msg) + PopupCheckWearable(Evas_Object *parent, const std::string msg) : PopupCheck(parent, msg) - { - setId(popupId); - } + {} ~PopupCheckWearable() {} virtual void create() { diff --git a/src/notification-daemon/ui/Popupper.cpp b/src/notification-daemon/ui/Popupper.cpp index ee31ec6..e8194bb 100644 --- a/src/notification-daemon/ui/Popupper.cpp +++ b/src/notification-daemon/ui/Popupper.cpp @@ -68,12 +68,12 @@ void Popupper::unfocusedCb(void *data, Evas_Object *, void *) } } -void Popupper::popupClose(int popupId) +void Popupper::popupClose() { ALOGD("Window close"); m_shouldRaise = false; - if (!m_elementPtr || popupId == -1 || popupId != m_elementPtr->getId()) + if (!m_elementPtr) ALOGD("Closing non-existing popup"); m_elementPtr.reset(nullptr); @@ -101,7 +101,7 @@ Eina_Bool Popupper::hwKeyClickedCb(void *data, int type, void *event) ALOGD("HW button pressed. type <" << type << "> pressed key is <" << ev->key << ">"); if ((!strcmp("XF86Home", ev->key) || !strcmp("XF86Back", ev->key)) && runner->m_elementPtr) { ALOGD("Respond as deny once."); - runner->m_popupResponseHandler(runner->m_elementPtr->getId(), NResponseType::None); + runner->m_popupResponseHandler(NResponseType::None); } return EINA_TRUE; } @@ -154,21 +154,21 @@ void Popupper::show() { evas_object_show(m_win); } -void Popupper::popupCheck(int popupId, const std::string &appId, const std::string &pkgId, const std::string &priv) { +void Popupper::popupCheck(const std::string &pkgId, const std::string &priv) { std::string profileName = getProfileName(); PopupCheck *popup; try { if (profileName[0] != 'w' && profileName[0] != 'W') { // Not wearable - popup = new PopupCheckMobile(m_win, popupId, Po::createPopupCheckMsg(appId, pkgId, priv)); + popup = new PopupCheckMobile(m_win, Po::createPopupCheckMsg(pkgId, priv)); } else { // Wearable - popup = new PopupCheckWearable(m_win, popupId, Po::createPopupCheckMsg(appId, pkgId, priv)); + popup = new PopupCheckWearable(m_win, Po::createPopupCheckMsg(pkgId, priv)); } popup->create(); } catch (const std::exception &e) { ALOGE("Failed to create popup check : " << e.what()); - m_popupResponseHandler(popupId, NResponseType::Error); + m_popupResponseHandler(NResponseType::Error); return; } diff --git a/src/notification-daemon/ui/Popupper.h b/src/notification-daemon/ui/Popupper.h index 478f682..5855d53 100644 --- a/src/notification-daemon/ui/Popupper.h +++ b/src/notification-daemon/ui/Popupper.h @@ -39,7 +39,7 @@ namespace Notification { class Popupper { public: - typedef std::function PopupHandler; + typedef std::function PopupHandler; Popupper() = default; void initialize(); @@ -47,9 +47,9 @@ public: void registerPopupResponseHandler(PopupHandler handler); void start(); - void popupCheck(int popupId, const std::string &appId, const std::string &pkgId, const std::string &priv); + void popupCheck(const std::string &pkgId, const std::string &priv); - void popupClose(int popupId); + void popupClose(); void stop(); void shutdown(); diff --git a/src/notification-daemon/ui/UIElement.h b/src/notification-daemon/ui/UIElement.h index 998b8e6..c59ad01 100644 --- a/src/notification-daemon/ui/UIElement.h +++ b/src/notification-daemon/ui/UIElement.h @@ -28,14 +28,11 @@ namespace Notification { class UIElement { public: - explicit UIElement(Evas_Object *parent) : m_parent(parent), m_elementId(-1) {} - void setId(int id) { m_elementId = id;} - int getId() { return m_elementId; } + explicit UIElement(Evas_Object *parent) : m_parent(parent) {} virtual void create() = 0; virtual ~UIElement() {} protected: Evas_Object *m_parent; - int m_elementId; }; } /* namespace Notification */