[Task-mgr] Merge 3.0 into 2.4
[apps/core/preloaded/taskmanager.git] / src / util.c
1 /*
2  *  Task Manager
3  *
4  * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <Elementary.h>
21 #include <app_manager.h>
22 //#include <app_manager_extension.h>
23 #include <app_control.h>
24 #include <stdbool.h>
25
26 #include "log.h"
27 #include "util.h"
28
29
30
31 extern Eina_Bool util_kill_app(const char *appid)
32 {
33         app_context_h context = NULL;
34         Eina_Bool ret = EINA_TRUE;
35
36         retv_if(!appid, EINA_FALSE);
37
38         ret = app_manager_get_app_context(appid, &context);
39         if (ret != APP_MANAGER_ERROR_NONE) {
40                 _E("fail to app_manager_get_app_context(%d)", ret);
41                 return EINA_FALSE;
42         }
43
44         ret = app_manager_terminate_app(context);
45         app_context_destroy(context);
46
47         if (ret != APP_MANAGER_ERROR_NONE) {
48                 _E("fail to terminate_app (%d)", ret);
49                 return EINA_FALSE;
50         }
51
52         _D("terminate app = %s", appid);
53
54         return ret;
55 }
56
57
58
59 extern Eina_Bool util_launch_app(const char *appid)
60 {
61         int ret;
62         bool running = false;
63
64         if (!appid || strlen(appid) == 0) {
65                  _E("Fail to launch, due to Null appid.");
66                 return EINA_FALSE;
67         }
68         _D("Launching: %s", appid);
69         ret = app_manager_is_running(appid, &running);
70         retv_if(APP_MANAGER_ERROR_NONE != ret, EINA_FALSE);
71
72         if (running) {
73                 _D("THE APP IS RUNNING");
74
75                 app_context_h context = NULL;
76                 ret = app_manager_get_app_context(appid, &context);
77                 if (ret != APP_MANAGER_ERROR_NONE) {
78                         _E("fail to app_manager_get_app_context(%d)", ret);
79                         return EINA_FALSE;
80                 }
81
82                 ret = app_manager_resume_app(context);
83                 app_context_destroy(context);
84
85                 if (ret != APP_MANAGER_ERROR_NONE) {
86                         _E("fail to app_manager_resume_app(%d)", ret);
87                         return EINA_FALSE;
88                 }
89
90         } else {
91                 _D("THE APP IS NOT RUNNING");
92
93                 app_control_h service = NULL;
94                 retv_if(APP_CONTROL_ERROR_NONE != app_control_create(&service), EINA_FALSE);
95                 retv_if(!service, EINA_FALSE);
96
97                 app_control_set_operation(service, APP_CONTROL_OPERATION_MAIN);
98                 app_control_set_app_id(service, appid);
99
100                 ret = app_control_send_launch_request(service, NULL, NULL);
101                 (void)app_control_destroy(service);
102                 retv_if(APP_CONTROL_ERROR_NONE != ret, EINA_FALSE);
103         }
104
105         return EINA_TRUE;
106 }
107
108
109
110 //End of file