2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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.
17 #include <app_manager.h>
18 #include <package_manager.h>
19 #include "homescreen-efl.h"
22 #include "data_model.h"
27 package_manager_h pack_mgr;
32 static bool __app_info_cb(app_info_h ai, void *ud);
33 static void __app_mgr_event_cb(const char *type, const char *package,
34 package_manager_event_type_e event_type,
35 package_manager_event_state_e event_state,
37 package_manager_error_e error,
40 static app_mgr_item_t *__app_mgr_load_item_info(app_info_h ai_h);
42 HAPI void app_mgr_init(void)
44 package_manager_error_e res_stat = PACKAGE_MANAGER_ERROR_NONE;
45 package_manager_error_e res_cb = PACKAGE_MANAGER_ERROR_NONE;
47 if (s_app_mgr_info.pack_mgr)
50 if (PACKAGE_MANAGER_ERROR_NONE ==
51 package_manager_create(&s_app_mgr_info.pack_mgr)) {
52 LOGD("PACKAGE_EVENT_MGR - handle obtained");
54 res_stat = package_manager_set_event_status(
55 s_app_mgr_info.pack_mgr,
56 PACKAGE_MANAGER_STATUS_TYPE_INSTALL |
57 PACKAGE_MANAGER_STATUS_TYPE_UNINSTALL);
59 res_cb = package_manager_set_event_cb(
60 s_app_mgr_info.pack_mgr, __app_mgr_event_cb, NULL);
62 if (res_stat != PACKAGE_MANAGER_ERROR_NONE ||
63 res_cb != PACKAGE_MANAGER_ERROR_NONE)
64 LOGE("App mgr initialization failed!");
66 s_app_mgr_info.pack_mgr = NULL;
70 HAPI void app_mgr_deinit(void)
72 if (s_app_mgr_info.pack_mgr) {
73 LOGD("PACKAGE_EVENT_MGR - freeing handle");
74 package_manager_unset_event_cb(s_app_mgr_info.pack_mgr);
75 package_manager_destroy(s_app_mgr_info.pack_mgr);
79 HAPI Eina_List *app_mgr_get_apps(void)
81 Eina_List *apps = NULL;
82 app_manager_foreach_app_info(__app_info_cb, &apps);
86 HAPI void app_mgr_free_apps(Eina_List *apps)
88 app_mgr_item_t *app_mgr_item;
89 EINA_LIST_FREE(apps, app_mgr_item)
93 HAPI Eina_Bool app_mgr_uninstall_app(const char *appid)
97 package_manager_request_h request;
100 if (package_manager_request_create(&request)
101 != PACKAGE_MANAGER_ERROR_NONE) {
102 LOGE("Could not create unistall request. App: %s", appid);
106 int ret = package_manager_request_set_mode(request, PACKAGE_MANAGER_REQUEST_MODE_DEFAULT);
107 if (ret != PACKAGE_MANAGER_ERROR_NONE) {
108 LOGE("Could not set request mode. App: %s", appid);
112 if (package_manager_request_uninstall(request, appid, &id) !=
113 PACKAGE_MANAGER_ERROR_NONE) {
114 LOGE("Could not uninstall application. App: %s", appid);
118 if (package_manager_request_destroy(request) !=
119 PACKAGE_MANAGER_ERROR_NONE) {
120 LOGE("Could not destroy unistall request. App: %s", appid);
127 HAPI Eina_Bool app_mgr_app_get_badge_count(const char *app_id,
130 unsigned int to_be_displayed = 0;
131 int result = BADGE_ERROR_NONE;
134 LOGE("app_item is NULL in badge count");
139 result = badge_get_display(app_id, &to_be_displayed);
141 if (result != BADGE_ERROR_NONE) {
142 if ((result == BADGE_ERROR_SERVICE_NOT_READY ||
143 result == BADGE_ERROR_NOT_EXIST))
146 LOGE("badge_get_display error %d", result);
150 if (!to_be_displayed)
153 result = badge_get_count(app_id, count);
155 if (result != BADGE_ERROR_NONE) {
157 if ((result == BADGE_ERROR_SERVICE_NOT_READY ||
158 result == BADGE_ERROR_NOT_EXIST))
161 LOGE("badge_get_count error %d", result);
168 HAPI void app_mgr_register_badge_callback(badge_change_cb callback)
170 int ret = BADGE_ERROR_NONE;
171 ret = badge_register_changed_cb(callback, NULL);
173 if (ret != BADGE_ERROR_NONE)
174 LOGE("Could not register badge callback");
177 HAPI void app_mgr_unregister_badge_callback(badge_change_cb callback)
179 int ret = BADGE_ERROR_NONE;
180 ret = badge_unregister_changed_cb(callback);
182 if (ret != BADGE_ERROR_NONE)
183 LOGE("Could not unregister badge callback");
186 HAPI char *app_mgr_get_app_label(const char *app_id)
188 app_info_h ai_handle;
192 LOGE("Invalid parameter");
196 if (app_info_create(app_id, &ai_handle) != APP_MANAGER_ERROR_NONE) {
197 LOGE("Failed to load application id");
201 if (app_info_get_label(ai_handle, &label) != APP_MANAGER_ERROR_NONE) {
202 LOGE("Failed to get label!");
203 app_info_destroy(ai_handle);
207 app_info_destroy(ai_handle);
211 static void __app_mgr_event_cb(const char *type, const char *package,
212 package_manager_event_type_e event_type,
213 package_manager_event_state_e event_state, int progress,
214 package_manager_error_e error, void *user_data)
216 if (PACKAGE_MANAGER_ERROR_NONE != error) {
217 LOGE("PACKAGE_EVENT_MGR error in cb");
221 if (PACKAGE_MANAGER_EVENT_STATE_FAILED == event_state)
224 if (PACKAGE_MANAGER_EVENT_TYPE_INSTALL == event_type && progress == 100) {
226 app_info_h ai_handle = NULL;
227 app_mgr_item_t *app_mgr_item = NULL;
228 Tree_node_t *item = NULL;
230 app_info_create(package, &ai_handle);
232 LOGE("Failed to get app info handle");
236 app_mgr_item = __app_mgr_load_item_info(ai_handle);
237 item = data_model_install_application(app_mgr_item);
239 LOGE("Failed to create app item");
240 app_info_destroy(ai_handle);
244 item->data->layout = app_icon_create(item, APP_ICON_TYPE_APP);
245 app_info_destroy(ai_handle);
246 home_screen_mvc_update_view();
250 if (PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL == event_type && progress == 100)
254 static bool __app_info_cb(app_info_h ai, void *ud)
256 app_mgr_item_t *app_mgr_item = NULL;
257 bool nodisplay = false;
258 Eina_List **list = (Eina_List **)ud;
260 if (app_info_is_nodisplay(ai, &nodisplay)) {
261 LOGE("[FAILED][app_info_is_nodisplay]");
265 #ifndef HOME_SCREEN_EFL_TEST_RUN
270 app_mgr_item = __app_mgr_load_item_info(ai);
273 LOGE("[Failed to initialie app_mgr_item]");
278 *list = eina_list_append(*list, app_mgr_item);
282 static app_mgr_item_t *__app_mgr_load_item_info(app_info_h ai_h)
284 package_info_h p_handle = NULL;
285 package_manager_error_e ret = PACKAGE_MANAGER_ERROR_NONE;
288 LOGE("[INVALID_PARAMS]");
292 app_mgr_item_t *item = (app_mgr_item_t *) calloc(1, sizeof(*item));
294 LOGE("Failed to create app_mgr_item");
298 if (app_info_get_label(ai_h, &item->label)) {
299 LOGE("[FAILED][app_info_get_label]");
304 if (app_info_get_exec(ai_h, &item->exec)) {
305 LOGE("[FAILED][app_info_get_exec]");
311 if (app_info_get_icon(ai_h, &item->icon)) {
312 LOGE("[FAILED][app_info_get_icon]");
319 if (app_info_get_app_id(ai_h, &item->appid)) {
320 LOGE("[FAILED][app_info_get_app_id]");
328 if (app_info_get_package(ai_h, &item->package)) {
329 LOGE("[FAILED][app_info_get_package]");
338 ret = package_manager_get_package_info(item->package, &p_handle);
339 if (ret != PACKAGE_MANAGER_ERROR_NONE) {
340 LOGW("Failed to inialize package handle for item : %s",
342 item->removable = false;
346 ret = package_info_is_removable_package(p_handle, &item->removable);
348 if (ret != PACKAGE_MANAGER_ERROR_NONE) {
349 LOGE("Failed to get pacakge removeable flag");
359 package_info_destroy(p_handle);