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.
10 #include <appcore/appcore-common.h>
11 #include <pkgmgr-info.h>
13 #include "xwalk/application/common/id_util.h"
14 #include "xwalk/application/tools/linux/xwalk_launcher_tizen.h"
28 // Private struct from appcore-internal, necessary to get events from
32 void (*cb_app)(enum app_event evnt, void* data, bundle* b);
35 static struct ui_ops appcore_ops;
37 static const char* event2str(enum app_event event) {
44 return "AE_TERMINATE";
52 return "AE_LOWMEM_POST";
54 return "AE_MEM_FLUSH";
59 return "INVALID EVENT";
62 static void application_event_cb(enum app_event event, void* data, bundle* b) {
63 fprintf(stderr, "event '%s'\n", event2str(event));
64 GDBusProxy* app_proxy = reinterpret_cast<GDBusProxy*>(data);
67 fprintf(stderr, "Invalid DBus proxy.");
80 app_proxy, "Suspend", NULL,
81 G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
85 app_proxy, "Resume", NULL,
86 G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
96 int xwalk_appcore_init(
97 int argc, char** argv, const char* name, GDBusProxy* app_proxy) {
98 appcore_ops.cb_app = application_event_cb;
99 appcore_ops.data = app_proxy;
101 return appcore_init(name, &appcore_ops, argc, argv);
104 int xwalk_change_cmdline(int argc, char** argv, const char* app_id) {
105 // Change /proc/<pid>/cmdline to app exec path. See XWALK-1722 for details.
106 pkgmgrinfo_appinfo_h handle;
107 char* exec_path = NULL;
108 if (pkgmgrinfo_appinfo_get_appinfo(app_id, &handle) != PMINFO_R_OK ||
109 pkgmgrinfo_appinfo_get_exec(handle, &exec_path) != PMINFO_R_OK ||
111 fprintf(stderr, "Couldn't find exec path for application: %s\n", app_id);
115 for (int i = 0; i < argc; ++i)
116 memset(argv[i], 0, strlen(argv[i]));
117 strncpy(argv[0], exec_path, strlen(exec_path)+1);
118 pkgmgrinfo_appinfo_destroy_appinfo(handle);