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 */
37 #define _AI_START _AI_NAME /* start index */
41 enum appinfo_type type;
44 static struct appinfo_t _appinfos[] = {
45 [_AI_NAME] = { "Name", AIT_NAME, },
46 [_AI_COMP] = { "Component", AIT_COMP, },
47 [_AI_EXEC] = { "Exec", AIT_EXEC, },
48 [_AI_TYPE] = { "PkgType", AIT_TYPE, },
49 [_AI_ONBOOT] = { "StartOnBoot", AIT_ONBOOT, },
50 [_AI_RESTART] = { "AutoRestart", AIT_RESTART, },
51 [_AI_MULTI] = { "Multiple", AIT_MULTI, },
52 [_AI_HWACC] = { "Hwacceleration", AIT_HWACC, },
53 [_AI_PERM] = { "PermissionType", AIT_PERM, },
54 [_AI_PKGID] = { "PackageId", AIT_PKGID, },
55 [_AI_PRELOAD] = { "Preload", AIT_PRELOAD, },
64 static void _free_appinfo(gpointer data)
66 struct appinfo *c = data;
72 for (i = 0; i < sizeof(c->val)/sizeof(c->val[0]); i++)
78 static void _fini(struct appinfomgr *cf)
82 g_hash_table_destroy(cf->tbl);
86 static int __app_info_insert_handler (const pkgmgrinfo_appinfo_h handle, void *data)
89 struct appinfomgr *cf = (struct appinfomgr *)data;
98 pkgmgrinfo_app_hwacceleration hwacc;
99 pkgmgrinfo_app_component component;
100 pkgmgrinfo_permission_type permission;
105 _E("null app handle");
109 ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
111 _E("fail to get appinfo");
115 g_hash_table_remove(cf->tbl, appid);
117 c = calloc(1, sizeof(*c));
119 _E("create appinfo: %s", strerror(errno));
123 memset(c, 0, sizeof(struct appinfo));
125 c->val[_AI_FILE] = strdup(appid);
126 if (!c->val[_AI_FILE]) {
127 _E("create appinfo: %s", strerror(errno));
132 c->val[_AI_NAME] = strdup(appid); //TODO :
134 pkgmgrinfo_appinfo_get_component(handle, &component);
135 if(component == PMINFO_UI_APP) {
136 c->val[_AI_COMP] = strdup("ui"); //TODO :
138 r = pkgmgrinfo_appinfo_is_multiple(handle, &multiple);
140 c->val[_AI_MULTI] = strdup("true");
141 else c->val[_AI_MULTI] = strdup("false");
144 c->val[_AI_HWACC] = strdup("NOT_USE");
147 r = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc);
148 if (hwacc == PMINFO_HWACCELERATION_USE_GL) {
149 c->val[_AI_HWACC] = strdup("USE");
150 } else if (hwacc == PMINFO_HWACCELERATION_USE_SYSTEM_SETTING) {
151 c->val[_AI_HWACC] = strdup("SYS");
153 c->val[_AI_HWACC] = strdup("NOT_USE");
157 c->val[_AI_COMP] = strdup("svc");
159 r = pkgmgrinfo_appinfo_is_onboot(handle, &onboot);
161 c->val[_AI_ONBOOT] = strdup("true");
162 else c->val[_AI_ONBOOT] = strdup("false");
164 r = pkgmgrinfo_appinfo_is_autorestart(handle, &restart);
166 c->val[_AI_RESTART] = strdup("true");
167 else c->val[_AI_RESTART] = strdup("false");
170 r = pkgmgrinfo_appinfo_get_exec(handle, &exec);
171 c->val[_AI_EXEC] = strdup(exec);
173 r = pkgmgrinfo_appinfo_get_apptype(handle, &type);
174 if(strncmp(type, "capp", 4) == 0 ) {
175 c->val[_AI_TYPE] = strdup("rpm");
176 } else if (strncmp(type, "c++app", 6) == 0 || strncmp(type, "ospapp", 6) == 0) {
177 c->val[_AI_TYPE] = strdup("tpk");
178 } else if (strncmp(type, "webapp", 6) == 0) {
179 c->val[_AI_TYPE] = strdup("wgt");
182 r = pkgmgrinfo_appinfo_get_permission_type(handle, &permission);
183 if (permission == PMINFO_PERMISSION_SIGNATURE) {
184 c->val[_AI_PERM] = strdup("signature");
185 } else if (permission == PMINFO_PERMISSION_PRIVILEGE) {
186 c->val[_AI_PERM] = strdup("privilege");
188 c->val[_AI_PERM] = strdup("normal");
191 r = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
192 c->val[_AI_PKGID] = strdup(pkgid);
194 r = pkgmgrinfo_appinfo_is_preload(handle, &preload);
195 if (preload == false) {
196 c->val[_AI_PRELOAD] = strdup("false");
198 c->val[_AI_PRELOAD] = strdup("true");
201 _D("%s : %s : %s", c->val[_AI_FILE], c->val[_AI_COMP], c->val[_AI_TYPE]);
203 g_hash_table_insert(cf->tbl, c->val[_AI_FILE], c);
208 static int __app_info_delete_handler (const pkgmgrinfo_appinfo_h handle, void *data)
210 struct appinfomgr *cf = (struct appinfomgr *)data;
213 pkgmgrinfo_appinfo_get_appid(handle, &appid);
215 g_hash_table_remove(cf->tbl, appid);
220 static int _read_pkg_info(struct appinfomgr *cf)
224 r = pkgmgrinfo_appinfo_get_installed_list(__app_info_insert_handler, cf);
229 static struct appinfomgr *_init()
231 struct appinfomgr *cf;
233 cf = calloc(1, sizeof(*cf));
235 _E("appinfo init: %s", strerror(errno));
239 cf->tbl = g_hash_table_new_full(g_str_hash, g_str_equal,
240 NULL, _free_appinfo);
245 static void __vconf_cb(keynode_t *key, void *data)
251 pkgmgrinfo_appinfo_h handle;
252 struct appinfomgr *cf = (struct appinfomgr *)data;
255 noti_string = vconf_keynode_get_str(key);
256 if( noti_string == NULL ) {
260 _D("noti_string : %s",noti_string);
262 type_string = strtok_r(noti_string, ":", &saveptr);
263 appid = strtok_r(NULL, ":", &saveptr);
265 if ( strncmp(type_string, "create", 6) == 0) {
266 ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
268 _E("pkgmgrinfo_appinfo_get_appinfo fail");
271 _D("appid : %s /handle : %x", appid, handle);
273 __app_info_insert_handler(handle, data);
275 pkgmgrinfo_appinfo_destroy_appinfo(handle);
276 } else if ( strncmp(type_string, "delete", 6) == 0) {
277 g_hash_table_remove(cf->tbl, appid);
278 } else if (strncmp(type_string, "update", 6) == 0){
279 /*REMOVE EXISTING ENTRY & CREATE AGAIN*/
280 if (g_hash_table_remove(cf->tbl, appid) == true){
281 if (pkgmgrinfo_appinfo_get_appinfo(appid, &handle) == PMINFO_R_OK){
282 __app_info_insert_handler(handle, data);
283 pkgmgrinfo_appinfo_destroy_appinfo(handle);
289 int appinfo_init(struct appinfomgr **cf)
291 struct appinfomgr *_cf;
294 char buf[4096] = {0,};
299 _E("appinfo init: %s", strerror(errno));
303 fp = fopen("/proc/cmdline", "r");
305 _E("appinfo init failed: %s", strerror(errno));
308 r = fgets(buf, sizeof(buf), fp);
309 tmp = strstr(buf, "gles");
311 sscanf(tmp,"gles=%d", &gles);
319 r = _read_pkg_info(_cf);
320 if (r != PMINFO_R_OK) {
325 r = vconf_notify_key_changed(VCONFKEY_MENUSCREEN_DESKTOP, __vconf_cb, _cf);
327 _E("Unable to register vconf notification callback for VCONFKEY_MENUSCREEN_DESKTOP\n");
334 void appinfo_fini(struct appinfomgr **cf)
343 const struct appinfo *appinfo_insert(struct appinfomgr *cf, const char *pkg_name)
345 pkgmgrinfo_pkginfo_h handle;
346 if (pkgmgrinfo_pkginfo_get_pkginfo(pkg_name, &handle) == PMINFO_R_OK){
347 pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, __app_info_insert_handler, cf);
348 pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __app_info_insert_handler, cf);
349 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
354 void appinfo_delete(struct appinfomgr *cf, const char *pkg_name)
356 pkgmgrinfo_pkginfo_h handle;
357 if (pkgmgrinfo_pkginfo_get_pkginfo(pkg_name, &handle) != PMINFO_R_OK)
359 pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, __app_info_delete_handler, cf);
360 pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __app_info_delete_handler, cf);
361 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
364 const struct appinfo *appinfo_find(struct appinfomgr *cf, const char *filename)
366 if (!cf || !filename || !*filename) {
368 _E("appinfo find: %s", strerror(errno));
372 return g_hash_table_lookup(cf->tbl, FILENAME(filename));
375 const char *appinfo_get_value(const struct appinfo *c, enum appinfo_type type)
381 _E("appinfo get value: %s", strerror(errno));
385 for (i = _AI_START; i < sizeof(_appinfos)/sizeof(_appinfos[0]); i++) {
386 if (type == _appinfos[i].type)
391 _E("appinfo get value: %s", strerror(errno));
396 const char *appinfo_get_filename(const struct appinfo *c)
400 _E("appinfo get filename: %s", strerror(errno));
404 return c->val[_AI_FILE];
408 appinfo_iter_callback cb;
412 static void _iter_cb(gpointer key, gpointer value, gpointer user_data)
414 struct _cbinfo *cbi = user_data;
418 cbi->cb(cbi->cb_data, key, value);
421 void appinfo_foreach(struct appinfomgr *cf, appinfo_iter_callback cb, void *user_data)
427 _E("appinfo foreach: %s", strerror(errno));
432 cbi.cb_data = user_data;
434 g_hash_table_foreach(cf->tbl, _iter_cb, &cbi);
437 int appinfo_get_boolean(const struct appinfo *c, enum appinfo_type type)
441 v = appinfo_get_value(c, type);
445 if (!strcmp(v, "1") || !strcasecmp(v, "true"))
448 if (!strcmp(v, "0") || !strcasecmp(v, "false"))