#include <sys/types.h>
#include <time.h>
+#include <list>
+#include <utility>
#include <app_manager.h>
#include <Json.h>
/* Active window changes frequently.
* We thus consider the apps being foregrounded at least 3 secs */
#define ONE_DAY_IN_SEC 86400
+#define DEFAULT_CACHE_SIZE 10
+#define TOP_TIER_LIMIT 2
+
+class AppDisplayTypeCache {
+private:
+ unsigned int __size;
+ std::list<std::pair<std::string, bool>> __cache;
+
+public:
+ AppDisplayTypeCache(unsigned int size) :
+ __size(size)
+ {
+ }
+
+ void put(const std::string& appId, bool noDisp)
+ {
+ __cache.push_front(std::make_pair(appId, noDisp));
+
+ if (__cache.size() > __size)
+ __cache.pop_back();
+ }
+
+ bool get(const std::string& appId, bool* noDisp)
+ {
+ int index = 0;
+
+ for (auto it = __cache.begin(); it != __cache.end(); ++it) {
+ if ((*it).first != appId) {
+ ++index;
+ continue;
+ }
+
+ *noDisp = (*it).second;
+
+ if (index > TOP_TIER_LIMIT) {
+ __cache.erase(it);
+ __cache.push_front(std::make_pair(appId, *noDisp));
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+};
ctx::AppUseMonitor::AppUseMonitor() :
__signalId(-1),
bool ctx::AppUseMonitor::__isSkippable(std::string appId)
{
- /* TODO: circular cache */
+ static AppDisplayTypeCache __cache(DEFAULT_CACHE_SIZE);
+
+ bool noDisp = false;
+
+ if (__cache.get(appId, &noDisp))
+ return noDisp;
+
+ _D("No cache for '%s'", appId.c_str());
+
app_info_h appInfo = NULL;
int err = app_manager_get_app_info(appId.c_str(), &appInfo);
IF_FAIL_RETURN_TAG(err == APP_MANAGER_ERROR_NONE && appInfo, true, _E, "app_manager_get_app_info() failed");
- bool nodisp = false;
- err = app_info_is_nodisplay(appInfo, &nodisp);
+ err = app_info_is_nodisplay(appInfo, &noDisp);
if (err != APP_MANAGER_ERROR_NONE) {
app_info_destroy(appInfo);
_E("app_info_is_nodisplay() failed");
}
app_info_destroy(appInfo);
- return nodisp;
+
+ __cache.put(appId, noDisp);
+
+ return noDisp;
}
void ctx::AppUseMonitor::__removeExpired()