4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Junsuk Oh <junsuk77.oh@samsung.com>,
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #include "pkgmgrinfo_private.h"
27 #define LOG_TAG "PKGMGR_INFO"
29 typedef int (*pkgmgr_handler)(int req_id, const char *pkg_type,
30 const char *pkgid, const char *key,
31 const char *val, const void *pmsg, void *data);
33 typedef void pkgmgr_client;
34 typedef void pkgmgr_info;
39 PM_REQUEST_GET_SIZE = 2,
40 PM_REQUEST_KILL_APP = 3,
41 PM_REQUEST_CHECK_APP = 4,
43 }pkgmgr_request_service_type;
50 PM_GET_TOTAL_AND_DATA = 4,
61 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
63 pkgmgr_pkginfo_x *udata = (pkgmgr_pkginfo_x *)data;
65 pkgmgr_pkginfo_x *info = NULL;
66 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
67 retvm_if(info == NULL, PMINFO_R_ERROR, "our of memory");
68 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
69 if (info->manifest_info == NULL) {
70 _LOGE("out of memory");
72 return PMINFO_R_ERROR;
76 for(i = 0; i < ncols; i++)
78 if (strcmp(colname[i], "package") == 0) {
80 info->manifest_info->package = strdup(coltxt[i]);
82 info->manifest_info->package = NULL;
90 API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
92 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
93 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
94 pkgmgr_pkginfo_x *pkginfo = NULL;
95 int ret = PMINFO_R_OK;
100 description_x *tmp3 = NULL;
101 author_x *tmp4 = NULL;
102 privilege_x *tmp5 = NULL;
103 sqlite3 *pkginfo_db = NULL;
106 ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
107 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
109 /*get system locale*/
110 locale = __convert_system_locale_to_manifest_locale();
111 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
113 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
114 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
116 pkginfo->locale = strdup(locale);
118 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
119 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
121 pkginfo->manifest_info->package = strdup(pkgid);
122 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
123 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
125 /*populate manifest_info from DB*/
126 query= sqlite3_mprintf("select * from disabled_package_info where package=%Q", pkgid);
127 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
129 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
131 query= sqlite3_mprintf("select * from disabled_package_localized_info where package=%Q and package_locale=%Q", pkgid, locale);
132 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
134 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
136 /*Also store the values corresponding to default locales*/
137 query= sqlite3_mprintf("select * from disabled_package_localized_info where package=%Q and package_locale=%Q", pkgid, DEFAULT_LOCALE);
138 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
140 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
142 SAFE_LISTHEAD(pkginfo->manifest_info->label, tmp1);
143 SAFE_LISTHEAD(pkginfo->manifest_info->icon, tmp2);
144 SAFE_LISTHEAD(pkginfo->manifest_info->description, tmp3);
145 SAFE_LISTHEAD(pkginfo->manifest_info->author, tmp4);
146 SAFE_LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
149 if (ret == PMINFO_R_OK)
150 *handle = (void*)pkginfo;
153 __cleanup_pkginfo(pkginfo);
155 sqlite3_close(pkginfo_db);
164 API int pkgmgrinfo_pkginfo_get_disabled_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
166 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
167 int ret = PMINFO_R_OK;
168 char query[MAX_QUERY_LEN] = {'\0'};
170 pkgmgr_pkginfo_x *pkginfo = NULL;
171 label_x *tmp1 = NULL;
173 description_x *tmp3 = NULL;
174 author_x *tmp4 = NULL;
175 sqlite3 *pkginfo_db = NULL;
176 pkgmgr_pkginfo_x *tmphead = NULL;
177 pkgmgr_pkginfo_x *node = NULL;
178 pkgmgr_pkginfo_x *temp_node = NULL;
181 ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
182 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
184 /*get system locale*/
185 locale = __convert_system_locale_to_manifest_locale();
186 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
188 tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
190 _LOGE("@calloc failed!!");
191 FREE_AND_NULL(locale);
192 return PMINFO_R_ERROR;
195 snprintf(query, MAX_QUERY_LEN, "select * from disabled_package_info");
196 ret = __exec_db_query(pkginfo_db, query, __pkg_list_cb, (void *)tmphead);
197 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
199 LISTHEAD(tmphead, node);
201 for(node = node->next; node ; node = node->next) {
203 pkginfo->locale = strdup(locale);
204 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
205 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info\n");
207 /*populate manifest_info from DB*/
208 snprintf(query, MAX_QUERY_LEN, "select * from disabled_package_info where package='%s' ", pkginfo->manifest_info->package);
209 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
210 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
212 memset(query, '\0', MAX_QUERY_LEN);
213 snprintf(query, MAX_QUERY_LEN, "select * from disabled_package_localized_info where" \
214 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
215 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
216 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
218 /*Also store the values corresponding to default locales*/
219 memset(query, '\0', MAX_QUERY_LEN);
220 snprintf(query, MAX_QUERY_LEN, "select * from disabled_package_localized_info where" \
221 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
222 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
223 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
225 SAFE_LISTHEAD(pkginfo->manifest_info->label, tmp1);
226 SAFE_LISTHEAD(pkginfo->manifest_info->icon, tmp2);
227 SAFE_LISTHEAD(pkginfo->manifest_info->description, tmp3);
228 SAFE_LISTHEAD(pkginfo->manifest_info->author, tmp4);
231 LISTHEAD(tmphead, node);
233 for(node = node->next; node ; node = node->next) {
236 ret = pkg_list_cb( (void *)pkginfo, user_data);
244 sqlite3_close(pkginfo_db);
250 LISTHEAD(tmphead, node);
251 temp_node = node->next;
254 temp_node = node->next;
255 __cleanup_pkginfo(node);
258 __cleanup_pkginfo(tmphead);
263 API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
265 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
266 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
268 pkgmgr_appinfo_x *appinfo = NULL;
272 label_x *tmp1 = NULL;
274 category_x *tmp3 = NULL;
275 metadata_x *tmp4 = NULL;
278 sqlite3 *appinfo_db = NULL;
281 ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
282 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
284 /*check appid exist on db*/
285 query = sqlite3_mprintf("select exists(select * from disabled_package_app_info where app_id=%Q)", appid);
286 ret = __exec_db_query(appinfo_db, query, _pkgmgrinfo_validate_cb, (void *)&exist);
288 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
289 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
291 /*get system locale*/
292 locale = __convert_system_locale_to_manifest_locale();
293 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
296 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
297 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
299 /*calloc app_component*/
300 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
301 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
303 appinfo->locale = strdup(locale);
305 /*populate app_info from DB*/
306 query = sqlite3_mprintf("select * from disabled_package_app_info where app_id=%Q ", appid);
307 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
309 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
311 query = sqlite3_mprintf("select * from disabled_package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
312 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
314 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
316 /*Also store the values corresponding to default locales*/
317 query = sqlite3_mprintf("select * from disabled_package_app_localized_info where app_id=%Q and app_locale=%Q", appid, DEFAULT_LOCALE);
318 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
320 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
322 /*Populate app category*/
323 query = sqlite3_mprintf("select * from disabled_package_app_app_category where app_id=%Q", appid);
324 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
326 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
328 /*Populate app metadata*/
329 query = sqlite3_mprintf("select * from disabled_package_app_app_metadata where app_id=%Q", appid);
330 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
332 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
334 SAFE_LISTHEAD(appinfo->uiapp_info->label, tmp1);
335 SAFE_LISTHEAD(appinfo->uiapp_info->icon, tmp2);
336 SAFE_LISTHEAD(appinfo->uiapp_info->category, tmp3);
337 SAFE_LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
342 if (ret == PMINFO_R_OK)
343 *handle = (void*)appinfo;
346 __cleanup_appinfo(appinfo);
349 sqlite3_close(appinfo_db);
357 API int pkgmgrinfo_appinfo_get_disabled_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
358 pkgmgrinfo_app_list_cb app_func, void *user_data)
360 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
361 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
362 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
366 char query[MAX_QUERY_LEN] = {'\0'};
367 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
368 pkgmgr_pkginfo_x *allinfo = NULL;
369 pkgmgr_appinfo_x *appinfo = NULL;
371 label_x *ptr2 = NULL;
372 category_x *ptr3 = NULL;
373 metadata_x *ptr4 = NULL;
374 permission_x *ptr5 = NULL;
375 image_x *ptr6 = NULL;
376 sqlite3 *appinfo_db = NULL;
378 /*check installed storage*/
379 ret = __pkginfo_check_installed_storage(info);
380 retvm_if(ret < 0, PMINFO_R_EINVAL, "[%s] is installed external, but is not in mmc", info->manifest_info->package);
382 /*get system locale*/
383 locale = __convert_system_locale_to_manifest_locale();
384 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
387 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
388 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
390 /*calloc manifest_info*/
391 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
392 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
395 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
396 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
399 ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
400 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
402 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * from disabled_package_app_info where package='%s'", info->manifest_info->package);
404 /*Populate ui app info */
405 ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
406 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
408 uiapplication_x *tmp = NULL;
409 SAFE_LISTHEAD(info->manifest_info->uiapplication, tmp);
411 /*Populate localized info for default locales and call callback*/
412 /*If the callback func return < 0 we break and no more call back is called*/
416 appinfo->locale = strdup(locale);
417 appinfo->uiapp_info = tmp;
418 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
422 locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid);
425 memset(query, '\0', MAX_QUERY_LEN);
426 snprintf(query, MAX_QUERY_LEN, "select * from disabled_package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
427 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
428 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
430 memset(query, '\0', MAX_QUERY_LEN);
431 snprintf(query, MAX_QUERY_LEN, "select * from disabled_package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, DEFAULT_LOCALE);
432 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
433 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
435 /*Populate app category*/
436 memset(query, '\0', MAX_QUERY_LEN);
437 snprintf(query, MAX_QUERY_LEN, "select * from disabled_package_app_app_category where app_id=='%s'", appinfo->uiapp_info->appid);
438 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
439 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
441 /*Populate app metadata*/
442 memset(query, '\0', MAX_QUERY_LEN);
443 snprintf(query, MAX_QUERY_LEN, "select * from disabled_package_app_app_metadata where app_id='%s'", appinfo->uiapp_info->appid);
444 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
445 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
447 SAFE_LISTHEAD(appinfo->uiapp_info->icon, ptr1);
448 SAFE_LISTHEAD(appinfo->uiapp_info->label, ptr2);
449 SAFE_LISTHEAD(appinfo->uiapp_info->category, ptr3);
450 SAFE_LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
451 SAFE_LISTHEAD(appinfo->uiapp_info->permission, ptr5);
452 SAFE_LISTHEAD(appinfo->uiapp_info->image, ptr6);
454 ret = app_func((void *)appinfo, user_data);
470 __cleanup_pkginfo(allinfo);
472 sqlite3_close(appinfo_db);