Set app properties in popup 65/73165/2
authorsangwan.kwon <sangwan.kwon@samsung.com>
Tue, 7 Jun 2016 01:54:35 +0000 (10:54 +0900)
committersangwan.kwon <sangwan.kwon@samsung.com>
Tue, 7 Jun 2016 05:03:04 +0000 (14:03 +0900)
* Show app icon image.
* Set app version and label.

Change-Id: Iccfc93c1af0cb9cfc3b834298aa32448a777ad85

CMakeLists.txt
packaging/csr-framework.spec
src/framework/ui/CMakeLists.txt
src/framework/ui/popup/logic.cpp
src/framework/ui/popup/popup.cpp
src/framework/ui/popup/popup.h
src/framework/ui/res/default-icon.png [new file with mode: 0644]
test/popup/test-popup.cpp

index 1369c9e..43add48 100644 (file)
@@ -48,6 +48,7 @@ ADD_DEFINITIONS("-DPOPUP_SERVICE_ENV_FILE_PATH=\"${POPUP_SERVICE_ENV_FILE_PATH}\
 ADD_DEFINITIONS("-DENGINE_RW_WORKING_DIR=\"${ENGINE_RW_WORKING_DIR}\"")
 ADD_DEFINITIONS("-DENGINE_DIR=\"${ENGINE_DIR}\"")
 ADD_DEFINITIONS("-DTEST_DIR=\"${TEST_DIR}\"")
+ADD_DEFINITIONS("-DDEFAULT_ICON_PATH=\"${RO_RES_DIR}/default-icon.png\"")
 
 IF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
        ADD_DEFINITIONS("-DTIZEN_DEBUG_ENABLE")
index 7e8cc47..0b48e5d 100644 (file)
@@ -56,6 +56,7 @@ file contents and checking url to prevent malicious items.
 %global rw_data_dir                  /opt/share
 %global ro_db_dir                    %{ro_data_dir}/%{service_name}/dbspace
 %global rw_db_dir                    %{rw_data_dir}/%{service_name}/dbspace
+%global ro_res_dir                   %{ro_data_dir}/%{service_name}/res
 %global engine_rw_working_dir        %{rw_data_dir}/%{service_name}/%{engine_rw_dir_name}
 %global engine_dir                   %{ro_data_dir}/%{service_name}/%{engine_ro_dir_name}
 %global test_dir                     %{rw_data_dir}/%{service_name}-test
@@ -157,6 +158,7 @@ test program of csr-framework
     -DPOPUP_SYSTEMD_UNIT_DIR=%{popup_unitdir} \
     -DRO_DBSPACE:PATH=%{ro_db_dir} \
     -DRW_DBSPACE:PATH=%{rw_db_dir} \
+    -DRO_RES_DIR:PATH=%{ro_res_dir} \
     -DSERVICE_IDLE_TIMEOUT_TIME=%{service_idle_timeout_time} \
     -DPOPUP_SERVICE_IDLE_TIMEOUT_TIME=%{popup_service_idle_timeout_time} \
     -DENGINE_RW_WORKING_DIR:PATH=%{engine_rw_working_dir} \
@@ -252,6 +254,7 @@ fi
 %{popup_unitdir}/%{service_name}-popup.socket
 %{popup_unitdir}/sockets.target.wants/%{service_name}-popup.socket
 %{popup_unitdir}/%{service_name}-popup.service
+%{ro_res_dir}/default-icon.png
 
 %dir %{ro_data_dir}/%{service_name}
 %dir %attr(-, %{service_user}, %{service_group}) %{rw_data_dir}/%{service_name}
index 874139c..887fdea 100644 (file)
@@ -17,3 +17,4 @@
 # @brief
 #
 ADD_SUBDIRECTORY(popup)
+INSTALL(FILES res/default-icon.png DESTINATION ${RO_RES_DIR})
index 1b457bc..928aaca 100755 (executable)
@@ -30,7 +30,7 @@
 #include "common/audit/logger.h"
 #include "common/exception.h"
 #include "ui/common.h"
-
+#include "package-info.h"
 #include "popup.h"
 
 #include <csr-content-screening-types.h>
@@ -114,6 +114,7 @@ RawBuffer Logic::csPromptFile(const std::string &message, const CsDetected &d) c
 RawBuffer Logic::csPromptApp(const std::string &message, const CsDetected &d) const
 {
        std::string risk(d.severity == CSR_CS_SEVERITY_LOW ? "Low" : "Medium");
+       PackageInfo info(d.pkgId);
 
        Popup p(3);
 
@@ -121,9 +122,10 @@ RawBuffer Logic::csPromptApp(const std::string &message, const CsDetected &d) co
        p.setTitle("    Malware detected");
        p.setHeader("    Malware which is harm your phone is detected.");
        p.setBody(FORMAT(
-               "    App name : " << d.targetName << "<br>" <<
-               "    Version : " << "1.0" << "<br>" <<
+               "    App name : " << info.getLabel() << "<br>" <<
+               "    Version : " << info.getVersion() << "<br>" <<
                "    Risk : " << risk << " (" << d.malwareName << ")"));
+       p.setIcon(info.getIconPath());
        p.setFooter(
                "    Tap Uninstall to uninstall infected<br>"
                "    application and protect your phone.<br>"
@@ -203,14 +205,17 @@ RawBuffer Logic::csNotifyFile(const std::string &message, const CsDetected &d) c
 
 RawBuffer Logic::csNotifyApp(const std::string &message, const CsDetected &d) const
 {
+       PackageInfo info(d.pkgId);
+
        Popup p(2);
 
        p.setMessage(message);
        p.setTitle("    Malware detected");
        p.setHeader("    Malware which is harm your phone is detected.");
+       p.setIcon(info.getIconPath());
        p.setBody(FORMAT(
-               "    App name : " << d.targetName << "<br>" <<
-               "    Version : " << "1.0" << "<br>" <<
+               "    App name : " << info.getLabel() << "<br>" <<
+               "    Version : " << info.getVersion() << "<br>" <<
                "    Risk : " << "High" << " (" << d.malwareName << ")"));
        p.setFooter(
                "    Tap Uninstall to uninstall infected<br>"
index 9bb5517..89829c3 100644 (file)
  * @brief
  */
 #include "popup.h"
+#include <package-info.h>
 
 namespace Csr {
 namespace Ui {
 
 Popup::Popup(int buttonN)
 {
+       // Set win properties.
        m_win = elm_win_add(nullptr, "CSR popup", ELM_WIN_NOTIFICATION);
        elm_win_indicator_opacity_set(m_win, ELM_WIN_INDICATOR_TRANSLUCENT);
        elm_win_borderless_set(m_win, EINA_TRUE);
        elm_win_alpha_set(m_win, EINA_TRUE);
 
+       // Set popup properties.
        m_popup = elm_popup_add(m_win);
        evas_object_size_hint_weight_set(m_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
 
+       // Wrap objects with box.
        m_box = elm_box_add(m_popup);
-
        m_header = elm_label_add(m_box);
+
        evas_object_size_hint_align_set(m_header, EVAS_HINT_FILL, 0);
        elm_box_pack_end(m_box, m_header);
        evas_object_show(m_header);
 
-       m_body = elm_label_add(m_box);
+       // Subbox is for icon.
+       m_subBox = elm_box_add(m_box);
+       evas_object_size_hint_align_set(m_subBox, 0, 0);
+       elm_box_horizontal_set(m_subBox, TRUE);
+
+       // If icon is not set, it doesn't appear.
+       m_icon = elm_icon_add(m_subBox);
+       // TODO(sangwan.kwon) Fix icon size
+       elm_image_resizable_set(m_icon, EINA_FALSE, EINA_FALSE);
+       elm_box_pack_end(m_subBox, m_icon);
+       evas_object_show(m_icon);
+
+       m_body = elm_label_add(m_subBox);
        evas_object_size_hint_align_set(m_body, EVAS_HINT_FILL, 0);
-       elm_box_pack_end(m_box, m_body);
+       elm_box_pack_end(m_subBox, m_body);
        evas_object_show(m_body);
 
+       elm_box_pack_end(m_box, m_subBox);
+       evas_object_show(m_subBox);
+
+       // This label is for linking to webview.
        m_hypertext = elm_label_add(m_box);
        elm_object_text_set(m_hypertext,"<color=#0000FFFF>"
                "    More information</color>");
@@ -61,6 +81,7 @@ Popup::Popup(int buttonN)
 
        elm_object_content_set(m_popup, m_box);
 
+       // Add buttons dynamically.
        for(int i=1 ; i <= buttonN; i++) {
                std::string id("button" + std::to_string(i));
                Evas_Object *button = elm_button_add(m_popup);
@@ -101,12 +122,22 @@ void Popup::setMessage(const std::string &msg) noexcept
        m_message = msg;
 }
 
+void Popup::setIcon(const std::string &path) noexcept
+{
+       if (path.compare(PackageInfo::UNKNOWN) == 0)
+               elm_image_file_set(m_icon, DEFAULT_ICON_PATH, NULL);
+       else
+               elm_image_file_set(m_icon, path.c_str(), NULL);
+}
+
 void Popup::run(void)
 {
        m_objects.emplace_back(m_header);
        m_objects.emplace_back(m_body);
        m_objects.emplace_back(m_hypertext);
        m_objects.emplace_back(m_footer);
+       m_objects.emplace_back(m_icon);
+       m_objects.emplace_back(m_subBox);
        m_objects.emplace_back(m_box);
 
        for (auto &btn : m_buttons)
index 8e86720..31ade9c 100644 (file)
@@ -39,11 +39,15 @@ namespace Ui {
 /*
  * --------------------
  * |      title       |
- * --------------------
+ * ========box=========
  * | content(header)  |
- * | content(body)    |
+ * |------subBox------|
+ * |icon|content(body)|
+ * |------------------|
+ * | -hypertext       |
+ * |                  |
  * | content(footer)  |
- * --------------------
+ * ====================
  * |     button(N)    |
  * --------------------
  */
@@ -66,6 +70,7 @@ public:
        void setHeader(const std::string &header) noexcept;
        void setBody(const std::string &body) noexcept;
        void setFooter(const std::string &footer) noexcept;
+       void setIcon(const std::string &path) noexcept;
        void setText(Evas_Object *obj, const std::string &text) noexcept;
 
        void callbackRegister(Evas_Object *obj, const char *event, int *type);
@@ -79,12 +84,15 @@ private:
        Evas_Object *m_win;
        Evas_Object *m_popup;
        Evas_Object *m_box;
+       Evas_Object *m_subBox;
        Evas_Object *m_header;
        Evas_Object *m_body;
        Evas_Object *m_hypertext;
        Evas_Object *m_footer;
+       Evas_Object *m_icon;
 
        std::string m_message;
+       std::string m_iconPath;
        std::string m_hypertextUrl;
 
        static int response;
diff --git a/src/framework/ui/res/default-icon.png b/src/framework/ui/res/default-icon.png
new file mode 100644 (file)
index 0000000..9765b1b
Binary files /dev/null and b/src/framework/ui/res/default-icon.png differ
index 8883324..a87669a 100644 (file)
@@ -27,6 +27,7 @@
 #include <iostream>
 #include <boost/test/unit_test.hpp>
 
+#include "test-resource.h"
 #include "test-common.h"
 
 using namespace Csr;
@@ -125,7 +126,8 @@ BOOST_AUTO_TEST_CASE(prompt_app)
        EXCEPTION_GUARD_START
 
        CsDetected d;
-       d.targetName = "pkg_id_of_app";
+       // message pkg is for get icon temporary.
+       d.pkgId = "org.tizen.message";
        d.malwareName = "dummy malware in app";
        d.detailedUrl = "http://detailedurl/cs_prompt_app";
        d.severity = CSR_CS_SEVERITY_MEDIUM;
@@ -176,7 +178,11 @@ BOOST_AUTO_TEST_CASE(notify_app)
        EXCEPTION_GUARD_START
 
        CsDetected d;
-       d.targetName = "pkg_id_of_app";
+
+       Test::uninstall_app(TEST_WGT_PKG_ID);
+       ASSERT_INSTALL_APP(TEST_WGT_PATH, TEST_WGT_TYPE);
+
+       d.pkgId = TEST_WGT_PKG_ID;
        d.malwareName = "dummy malware in app";
        d.detailedUrl = "http://detailedurl/cs_notify_app";
        d.severity = CSR_CS_SEVERITY_HIGH;