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;
93 _E("null app handle");
97 pkgmgrinfo_appinfo_get_appid(handle, &appid);
99 g_hash_table_remove(cf->tbl, appid);
101 c = calloc(1, sizeof(*c));
103 _E("create appinfo: %s", strerror(errno));
107 memset(c, 0, sizeof(struct appinfo));
109 c->val[_AI_FILE] = strdup(appid);
110 if (!c->val[_AI_FILE]) {
111 _E("create appinfo: %s", strerror(errno));
116 c->val[_AI_NAME] = strdup(appid); //TODO :
118 pkgmgrinfo_appinfo_get_component(handle, &component);
119 if(component == PMINFO_UI_APP) {
120 c->val[_AI_COMP] = strdup("ui"); //TODO :
122 r = pkgmgrinfo_appinfo_is_multiple(handle, &multiple);
124 c->val[_AI_MULTI] = strdup("true");
125 else c->val[_AI_MULTI] = strdup("false");
127 r = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc);
128 if (hwacc == PMINFO_HWACCELERATION_USE_GL) {
129 c->val[_AI_HWACC] = strdup("USE");
130 } else if (hwacc == PMINFO_HWACCELERATION_USE_SYSTEM_SETTING) {
131 c->val[_AI_HWACC] = strdup("SYS");
133 c->val[_AI_HWACC] = strdup("NOT_USE");
136 c->val[_AI_COMP] = strdup("svc");
138 r = pkgmgrinfo_appinfo_is_onboot(handle, &onboot);
140 c->val[_AI_ONBOOT] = strdup("true");
141 else c->val[_AI_ONBOOT] = strdup("false");
143 r = pkgmgrinfo_appinfo_is_autorestart(handle, &restart);
145 c->val[_AI_RESTART] = strdup("true");
146 else c->val[_AI_RESTART] = strdup("false");
149 r = pkgmgrinfo_appinfo_get_exec(handle, &exec);
150 c->val[_AI_EXEC] = strdup(exec);
152 r = pkgmgrinfo_appinfo_get_apptype(handle, &type);
153 if(strncmp(type, "capp", 4) == 0 ) {
154 c->val[_AI_TYPE] = strdup("rpm");
155 } else if (strncmp(type, "c++app", 6) == 0 || strncmp(type, "ospapp", 6) == 0) {
156 c->val[_AI_TYPE] = strdup("tpk");
157 } else if (strncmp(type, "webapp", 6) == 0) {
158 c->val[_AI_TYPE] = strdup("wgt");
161 _D("%s : %s : %s", c->val[_AI_FILE], c->val[_AI_COMP], c->val[_AI_TYPE]);
163 g_hash_table_insert(cf->tbl, c->val[_AI_FILE], c);
168 static int __app_info_delete_handler (const pkgmgrinfo_appinfo_h handle, void *data)
170 struct appinfomgr *cf = (struct appinfomgr *)data;
173 pkgmgrinfo_appinfo_get_appid(handle, &appid);
175 g_hash_table_remove(cf->tbl, appid);
180 static int _read_pkg_info(struct appinfomgr *cf)
184 r = pkgmgrinfo_appinfo_get_installed_list(__app_info_insert_handler, cf);
189 static struct appinfomgr *_init()
191 struct appinfomgr *cf;
193 cf = calloc(1, sizeof(*cf));
195 _E("appinfo init: %s", strerror(errno));
199 cf->tbl = g_hash_table_new_full(g_str_hash, g_str_equal,
200 NULL, _free_appinfo);
205 static void __vconf_cb(keynode_t *key, void *data)
212 pkgmgrinfo_appinfo_h handle;
213 struct appinfomgr *cf = (struct appinfomgr *)data;
215 noti_string = vconf_keynode_get_str(key);
216 if( noti_string == NULL ) {
220 _D("noti_string : %s",noti_string);
222 type_string = strtok_r(noti_string, ":", &saveptr);
223 appid = strtok_r(NULL, ":", &saveptr);
225 if ( strncmp(type_string, "create", 6) == 0) {
226 pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
228 _D("appid : %s /handle : %x", appid, handle);
230 __app_info_insert_handler(handle, data);
232 pkgmgrinfo_appinfo_destroy_appinfo(handle);
233 } else if ( strncmp(type_string, "delete", 6) == 0) {
234 g_hash_table_remove(cf->tbl, appid);
238 int appinfo_init(struct appinfomgr **cf)
240 struct appinfomgr *_cf;
245 _E("appinfo init: %s", strerror(errno));
253 r = _read_pkg_info(_cf);
259 r = vconf_notify_key_changed("memory/menuscreen/desktop", __vconf_cb, _cf);
266 void appinfo_fini(struct appinfomgr **cf)
275 const struct appinfo *appinfo_insert(struct appinfomgr *cf, const char *pkg_name)
278 pkgmgrinfo_pkginfo_h handle;
280 r = pkgmgrinfo_pkginfo_get_pkginfo(pkg_name, &handle);
281 r = pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, __app_info_insert_handler, cf);
282 r = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __app_info_insert_handler, cf);
283 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
288 void appinfo_delete(struct appinfomgr *cf, const char *pkg_name)
291 pkgmgrinfo_pkginfo_h handle;
293 r = pkgmgrinfo_pkginfo_get_pkginfo(pkg_name, &handle);
294 r = pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, __app_info_delete_handler, cf);
295 r = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __app_info_delete_handler, cf);
296 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
299 const struct appinfo *appinfo_find(struct appinfomgr *cf, const char *filename)
301 if (!cf || !filename || !*filename) {
303 _E("appinfo find: %s", strerror(errno));
307 return g_hash_table_lookup(cf->tbl, FILENAME(filename));
310 const char *appinfo_get_value(const struct appinfo *c, enum appinfo_type type)
316 _E("appinfo get value: %s", strerror(errno));
320 for (i = _AI_START; i < sizeof(_appinfos)/sizeof(_appinfos[0]); i++) {
321 if (type == _appinfos[i].type)
326 _E("appinfo get value: %s", strerror(errno));
331 const char *appinfo_get_filename(const struct appinfo *c)
335 _E("appinfo get filename: %s", strerror(errno));
339 return c->val[_AI_FILE];
343 appinfo_iter_callback cb;
347 static void _iter_cb(gpointer key, gpointer value, gpointer user_data)
349 struct _cbinfo *cbi = user_data;
353 cbi->cb(cbi->cb_data, key, value);
356 void appinfo_foreach(struct appinfomgr *cf, appinfo_iter_callback cb, void *user_data)
362 _E("appinfo foreach: %s", strerror(errno));
367 cbi.cb_data = user_data;
369 g_hash_table_foreach(cf->tbl, _iter_cb, &cbi);
372 int appinfo_get_boolean(const struct appinfo *c, enum appinfo_type type)
376 v = appinfo_get_value(c, type);
380 if (!strcmp(v, "1") || !strcasecmp(v, "true"))
383 if (!strcmp(v, "0") || !strcasecmp(v, "false"))