9 #include <pkgmgr-info.h>
11 #include "amd_config.h"
12 #include "simple_util.h"
13 #include "amd_appinfo.h"
16 #define SERVICE_GROUP "Service"
19 GHashTable *tbl; /* key is filename, value is struct appinfo */
23 _AI_FILE = 0, /* service filename */
33 #define _AI_START _AI_NAME /* start index */
37 enum appinfo_type type;
40 static struct appinfo_t _appinfos[] = {
41 [_AI_NAME] = { "Name", AIT_NAME, },
42 [_AI_COMP] = { "Component", AIT_COMP, },
43 [_AI_EXEC] = { "Exec", AIT_EXEC, },
44 [_AI_TYPE] = { "PkgType", AIT_TYPE, },
45 [_AI_ONBOOT] = { "StartOnBoot", AIT_ONBOOT, },
46 [_AI_RESTART] = { "AutoRestart", AIT_RESTART, },
47 [_AI_MULTI] = { "Multiple", AIT_MULTI, },
54 static void _free_appinfo(gpointer data)
56 struct appinfo *c = data;
62 for (i = 0; i < sizeof(c->val)/sizeof(c->val[0]); i++)
68 static void _fini(struct appinfomgr *cf)
72 g_hash_table_destroy(cf->tbl);
76 pkgmgrinfo_pkginfo_h p_handle;
78 static int __svc_app_info_insert_handler (const pkgmgrinfo_appinfo_h handle, void *data)
81 struct appinfomgr *cf = (struct appinfomgr *)data;
89 pkgmgrinfo_appinfo_get_appid(handle, &appid);
91 g_hash_table_remove(cf->tbl, appid);
93 c = calloc(1, sizeof(*c));
95 _E("create appinfo: %s", strerror(errno));
99 memset(c, 0, sizeof(struct appinfo));
101 c->val[_AI_FILE] = strdup(appid);
102 if (!c->val[_AI_FILE]) {
103 _E("create appinfo: %s", strerror(errno));
108 c->val[_AI_NAME] = strdup(appid); //TODO :
110 c->val[_AI_COMP] = strdup("svc"); //TODO :
112 r = pkgmgrinfo_appinfo_get_exec(handle, &exec);
113 c->val[_AI_EXEC] = strdup(exec);
115 r = pkgmgrinfo_pkginfo_get_type(p_handle, &type);
116 c->val[_AI_TYPE] = strdup(type);
118 r = pkgmgrinfo_appinfo_is_onboot(handle, &onboot);
120 c->val[_AI_ONBOOT] = strdup("true");
121 else c->val[_AI_ONBOOT] = strdup("false");
123 r = pkgmgrinfo_appinfo_is_autorestart(handle, &restart);
125 c->val[_AI_RESTART] = strdup("true");
126 else c->val[_AI_RESTART] = strdup("false");
128 _D("%s : %s : %s : %s : %s", c->val[_AI_FILE], c->val[_AI_COMP], c->val[_AI_TYPE], c->val[_AI_ONBOOT], c->val[_AI_RESTART]);
130 g_hash_table_insert(cf->tbl, c->val[_AI_FILE], c);
135 static int __ui_app_info_insert_handler (const pkgmgrinfo_appinfo_h handle, void *data)
138 struct appinfomgr *cf = (struct appinfomgr *)data;
145 pkgmgrinfo_appinfo_get_appid(handle, &appid);
147 g_hash_table_remove(cf->tbl, appid);
149 c = calloc(1, sizeof(*c));
151 _E("create appinfo: %s", strerror(errno));
155 memset(c, 0, sizeof(struct appinfo));
157 c->val[_AI_FILE] = strdup(appid);
158 if (!c->val[_AI_FILE]) {
159 _E("create appinfo: %s", strerror(errno));
164 c->val[_AI_NAME] = strdup(appid); //TODO :
166 c->val[_AI_COMP] = strdup("ui"); //TODO :
168 r = pkgmgrinfo_appinfo_get_exec(handle, &exec);
169 c->val[_AI_EXEC] = strdup(exec);
171 r = pkgmgrinfo_pkginfo_get_type(p_handle, &type);
172 c->val[_AI_TYPE] = strdup(type);
174 r = pkgmgrinfo_appinfo_is_multiple(handle, &multiple);
176 c->val[_AI_MULTI] = strdup("true");
177 else c->val[_AI_MULTI] = strdup("false");
179 _D("%s : %s : %s : %s", c->val[_AI_FILE], c->val[_AI_COMP], c->val[_AI_TYPE], c->val[_AI_MULTI]);
181 g_hash_table_insert(cf->tbl, c->val[_AI_FILE], c);
186 static int __app_info_delete_handler (const pkgmgrinfo_appinfo_h handle, void *data)
188 struct appinfomgr *cf = (struct appinfomgr *)data;
191 pkgmgrinfo_appinfo_get_appid(handle, &appid);
193 g_hash_table_remove(cf->tbl, appid);
198 static int __pkg_info_handler(const pkgmgrinfo_pkginfo_h handle, void *data)
203 r = pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, __svc_app_info_insert_handler, data);
204 r = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __ui_app_info_insert_handler, data);
209 static int _read_pkg_info(struct appinfomgr *cf)
213 r = pkgmgrinfo_pkginfo_get_list(__pkg_info_handler, cf);
218 static struct appinfomgr *_init()
220 struct appinfomgr *cf;
222 cf = calloc(1, sizeof(*cf));
224 _E("appinfo init: %s", strerror(errno));
228 cf->tbl = g_hash_table_new_full(g_str_hash, g_str_equal,
229 NULL, _free_appinfo);
234 static void __vconf_cb(keynode_t *key, void *data)
240 pkgmgrinfo_appinfo_h handle;
241 pkgmgrinfo_app_component component;
242 struct appinfomgr *cf = (struct appinfomgr *)data;
244 noti_string = vconf_keynode_get_str(key);
245 if( noti_string == NULL ) {
249 _D("noti_string : %s",noti_string);
251 type_string = strtok_r(noti_string, ":", &saveptr);
252 appid = strtok_r(NULL, ":", &saveptr);
254 if ( strncmp(type_string, "create", 6) == 0) {
255 pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
257 _D("appid : %s /handle : %x", appid, handle);
258 pkgmgrinfo_appinfo_get_component(handle, &component);
260 if(component == PMINFO_UI_APP) {
261 __ui_app_info_insert_handler(handle, data);
262 } else if (component == PMINFO_SVC_APP) {
263 __svc_app_info_insert_handler(handle, data);
266 pkgmgrinfo_appinfo_destroy_appinfo(handle);
267 } else if ( strncmp(type_string, "delete", 6) == 0) {
268 g_hash_table_remove(cf->tbl, appid);
272 int appinfo_init(struct appinfomgr **cf)
274 struct appinfomgr *_cf;
279 _E("appinfo init: %s", strerror(errno));
287 r = _read_pkg_info(_cf);
293 r = vconf_notify_key_changed("memory/menuscreen/desktop", __vconf_cb, _cf);
300 void appinfo_fini(struct appinfomgr **cf)
309 const struct appinfo *appinfo_insert(struct appinfomgr *cf, const char *pkg_name)
312 pkgmgrinfo_pkginfo_h handle;
314 r = pkgmgrinfo_pkginfo_get_pkginfo(pkg_name, &handle);
316 r = pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, __svc_app_info_insert_handler, cf);
317 r = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __ui_app_info_insert_handler, cf);
318 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
323 void appinfo_delete(struct appinfomgr *cf, const char *pkg_name)
326 pkgmgrinfo_pkginfo_h handle;
328 r = pkgmgrinfo_pkginfo_get_pkginfo(pkg_name, &handle);
329 r = pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, __app_info_delete_handler, cf);
330 r = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __app_info_delete_handler, cf);
331 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
334 const struct appinfo *appinfo_find(struct appinfomgr *cf, const char *filename)
336 if (!cf || !filename || !*filename) {
338 _E("appinfo find: %s", strerror(errno));
342 return g_hash_table_lookup(cf->tbl, FILENAME(filename));
345 const char *appinfo_get_value(const struct appinfo *c, enum appinfo_type type)
351 _E("appinfo get value: %s", strerror(errno));
355 for (i = _AI_START; i < sizeof(_appinfos)/sizeof(_appinfos[0]); i++) {
356 if (type == _appinfos[i].type)
361 _E("appinfo get value: %s", strerror(errno));
366 const char *appinfo_get_filename(const struct appinfo *c)
370 _E("appinfo get filename: %s", strerror(errno));
374 return c->val[_AI_FILE];
378 appinfo_iter_callback cb;
382 static void _iter_cb(gpointer key, gpointer value, gpointer user_data)
384 struct _cbinfo *cbi = user_data;
388 cbi->cb(cbi->cb_data, key, value);
391 void appinfo_foreach(struct appinfomgr *cf, appinfo_iter_callback cb, void *user_data)
397 _E("appinfo foreach: %s", strerror(errno));
402 cbi.cb_data = user_data;
404 g_hash_table_foreach(cf->tbl, _iter_cb, &cbi);
407 int appinfo_get_boolean(const struct appinfo *c, enum appinfo_type type)
411 v = appinfo_get_value(c, type);
415 if (!strcmp(v, "1") || !strcasecmp(v, "true"))
418 if (!strcmp(v, "0") || !strcasecmp(v, "false"))