2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 /* @file wrt-installer.cpp
18 * @brief Implementation file for installer
21 #include "wrt-installer.h"
22 #include "plugin_utils.h"
28 #include <sys/resource.h>
30 #include <dpl/optional_typedefs.h>
31 #include <dpl/wrt-dao-ro/global_config.h>
32 #include <dpl/wrt-dao-ro/config_parser_data.h>
33 #include <dpl/abstract_waitable_input_adapter.h>
34 #include <dpl/abstract_waitable_output_adapter.h>
35 #include <dpl/zip_input.h>
36 #include <dpl/binary_queue.h>
38 #include <dpl/errno_string.h>
39 #include <dpl/utils/wrt_global_settings.h>
40 #include <dpl/utils/wrt_utility.h>
41 #include <parser_runner.h>
42 #include <widget_parser.h>
43 #include <root_parser.h>
44 #include <pkgmgr-info.h>
46 #include <Elementary.h>
48 #include <pkg-manager/pkgmgr_signal_dummy.h>
49 #include <pkg-manager/pkgmgr_signal.h>
50 #include <installer_log.h>
52 using namespace WrtDB;
54 namespace { // anonymous
55 const char * const PKGMGR_INSTALL_MSG = "Install widget";
56 const char * const PKGMGR_UNINSTALL_MSG = "Uninstall widget";
58 const char * const CONFIG_XML = "config.xml";
59 const char * const HYBRID_CONFIG_XML = "res/wgt/config.xml";
61 const unsigned int NOFILE_CNT_FOR_INSTALLER = 9999;
65 void operator()(void* x)
71 struct PluginInstallerData
74 std::string pluginPath;
76 } // namespace anonymous
78 WrtInstaller::WrtInstaller(int argc, char **argv) :
79 Application(argc, argv, "backend", false),
80 DPL::TaskDecl<WrtInstaller>(this),
83 m_numPluginsToInstall(0),
86 m_installByPkgmgr(false),
87 m_startupPluginInstallation(false)
93 WrtInstaller::~WrtInstaller()
98 int WrtInstaller::getReturnStatus() const
100 return m_returnStatus;
103 void WrtInstaller::OnStop()
105 _D("Stopping Dummy Client");
108 void WrtInstaller::OnCreate()
110 _D("Creating DummyClient");
113 AddStep(&WrtInstaller::initStep);
115 std::string arg = m_argv[0];
117 pkgmgrSignalInterface =
118 std::static_pointer_cast<PackageManager::IPkgmgrSignal>(
119 std::shared_ptr<PackageManager::PkgmgrSignalDummy>(
120 new PackageManager::PkgmgrSignalDummy()
125 return showHelpAndQuit();
130 if (arg.find("wrt-installer") != std::string::npos) {
132 return showHelpAndQuit();
136 if (arg == "-h" || arg == "--help") {
138 return showHelpAndQuit();
142 return showHelpAndQuit();
143 } else if (arg == "-p" || arg == "--install-plugins") {
145 return showHelpAndQuit();
148 if (!m_startupPluginInstallation) {
149 AddStep(&WrtInstaller::installPluginsStep);
151 _D("Plugin installation alredy started");
153 } else if (arg == "-i" || arg == "--install") {
155 return showHelpAndQuit();
159 if (-1 != stat(m_argv[2], &info) && S_ISDIR(info.st_mode)) {
160 _D("Installing package directly from directory");
161 m_installMode.extension = InstallMode::ExtensionType::DIR;
163 _D("Installing from regular location");
164 m_installMode.extension = InstallMode::ExtensionType::WGT;
166 m_packagePath = m_argv[2];
168 AddStep(&WrtInstaller::installStep);
169 } else if (arg == "-ip" || arg == "--install-preload") {
170 _D("Install preload web app");
172 return showHelpAndQuit();
174 m_packagePath = m_argv[2];
175 m_installMode.installTime = InstallMode::InstallTime::PRELOAD;
176 m_installMode.rootPath = InstallMode::RootPath::RO;
177 AddStep(&WrtInstaller::installStep);
178 } else if (arg == "-ipw" || arg == "--install-preload-writable") {
179 _D("Install preload web application to writable storage");
181 return showHelpAndQuit();
183 m_packagePath = m_argv[2];
184 m_installMode.installTime = InstallMode::InstallTime::PRELOAD;
185 m_installMode.rootPath = InstallMode::RootPath::RW;
186 AddStep(&WrtInstaller::installStep);
187 } else if (arg == "-c" || arg == "--csc-update") {
188 // "path=/opt/system/csc/Ozq2iEG15R-2.0.0-arm.wgt:op=install:removable=true"
189 _D("Install & uninstall by csc configuration");
191 return showHelpAndQuit();
193 m_installMode.installTime = InstallMode::InstallTime::CSC;
194 std::string configuration = m_argv[2];
195 m_CSCconfigurationMap = parseCSCConfiguration(configuration);
197 CSCConfiguration::dataMap::iterator it;
198 it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_OP);
199 if (it == m_CSCconfigurationMap.end()) {
200 return showHelpAndQuit();
203 if (it->second == CSCConfiguration::VALUE_INSTALL) {
204 _D("operation = %s", it->second.c_str());
205 m_installMode.extension = InstallMode::ExtensionType::WGT;
206 it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_PATH);
207 if (it == m_CSCconfigurationMap.end()) {
208 return showHelpAndQuit();
210 m_packagePath = it->second;
212 it = m_CSCconfigurationMap.find(
213 CSCConfiguration::KEY_REMOVABLE);
214 if (it == m_CSCconfigurationMap.end()) {
215 return showHelpAndQuit();
218 m_installMode.removable =
219 (it->second.compare(CSCConfiguration::VALUE_FALSE) == 0)
222 AddStep(&WrtInstaller::installStep);
223 _D("path = %s", m_packagePath.c_str());
224 } else if (it->second == CSCConfiguration::VALUE_UNINSTALL) {
225 _D("operation = %s", it->second.c_str());
226 // uninstall command isn't confirmed yet
227 it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_PATH);
228 if (it == m_CSCconfigurationMap.end()) {
229 return showHelpAndQuit();
231 m_packagePath = it->second;
232 AddStep(&WrtInstaller::unistallWgtFileStep);
233 _D("operation = uninstall");
234 _D("path = %s", m_packagePath.c_str());
236 _E("Unknown operation : %s", it->second.c_str());
237 _D("operation = %s", it->second.c_str());
238 return showHelpAndQuit();
240 } else if (arg == "-un" || arg == "--uninstall-name") {
242 return showHelpAndQuit();
245 AddStep(&WrtInstaller::uninstallPkgNameStep);
246 } else if (arg == "-up" || arg == "--uninstall-packagepath") {
248 return showHelpAndQuit();
250 m_packagePath = m_argv[2];
251 AddStep(&WrtInstaller::unistallWgtFileStep);
252 } else if (arg == "-r" || arg == "--reinstall") {
254 return showHelpAndQuit();
256 _D("Installing package directly from directory");
257 m_installMode.command = InstallMode::Command::REINSTALL;
258 m_installMode.extension = InstallMode::ExtensionType::DIR;
259 m_packagePath = m_argv[2];
260 AddStep(&WrtInstaller::installStep);
262 return showHelpAndQuit();
264 } else if (arg.find("backend") != std::string::npos) {
265 using namespace PackageManager;
266 m_installByPkgmgr = true;
268 auto pkgmgrSignal = std::shared_ptr<PackageManager::PkgmgrSignal>(
269 new PackageManager::PkgmgrSignal()
272 pkgmgrSignal->initialize(m_argc, m_argv);
274 PackageManager::PkgmgrSignal::RequestType reqType = pkgmgrSignal->getRequestedType();
276 pkgmgrSignalInterface =
277 std::static_pointer_cast<PackageManager::IPkgmgrSignal>(
280 case PackageManager::PkgmgrSignal::RequestType::INSTALL:
281 m_packagePath = m_argv[4];
283 m_name = std::string(m_argv[6]);
287 if (-1 != stat(m_argv[4], &info) && S_ISDIR(info.st_mode)) {
288 _D("Installing package directly from directory");
289 m_installMode.extension = InstallMode::ExtensionType::DIR;
291 _D("Installing from regular location");
292 m_installMode.extension = InstallMode::ExtensionType::WGT;
294 AddStep(&WrtInstaller::installStep);
296 case PackageManager::PkgmgrSignal::RequestType::UNINSTALL:
299 pkgmgrinfo_pkginfo_h handle = NULL;
300 bool system_app = false; // system app is preloaded and unremovable.
303 if (0 == pkgmgrinfo_pkginfo_get_pkginfo(m_name.c_str(), &handle)) {
304 if (0 > pkgmgrinfo_pkginfo_is_system(handle, &system_app)) {
305 _E("Can't get package information : %s", m_name.c_str());
307 if (0 > pkgmgrinfo_pkginfo_is_update(handle, &update)) {
308 _E("Can't get package information about update : %s", m_name.c_str());
312 _D("system app : %d", system_app);
313 _D("update : %d", update);
315 if (system_app && update) {
316 AddStep(&WrtInstaller::removeUpdateStep);
318 AddStep(&WrtInstaller::uninstallPkgNameStep);
322 case PackageManager::PkgmgrSignal::RequestType::REINSTALL:
323 m_packagePath = m_argv[4];
324 m_installMode.command = InstallMode::Command::REINSTALL;
325 m_installMode.extension = InstallMode::ExtensionType::DIR;
326 AddStep(&WrtInstaller::installStep);
329 _D("Not available type");
334 AddStep(&WrtInstaller::shutdownStep);
335 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::
337 WRTInstallerNS::NextStepEvent());
340 void WrtInstaller::OnReset(bundle* /*b*/)
345 void WrtInstaller::OnTerminate()
347 _D("Wrt Shutdown now");
348 PluginUtils::unlockPluginInstallation(
349 m_installMode.installTime == InstallMode::InstallTime::PRELOAD);
351 wrt_installer_shutdown();
355 void WrtInstaller::showHelpAndQuit()
357 printf("Usage: wrt-installer [OPTION]... [WIDGET: ID/NAME/PATH]...\n"
358 "Operate with WebRuntime daemon: install, uninstall"
359 " and launch widgets.\n"
360 "Query list of installed widgets and setup up debugging support.\n"
362 "Exactly one option must be selected.\n"
363 "Mandatory arguments to long options are mandatory for short "
365 " -h, --help show this help\n"
366 " -p, --install-plugins install plugins\n"
368 "install or update widget package for given path\n"
370 "install or uninstall by CSC configuration \n"
371 " -un, --uninstall-name "
372 "uninstall widget for given package name\n"
373 " -up, --uninstall-packagepath "
374 "uninstall widget for given package file path\n"
376 "reinstall web application\n"
382 void WrtInstaller::showArguments()
385 "===========================================================\n");
386 fprintf(stderr, "# wrt-installer #\n");
387 fprintf(stderr, "# argc [%d]\n", m_argc);
388 for (int i = 0; i < m_argc; i++) {
389 fprintf(stderr, "# argv[%d] = [%s]\n", i, m_argv[i]);
392 "===========================================================\n");
394 _D("===========================================================");
395 _D("# wrt-installer #");
396 _D("# argc %d", m_argc);
397 for (int i = 0; i < m_argc; i++) {
398 _D("# argv[%d] = %s", i, m_argv[i]);
400 _D("===========================================================");
404 void WrtInstaller::OnEventReceived(const WRTInstallerNS::QuitEvent& /*event*/)
409 _D("Wrt Shutdown now");
410 SwitchToStep(&WrtInstaller::shutdownStep);
411 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::
413 WRTInstallerNS::NextStepEvent());
415 _D("Quiting application");
420 void WrtInstaller::OnEventReceived(
421 const WRTInstallerNS::NextStepEvent& /*event*/)
423 _D("Executing next step");
427 void WrtInstaller::OnEventReceived(
428 const WRTInstallerNS::InstallPluginEvent& /*event*/)
430 PluginInstallerData* privateData = new PluginInstallerData;
431 privateData->wrtInstaller = this;
433 if (!(*m_pluginsPaths).empty()) {
434 privateData->pluginPath = (*m_pluginsPaths).front();
435 (*m_pluginsPaths).pop_front();
437 wrt_install_plugin(privateData->pluginPath.c_str(),
438 static_cast<void*>(privateData),
439 &staticWrtPluginInstallationCallback,
440 &staticWrtPluginInstallProgressCb);
446 void WrtInstaller::initStep()
448 wrt_installer_init(this, staticWrtInitCallback);
451 void WrtInstaller::installStep()
453 _D("Installing widget ...");
454 std::unique_ptr<char, free_deleter> packagePath(canonicalize_file_name(
455 m_packagePath.c_str()));
457 wrt_install_widget(packagePath ? packagePath.get() : m_packagePath.c_str(),
458 m_name.c_str(), this, &staticWrtStatusCallback,
460 ? &staticWrtInstallProgressCallback : NULL,
462 pkgmgrSignalInterface);
465 void WrtInstaller::installPluginsStep()
467 _D("Installing plugins ...");
468 fprintf(stderr, "Installing plugins ...\n");
470 if (m_startupPluginInstallation) {
471 _D("Plugin installation started because new plugin package found");
472 } else if (!PluginUtils::lockPluginInstallation(
473 m_installMode.installTime == InstallMode::InstallTime::PRELOAD))
475 _E("Failed to open plugin installation lock file"
476 " Plugins are currently installed by other process");
477 staticWrtPluginInstallationCallback(WRT_INSTALLER_ERROR_PLUGIN_INSTALLATION_FAILED,
482 std::string PLUGIN_PATH = std::string(GlobalConfig::GetDevicePluginPath());
485 dir = opendir(PLUGIN_PATH.c_str());
491 _D("Plugin DIRECTORY IS %s", PLUGIN_PATH.c_str());
493 std::list<std::string> pluginsPaths;
494 struct dirent libdir;
495 struct dirent *result;
498 for (return_code = readdir_r(dir, &libdir, &result);
499 result != NULL && return_code == 0;
500 return_code = readdir_r(dir, &libdir, &result))
502 if (strcmp(libdir.d_name, ".") == 0 ||
503 strcmp(libdir.d_name, "..") == 0)
508 std::string path = PLUGIN_PATH;
510 path += libdir.d_name;
514 if (stat(path.c_str(), &tmp) == -1) {
515 _E("Failed to open file %s", path.c_str());
519 if (!S_ISDIR(tmp.st_mode)) {
520 _E("Not a directory %s", path.c_str());
524 pluginsPaths.push_back(path);
527 if (return_code != 0 || errno != 0) {
528 _E("readdir_r() failed with %s", DPL::GetErrnoString().c_str());
531 //set nb of plugins to install
532 //this value indicate how many callbacks are expected
533 m_numPluginsToInstall = pluginsPaths.size();
534 _D("Plugins to install: %d", m_numPluginsToInstall);
535 m_pluginsPaths = pluginsPaths;
537 m_totalPlugins = m_numPluginsToInstall;
538 DPL::Event::ControllerEventHandler<WRTInstallerNS::InstallPluginEvent>
539 ::PostEvent(WRTInstallerNS::InstallPluginEvent());
541 if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
542 _E("Failed to close dir: %s with error: %s", PLUGIN_PATH.c_str(), DPL::GetErrnoString().c_str());
546 void WrtInstaller::uninstallPkgNameStep()
548 _D("Uninstalling widget ...");
549 _D("Package name : %s", m_name.c_str());
551 wrt_uninstall_widget(m_name.c_str(), this,
552 &staticWrtStatusCallback,
554 ? &staticWrtUninstallProgressCallback : NULL,
555 pkgmgrSignalInterface);
558 void WrtInstaller::removeUpdateStep()
560 _D("This web app need to initialize preload app");
561 _D("Package name : %s", m_name.c_str());
563 wrt_uninstall_widget(m_name.c_str(), this,
564 &staticWrtInitializeToPreloadCallback,
566 ? &staticWrtUninstallProgressCallback : NULL,
567 pkgmgrSignalInterface);
571 void WrtInstaller::unistallWgtFileStep()
573 _D("Uninstalling widget ...");
578 ConfigParserData configInfo;
581 std::unique_ptr<DPL::ZipInput> zipFile(
582 new DPL::ZipInput(m_packagePath));
583 std::unique_ptr<DPL::ZipInput::File> configFile;
586 // Open config.xml file
587 configFile.reset(zipFile->OpenFile(CONFIG_XML));
589 Catch(DPL::ZipInput::Exception::OpenFileFailed)
591 // Open config.xml file for hybrid
592 configFile.reset(zipFile->OpenFile(HYBRID_CONFIG_XML));
596 DPL::BinaryQueue buffer;
597 DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get());
598 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
599 DPL::Copy(&inputAdapter, &outputAdapter);
600 parser.Parse(&buffer,
602 new RootParser<WidgetParser>(configInfo,
603 DPL::FromUTF32String(
606 DPL::OptionalString pkgId = configInfo.tizenPkgId;
607 if (!pkgId.IsNull()) {
608 _D("Pkgid from packagePath : %ls", (*pkgId).c_str());
609 wrt_uninstall_widget(
610 DPL::ToUTF8String(*pkgId).c_str(), this, &staticWrtStatusCallback,
611 !m_installByPkgmgr ? &staticWrtUninstallProgressCallback
613 pkgmgrSignalInterface);
615 _E("Fail to uninstalling widget... ");
617 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
619 WRTInstallerNS::QuitEvent());
622 Catch(DPL::ZipInput::Exception::OpenFailed)
624 _E("Failed to open widget package");
625 printf("failed: widget package does not exist\n");
627 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
629 WRTInstallerNS::QuitEvent());
631 Catch(DPL::ZipInput::Exception::OpenFileFailed)
633 printf("failed: widget config file does not exist\n");
634 _E("Failed to open config.xml file");
636 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
638 WRTInstallerNS::QuitEvent());
640 Catch(ElementParser::Exception::ParseError)
642 printf("failed: can not parse config file\n");
643 _E("Failed to parse config.xml file");
645 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
647 WRTInstallerNS::QuitEvent());
651 void WrtInstaller::shutdownStep()
653 _D("Closing Wrt connection ...");
655 wrt_installer_shutdown();
656 m_initialized = false;
657 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
659 WRTInstallerNS::QuitEvent());
663 void WrtInstaller::staticWrtInitCallback(WrtErrStatus status,
666 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
669 if (status == WRT_SUCCESS) {
670 _D("Init succesfull");
671 This->m_initialized = true;
672 This->m_returnStatus = 0;
674 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
675 ::PostEvent(WRTInstallerNS::NextStepEvent());
677 _E("Init unsuccesfull");
678 This->m_returnStatus = -1;
679 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
681 WRTInstallerNS::QuitEvent());
685 void WrtInstaller::staticWrtInitializeToPreloadCallback(std::string tizenId, WrtErrStatus
686 status, void* userdata)
688 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
691 std::string printMsg = "uninstallation";
693 if (WRT_SUCCESS != status) {
696 This->m_returnStatus = 1;
698 This->showErrorMsg(status, tizenId, printMsg);
700 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
701 ::PostEvent(WRTInstallerNS::QuitEvent());
704 mode.extension = InstallMode::ExtensionType::DIR;
705 mode.installTime = InstallMode::InstallTime::PRELOAD;
706 mode.rootPath = InstallMode::RootPath::RO;
707 std::string packagePath =
708 std::string(WrtDB::GlobalConfig::GetUserPreloadedWidgetPath()) + "/" +
711 wrt_install_widget(packagePath.c_str(), tizenId.c_str(),
712 This, &staticWrtInitPreloadStatusCallback,
715 This->pkgmgrSignalInterface);
719 void WrtInstaller::staticWrtInitPreloadStatusCallback(std::string tizenId,
723 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
726 std::string printMsg = "initialization";
728 if (WRT_SUCCESS != status) {
731 This->m_returnStatus = status;
733 This->showErrorMsg(status, tizenId, printMsg);
735 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
736 ::PostEvent(WRTInstallerNS::QuitEvent());
739 "## wrt-installer : %s %s was successful.\n",
742 _D("Status succesfull");
743 This->m_returnStatus = 0;
745 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
747 ::PostEvent(WRTInstallerNS::NextStepEvent());
751 void WrtInstaller::staticWrtStatusCallback(std::string tizenId,
755 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
758 Step current = This->GetCurrentStep();
759 std::string printMsg;
761 if (current == &WrtInstaller::installStep) {
762 printMsg = "installation";
763 } else if (current == &WrtInstaller::uninstallPkgNameStep ||
764 current == &WrtInstaller::unistallWgtFileStep)
766 printMsg = "uninstallation";
769 if (WRT_SUCCESS != status) {
772 This->m_returnStatus = status;
774 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
775 ::PostEvent(WRTInstallerNS::QuitEvent());
777 This->showErrorMsg(status, tizenId, printMsg);
780 "## wrt-installer : %s %s was successful.\n",
783 _D("Status succesfull");
784 This->m_returnStatus = 0;
786 if (This->m_installMode.installTime == InstallMode::InstallTime::PRELOAD &&
787 !This->m_packagePath.empty())
789 _D("This widget is preloaded so it will be removed : %s", This->m_packagePath.c_str());
790 if (!WrtUtilRemove(This->m_packagePath)) {
791 _E("Failed to remove %s", This->m_packagePath.c_str());
795 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
797 ::PostEvent(WRTInstallerNS::NextStepEvent());
801 void WrtInstaller::showErrorMsg(WrtErrStatus status, std::string tizenId,
802 std::string printMsg)
805 case WRT_INSTALLER_ERROR_PACKAGE_NOT_FOUND:
806 fprintf(stderr, "## wrt-installer : %s %s has failed - widget package does not exist\n",
807 tizenId.c_str(), printMsg.c_str());
810 case WRT_INSTALLER_ERROR_PACKAGE_INVALID:
811 fprintf(stderr, "## wrt-installer : %s %s has failed - invalid widget package\n",
812 tizenId.c_str(), printMsg.c_str());
815 case WRT_INSTALLER_ERROR_PACKAGE_LOWER_VERSION:
816 fprintf(stderr, "## wrt-installer : %s %s has failed - given"
817 " version is lower than existing version\n",
818 tizenId.c_str(), printMsg.c_str());
821 case WRT_INSTALLER_ERROR_MANIFEST_NOT_FOUND:
822 fprintf(stderr, "## wrt-installer : %s %s has failed - manifest"
823 " file doesn't find in package.\n",
824 tizenId.c_str(), printMsg.c_str());
827 case WRT_INSTALLER_ERROR_MANIFEST_INVALID:
828 fprintf(stderr, "## wrt-installer : %s %s has failed - "
829 "invalid manifestx.xml\n",
830 tizenId.c_str(), printMsg.c_str());
833 case WRT_INSTALLER_CONFIG_NOT_FOUND:
834 fprintf(stderr, "## wrt-installer : %s %s has failed - "
835 "config.xml does not exist\n",
836 tizenId.c_str(), printMsg.c_str());
839 case WRT_INSTALLER_ERROR_CONFIG_INVALID:
840 fprintf(stderr, "## wrt-installer : %s %s has failed - "
841 "invalid config.xml\n",
842 tizenId.c_str(), printMsg.c_str());
845 case WRT_INSTALLER_ERROR_SIGNATURE_NOT_FOUND:
846 fprintf(stderr, "## wrt-installer : %s %s has failed - "
847 "signature doesn't exist in package.\n",
848 tizenId.c_str(), printMsg.c_str());
851 case WRT_INSTALLER_ERROR_SIGNATURE_INVALID:
852 fprintf(stderr, "## wrt-installer : %s %s has failed - "
853 "invalid signature.\n",
854 tizenId.c_str(), printMsg.c_str());
857 case WRT_INSTALLER_ERROR_SIGNATURE_VERIFICATION_FAILED:
858 fprintf(stderr, "## wrt-installer : %s %s has failed - "
859 "signature verification failed.\n",
860 tizenId.c_str(), printMsg.c_str());
863 case WRT_INSTALLER_ERROR_ROOT_CERTIFICATE_NOT_FOUND:
864 fprintf(stderr, "## wrt-installer : %s %s has failed - "
865 "root certificate could not find.\n",
866 tizenId.c_str(), printMsg.c_str());
869 case WRT_INSTALLER_ERROR_CERTIFICATION_INVAID:
870 fprintf(stderr, "## wrt-installer : %s %s has failed - "
871 "invalid certification.\n",
872 tizenId.c_str(), printMsg.c_str());
875 case WRT_INSTALLER_ERROR_CERTIFICATE_CHAIN_VERIFICATION_FAILED:
876 fprintf(stderr, "## wrt-installer : %s %s has failed - "
877 "certificate chain verification failed.\n",
878 tizenId.c_str(), printMsg.c_str());
881 case WRT_INSTALLER_ERROR_CERTIFICATE_EXPIRED:
882 fprintf(stderr, "## wrt-installer : %s %s has failed - "
883 "certificate expired.\n",
884 tizenId.c_str(), printMsg.c_str());
887 case WRT_INSTALLER_ERROR_INVALID_PRIVILEGE:
888 fprintf(stderr, "## wrt-installer : %s %s has failed - "
889 "invalid privilege\n",
890 tizenId.c_str(), printMsg.c_str());
893 case WRT_INSTALLER_ERROR_PRIVILEGE_LEVEL_VIOLATION:
894 fprintf(stderr, "## wrt-installer : %s %s has failed - "
895 "privilege level violation\n",
896 tizenId.c_str(), printMsg.c_str());
899 case WRT_INSTALLER_ERROR_MENU_ICON_NOT_FOUND:
900 fprintf(stderr, "## wrt-installer : %s %s has failed - "
901 "menu icon could not find\n",
902 tizenId.c_str(), printMsg.c_str());
905 case WRT_INSTALLER_ERROR_FATAL_ERROR:
906 fprintf(stderr, "## wrt-installer : %s %s has failed - "
908 tizenId.c_str(), printMsg.c_str());
911 case WRT_INSTALLER_ERROR_OUT_OF_STORAGE:
912 fprintf(stderr, "## wrt-installer : %s %s has failed - "
914 tizenId.c_str(), printMsg.c_str());
917 case WRT_INSTALLER_ERROR_OUT_OF_MEMORY:
918 fprintf(stderr, "## wrt-installer : %s %s has failed - "
920 tizenId.c_str(), printMsg.c_str());
923 case WRT_INSTALLER_ERROR_ARGUMENT_INVALID:
924 fprintf(stderr, "## wrt-installer : %s %s has failed - "
925 "invalid argument\n",
926 tizenId.c_str(), printMsg.c_str());
929 case WRT_INSTALLER_ERROR_PACKAGE_ALREADY_INSTALLED:
930 fprintf(stderr, "## wrt-installer : %s %s has failed - "
931 "package already installed\n",
932 tizenId.c_str(), printMsg.c_str());
935 case WRT_INSTALLER_ERROR_ACE_CHECK_FAILED:
936 fprintf(stderr, "## wrt-installer : %s %s has failed - "
937 "ace check failure\n",
938 tizenId.c_str(), printMsg.c_str());
941 case WRT_INSTALLER_ERROR_MANIFEST_CREATE_FAILED:
942 fprintf(stderr, "## wrt-installer : %s %s has failed - "
943 "to create manifest failed\n",
944 tizenId.c_str(), printMsg.c_str());
947 case WRT_INSTALLER_ERROR_ENCRYPTION_FAILED:
948 fprintf(stderr, "## wrt-installer : %s %s has failed - "
949 "encryption of resource failed\n",
950 tizenId.c_str(), printMsg.c_str());
953 case WRT_INSTALLER_ERROR_INSTALL_OSP_SERVCIE:
954 fprintf(stderr, "## wrt-installer : %s %s has failed - "
955 "installation of osp service failed\n",
956 tizenId.c_str(), printMsg.c_str());
959 case WRT_INSTALLER_ERROR_UNINSTALLATION_FAILED:
960 fprintf(stderr, "## wrt-installer : %s %s has failed - "
961 "widget uninstallation failed\n",
962 tizenId.c_str(), printMsg.c_str());
966 case WRT_INSTALLER_ERROR_UNKNOWN:
967 fprintf(stderr,"## wrt-installer : %s %s has failed - unknown error\n",
968 tizenId.c_str(), printMsg.c_str());
977 void WrtInstaller::staticWrtPluginInstallationCallback(WrtErrStatus status,
982 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
984 WrtInstaller *This = static_cast<WrtInstaller*>(data->wrtInstaller);
986 std::string path = std::string(data->pluginPath);
989 This->m_numPluginsToInstall--;
990 _D("Plugins to install: %d", This->m_numPluginsToInstall);
992 if (This->m_numPluginsToInstall < 1) {
993 _D("All plugins installation completed");
994 fprintf(stderr, "All plugins installation completed.\n");
996 //remove installation request
997 if (!PluginUtils::removeInstallationRequiredFlag()) {
998 _D("Failed to remove file initializing plugin installation");
1002 if (!PluginUtils::unlockPluginInstallation(
1003 This->m_installMode.installTime == InstallMode::InstallTime::PRELOAD))
1005 _D("Failed to remove installation lock");
1008 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
1009 ::PostEvent(WRTInstallerNS::NextStepEvent());
1011 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
1012 InstallPluginEvent>::
1014 WRTInstallerNS::InstallPluginEvent());
1017 if (WRT_SUCCESS == status) {
1018 This->m_returnStatus = 0;
1020 "## wrt-installer : plugin installation successfull [%s]\n",
1022 _D("One plugin Installation succesfull: %s", path.c_str());
1027 _W("One of the plugins installation failed!: %s", path.c_str());
1030 case WRT_INSTALLER_ERROR_PLUGIN_INSTALLATION_FAILED:
1031 _E("failed: plugin installation failed\n");
1034 case WRT_INSTALLER_ERROR_UNKNOWN:
1035 _E("failed: unknown error\n");
1043 void WrtInstaller::staticWrtPluginInstallProgressCb(float percent,
1044 const char* description,
1047 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
1049 std::string path = std::string(data->pluginPath);
1051 _D("Plugin Installation: %s progress: %2.0f description: %s", path.c_str(), percent, description);
1054 void WrtInstaller::staticWrtInstallProgressCallback(float percent,
1055 const char* description,
1058 //WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
1059 _D(" progress: %2.0f description: %s", percent, description);
1061 void WrtInstaller::staticWrtUninstallProgressCallback(float percent,
1062 const char* description,
1065 //WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
1066 _D(" progress: %2.0f description: %s", percent, description);
1069 void WrtInstaller::installNewPlugins()
1071 _D("Install new plugins");
1073 if (!PluginUtils::lockPluginInstallation(
1074 m_installMode.installTime == InstallMode::InstallTime::PRELOAD))
1076 _D("Lock NOT created");
1080 if (!PluginUtils::checkPluginInstallationRequired()) {
1081 _D("Plugin installation not required");
1082 PluginUtils::unlockPluginInstallation(
1083 m_installMode.installTime == InstallMode::InstallTime::PRELOAD);
1087 m_startupPluginInstallation = true;
1088 AddStep(&WrtInstaller::installPluginsStep);
1091 CSCConfiguration::dataMap WrtInstaller::parseCSCConfiguration(
1094 // path=/opt/system/csc/Ozq2iEG15R-2.0.0-arm.wgt:op=install:removable=true
1095 // parsing CSC configuration string
1096 _D("parseConfiguration");
1097 CSCConfiguration::dataMap result;
1100 _D("Input argument is empty");
1104 char* buf = strdup(str.c_str());
1105 const char* ptr = strtok(buf,":");
1106 while (ptr != NULL) {
1107 std::string string = ptr;
1108 ptr = strtok (NULL, ":");
1109 size_t pos = string.find('=');
1110 if (pos == std::string::npos) {
1114 CSCConfiguration::dataPair(string.substr(0, pos),
1115 string.substr(pos+1)));
1121 int main(int argc, char *argv[])
1123 UNHANDLED_EXCEPTION_HANDLER_BEGIN
1125 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT_INSTALLER");
1127 // Output on stdout will be flushed after every newline character,
1128 // even if it is redirected to a pipe. This is useful for running
1129 // from a script and parsing output.
1130 // (Standard behavior of stdlib is to use full buffering when
1131 // redirected to a pipe, which means even after an end of line
1132 // the output may not be flushed).
1135 // Check and re-set the file open limitation
1137 if (getrlimit(RLIMIT_NOFILE, &rlim) != -1) {
1138 _D("RLIMIT_NOFILE sft(%d)", rlim.rlim_cur);
1139 _D("RLIMIT_NOFILE hrd(%d)", rlim.rlim_max);
1141 if (rlim.rlim_cur < NOFILE_CNT_FOR_INSTALLER) {
1142 rlim.rlim_cur = NOFILE_CNT_FOR_INSTALLER;
1143 rlim.rlim_max = NOFILE_CNT_FOR_INSTALLER;
1144 if (setrlimit(RLIMIT_NOFILE, &rlim) == -1) {
1145 _E("setrlimit is fail!!");
1149 _E("getrlimit is fail!!");
1152 WrtInstaller app(argc, argv);
1153 int ret = app.Exec();
1154 _D("App returned: %d", ret);
1155 ret = app.getReturnStatus();
1156 _D("WrtInstaller returned: %d", ret);
1159 UNHANDLED_EXCEPTION_HANDLER_END