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 */
34 #define _AI_START _AI_NAME /* start index */
38 enum appinfo_type type;
41 static struct appinfo_t _appinfos[] = {
42 [_AI_NAME] = { "Name", AIT_NAME, },
43 [_AI_COMP] = { "Component", AIT_COMP, },
44 [_AI_EXEC] = { "Exec", AIT_EXEC, },
45 [_AI_TYPE] = { "PkgType", AIT_TYPE, },
46 [_AI_ONBOOT] = { "StartOnBoot", AIT_ONBOOT, },
47 [_AI_RESTART] = { "AutoRestart", AIT_RESTART, },
48 [_AI_MULTI] = { "Multiple", AIT_MULTI, },
49 [_AI_HWACC] = { "Hwacceleration", AIT_HWACC, },
56 static void _free_appinfo(gpointer data)
58 struct appinfo *c = data;
64 for (i = 0; i < sizeof(c->val)/sizeof(c->val[0]); i++)
70 static void _fini(struct appinfomgr *cf)
74 g_hash_table_destroy(cf->tbl);
78 static int __app_info_insert_handler (const pkgmgrinfo_appinfo_h handle, void *data)
81 struct appinfomgr *cf = (struct appinfomgr *)data;
89 pkgmgrinfo_app_hwacceleration hwacc;
90 pkgmgrinfo_app_component component;
94 _E("null app handle");
98 ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
100 _E("fail to get appinfo");
104 g_hash_table_remove(cf->tbl, appid);
106 c = calloc(1, sizeof(*c));
108 _E("create appinfo: %s", strerror(errno));
112 memset(c, 0, sizeof(struct appinfo));
114 c->val[_AI_FILE] = strdup(appid);
115 if (!c->val[_AI_FILE]) {
116 _E("create appinfo: %s", strerror(errno));
121 c->val[_AI_NAME] = strdup(appid); //TODO :
123 pkgmgrinfo_appinfo_get_component(handle, &component);
124 if(component == PMINFO_UI_APP) {
125 c->val[_AI_COMP] = strdup("ui"); //TODO :
127 r = pkgmgrinfo_appinfo_is_multiple(handle, &multiple);
129 c->val[_AI_MULTI] = strdup("true");
130 else c->val[_AI_MULTI] = strdup("false");
132 r = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc);
133 if (hwacc == PMINFO_HWACCELERATION_USE_GL) {
134 c->val[_AI_HWACC] = strdup("USE");
135 } else if (hwacc == PMINFO_HWACCELERATION_USE_SYSTEM_SETTING) {
136 c->val[_AI_HWACC] = strdup("SYS");
138 c->val[_AI_HWACC] = strdup("NOT_USE");
141 c->val[_AI_COMP] = strdup("svc");
143 r = pkgmgrinfo_appinfo_is_onboot(handle, &onboot);
145 c->val[_AI_ONBOOT] = strdup("true");
146 else c->val[_AI_ONBOOT] = strdup("false");
148 r = pkgmgrinfo_appinfo_is_autorestart(handle, &restart);
150 c->val[_AI_RESTART] = strdup("true");
151 else c->val[_AI_RESTART] = strdup("false");
154 r = pkgmgrinfo_appinfo_get_exec(handle, &exec);
155 c->val[_AI_EXEC] = strdup(exec);
157 r = pkgmgrinfo_appinfo_get_apptype(handle, &type);
158 if(strncmp(type, "capp", 4) == 0 ) {
159 c->val[_AI_TYPE] = strdup("rpm");
160 } else if (strncmp(type, "c++app", 6) == 0 || strncmp(type, "ospapp", 6) == 0) {
161 c->val[_AI_TYPE] = strdup("tpk");
162 } else if (strncmp(type, "webapp", 6) == 0) {
163 c->val[_AI_TYPE] = strdup("wgt");
166 _D("%s : %s : %s", c->val[_AI_FILE], c->val[_AI_COMP], c->val[_AI_TYPE]);
168 g_hash_table_insert(cf->tbl, c->val[_AI_FILE], c);
173 static int __app_info_delete_handler (const pkgmgrinfo_appinfo_h handle, void *data)
175 struct appinfomgr *cf = (struct appinfomgr *)data;
178 pkgmgrinfo_appinfo_get_appid(handle, &appid);
180 g_hash_table_remove(cf->tbl, appid);
185 static int _read_pkg_info(struct appinfomgr *cf)
189 r = pkgmgrinfo_appinfo_get_installed_list(__app_info_insert_handler, cf);
194 static struct appinfomgr *_init()
196 struct appinfomgr *cf;
198 cf = calloc(1, sizeof(*cf));
200 _E("appinfo init: %s", strerror(errno));
204 cf->tbl = g_hash_table_new_full(g_str_hash, g_str_equal,
205 NULL, _free_appinfo);
210 static void __vconf_cb(keynode_t *key, void *data)
217 pkgmgrinfo_appinfo_h handle;
218 struct appinfomgr *cf = (struct appinfomgr *)data;
220 noti_string = vconf_keynode_get_str(key);
221 if( noti_string == NULL ) {
225 _D("noti_string : %s",noti_string);
227 type_string = strtok_r(noti_string, ":", &saveptr);
228 appid = strtok_r(NULL, ":", &saveptr);
230 if ( strncmp(type_string, "create", 6) == 0) {
231 pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
233 _D("appid : %s /handle : %x", appid, handle);
235 __app_info_insert_handler(handle, data);
237 pkgmgrinfo_appinfo_destroy_appinfo(handle);
238 } else if ( strncmp(type_string, "delete", 6) == 0) {
239 g_hash_table_remove(cf->tbl, appid);
243 int appinfo_init(struct appinfomgr **cf)
245 struct appinfomgr *_cf;
250 _E("appinfo init: %s", strerror(errno));
258 r = _read_pkg_info(_cf);
264 r = vconf_notify_key_changed(VCONFKEY_MENUSCREEN_DESKTOP, __vconf_cb, _cf);
271 void appinfo_fini(struct appinfomgr **cf)
280 const struct appinfo *appinfo_insert(struct appinfomgr *cf, const char *pkg_name)
283 pkgmgrinfo_pkginfo_h handle;
285 r = pkgmgrinfo_pkginfo_get_pkginfo(pkg_name, &handle);
286 r = pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, __app_info_insert_handler, cf);
287 r = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __app_info_insert_handler, cf);
288 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
293 void appinfo_delete(struct appinfomgr *cf, const char *pkg_name)
296 pkgmgrinfo_pkginfo_h handle;
298 r = pkgmgrinfo_pkginfo_get_pkginfo(pkg_name, &handle);
299 r = pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, __app_info_delete_handler, cf);
300 r = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __app_info_delete_handler, cf);
301 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
304 const struct appinfo *appinfo_find(struct appinfomgr *cf, const char *filename)
306 if (!cf || !filename || !*filename) {
308 _E("appinfo find: %s", strerror(errno));
312 return g_hash_table_lookup(cf->tbl, FILENAME(filename));
315 const char *appinfo_get_value(const struct appinfo *c, enum appinfo_type type)
321 _E("appinfo get value: %s", strerror(errno));
325 for (i = _AI_START; i < sizeof(_appinfos)/sizeof(_appinfos[0]); i++) {
326 if (type == _appinfos[i].type)
331 _E("appinfo get value: %s", strerror(errno));
336 const char *appinfo_get_filename(const struct appinfo *c)
340 _E("appinfo get filename: %s", strerror(errno));
344 return c->val[_AI_FILE];
348 appinfo_iter_callback cb;
352 static void _iter_cb(gpointer key, gpointer value, gpointer user_data)
354 struct _cbinfo *cbi = user_data;
358 cbi->cb(cbi->cb_data, key, value);
361 void appinfo_foreach(struct appinfomgr *cf, appinfo_iter_callback cb, void *user_data)
367 _E("appinfo foreach: %s", strerror(errno));
372 cbi.cb_data = user_data;
374 g_hash_table_foreach(cf->tbl, _iter_cb, &cbi);
377 int appinfo_get_boolean(const struct appinfo *c, enum appinfo_type type)
381 v = appinfo_get_value(c, type);
385 if (!strcmp(v, "1") || !strcasecmp(v, "true"))
388 if (!strcmp(v, "0") || !strcasecmp(v, "false"))