From 3efc27ca415d134c21495f27e67f499a3c971a59 Mon Sep 17 00:00:00 2001 From: Yunjin Lee Date: Mon, 11 Jun 2018 16:45:14 +0900 Subject: [PATCH] Add language changed callback for wearable profile - In case of wearable, language can be changed by connected mobile device while popup is showing hence add language changed callback for it. Change-Id: I1624314471f10bda9b6bceeaf11bad8b909dc51e Signed-off-by: Yunjin Lee (cherry picked from commit 5eee3a9a2ec91133b8052188fe64529aba4516b8) --- src/common/policy/Policy.cpp | 4 ++-- src/common/policy/Policy.h | 2 +- src/notification-daemon/Logic.cpp | 13 ++++++------ src/notification-daemon/Logic.h | 2 +- src/notification-daemon/event/Event.h | 8 +++---- src/notification-daemon/ui/Po.cpp | 28 ++++++++++++------------- src/notification-daemon/ui/Po.h | 3 ++- src/notification-daemon/ui/PopupCheckWearable.h | 22 +++++++++++++++++-- src/notification-daemon/ui/Popupper.cpp | 18 +++------------- src/notification-daemon/ui/Popupper.h | 4 ++-- 10 files changed, 56 insertions(+), 48 deletions(-) diff --git a/src/common/policy/Policy.cpp b/src/common/policy/Policy.cpp index 014871a..22ef685 100644 --- a/src/common/policy/Policy.cpp +++ b/src/common/policy/Policy.cpp @@ -124,7 +124,7 @@ std::vector getAppPolicy(const std::string &appId) { return fetch.fetchPolicy(); } -void identifyApp(PkgInfo &pkgInfo, const std::string &client, std::string &appId, std::string &pkgLabel) +void identifyApp(PkgInfo &pkgInfo, const std::string &client, std::string &appId, std::string &pkgId) { char *pkgName = nullptr; char *appName = nullptr; @@ -145,7 +145,7 @@ void identifyApp(PkgInfo &pkgInfo, const std::string &client, std::string &appId else appId = appName; - pkgLabel = pkgInfo.pkgLabel(pkgName, uid); + pkgId = pkgName; } std::string getOwnAppId(PkgInfo &pkgInfo) diff --git a/src/common/policy/Policy.h b/src/common/policy/Policy.h index 5be4334..5bcfb86 100644 --- a/src/common/policy/Policy.h +++ b/src/common/policy/Policy.h @@ -36,7 +36,7 @@ namespace AskUser { class PolicyEntryCopy; std::string getOwnAppId(PkgInfo &pkgInfo); -void identifyApp(PkgInfo &pkgInfo, const std::string &client, std::string &appId, std::string &pkgLabel); +void identifyApp(PkgInfo &pkgInfo, const std::string &client, std::string &appId, std::string &pkgId); std::set getManifestPrivs(const std::string &appId); diff --git a/src/notification-daemon/Logic.cpp b/src/notification-daemon/Logic.cpp index 14ac205..216f0ee 100644 --- a/src/notification-daemon/Logic.cpp +++ b/src/notification-daemon/Logic.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include "PolicyUpdater.h" #include "ServerCallbacks.h" @@ -105,14 +106,14 @@ void Logic::addChannelFd(Protocol::ConnectionFd fd, const Protocol::Credentials m_serverChannel->process(fd, 0); } - std::string appId, pkgLabel; + std::string appId, pkgId; PkgMgrPkgInfo pkgInfo; - identifyApp(pkgInfo, creds.label, appId, pkgLabel); + identifyApp(pkgInfo, creds.label, appId, pkgId); ALOGD("Proper client connected"); stopTimer(); - ConnectionInfo connInfo{appId, pkgLabel, creds.uid}; + ConnectionInfo connInfo{appId, pkgId, creds.uid}; m_connToInfo.insert(it, std::make_pair(fd, connInfo)); } catch (const std::exception &e) { ALOGE("Failed to add channel fd " << fd); @@ -216,7 +217,7 @@ void Logic::addEvent(Protocol::ConnectionFd fd, Protocol::RequestId id, const st Privacy currentPrivacy; seq.getNextPrivacy(currentPrivacy); - FdEvent fdEvent{eventId, std::unique_ptr(new EventPopupCheck(&m_popupper, conn.pkgLabel, currentPrivacy))}; + FdEvent fdEvent{eventId, std::unique_ptr(new EventPopupCheck(&m_popupper, conn.pkgId, currentPrivacy))}; m_pendingEvents.emplace_back(std::move(fdEvent)); } @@ -375,7 +376,7 @@ void Logic::updateChannel(int fd, int mask) { void Logic::init() { init_agent_log(); m_popupper.initialize(); - m_popupper.setLocale(); + Po::setLocale(); m_popupper.registerPopupResponseHandler([&](NResponseType response) { popupResponse(response);}); registerSignalFd(); @@ -455,7 +456,7 @@ void Logic::popupResponse(NResponseType response) { Privacy nextPrivacy; if (seq.getNextPrivacy(nextPrivacy)) { // More privacies to process - replace existing event with new privacy - FdEvent fdEvent{m_currentEvent, std::unique_ptr(new EventPopupCheck(&m_popupper, conn.pkgLabel, nextPrivacy))}; + FdEvent fdEvent{m_currentEvent, std::unique_ptr(new EventPopupCheck(&m_popupper, conn.pkgId, nextPrivacy))}; m_pendingEvents[0] = std::move(fdEvent); // don't call finishCurrentRequest here, because it will pop event, which we replaced m_currentEvent = EventId(); diff --git a/src/notification-daemon/Logic.h b/src/notification-daemon/Logic.h index 298d394..7360ae3 100644 --- a/src/notification-daemon/Logic.h +++ b/src/notification-daemon/Logic.h @@ -71,7 +71,7 @@ private: struct ConnectionInfo { std::string appId; - std::string pkgLabel; + std::string pkgId; std::string user; }; diff --git a/src/notification-daemon/event/Event.h b/src/notification-daemon/event/Event.h index ab4a91a..a56f523 100644 --- a/src/notification-daemon/event/Event.h +++ b/src/notification-daemon/event/Event.h @@ -40,15 +40,15 @@ protected: class EventPopupCheck : public IUIEvent { public: - EventPopupCheck(Popupper *popupper, const std::string &pkgLabel, const std::string &privacy) - : IUIEvent(popupper), m_pkgLabel(pkgLabel), m_privacy(privacy) + EventPopupCheck(Popupper *popupper, const std::string &pkgId, const std::string &privacy) + : IUIEvent(popupper), m_pkgId(pkgId), m_privacy(privacy) {} virtual void process() { - m_popupper->popupCheck(m_pkgLabel, m_privacy); + m_popupper->popupCheck(m_pkgId, m_privacy); } private: - std::string m_pkgLabel; + std::string m_pkgId; std::string m_privacy; }; diff --git a/src/notification-daemon/ui/Po.cpp b/src/notification-daemon/ui/Po.cpp index 10a5d63..9c78cd1 100644 --- a/src/notification-daemon/ui/Po.cpp +++ b/src/notification-daemon/ui/Po.cpp @@ -64,17 +64,6 @@ std::map MSG_PO = { {MsgType::MSG_TOAST_FAIL_TEXT, "IDS_IDLE_TPOP_TO_USE_APP_ALLOW_ALL_RELEVANT_PERMISSIONS"} }; -void setLocale() { - char *lang = vconf_get_str(VCONFKEY_LANGSET); - if (lang) - { - elm_language_set(lang); - free(lang); - } else { - ALOGE("Couldn't fetch language from vconf failed."); - } -} - template std::string makeFromFormat(const char *format, Args... args) { char *buf; @@ -87,7 +76,6 @@ std::string makeFromFormat(const char *format, Args... args) { } const char *getFormat(enum MsgType type) { - setLocale(); return dgettext(PROJECT_NAME, MSG_PO[type]); } @@ -95,8 +83,20 @@ const char *getFormat(enum MsgType type) { namespace Notification { namespace Po { -std::string createPopupCheckMsg(const std::string &pkgLabel, const std::string &privacy) { - return makeFromFormat(getFormat(MsgType::MSG_POPUP_TEXT), pkgLabel.c_str(), +void setLocale() { + char *lang = vconf_get_str(VCONFKEY_LANGSET); + if (lang) + { + elm_language_set(lang); + free(lang); + } else { + ALOGE("Couldn't fetch language from vconf failed."); + } +} + +std::string createPopupCheckMsg(const std::string &pkgId, const std::string &privacy) { + PkgMgrPkgInfo pkgInfo; + return makeFromFormat(getFormat(MsgType::MSG_POPUP_TEXT), pkgInfo.pkgLabel(pkgId, getuid()).c_str(), PrivilegeInfo::getPrivacyDisplayName(privacy).c_str()); } diff --git a/src/notification-daemon/ui/Po.h b/src/notification-daemon/ui/Po.h index d4cb8bd..b76d2e3 100644 --- a/src/notification-daemon/ui/Po.h +++ b/src/notification-daemon/ui/Po.h @@ -26,9 +26,10 @@ namespace AskUser { namespace Notification { namespace Po { -std::string createPopupCheckMsg(const std::string &pkgLabel, const std::string &priv); +std::string createPopupCheckMsg(const std::string &pkgId, const std::string &priv); std::string createPrivilegeDescr(const std::string &priv); +void setLocale(); std::string getPopupTitleMsg(); std::string getAllowButtonMsg(); std::string getDenyButtonMsg(); diff --git a/src/notification-daemon/ui/PopupCheckWearable.h b/src/notification-daemon/ui/PopupCheckWearable.h index a6fa126..656fd82 100644 --- a/src/notification-daemon/ui/PopupCheckWearable.h +++ b/src/notification-daemon/ui/PopupCheckWearable.h @@ -33,8 +33,8 @@ namespace Notification { class PopupCheckWearable : public PopupCheck { public: - PopupCheckWearable(Evas_Object *parent, const std::string msg) - : PopupCheck(parent, msg) + PopupCheckWearable(Evas_Object *parent, const std::string &msg, const std::string &pkgId, const std::string &privacy) + : PopupCheck(parent, msg), m_pkgId(pkgId), m_privacy(privacy) {} ~PopupCheckWearable() {} static Eina_Bool rotaryChangedCb(void *data, Evas_Object *, Eext_Rotary_Event_Info *info) { @@ -56,6 +56,19 @@ public: } return EINA_TRUE; } + static void langChangedCb(keynode_t *, void *data) + { + PopupCheckWearable *popup = static_cast(data); + + Po::setLocale(); + elm_object_part_text_set(popup->m_layout, "elm.text.title", Po::getPopupTitleMsg().c_str()); + elm_atspi_accessible_name_set(popup->ao_title_text, Po::getPopupTitleMsg().c_str()); + elm_object_text_set(popup->m_content, Po::createPopupCheckMsg(popup->m_pkgId, popup->m_privacy).c_str()); + elm_object_text_set(popup->m_checkBox, Po::getCheckBoxMsg().c_str()); + elm_atspi_accessible_name_set(popup->m_allowButton, Po::getAllowButtonMsg().c_str()); + elm_atspi_accessible_name_set(popup->m_denyButton, Po::getDenyButtonMsg().c_str()); + + } virtual void create() { elm_object_style_set(m_popup, "circle"); elm_popup_scrollable_set(m_popup, EINA_FALSE); @@ -158,6 +171,9 @@ public: evas_object_show(icon); elm_atspi_accessible_name_set(m_denyButton, Po::getDenyButtonMsg().c_str()); + /* language changed callback */ + vconf_notify_key_changed(VCONFKEY_LANGSET, &PopupCheckWearable::langChangedCb, this); + evas_object_show(m_popup); } private: @@ -167,6 +183,8 @@ private: Evas_Object *m_layout = nullptr; Evas_Object *m_layoutInner = nullptr; Evas_Object *m_scroller = nullptr; + std::string m_pkgId; + std::string m_privacy; }; } /* namespace Notification */ diff --git a/src/notification-daemon/ui/Popupper.cpp b/src/notification-daemon/ui/Popupper.cpp index bc3e3b4..6c8d4ca 100644 --- a/src/notification-daemon/ui/Popupper.cpp +++ b/src/notification-daemon/ui/Popupper.cpp @@ -150,32 +150,20 @@ void Popupper::initialize() ecore_event_handler_add(ECORE_EVENT_KEY_UP, &Popupper::hwKeyClickedCb, this); } -void Popupper::setLocale() -{ - char *lang = vconf_get_str(VCONFKEY_LANGSET); - if (lang) - { - elm_language_set(lang); - free(lang); - } else { - ALOGE("Couldn't fetch language from vconf failed."); - } -} - void Popupper::show() { evas_object_show(m_win); } -void Popupper::popupCheck(const std::string &pkgLabel, const std::string &privacy) { +void Popupper::popupCheck(const std::string &pkgId, const std::string &privacy) { std::string profileName = getProfileName(); PopupCheck *popup; try { if (profileName[0] != 'w' && profileName[0] != 'W') { // Not wearable - popup = new PopupCheckMobile(m_win, Po::createPopupCheckMsg(pkgLabel, privacy)); + popup = new PopupCheckMobile(m_win, Po::createPopupCheckMsg(pkgId, privacy)); } else { // Wearable - popup = new PopupCheckWearable(m_win, Po::createPopupCheckMsg(pkgLabel, privacy)); + popup = new PopupCheckWearable(m_win, Po::createPopupCheckMsg(pkgId, privacy), pkgId, privacy); } popup->create(); } catch (const std::exception &e) { diff --git a/src/notification-daemon/ui/Popupper.h b/src/notification-daemon/ui/Popupper.h index c83ea81..711721b 100644 --- a/src/notification-daemon/ui/Popupper.h +++ b/src/notification-daemon/ui/Popupper.h @@ -27,6 +27,7 @@ #include #include #include +#include #include "Answerable.h" #include "Popup.h" @@ -43,11 +44,10 @@ public: Popupper() = default; void initialize(); - void setLocale(); void registerPopupResponseHandler(PopupHandler handler); void start(); - void popupCheck(const std::string &pkgLabel, const std::string &privacy); + void popupCheck(const std::string &pkgId, const std::string &privacy); void popupClose(); void stop(); -- 2.7.4