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/tools/linux/xwalk_launcher_tizen.h"
26 // Private struct from appcore-internal, necessary to get events from
30 void (*cb_app)(enum app_event evnt, void* data, bundle* b);
33 static struct ui_ops appcore_ops;
35 static const char* event2str(enum app_event event) {
42 return "AE_TERMINATE";
50 return "AE_LOWMEM_POST";
52 return "AE_MEM_FLUSH";
57 return "INVALID EVENT";
60 static void application_event_cb(enum app_event event, void* data, bundle* b) {
61 fprintf(stderr, "event '%s'\n", event2str(event));
63 if (event == AE_TERMINATE) {
68 int xwalk_appcore_init(int argc, char** argv, const char* name) {
69 appcore_ops.cb_app = application_event_cb;
70 appcore_ops.data = NULL;
72 return appcore_init(name, &appcore_ops, argc, argv);
75 int xwalk_change_cmdline(int argc, char** argv, const char* app_id) {
76 // Change /proc/<pid>/cmdline to app exec path. See XWALK-1722 for details.
77 gchar* tizen_app_id = g_strconcat("xwalk.", app_id, NULL);
78 pkgmgrinfo_appinfo_h handle;
79 char* exec_path = NULL;
80 if (pkgmgrinfo_appinfo_get_appinfo(tizen_app_id, &handle) != PMINFO_R_OK ||
81 pkgmgrinfo_appinfo_get_exec(handle, &exec_path) != PMINFO_R_OK ||
83 fprintf(stderr, "Couldn't find exec path for application: %s\n",
88 for (int i = 0; i < argc; ++i)
89 memset(argv[i], 0, strlen(argv[i]));
90 strncpy(argv[0], exec_path, strlen(exec_path)+1);
92 pkgmgrinfo_appinfo_destroy_appinfo(handle);
96 char* xwalk_extract_app_id(const char* tizen_app_id) {
97 // The Tizen application ID will have a format like
98 // "xwalk.crosswalk_32bytes_app_id".
100 gchar** tokens = g_strsplit(tizen_app_id, ".", 2);
101 if (g_strv_length(tokens) != 2)
102 fprintf(stderr, "Invalid Tizen AppID, fallback to Crosswalk AppID.\n");
104 app_id = strdup(tokens[1]);