3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Flora License, Version 1.0 (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;
92 static void _back_cb(void *data, Evas_Object *obj, void *event_info)
97 int _app_create(struct appdata *ad)
99 Evas_Object *ly, *bg, *nv, *bt, *gl;
101 retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
102 ad->ending = EINA_FALSE;
104 ly = _add_layout_main(ad->win, EINA_TRUE, EINA_FALSE);
105 retvm_if(ly == NULL, -1, "Failed to add layout main\n");
107 bg = _add_bg(ad->win, "group_list");
108 retvm_if(bg == NULL, -1, "Failed to add bg\n");
109 elm_object_part_content_set(ly, "elm.swallow.bg", bg);
111 nv = _add_naviframe(ly);
112 retvm_if(nv == NULL, -1, "Failed to add naviframe\n");
115 ly = _add_layout(ad->nv, EDJ_NAME, GRP_TM);
116 retvm_if(ly == NULL, -1, "Failed to add layout\n");
119 /* Load default content (running task) */
120 gl = _add_genlist(ly);
121 retvm_if(gl == NULL, -1, "Failed to add genlist\n");
122 elm_genlist_block_count_set(gl, 20);
123 evas_object_data_set(gl, "appdata", ad);
124 elm_object_part_content_set(ly, "list", gl);
127 bt = elm_button_add(nv);
128 retvm_if(bt == NULL, -1, "Failed to add button\n");
129 elm_object_style_set(bt, "naviframe/end_btn/default");
130 evas_object_smart_callback_add(bt, "clicked", _back_cb, ad);
132 elm_naviframe_item_push(nv,
133 T_("IDS_TASKMGR_HEADER_TASK_SWITCHER"),
139 static void _get_win_geometry(struct appdata *ad)
141 Ecore_X_Window focus_win;
142 Ecore_X_Window root_win;
144 focus_win = ecore_x_window_focus_get();
145 root_win = ecore_x_window_root_get(focus_win);
146 ecore_x_window_size_get(root_win, &ad->root_w, &ad->root_h);
149 /* this func is to exit taskmanager after launching application */
150 static Eina_Bool __climsg_cb(void *data, int type, void *event)
152 _D("%s\n", __func__);
156 struct appdata *ad = (struct appdata *)data;
157 Ecore_X_Event_Client_Message *ev = event;
160 _E("Invalid argument: event is NULL\n");
161 ad->exit_timer = ecore_timer_add(0.3, _exit_cb, ad);
162 return ECORE_CALLBACK_CANCEL;
165 pid_a = ev->data.l[1];
166 pid_d = ev->data.l[3];
167 a_deact = ecore_x_atom_get("_X_ILLUME_DEACTIVATE_WINDOW");
169 /* when pid_a == pid_d, this is useless data */
170 if (pid_a == pid_d) {
171 return ECORE_CALLBACK_RENEW;
174 if (ev->message_type == a_deact) {
175 ad->exit_timer = ecore_timer_add(0.3, _exit_cb, ad);
176 return ECORE_CALLBACK_CANCEL;
178 _D("messagre is act\n");
182 return ECORE_CALLBACK_CANCEL;
185 static int runapp_count = 0;
187 int _runapp_info_get_count(const aul_app_info *ainfo, void *data)
189 ail_appinfo_h handle;
193 retvm_if(ainfo == NULL, -1, "Invalid argument: ainfo is NULL\n");
195 retvm_if(ainfo->pid <= 0, -1, "Invalid pid(%u)\n", ainfo->pid);
198 if (ainfo->pid == getpid())
203 retvm_if(ainfo->pkg_name == NULL, 0, "Invalid pkg_name(%s)\n", ainfo->pkg_name);
205 ret = ail_package_get_appinfo(ainfo->pkg_name, &handle);
206 retvm_if(ret != AIL_ERROR_OK, -1,
207 "Failed to get appinfo, pkg_name:%s\n", ainfo->pkg_name);
209 ret = ail_appinfo_get_bool(handle, AIL_PROP_X_SLP_TASKMANAGE_BOOL, &is_taskmanage);
210 if (is_taskmanage == 0) {
211 ret = ail_package_destroy_appinfo(handle);
212 retvm_if(ret != AIL_ERROR_OK, -1, "Failed to destroy appinfo\n");
217 _D("running(%s)\n", ainfo->pkg_name);
218 _D("runapp count : %d\n", runapp_count);
220 ret = ail_package_destroy_appinfo(handle);
221 retvm_if(ret != AIL_ERROR_OK, -1, "Failed to destroy appinfo\n");
225 Eina_Bool _kill_all_timer_cb(void *data)
229 struct appdata *ad = data;
231 int ret = AUL_R_ERROR;
233 int sleep_value = 500;
237 while(ret != AUL_R_OK && retry_cnt < 5)
240 ret = aul_app_get_running_app_info(_runapp_info_get_count, ad);
244 _D("Fail to get running app information\n");
250 _D("runapp count : %d\n", runapp_count);
252 /* count inuse app number */
253 /** if(count == 0) dead_cb */
254 if(runapp_count == 0)
256 _D("runapp_count == 0\n");
257 _del_popup_timer(ad);
258 _del_progressbar(ad);
259 refresh_app_info(ad);
260 //_restart_pthread(ad);
261 return ECORE_CALLBACK_CANCEL;
264 return ECORE_CALLBACK_RENEW;
267 void _ok_response_cb(void *data, Evas_Object *obj, void *event_info)
269 struct appdata *ad = (struct appdata *)data;
271 retm_if(data == NULL, "Invalid argument: appdata is NULL\n");
273 evas_object_del(ad->popup_ask);
274 ad->popup_ask = NULL;
280 _del_popup_timer(ad);
281 _show_progressbar(ad);
282 response_end_inuse(ad);
283 //_restart_pthread(ad);
286 case MODE_END_ALL_INUSE:
287 _D("end all inuse\n");
288 _del_popup_timer(ad);
289 _show_progressbar(ad);
290 response_end_all_inuse(ad);
291 ad->killall_timer = ecore_timer_add(2.0, _kill_all_timer_cb, ad);
294 case MODE_DEL_HISTORY:
296 _del_popup_timer(ad);
297 response_del_history(ad);
300 case MODE_DEL_ALL_HISTORY:
301 _D("del all inuse\n");
302 _del_popup_timer(ad);
303 response_del_all_history(ad);
306 case MODE_KILL_INUSE:
307 _D("kill all inuse\n");
308 response_kill_inuse(ad);
311 case MODE_KILL_ALL_INUSE:
312 _D("kill all inuse\n");
313 response_kill_all_inuse(ad);
317 printf("[Wanning] taskmanager: check mode [%d]\n",
323 void _cancel_response_cb(void *data, Evas_Object *obj, void *event_info)
325 struct appdata *ad = (struct appdata *)data;
327 retm_if(data == NULL, "Invalid argument: appdata is NULL\n");
329 evas_object_del(ad->popup_ask);
330 ad->popup_ask = NULL;
334 Eina_Bool _create_idler_cb(void *data)
336 struct appdata *ad = (struct appdata *)data;
337 retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "Invalid argument\n");
339 evas_object_show(ad->win);
343 _get_win_geometry(ad);
344 ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, __climsg_cb, ad);
346 return ECORE_CALLBACK_CANCEL;