2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
26 #include <app_manager.h>
27 #include <app_manager_private.h>
33 #define LOG_TAG "CAPI_APPFW_APP_MANAGER"
36 static const char* app_manager_error_to_string(app_manager_error_e error)
40 case APP_MANAGER_ERROR_NONE:
43 case APP_MANAGER_ERROR_INVALID_PARAMETER:
44 return "INVALID_PARAMETER";
46 case APP_MANAGER_ERROR_OUT_OF_MEMORY:
47 return "OUT_OF_MEMORY";
49 case APP_MANAGER_ERROR_IO_ERROR:
52 case APP_MANAGER_ERROR_NO_SUCH_APP:
55 case APP_MANAGER_ERROR_DB_FAILED:
58 case APP_MANAGER_ERROR_INVALID_PACKAGE:
59 return "INVALID_PACKAGE";
66 int app_manager_error(app_manager_error_e error, const char* function, const char *description)
70 LOGE("[%s] %s(0x%08x) : %s", function, app_manager_error_to_string(error), error, description);
74 LOGE("[%s] %s(0x%08x)", function, app_manager_error_to_string(error), error);
81 int app_manager_set_app_context_event_cb(app_manager_app_context_event_cb callback, void *user_data)
85 retval = app_context_set_event_cb(callback, user_data);
87 if (retval != APP_MANAGER_ERROR_NONE)
89 return app_manager_error(retval, __FUNCTION__, NULL);
93 return APP_MANAGER_ERROR_NONE;
97 void app_manager_unset_app_context_event_cb(void)
99 app_context_unset_event_cb();
102 int app_manager_foreach_app_context(app_manager_app_context_cb callback, void *user_data)
106 retval = app_context_foreach_app_context(callback, user_data);
108 if (retval != APP_MANAGER_ERROR_NONE)
110 return app_manager_error(retval, __FUNCTION__, NULL);
114 return APP_MANAGER_ERROR_NONE;
118 int app_manager_get_app_context(const char *app_id, app_context_h *app_context)
122 retval = app_context_get_app_context(app_id, app_context);
124 if (retval != APP_MANAGER_ERROR_NONE)
126 return app_manager_error(retval, __FUNCTION__, NULL);
130 return APP_MANAGER_ERROR_NONE;
134 int app_manager_resume_app(app_context_h app_context)
138 if (app_context == NULL)
140 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
143 if (app_context_get_app_id(app_context, &app_id) != APP_MANAGER_ERROR_NONE)
145 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to get the application ID");
148 aul_resume_app(app_id);
150 return APP_MANAGER_ERROR_NONE;
153 int app_manager_set_app_info_event_cb(app_manager_app_info_event_cb callback, void *user_data)
157 retval = app_info_set_event_cb(callback, user_data);
159 if (retval != APP_MANAGER_ERROR_NONE)
161 return app_manager_error(retval, __FUNCTION__, NULL);
165 return APP_MANAGER_ERROR_NONE;
169 void app_manager_unset_app_info_event_cb(void)
171 app_info_unset_event_cb();
175 int app_manager_foreach_app_info(app_manager_app_info_cb callback, void *user_data)
179 retval = app_info_foreach_app_info(callback, user_data);
181 if (retval != APP_MANAGER_ERROR_NONE)
183 return app_manager_error(retval, __FUNCTION__, NULL);
187 return APP_MANAGER_ERROR_NONE;
191 int app_manager_get_app_info(const char *app_id, app_info_h *app_info)
195 retval = app_info_get_app_info(app_id, app_info);
197 if (retval != APP_MANAGER_ERROR_NONE)
199 return app_manager_error(retval, __FUNCTION__, NULL);
203 return APP_MANAGER_ERROR_NONE;
207 int app_manager_get_ui_app_info(const char *app_id, ui_app_info_h *ui_app_info)
211 retval = ui_app_info_get_app_info(app_id, ui_app_info);
213 if (retval != APP_MANAGER_ERROR_NONE)
215 return app_manager_error(retval, __FUNCTION__, NULL);
219 return APP_MANAGER_ERROR_NONE;
223 int app_manager_get_service_app_info(const char *app_id, service_app_info_h *service_app_info)
227 retval = service_app_info_get_app_info(app_id, service_app_info);
229 if (retval != APP_MANAGER_ERROR_NONE)
231 return app_manager_error(retval, __FUNCTION__, NULL);
235 return APP_MANAGER_ERROR_NONE;
239 int app_manager_get_package(pid_t pid, char **package)
241 // TODO: this function must be deprecated
242 return app_manager_get_app_id(pid, package);
245 int app_manager_get_app_id(pid_t pid, char **app_id)
247 char buffer[256] = {0, };
248 char *app_id_dup = NULL;
252 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
255 if (aul_app_get_appid_bypid(pid, buffer, sizeof(buffer)) != AUL_R_OK)
257 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, "Invalid process ID");
260 app_id_dup = strdup(buffer);
262 if (app_id_dup == NULL)
264 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
267 *app_id = app_id_dup;
269 return APP_MANAGER_ERROR_NONE;
273 int app_manager_terminate_app(app_context_h app_context)
277 if (app_context == NULL)
279 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
282 if (app_context_get_pid(app_context, &pid) != APP_MANAGER_ERROR_NONE) {
283 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to get the process ID");
286 aul_terminate_pid(pid);
288 return APP_MANAGER_ERROR_NONE;
291 int app_manager_is_running(const char *app_id, bool *running)
295 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid package", __FUNCTION__, APP_MANAGER_ERROR_INVALID_PARAMETER);
296 return APP_MANAGER_ERROR_INVALID_PARAMETER;
301 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, APP_MANAGER_ERROR_INVALID_PARAMETER);
302 return APP_MANAGER_ERROR_INVALID_PARAMETER;
305 *running = aul_app_is_running(app_id);
307 return APP_MANAGER_ERROR_NONE;