From: Zofia Grzelewska Date: Mon, 29 Jan 2018 17:37:40 +0000 (+0100) Subject: Add timer to stop askuser-notification after being idle X-Git-Tag: submit/tizen/20180320.104353~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F05%2F168605%2F8;p=platform%2Fcore%2Fsecurity%2Faskuser.git Add timer to stop askuser-notification after being idle Timer is set for 1 seconds and if triggered and no event is to process for askuser-notification, then whole service is shutdown. Change-Id: I049e091494859d290232b6d10dc7f03a36442825 --- diff --git a/src/notification-daemon/Logic.cpp b/src/notification-daemon/Logic.cpp index 4c11f14..4967110 100644 --- a/src/notification-daemon/Logic.cpp +++ b/src/notification-daemon/Logic.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co. + * Copyright (c) 2017-2018 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. @@ -42,6 +42,8 @@ namespace Notification { namespace { +int ASKUSER_IDLE_TIMER_SEC = 4; + int uiResponseToClientResponse(NResponseType response) { int clientResponse; @@ -104,6 +106,10 @@ void Logic::addChannelFd(Protocol::ConnectionFd fd, const Protocol::Credentials std::string appId, pkgLabel; identifyApp(creds.label, appId, pkgLabel); + + ALOGD("Proper client connected"); + stopTimer(); + ConnectionInfo connInfo{appId, pkgLabel, creds.uid}; m_connToInfo.insert(it, std::make_pair(fd, connInfo)); } @@ -131,6 +137,10 @@ void Logic::removeChannelFd(Protocol::ConnectionFd fd) { ALOGD("Removing channel with fd " << fd); m_connToInfo.erase(fd); + if (m_connToInfo.empty()) { + ALOGD("No more clients"); + startTimer(); + } auto it = m_fdInfo.find(fd); if (it == m_fdInfo.end()) { return; @@ -335,6 +345,32 @@ Eina_Bool Logic::signalHandler(void *data, Ecore_Fd_Handler *) { return ECORE_CALLBACK_CANCEL; } +void Logic::startTimer() { + if (m_timer) + return; + ALOGD("Starting timer"); + m_timer = ecore_timer_add(ASKUSER_IDLE_TIMER_SEC, &Logic::timerHandler, this); + if (m_timer == nullptr) + ALOGE("Failed to add ecore timer"); +} + +void Logic::stopTimer() { + ALOGD("Stopping timer"); + if (m_timer == nullptr) + return; + (void)ecore_timer_del(m_timer); + m_timer = nullptr; +} + +Eina_Bool Logic::timerHandler(void *data) { + Logic *logic = static_cast(data); + if (logic->m_connToInfo.empty()) { + ALOGD("No connected clients to handle after timer run out. Closing..."); + logic->stop(); + } + return ECORE_CALLBACK_CANCEL; +} + void Logic::prepareChannel() { AskUser::Protocol::ServerCallbacksPtr callbacks(new AskUser::Protocol::ServerCallbacks(this)); std::unique_ptr channel(new AskUser::Protocol::ServerChannel(std::move(callbacks))); diff --git a/src/notification-daemon/Logic.h b/src/notification-daemon/Logic.h index 6c502bb..298d394 100644 --- a/src/notification-daemon/Logic.h +++ b/src/notification-daemon/Logic.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co. + * Copyright (c) 2017-2018 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. @@ -25,6 +25,8 @@ #include #include +#include + #include "event/Event.h" #include "PrivaciesSequence.h" @@ -43,7 +45,7 @@ public: private: std::string m_msg; }; - Logic() : m_currentEvent{-1, -1} {} + Logic() : m_currentEvent{-1, -1}, m_timer(nullptr) {} void init(); void run(); void stop(); @@ -81,15 +83,21 @@ private: // Descriptor handlers static Eina_Bool clientChHandler(void *data, Ecore_Fd_Handler *handler); static Eina_Bool signalHandler(void *data, Ecore_Fd_Handler *handler); + static Eina_Bool timerHandler(void *data); //static Eina_Bool signalHandler(void *data, int type, void *event); void addEvent(Protocol::ConnectionFd fd, Protocol::RequestId id, const std::vector &privacies); Eina_Bool processChannel(int fd, int mask); bool identifyClient(const std::string &label, std::string &appId, std::string &pkgId); + void processEvents(); void processResponse(const ConnectionInfo &conn, int clientResponse, const Policy &level); bool isEventProcessed(); void finishCurrentRequest(); + + void startTimer(); + void stopTimer(); + void popupResponse(NResponseType response); bool processError(EventId id, int error); @@ -120,11 +128,11 @@ private: std::map m_fdInfo; - - std::map m_connToInfo; std::map m_eventToPrivaciesSeq; + + Ecore_Timer *m_timer; }; } // namespace Notification