1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
6 #include "xwalk/application/tools/linux/xwalk_launcher_tizen.h"
9 #include <pkgmgr-info.h>
16 #include "base/logging.h"
19 // Private struct from appcore-internal, necessary to get events from
23 void (*cb_app)(app_event evnt, void* data, bundle* b);
28 const char* Event2Str(app_event event) {
35 return "AE_TERMINATE";
43 return "AE_LOWMEM_POST";
45 return "AE_MEM_FLUSH";
50 return "INVALID EVENT";
57 XWalkLauncherTizen::XWalkLauncherTizen(bool query_running,
58 base::MessageLoop* main_loop)
59 : XWalkLauncher(query_running, main_loop) {
62 int XWalkLauncherTizen::Launch(const std::string& appid_or_url, bool fullscreen,
63 bool remote_debugging, int argc, char* argv[]) {
64 appid_or_url_ = appid_or_url;
65 fullscreen_ = fullscreen;
66 remote_debugging_ = remote_debugging;
69 return dbus_object_manager_->IsApplicationRunning(appid_or_url_);
71 std::string name = "xwalk-" + appid_or_url_;
73 if (XwalkAppcoreInit(name, argc, argv)) {
74 LOG(ERROR) << "Failed to initialize appcore.";
77 if (GURL(appid_or_url_).spec().empty()
78 && XwalkChangeCmdline(appid_or_url_, argc, argv))
83 bool XWalkLauncherTizen::Suspend() {
84 return dbus_object_manager_->Suspend();
87 bool XWalkLauncherTizen::Resume() {
88 return dbus_object_manager_->Resume();
91 void XWalkLauncherTizen::application_event_cb(app_event event,
92 void* data, bundle* b) {
93 XWalkLauncherTizen* xwalk_launcher = static_cast<XWalkLauncherTizen*>(data);
94 LOG(INFO) << "event '" << Event2Str(event) << "'";
101 xwalk_launcher->main_loop_->QuitNow();
104 if (!xwalk_launcher->Suspend())
105 LOG(ERROR) << "Suspending application failed";
108 if (!xwalk_launcher->Resume())
109 LOG(ERROR) << "Resuming application failed";
112 if (!xwalk_launcher->LaunchApplication())
113 xwalk_launcher->main_loop_->QuitNow();
122 int XWalkLauncherTizen::XwalkAppcoreInit(const std::string& name,
123 int argc, char* argv[]) {
124 app_ops.cb_app = application_event_cb;
126 return appcore_init(name.c_str(), &app_ops, argc, argv);
129 int XWalkLauncherTizen::XwalkChangeCmdline(const std::string& app_id,
130 int argc, char* argv[]) {
131 // Change /proc/<pid>/cmdline to app exec path. See XWALK-1722 for details.
132 pkgmgrinfo_appinfo_h handle;
133 char* exec_path = nullptr;
134 // todo : add is_admin
135 if (pkgmgrinfo_appinfo_get_usr_appinfo(app_id.c_str(),
136 getuid(), &handle) != PMINFO_R_OK ||
137 pkgmgrinfo_appinfo_get_exec(handle, &exec_path) != PMINFO_R_OK ||
139 if (pkgmgrinfo_appinfo_get_appinfo(app_id.c_str(), &handle) !=
141 pkgmgrinfo_appinfo_get_exec(handle, &exec_path) != PMINFO_R_OK ||
143 LOG(ERROR) << "Couldn't find exec path for application: " << app_id;
149 for (int i = 0; i < argc; ++i)
150 memset(argv[i], 0, strlen(argv[i]));
152 strncpy(argv[0], exec_path, strlen(exec_path) + 1);
153 pkgmgrinfo_appinfo_destroy_appinfo(handle);