3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Flora License, Version 1.1 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://floralicense.org/license/
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an AS IS BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 #include <appcore-common.h>
27 #include "taskmanager.h"
28 #include "_util_log.h"
29 #include "_util_efl.h"
32 #include "_progressbar.h"
35 int _dead_cb(int pid, void *data)
39 struct appdata *ad = (struct appdata *)data;
40 retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
44 if (ad->update_timer) {
45 ecore_timer_del(ad->update_timer);
46 ad->update_timer = NULL;
49 ret = _subt_einalist_item(ad, pid);
50 _D("mode(%d) count(%d) pid(%d) \n", ad->mode, ad->endcnt, pid);
56 case MODE_DEL_HISTORY:
57 case MODE_DEL_ALL_HISTORY:
63 //_restart_pthread(ad);
66 case MODE_END_ALL_INUSE:
67 case MODE_KILL_ALL_INUSE:
69 if (ad->endcnt <= 1) {
74 ecore_timer_del(ad->killall_timer);
75 ad->killall_timer = NULL;
81 evas_object_del(ad->popup_ask);
96 static void _back_cb(void *data, Evas_Object *obj, void *event_info)
101 int _app_create(struct appdata *ad)
103 Evas_Object *ly, *bg, *nv, *bt, *gl;
104 Evas_Object *conform = NULL;
107 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
109 retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
110 ad->ending = EINA_FALSE;
112 conform = elm_conformant_add(ad->win);
113 retvm_if(conform == NULL, -1, "Failed to add conformant \n");
114 evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
115 elm_win_resize_object_add(ad->win, conform);
116 evas_object_show(conform);
118 ly = _add_layout_main(conform, EINA_TRUE, EINA_FALSE);
119 retvm_if(ly == NULL, -1, "Failed to add layout main\n");
120 elm_object_content_set(conform, ly);
121 evas_object_resize(ly, w, h);
123 bg = _add_bg(ad->win, "group_list");
124 retvm_if(bg == NULL, -1, "Failed to add bg\n");
125 elm_object_part_content_set(ly, "elm.swallow.bg", bg);
127 nv = _add_naviframe(ly);
128 retvm_if(nv == NULL, -1, "Failed to add naviframe\n");
131 ly = _add_layout(ad->nv, EDJ_NAME, GRP_TM);
132 retvm_if(ly == NULL, -1, "Failed to add layout\n");
135 /* Load default content (running task) */
136 gl = _add_genlist(ly);
137 retvm_if(gl == NULL, -1, "Failed to add genlist\n");
138 elm_genlist_block_count_set(gl, 20);
139 evas_object_data_set(gl, "appdata", ad);
140 elm_object_part_content_set(ly, "list", gl);
143 bt = elm_button_add(nv);
144 retvm_if(bt == NULL, -1, "Failed to add button\n");
145 elm_object_style_set(bt, "naviframe/end_btn/default");
146 evas_object_smart_callback_add(bt, "clicked", _back_cb, ad);
148 elm_naviframe_item_push(nv,
149 T_("IDS_TASKMGR_HEADER_TASK_SWITCHER"),
154 static void _get_win_geometry(struct appdata *ad)
156 Ecore_X_Window focus_win;
157 Ecore_X_Window root_win;
159 focus_win = ecore_x_window_focus_get();
160 root_win = ecore_x_window_root_get(focus_win);
161 ecore_x_window_size_get(root_win, &ad->root_w, &ad->root_h);
164 /* this func is to exit taskmanager after launching application */
165 static Eina_Bool __climsg_cb(void *data, int type, void *event)
167 _D("%s\n", __func__);
171 struct appdata *ad = (struct appdata *)data;
172 Ecore_X_Event_Client_Message *ev = event;
175 _E("Invalid argument: event is NULL\n");
177 return ECORE_CALLBACK_CANCEL;
180 pid_a = ev->data.l[1];
181 pid_d = ev->data.l[3];
182 a_deact = ecore_x_atom_get("_X_ILLUME_DEACTIVATE_WINDOW");
184 /* when pid_a == pid_d, this is useless data */
185 if (pid_a == pid_d) {
186 return ECORE_CALLBACK_RENEW;
189 if (ev->message_type == a_deact) {
191 return ECORE_CALLBACK_CANCEL;
193 _D("messagre is act\n");
197 return ECORE_CALLBACK_CANCEL;
200 static int runapp_count = 0;
202 int _runapp_info_get_count(const aul_app_info *ainfo, void *data)
204 ail_appinfo_h handle;
208 retvm_if(ainfo == NULL, -1, "Invalid argument: ainfo is NULL\n");
210 retvm_if(ainfo->pid <= 0, -1, "Invalid pid(%u)\n", ainfo->pid);
213 if (ainfo->pid == getpid())
218 retvm_if(ainfo->pkg_name == NULL, 0, "Invalid pkg_name(%s)\n", ainfo->pkg_name);
220 ret = ail_package_get_appinfo(ainfo->pkg_name, &handle);
221 retvm_if(ret != AIL_ERROR_OK, -1,
222 "Failed to get appinfo, pkg_name:%s\n", ainfo->pkg_name);
224 ret = ail_appinfo_get_bool(handle, AIL_PROP_X_SLP_TASKMANAGE_BOOL, &is_taskmanage);
225 if (is_taskmanage == 0) {
226 ret = ail_package_destroy_appinfo(handle);
227 retvm_if(ret != AIL_ERROR_OK, -1, "Failed to destroy appinfo\n");
232 _D("running(%s)\n", ainfo->pkg_name);
233 _D("runapp count : %d\n", runapp_count);
235 ret = ail_package_destroy_appinfo(handle);
236 retvm_if(ret != AIL_ERROR_OK, -1, "Failed to destroy appinfo\n");
240 Eina_Bool _kill_all_timer_cb(void *data)
244 struct appdata *ad = data;
246 int ret = AUL_R_ERROR;
248 int sleep_value = 500;
252 while(ret != AUL_R_OK && retry_cnt < 5)
255 ret = aul_app_get_running_app_info(_runapp_info_get_count, ad);
259 _D("Fail to get running app information\n");
265 _D("runapp count : %d\n", runapp_count);
267 /* count inuse app number */
268 /** if(count == 0) dead_cb */
269 if(runapp_count == 0)
271 _D("runapp_count == 0\n");
272 _del_popup_timer(ad);
273 _del_progressbar(ad);
275 evas_object_del(ad->popup_ask);
276 ad->popup_ask = NULL;
278 refresh_app_info(ad);
279 //_restart_pthread(ad);
280 return ECORE_CALLBACK_CANCEL;
283 return ECORE_CALLBACK_RENEW;
286 void _ok_response_cb(void *data, Evas_Object *obj, void *event_info)
288 struct appdata *ad = (struct appdata *)data;
290 retm_if(data == NULL, "Invalid argument: appdata is NULL\n");
295 evas_object_del(ad->popup_ask);
296 ad->popup_ask = NULL;
299 _del_popup_timer(ad);
300 _show_progressbar(ad);
301 response_end_inuse(ad);
302 //_restart_pthread(ad);
305 case MODE_END_ALL_INUSE:
306 _D("end all inuse\n");
307 _del_popup_timer(ad);
308 _show_progressbar(ad);
309 _diable_popup(ad->popup_ask);
310 response_end_all_inuse(ad);
311 ad->killall_timer = ecore_timer_add(2.0, _kill_all_timer_cb, ad);
314 case MODE_DEL_HISTORY:
316 evas_object_del(ad->popup_ask);
317 ad->popup_ask = NULL;
320 _del_popup_timer(ad);
321 response_del_history(ad);
324 case MODE_DEL_ALL_HISTORY:
326 evas_object_del(ad->popup_ask);
327 ad->popup_ask = NULL;
329 _D("del all inuse\n");
330 _del_popup_timer(ad);
331 response_del_all_history(ad);
334 case MODE_KILL_INUSE:
336 evas_object_del(ad->popup_ask);
337 ad->popup_ask = NULL;
339 _D("kill all inuse\n");
340 response_kill_inuse(ad);
343 case MODE_KILL_ALL_INUSE:
345 evas_object_del(ad->popup_ask);
346 ad->popup_ask = NULL;
348 _D("kill all inuse\n");
349 response_kill_all_inuse(ad);
354 evas_object_del(ad->popup_ask);
355 ad->popup_ask = NULL;
357 printf("[Wanning] taskmanager: check mode [%d]\n",
363 void _cancel_response_cb(void *data, Evas_Object *obj, void *event_info)
365 struct appdata *ad = (struct appdata *)data;
367 retm_if(data == NULL, "Invalid argument: appdata is NULL\n");
369 evas_object_del(ad->popup_ask);
370 ad->popup_ask = NULL;
374 Eina_Bool _create_idler_cb(void *data)
376 struct appdata *ad = (struct appdata *)data;
377 retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "Invalid argument\n");
381 evas_object_show(ad->win);
385 _get_win_geometry(ad);
386 ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, __climsg_cb, ad);
388 return ECORE_CALLBACK_CANCEL;