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)
+++ /dev/null
-/*
- * 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 <z.abramowska@samsung.com>
- * @brief Implementation of Policy wrappers
- */
-
-#include <memory>
-
-#include <security-manager.h>
-
-#include <exception/Exception.h>
-#include <log/alog.h>
-
-#include <policy/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, 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<char, decltype(free)*> pkg_name_p(pkgName, free);
- std::unique_ptr<char, decltype(free)*> 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 */
+++ /dev/null
-/*
- * 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 <z.abramowska@samsung.com>
- * @brief Definition of Policy wrappers
- */
-
-#pragma once
-
-#include <string>
-#include <vector>
-
-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<PolicyEntry> m_entries;
-};
-
-} /* namespace AskUser */
+++ /dev/null
-/*
- * 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 <z.abramowska@samsung.com>
- * @brief This file implements class of policy updater
- */
-
-#include <csignal>
-#include <unistd.h>
-
-#include <exception/Exception.h>
-#include <log/alog.h>
-
-#include <policy/PrivilegeInfo.h>
-
-#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<std::mutex> 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<std::mutex> lock(m_mutex);
- m_events.push_back({appId, user, privilege, level});
- }
- m_event.notify_one();
-}
-
-} // namespace Agent
-
-} // namespace AskUser
+++ /dev/null
-/*
- * 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 <z.abramowska@samsung.com>
- * @brief This file declares class of policy updater
- */
-
-#pragma once
-
-#include <atomic>
-#include <mutex>
-#include <string>
-#include <vector>
-#include <thread>
-#include <condition_variable>
-
-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<bool> m_running;
- std::thread m_thread;
-
- std::mutex m_mutex;
- std::condition_variable m_event;
- std::vector<PolicyInfo> m_events;
- std::vector<PolicyInfo> m_eventsInternal;
-
- void run();
-};
-
-} // namespace Agent
-
-} // namespace AskUser
+++ /dev/null
-/*
- * 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 <z.abramowska@samsung.com>
- * @brief Definition of pkgmgr-info wrappers
- */
-
-#pragma once
-
-#include <string>
-#include <sys/types.h>
-#include <pkgmgr-info.h>
-
-#include <log/alog.h>
-
-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;
-};
+++ /dev/null
-/*
- * 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 <z.abramowska@samsung.com>
- * @brief Implementation of Privilege Info wrappers
- */
-
-#include <cstdlib>
-#include <memory>
-
-#include "PrivilegeInfo.h"
-
-#include <exception/Exception.h>
-#include <log/alog.h>
-
-#include <privilegemgr/privilege_info.h>
-#include <glib.h>
-
-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<char, decltype(free)*> 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<char, decltype(free) *> privacyNamePtr(privacyName, free);
- return std::string(privacyName);
-}
-
-std::vector<std::string> 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<std::string> privVector;
- for (GList *l = privList.get(); l != NULL; l = l->next) {
- privVector.push_back(static_cast<char*>(l->data));
- }
- return privVector;
-}
-
-}
-} /* namespace AskUser */
+++ /dev/null
-/*
- * 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 <z.abramowska@samsung.com>
- * @brief Definition of Privilege Info wrappers
- */
-
-#pragma once
-
-#include <string>
-#include <vector>
-
-namespace AskUser {
-
-namespace PrivilegeInfo {
- std::string getPrivacyDisplayName(const std::string &privilege);
- std::string getPrivacyName(const std::string &privilege);
- std::vector<std::string> getPrivacyPrivileges(const std::string &privacy);
-};
-
-} /* namespace AskUser */
-
-
typedef int ConnectionFd;
typedef int RequestId;
+const ConnectionFd INVALID_FD = -1;
+const RequestId INVALID_ID = -1;
+
enum FdMask {
READ = 1,
WRITE = 2,
capi-ui-efl-util
capi-system-info
security-privilege-manager
+ security-manager
)
INCLUDE_DIRECTORIES(SYSTEM
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
)
#include <exception/Exception.h>
#include <exception/ErrnoException.h>
+#include <policy/Policy.h>
+#include "PolicyUpdater.h"
#include "ServerCallbacks.h"
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));
}
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;
}
Eina_Bool Logic::processChannel(int fd, int mask) {
- m_fdInfo[fd].status = FdChange::NONE;
updateChannel(fd, mask);
switch (m_fdInfo[fd].status) {
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:
}
}
-void Logic::addEvent(IUIEvent *event) {
- FdEvent fdEvent{m_currentFd, std::unique_ptr<IUIEvent>(event)};
+void Logic::addEvent(EventId id, IUIEvent *event) {
+ FdEvent fdEvent{id, std::unique_ptr<IUIEvent>(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() {
return;
FdEvent fdEvent = std::move(m_pendingEvents.front());
- m_currentFd = fdEvent.fd;
- m_currentEventId = fdEvent.event->getId();
- m_pendingEvents.pop_front();
-
fdEvent.event->process();
}
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();
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<EventPopupCheck*>(m_pendingEvents.front().event.get());
+
int clientResponse;
+ std::string level;
// TODO translate ui response to policy result
switch (response) {
case NResponseType::Deny:
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;
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();
}
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();
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();
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<IUIEvent> 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<FdEvent> 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<int, FdInfo> m_fdInfo;
+ std::map<Protocol::ConnectionFd, FdInfo> m_fdInfo;
struct ConnectionInfo {
std::string appId;
std::string pkgId;
- std::vector<std::string> apps;
};
std::map<Protocol::ConnectionFd, ConnectionInfo> m_connToInfo;
--- /dev/null
+/*
+ * 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 <z.abramowska@samsung.com>
+ * @brief This file implements class of policy updater
+ */
+
+#include <csignal>
+#include <unistd.h>
+
+#include <exception/Exception.h>
+#include <log/alog.h>
+
+#include "PolicyUpdater.h"
+#include <policy/Policy.h>
+#include <policy/PrivilegeInfo.h>
+
+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
--- /dev/null
+/*
+ * 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 <z.abramowska@samsung.com>
+ * @brief This file declares class of policy updater
+ */
+
+#pragma once
+
+#include <atomic>
+#include <mutex>
+#include <string>
+#include <vector>
+#include <thread>
+#include <condition_variable>
+
+namespace AskUser {
+
+namespace Notification {
+
+namespace PolicyUpdater {
+ bool update(const std::string &appId, const std::string &privilege,
+ const std::string &level);
+};
+
+} // namespace Agent
+
+} // namespace AskUser
}
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 */
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;
};
--- /dev/null
+/*
+ * 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 <z.abramowska@samsung.com>
+ * @brief Definition of pkgmgr-info wrappers
+ */
+
+#pragma once
+
+#include <string>
+#include <sys/types.h>
+#include <pkgmgr-info.h>
+
+#include <log/alog.h>
+
+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;
+};
--- /dev/null
+/*
+ * 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 <z.abramowska@samsung.com>
+ * @brief Implementation of Policy wrappers
+ */
+
+#include <memory>
+
+#include <security-manager.h>
+
+#include <exception/Exception.h>
+#include <log/alog.h>
+
+#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<char, decltype(free)*> pkg_name_p(pkgName, free);
+ std::unique_ptr<char, decltype(free)*> 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 */
--- /dev/null
+/*
+ * 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 <z.abramowska@samsung.com>
+ * @brief Definition of Policy wrappers
+ */
+
+#pragma once
+
+#include <string>
+#include <vector>
+
+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<PolicyEntry> m_entries;
+};
+
+} /* namespace AskUser */
--- /dev/null
+/*
+ * 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 <z.abramowska@samsung.com>
+ * @brief Implementation of Privilege Info wrappers
+ */
+
+#include <cstdlib>
+#include <memory>
+
+#include "PrivilegeInfo.h"
+
+#include <exception/Exception.h>
+#include <log/alog.h>
+
+#include <privilegemgr/privilege_info.h>
+#include <glib.h>
+
+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<char, decltype(free)*> 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<char, decltype(free) *> privacyNamePtr(privacyName, free);
+ return std::string(privacyName);
+}
+
+std::vector<std::string> 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<std::string> privVector;
+ for (GList *l = privList.get(); l != NULL; l = l->next) {
+ privVector.push_back(static_cast<char*>(l->data));
+ }
+ return privVector;
+}
+
+}
+} /* namespace AskUser */
--- /dev/null
+/*
+ * 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 <z.abramowska@samsung.com>
+ * @brief Definition of Privilege Info wrappers
+ */
+
+#pragma once
+
+#include <string>
+#include <vector>
+
+namespace AskUser {
+
+namespace PrivilegeInfo {
+ std::string getPrivacyDisplayName(const std::string &privilege);
+ std::string getPrivacyName(const std::string &privilege);
+ std::vector<std::string> getPrivacyPrivileges(const std::string &privacy);
+};
+
+} /* namespace AskUser */
+
+
ALLOW,
DENY
};
- typedef std::function<void(int, NResponseType)> AnswerHandler;
+ typedef std::function<void(NResponseType)> AnswerHandler;
IAnswerable(AnswerHandler handler) : m_handler(handler) {}
virtual void process(enum Button) const = 0;
default:
answer = NResponseType::Error;
}
- m_handler(m_popup->getId(), answer);
+ m_handler( answer);
}
private:
PopupCheck *m_popup;
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());
}
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();
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);
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() {
}
}
-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);
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;
}
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;
}
class Popupper {
public:
- typedef std::function<void(int, NResponseType)> PopupHandler;
+ typedef std::function<void(NResponseType)> PopupHandler;
Popupper() = default;
void initialize();
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();
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 */