#define MEMLIMIT_CONFIG_SERVICE MEMLIMIT_CONFIG_LIM_PFX "Service"
#define MEMLIMIT_CONFIG_GUIAPP MEMLIMIT_CONFIG_LIM_PFX "GUIApp"
#define MEMLIMIT_CONFIG_WIDGET MEMLIMIT_CONFIG_LIM_PFX "Widget"
+#define MEMLIMIT_CONFIG_BGAPP MEMLIMIT_CONFIG_LIM_PFX "BgApp"
#define MIN_LIMIT_VALUE 1 /* MB */
enum mem_limit_type {
static int mem_service_limit;
static int mem_guiapp_limit;
static int mem_widget_limit;
+static int mem_bgapp_limit;
struct memory_limit_event {
fd_handler_h fdh;
mem_guiapp_limit = limit;
else if (!strcmp(result->name, MEMLIMIT_CONFIG_WIDGET))
mem_widget_limit = limit;
+ else if (!strcmp(result->name, MEMLIMIT_CONFIG_BGAPP))
+ mem_bgapp_limit = limit;
}
return RESOURCED_ERROR_NONE;
return RESOURCED_ERROR_NONE;
}
+static int lowmem_limit_bgapp(void *data)
+{
+ assert(data);
+
+ struct proc_status *ps = (struct proc_status *)data;
+
+ lowmem_limit_set(ps->pid, mem_bgapp_limit);
+
+ return RESOURCED_ERROR_NONE;
+}
+
+static int lowmem_limit_fgapp(void *data)
+{
+ assert(data);
+
+ struct proc_status *ps = (struct proc_status *)data;
+
+ if ((mem_guiapp_limit && ps->pai->type == PROC_TYPE_GUI) ||
+ (mem_widget_limit && ps->pai->type == PROC_TYPE_WIDGET))
+ return lowmem_limit_appwidget(data);
+
+ _E("Unable to set foreground app limit - app type not supported");
+
+ return RESOURCED_ERROR_NONE;
+}
void lowmem_limit_init(void)
{
/* Load configuration */
register_notifier(RESOURCED_NOTIFIER_SERVICE_LAUNCH, lowmem_limit_service);
if (mem_guiapp_limit || mem_widget_limit)
register_notifier(RESOURCED_NOTIFIER_APP_LAUNCH, lowmem_limit_appwidget);
+ if (mem_bgapp_limit) {
+ if (!mem_guiapp_limit || !mem_widget_limit) {
+ _W("Background app limit requires that both GUIApp and Widget limits to be set to work properly. Ignoring.");
+ } else {
+ register_notifier(RESOURCED_NOTIFIER_APP_BACKGRD, lowmem_limit_bgapp);
+ register_notifier(RESOURCED_NOTIFIER_APP_FOREGRD, lowmem_limit_fgapp);
+ register_notifier(RESOURCED_NOTIFIER_WIDGET_FOREGRD, lowmem_limit_fgapp);
+ register_notifier(RESOURCED_NOTIFIER_WIDGET_BACKGRD, lowmem_limit_bgapp);
+ }
+ }
}
void lowmem_limit_exit(void)
unregister_notifier(RESOURCED_NOTIFIER_SERVICE_LAUNCH, lowmem_limit_service);
unregister_notifier(RESOURCED_NOTIFIER_APP_LAUNCH, lowmem_limit_appwidget);
+ unregister_notifier(RESOURCED_NOTIFIER_APP_BACKGRD, lowmem_limit_bgapp);
+ unregister_notifier(RESOURCED_NOTIFIER_APP_FOREGRD, lowmem_limit_fgapp);
+ unregister_notifier(RESOURCED_NOTIFIER_WIDGET_FOREGRD, lowmem_limit_fgapp);
+ unregister_notifier(RESOURCED_NOTIFIER_WIDGET_BACKGRD, lowmem_limit_bgapp);
}