Make askuser-notification independent from security-manager 92/120892/11
authorDariusz Michaluk <d.michaluk@samsung.com>
Fri, 24 Mar 2017 08:03:33 +0000 (09:03 +0100)
committerTomasz Swierczek <t.swierczek@samsung.com>
Fri, 31 Mar 2017 12:23:18 +0000 (05:23 -0700)
Change-Id: I65ebc0780e0fe34770523d7db9dc1bee2bc7953b

18 files changed:
packaging/askuser-notification.spec
src/agent/CMakeLists.txt
src/agent/main/Agent.cpp
src/agent/main/Policy.cpp [moved from src/common/policy/Policy.cpp with 97% similarity]
src/agent/main/Policy.h [moved from src/common/policy/Policy.h with 93% similarity]
src/agent/main/PolicyUpdater.cpp
src/agent/notification-daemon/AskUserTalker.cpp
src/agent/notification-daemon/CMakeLists.txt
src/agent/notification-daemon/GuiRunner.cpp
src/agent/notification-daemon/GuiRunner.h
src/agent/ui/AskUIInterface.h
src/agent/ui/NotificationBackend.cpp
src/agent/ui/NotificationBackend.h
src/common/CMakeLists.txt
src/common/translator/Translator.cpp
src/common/translator/Translator.h
src/common/types/NotificationRequest.h
test/common/translator.cpp

index 58a7162..21607fd 100644 (file)
@@ -18,10 +18,8 @@ BuildRequires: pkgconfig(cynara-agent)
 %if %{with_systemd_daemon}
 BuildRequires: pkgconfig(libsystemd)
 %endif
-BuildRequires: pkgconfig(security-manager)
 BuildRequires: pkgconfig(security-privilege-manager)
 BuildRequires: pkgconfig(glib-2.0)
-BuildRequires: pkgconfig(pkgmgr-info)
 BuildRequires: pkgconfig(vconf)
 BuildRequires: pkgconfig(capi-ui-efl-util)
 BuildRequires: pkgconfig(capi-system-info)
index ea66de6..17f0dd7 100644 (file)
@@ -21,6 +21,8 @@ PKG_CHECK_MODULES(AGENT_DEP
     cynara-agent
     cynara-plugin
     libsystemd
+    security-manager
+    pkgmgr-info
     )
 
 SET(ASKUSER_AGENT_PATH ${ASKUSER_PATH}/agent)
@@ -30,6 +32,7 @@ SET(ASKUSER_SOURCES
     ${ASKUSER_AGENT_PATH}/main/CynaraTalker.cpp
     ${ASKUSER_AGENT_PATH}/main/main.cpp
     ${ASKUSER_AGENT_PATH}/main/PolicyUpdater.cpp
+    ${ASKUSER_AGENT_PATH}/main/Policy.cpp
     ${ASKUSER_AGENT_PATH}/ui/NotificationBackend.cpp
     ${ASKUSER_AGENT_PATH}/ui/FdNotifyObject.cpp
     )
index 8217fbb..eb1b7ba 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-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.
@@ -28,7 +28,6 @@
 #include <utility>
 
 #include <attributes/attributes.h>
-#include <policy/Policy.h>
 #include <translator/Translator.h>
 #include <types/AgentErrorMsg.h>
 #include <types/SupportedTypes.h>
@@ -37,6 +36,7 @@
 #include <log/alog.h>
 
 #include "Agent.h"
+#include "Policy.h"
 
 namespace AskUser {
 
@@ -229,7 +229,11 @@ bool Agent::startUIForRequest(Request *request) {
     auto handler = [&](RequestId requestId, UIResponseType resultType) -> void {
                        UIResponseHandler(requestId, resultType);
                    };
-    bool ret = ui->start(data.client, data.user, data.privilege, request->id(), handler);
+
+    std::string appId, pkgLabel;
+    identifyApp(data.client, data.user, appId, pkgLabel);
+
+    bool ret = ui->start(data.client, pkgLabel, data.user, data.privilege, request->id(), handler);
     if (ret) {
         m_UIs.insert(std::make_pair(request->id(), std::move(ui)));
     }
similarity index 97%
rename from src/common/policy/Policy.cpp
rename to src/agent/main/Policy.cpp
index 73145d6..3d4aa57 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2016 Samsung Electronics Co.
+ *  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.
@@ -14,7 +14,7 @@
  *  limitations under the License
  */
 /**
- * @file        src/agent/notification-daemon/Policy.cpp
+ * @file        src/agent/main/Policy.cpp
  * @author      Zofia Abramowska <z.abramowska@samsung.com>
  * @brief       Implementation of Policy wrappers
  */
similarity index 93%
rename from src/common/policy/Policy.h
rename to src/agent/main/Policy.h
index 9b9db55..66bf8d9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2016 Samsung Electronics Co.
+ *  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.
@@ -14,7 +14,7 @@
  *  limitations under the License
  */
 /**
- * @file        src/agent/notification-daemon/Policy.h
+ * @file        src/agent/main/Policy.h
  * @author      Zofia Abramowska <z.abramowska@samsung.com>
  * @brief       Definition of Policy wrappers
  */
index b7e6d86..a9fbd91 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * 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.
 
 #include <exception/Exception.h>
 #include <log/alog.h>
-#include <policy/Policy.h>
+
 #include <policy/PrivilegeInfo.h>
 
+#include "Policy.h"
 #include "PolicyUpdater.h"
 
 namespace AskUser {
index 19c93a9..9a37642 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2016 Samsung Electronics Co.
+ *  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.
@@ -26,7 +26,6 @@
 #include <string>
 #include <sys/signalfd.h>
 
-#include <policy/Policy.h>
 #include <policy/PrivilegeInfo.h>
 #include <socket/Socket.h>
 #include <socket/Poll.h>
@@ -130,7 +129,8 @@ bool AskUserTalker::fetchRequest(NotificationRequest &request) {
     }
 
     request = Translator::Gui::dataToNotificationRequest(requestData);
-    ALOGD("Recieved data " << request.data.client << " " << request.data.privilege);
+    ALOGD("Recieved data, client: " << request.data.client <<
+          " privilege: " << request.data.privilege);
 
     return true;
 }
@@ -158,7 +158,7 @@ void AskUserTalker::handlePeer() {
 
     NotificationResponse response;
     m_gui.setLocale();
-    response.response = m_gui.popupRun(request.data.client,
+    response.response = m_gui.popupRun(request.pkgLabel,
             PrivilegeInfo::getPrivacyDisplayName(request.data.privilege));
 
     m_gui.delDismissFd(m_currentPeerSocket.getFd());
index d7ce2f2..486015a 100644 (file)
@@ -14,9 +14,7 @@ PKG_CHECK_MODULES(ASKUSER_NOTIFICATION_DEP
     glib-2.0
     capi-ui-efl-util
     capi-system-info
-    security-manager
     security-privilege-manager
-    pkgmgr-info
 )
 
 INCLUDE_DIRECTORIES(SYSTEM
@@ -35,7 +33,6 @@ SET(ASKUSER_NOTIFICATION_SOURCES
     ${ASKUSER_PATH}/common/socket/Socket.cpp
     ${ASKUSER_PATH}/common/socket/Poll.cpp
     ${ASKUSER_PATH}/common/translator/Translator.cpp
-    ${ASKUSER_PATH}/common/policy/Policy.cpp
     ${ASKUSER_PATH}/common/policy/PrivilegeInfo.cpp
     ${ASKUSER_PATH}/common/config/Limits.cpp
     ${ASKUSER_PATH}/common/types/AgentErrorMsg.cpp
index 46745f5..cea335c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2016 Samsung Electronics Co.
+ *  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.
@@ -24,7 +24,6 @@
 
 #include <exception/ErrnoException.h>
 #include <exception/Exception.h>
-#include <policy/Policy.h>
 #include <translator/Translator.h>
 #include <libintl.h>
 #include <vconf.h>
@@ -331,7 +330,7 @@ void GuiRunner::setLocale()
         ALOGE("language_set failed.");
 }
 
-NResponseType GuiRunner::popupRun(const std::string &app, const std::string &perm)
+NResponseType GuiRunner::popupRun(const std::string &pkgLabel, const std::string &perm)
 {
     try {
         setLocale();
@@ -340,10 +339,6 @@ NResponseType GuiRunner::popupRun(const std::string &app, const std::string &per
         m_running = true;
         m_hwKeyClicked = false;
 
-        std::string appId;
-        std::string pkgLabel;
-        identifyApp(app, std::to_string(getuid()), appId, pkgLabel);
-
         // create message
         char *messageFormat = dgettext(PROJECT_NAME, "IDS_IDLE_POP_ALLOW_P1SS_TO_ACCESS_YOUR_P2SS_Q");
         char buf[BUFSIZ];
index dfa90d6..f3606fd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2016 Samsung Electronics Co.
+ *  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.
@@ -45,7 +45,7 @@ public:
     void delDismissFd(int fd);
     ~GuiRunner();
 
-    NResponseType popupRun(const std::string &app, const std::string &perm);
+    NResponseType popupRun(const std::string &pkgLabel, const std::string &perm);
     void stop();
 
     std::string getErrorMsg() { return m_errorMsg; }
index ee23e7f..09e8240 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015-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.
@@ -48,8 +48,9 @@ class AskUIInterface {
 public:
     virtual ~AskUIInterface() {};
 
-    virtual bool start(const std::string &client, const std::string &user,
-                       const std::string &privilege, RequestId requestId, UIResponseCallback) = 0;
+    virtual bool start(const std::string &client, const std::string &pkgLabel,
+                       const std::string &user, const std::string &privilege,
+                       RequestId requestId, UIResponseCallback) = 0;
     virtual bool setOutdated() = 0;
     virtual bool dismiss() = 0;
     virtual bool isDismissing() const = 0;
index 2519ff7..05873f3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2016 Samsung Electronics Co.
+ *  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.
@@ -55,9 +55,9 @@ namespace {
     }
 }
 
-bool NotificationBackend::start(const std::string &client, const std::string &user,
-                               const std::string &privilege, RequestId requestId,
-                               UIResponseCallback responseCb) {
+bool NotificationBackend::start(const std::string &client, const std::string &pkgLabel,
+                                const std::string &user, const std::string &privilege,
+                                RequestId requestId, UIResponseCallback responseCb) {
     if (!m_notify.init()) {
         ALOGW("Couldn't initialize notification object.");
         return false;
@@ -67,6 +67,7 @@ bool NotificationBackend::start(const std::string &client, const std::string &us
     m_request.data.client = client;
     m_request.data.user = user;
     m_request.data.privilege = privilege;
+    m_request.pkgLabel = pkgLabel;
 
     m_thread = std::thread(&NotificationBackend::run, this);
     return true;
@@ -97,6 +98,7 @@ bool NotificationBackend::sendRequest()
 {
     std::string data = Translator::Gui::notificationRequestToData(m_request.id,
                                                                   m_request.data.client,
+                                                                  m_request.pkgLabel,
                                                                   m_request.data.privilege);
     return m_clientSocket.send(data);
 }
index cb0975b..efbfa76 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2016 Samsung Electronics Co.
+ *  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.
@@ -44,8 +44,8 @@ public:
     NotificationBackend() : m_poller(2), m_clientSocket(Socket::PeerType::CLIENT), m_running(false) {}
     virtual ~NotificationBackend();
 
-    virtual bool start(const std::string &client, const std::string &user,
-                       const std::string &privilege, RequestId requestId,
+    virtual bool start(const std::string &client, const std::string &pkgLabel,
+                       const std::string &user, const std::string &privilege, RequestId requestId,
                        UIResponseCallback responseCb);
     virtual bool setOutdated();
     virtual bool dismiss();
index 9b8d70c..4a5402f 100644 (file)
@@ -22,8 +22,6 @@ PKG_CHECK_MODULES(COMMON_DEP
     cynara-agent
     glib-2.0
     libsystemd
-    pkgmgr-info
-    security-manager
     security-privilege-manager
     )
 
@@ -42,7 +40,6 @@ INCLUDE_DIRECTORIES(
 
 SET(COMMON_SOURCES
     ${COMMON_PATH}/log/alog.cpp
-    ${COMMON_PATH}/policy/Policy.cpp
     ${COMMON_PATH}/policy/PrivilegeInfo.cpp
     ${COMMON_PATH}/socket/Socket.cpp
     ${COMMON_PATH}/socket/Poll.cpp
index 470e4a4..d1908d8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2014-2016 Samsung Electronics Co.
+ *  Copyright (c) 2014-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.
@@ -118,7 +118,7 @@ NotificationRequest dataToNotificationRequest(const std::string &data) {
     char separator;
 
     cynara_agent_req_id id;
-    std::string members[2];
+    std::string members[3];
 
     stream >> id;
     stream.read(&separator, 1);
@@ -134,15 +134,16 @@ NotificationRequest dataToNotificationRequest(const std::string &data) {
         member.assign(buffer.begin(), buffer.end());
     }
 
-    return NotificationRequest({id, std::move(members[0]), "", std::move(members[1])});
+    return NotificationRequest({id, std::move(members[0]), std::move(members[1]), "", std::move(members[2])});
 }
 
 std::string notificationRequestToData(RequestId id, const std::string &client,
-                                      const std::string &privilege)
+                                      const std::string &pkgLabel, const std::string &privilege)
 {
     const char separator = ' ';
     return std::to_string(id) + separator +
          std::to_string(client.length()) + separator + client + separator +
+         std::to_string(pkgLabel.length()) + separator + pkgLabel + separator +
          std::to_string(privilege.length()) + separator + privilege + separator + separator;
 }
 
index 3b8efdc..598d5c0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2014-2016 Samsung Electronics Co.
+ *  Copyright (c) 2014-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.
@@ -61,7 +61,7 @@ namespace Gui {
 std::string responseToString(NResponseType response);
 NotificationRequest dataToNotificationRequest(const std::string &data);
 std::string notificationRequestToData(RequestId id, const std::string &client,
-                                      const std::string &privilege);
+                                      const std::string &pkgLabel, const std::string &privilege);
 } // namespace Gui
 } // namespace Translator
 } // namespace AskUser
index 35e9e65..0963a64 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- *  Copyright (c) 2016 Samsung Electronics Co.
+ *  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.
@@ -22,6 +22,7 @@
 
 #pragma once
 
+#include <string>
 #include <types/RequestId.h>
 #include <types/RequestData.h>
 
@@ -30,12 +31,15 @@ namespace AskUser {
 struct NotificationRequest {
     NotificationRequest() : id(-1) {};
     NotificationRequest(RequestId id_) : id(id_) {};
-    NotificationRequest(RequestId id_, std::string client, std::string user, std::string privilege)
+    NotificationRequest(RequestId id_, std::string client, std::string pkgLabel,
+                        std::string user, std::string privilege)
     : id(id_),
-      data{std::move(client), std::move(user), std::move(privilege)}
+      data{std::move(client), std::move(user), std::move(privilege)},
+      pkgLabel(std::move(pkgLabel))
     {}
     RequestId id;
     RequestData data;
+    std::string pkgLabel;
 };
 
 } // namespace AskUser
index 667d18c..a82ef78 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * 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.
@@ -44,13 +44,15 @@ TEST(TranslatorTest, PluginData_Strings) {
 
 TEST(TranslatorTest, NotificationRequest) {
     cynara_agent_req_id id = 1234;
-    std::string app = "lorem ipsum dolor est amet";
+    std::string client = "lorem ipsum dolor est amet";
+    std::string pkgLabel = "My app";
     std::string privilege = "http://example.com/permissions/example";
 
-    auto data = Translator::Gui::notificationRequestToData(id, app, privilege);
+    auto data = Translator::Gui::notificationRequestToData(id, client, pkgLabel, privilege);
     auto request = Translator::Gui::dataToNotificationRequest(data);
 
     ASSERT_EQ(id, request.id);
-    ASSERT_EQ(app, request.data.client);
+    ASSERT_EQ(client, request.data.client);
     ASSERT_EQ(privilege, request.data.privilege);
+    ASSERT_EQ(pkgLabel, request.pkgLabel);
 }