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 */
35 #define _AI_START _AI_NAME /* start index */
39 enum appinfo_type type;
42 static struct appinfo_t _appinfos[] = {
43 [_AI_NAME] = { "Name", AIT_NAME, },
44 [_AI_COMP] = { "Component", AIT_COMP, },
45 [_AI_EXEC] = { "Exec", AIT_EXEC, },
46 [_AI_TYPE] = { "PkgType", AIT_TYPE, },
47 [_AI_ONBOOT] = { "StartOnBoot", AIT_ONBOOT, },
48 [_AI_RESTART] = { "AutoRestart", AIT_RESTART, },
49 [_AI_MULTI] = { "Multiple", AIT_MULTI, },
50 [_AI_HWACC] = { "Hwacceleration", AIT_HWACC, },
51 [_AI_PERM] = { "PermissionType", AIT_PERM, },
60 static void _free_appinfo(gpointer data)
62 struct appinfo *c = data;
68 for (i = 0; i < sizeof(c->val)/sizeof(c->val[0]); i++)
74 static void _fini(struct appinfomgr *cf)
78 g_hash_table_destroy(cf->tbl);
82 static int __app_info_insert_handler (const pkgmgrinfo_appinfo_h handle, void *data)
85 struct appinfomgr *cf = (struct appinfomgr *)data;
93 pkgmgrinfo_app_hwacceleration hwacc;
94 pkgmgrinfo_app_component component;
95 pkgmgrinfo_permission_type permission;
99 _E("null app handle");
103 ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
105 _E("fail to get appinfo");
109 g_hash_table_remove(cf->tbl, appid);
111 c = calloc(1, sizeof(*c));
113 _E("create appinfo: %s", strerror(errno));
117 memset(c, 0, sizeof(struct appinfo));
119 c->val[_AI_FILE] = strdup(appid);
120 if (!c->val[_AI_FILE]) {
121 _E("create appinfo: %s", strerror(errno));
126 c->val[_AI_NAME] = strdup(appid); //TODO :
128 pkgmgrinfo_appinfo_get_component(handle, &component);
129 if(component == PMINFO_UI_APP) {
130 c->val[_AI_COMP] = strdup("ui"); //TODO :
132 r = pkgmgrinfo_appinfo_is_multiple(handle, &multiple);
134 c->val[_AI_MULTI] = strdup("true");
135 else c->val[_AI_MULTI] = strdup("false");
138 c->val[_AI_HWACC] = strdup("NOT_USE");
141 r = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc);
142 if (hwacc == PMINFO_HWACCELERATION_USE_GL) {
143 c->val[_AI_HWACC] = strdup("USE");
144 } else if (hwacc == PMINFO_HWACCELERATION_USE_SYSTEM_SETTING) {
145 c->val[_AI_HWACC] = strdup("SYS");
147 c->val[_AI_HWACC] = strdup("NOT_USE");
151 c->val[_AI_COMP] = strdup("svc");
153 r = pkgmgrinfo_appinfo_is_onboot(handle, &onboot);
155 c->val[_AI_ONBOOT] = strdup("true");
156 else c->val[_AI_ONBOOT] = strdup("false");
158 r = pkgmgrinfo_appinfo_is_autorestart(handle, &restart);
160 c->val[_AI_RESTART] = strdup("true");
161 else c->val[_AI_RESTART] = strdup("false");
164 r = pkgmgrinfo_appinfo_get_exec(handle, &exec);
165 c->val[_AI_EXEC] = strdup(exec);
167 r = pkgmgrinfo_appinfo_get_apptype(handle, &type);
168 if(strncmp(type, "capp", 4) == 0 ) {
169 c->val[_AI_TYPE] = strdup("rpm");
170 } else if (strncmp(type, "c++app", 6) == 0 || strncmp(type, "ospapp", 6) == 0) {
171 c->val[_AI_TYPE] = strdup("tpk");
172 } else if (strncmp(type, "webapp", 6) == 0) {
173 c->val[_AI_TYPE] = strdup("wgt");
176 r = pkgmgrinfo_appinfo_get_permission_type(handle, &permission);
177 if (permission == PMINFO_PERMISSION_SIGNATURE) {
178 c->val[_AI_PERM] = strdup("signature");
179 } else if (permission == PMINFO_PERMISSION_PRIVILEGE) {
180 c->val[_AI_PERM] = strdup("privilege");
182 c->val[_AI_PERM] = strdup("normal");
185 _D("%s : %s : %s", c->val[_AI_FILE], c->val[_AI_COMP], c->val[_AI_TYPE]);
187 g_hash_table_insert(cf->tbl, c->val[_AI_FILE], c);
192 static int __app_info_delete_handler (const pkgmgrinfo_appinfo_h handle, void *data)
194 struct appinfomgr *cf = (struct appinfomgr *)data;
197 pkgmgrinfo_appinfo_get_appid(handle, &appid);
199 g_hash_table_remove(cf->tbl, appid);
204 static int _read_pkg_info(struct appinfomgr *cf)
208 r = pkgmgrinfo_appinfo_get_installed_list(__app_info_insert_handler, cf);
213 static struct appinfomgr *_init()
215 struct appinfomgr *cf;
217 cf = calloc(1, sizeof(*cf));
219 _E("appinfo init: %s", strerror(errno));
223 cf->tbl = g_hash_table_new_full(g_str_hash, g_str_equal,
224 NULL, _free_appinfo);
229 static void __vconf_cb(keynode_t *key, void *data)
235 pkgmgrinfo_appinfo_h handle;
236 struct appinfomgr *cf = (struct appinfomgr *)data;
239 noti_string = vconf_keynode_get_str(key);
240 if( noti_string == NULL ) {
244 _D("noti_string : %s",noti_string);
246 type_string = strtok_r(noti_string, ":", &saveptr);
247 appid = strtok_r(NULL, ":", &saveptr);
249 if ( strncmp(type_string, "create", 6) == 0) {
250 ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
252 _E("pkgmgrinfo_appinfo_get_appinfo fail");
255 _D("appid : %s /handle : %x", appid, handle);
257 __app_info_insert_handler(handle, data);
259 pkgmgrinfo_appinfo_destroy_appinfo(handle);
260 } else if ( strncmp(type_string, "delete", 6) == 0) {
261 g_hash_table_remove(cf->tbl, appid);
262 } else if (strncmp(type_string, "update", 6) == 0){
263 /*REMOVE EXISTING ENTRY & CREATE AGAIN*/
264 if (g_hash_table_remove(cf->tbl, appid) == true){
265 if (pkgmgrinfo_appinfo_get_appinfo(appid, &handle) == PMINFO_R_OK){
266 __app_info_insert_handler(handle, data);
267 pkgmgrinfo_appinfo_destroy_appinfo(handle);
273 int appinfo_init(struct appinfomgr **cf)
275 struct appinfomgr *_cf;
278 char buf[4096] = {0,};
283 _E("appinfo init: %s", strerror(errno));
287 fp = fopen("/proc/cmdline", "r");
289 _E("appinfo init failed: %s", strerror(errno));
292 r = fgets(buf, sizeof(buf), fp);
293 tmp = strstr(buf, "gles");
295 sscanf(tmp,"gles=%d", &gles);
303 r = _read_pkg_info(_cf);
304 if (r != PMINFO_R_OK) {
309 r = vconf_notify_key_changed(VCONFKEY_MENUSCREEN_DESKTOP, __vconf_cb, _cf);
311 _E("Unable to register vconf notification callback for VCONFKEY_MENUSCREEN_DESKTOP\n");
318 void appinfo_fini(struct appinfomgr **cf)
327 const struct appinfo *appinfo_insert(struct appinfomgr *cf, const char *pkg_name)
329 pkgmgrinfo_pkginfo_h handle;
330 if (pkgmgrinfo_pkginfo_get_pkginfo(pkg_name, &handle) == PMINFO_R_OK){
331 pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, __app_info_insert_handler, cf);
332 pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __app_info_insert_handler, cf);
333 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
338 void appinfo_delete(struct appinfomgr *cf, const char *pkg_name)
340 pkgmgrinfo_pkginfo_h handle;
341 if (pkgmgrinfo_pkginfo_get_pkginfo(pkg_name, &handle) != PMINFO_R_OK)
343 pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, __app_info_delete_handler, cf);
344 pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __app_info_delete_handler, cf);
345 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
348 const struct appinfo *appinfo_find(struct appinfomgr *cf, const char *filename)
350 if (!cf || !filename || !*filename) {
352 _E("appinfo find: %s", strerror(errno));
356 return g_hash_table_lookup(cf->tbl, FILENAME(filename));
359 const char *appinfo_get_value(const struct appinfo *c, enum appinfo_type type)
365 _E("appinfo get value: %s", strerror(errno));
369 for (i = _AI_START; i < sizeof(_appinfos)/sizeof(_appinfos[0]); i++) {
370 if (type == _appinfos[i].type)
375 _E("appinfo get value: %s", strerror(errno));
380 const char *appinfo_get_filename(const struct appinfo *c)
384 _E("appinfo get filename: %s", strerror(errno));
388 return c->val[_AI_FILE];
392 appinfo_iter_callback cb;
396 static void _iter_cb(gpointer key, gpointer value, gpointer user_data)
398 struct _cbinfo *cbi = user_data;
402 cbi->cb(cbi->cb_data, key, value);
405 void appinfo_foreach(struct appinfomgr *cf, appinfo_iter_callback cb, void *user_data)
411 _E("appinfo foreach: %s", strerror(errno));
416 cbi.cb_data = user_data;
418 g_hash_table_foreach(cf->tbl, _iter_cb, &cbi);
421 int appinfo_get_boolean(const struct appinfo *c, enum appinfo_type type)
425 v = appinfo_get_value(c, type);
429 if (!strcmp(v, "1") || !strcasecmp(v, "true"))
432 if (!strcmp(v, "0") || !strcasecmp(v, "false"))