1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
9 #include <appcore/appcore-common.h>
10 #include <pkgmgr-info.h>
12 #include "xwalk/application/common/id_util.h"
13 #include "xwalk/application/tools/linux/xwalk_launcher_tizen.h"
27 // Private struct from appcore-internal, necessary to get events from
31 void (*cb_app)(enum app_event evnt, void* data, bundle* b);
34 static struct ui_ops appcore_ops;
36 static const char* event2str(enum app_event event) {
43 return "AE_TERMINATE";
51 return "AE_LOWMEM_POST";
53 return "AE_MEM_FLUSH";
58 return "INVALID EVENT";
61 static void application_event_cb(enum app_event event, void* data, bundle* b) {
62 fprintf(stderr, "event '%s'\n", event2str(event));
64 if (event == AE_TERMINATE) {
69 int xwalk_appcore_init(int argc, char** argv, const char* name) {
70 appcore_ops.cb_app = application_event_cb;
71 appcore_ops.data = NULL;
73 return appcore_init(name, &appcore_ops, argc, argv);
76 int xwalk_change_cmdline(int argc, char** argv, const char* app_id) {
77 // Change /proc/<pid>/cmdline to app exec path. See XWALK-1722 for details.
78 char* app_id_for_db = strdup(
79 xwalk::application::RawAppIdToAppIdForTizenPkgmgrDB(app_id).c_str());
80 pkgmgrinfo_appinfo_h handle;
81 char* exec_path = NULL;
82 if (pkgmgrinfo_appinfo_get_appinfo(app_id_for_db, &handle) != PMINFO_R_OK ||
83 pkgmgrinfo_appinfo_get_exec(handle, &exec_path) != PMINFO_R_OK ||
85 fprintf(stderr, "Couldn't find exec path for application: %s\n",
90 for (int i = 0; i < argc; ++i)
91 memset(argv[i], 0, strlen(argv[i]));
92 strncpy(argv[0], exec_path, strlen(exec_path)+1);
93 g_free(app_id_for_db);
94 pkgmgrinfo_appinfo_destroy_appinfo(handle);