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.
17 * @file AppLauncherManager.cpp
18 * @author Lukasz Marek (l.marek@samsung.com)
19 * @author Yujie Zeng (yj.zeng@samsung.com)
29 #include <dpl/scoped_free.h>
30 #include <dpl/log/log.h>
31 #include <commons/StringUtils.h>
32 #include <Filesystem/Manager.h>
33 #include "AppLauncherManager.h"
35 using namespace WrtPlugins::Api;
36 using namespace WrtPlugins::Api::AppLauncher;
39 const char* EMPTY_STRING_PATTERN = "^\\s*$";
40 const char* EMAIL_PATTERN = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+$";
41 //According to RFC1738,any character is possible in http address
42 const char* HTTP_ADDRESS_PATTERN = "^(http(s)?://)?\\w+.*$";
43 const char* FILE_ADDRESS_PATTERN = "^.*\\..*$";
45 const char* APPLICATION_ALARM = "org.tizen.clock"; // alarm has been
46 // included in clock app
47 const char* APPLICATION_BROWSER = "org.tizen.browser";
48 const char* APPLICATION_CALCULATOR = "org.tizen.calculator";
49 const char* APPLICATION_CALENDAR = "org.tizen.efl-calendar";
50 const char* APPLICATION_CAMERA = "org.tizen.camera-app";
51 const char* APPLICATION_CONTACTS = "org.tizen.contacts";
52 const char* APPLICATION_FILES = "org.tizen.myfile";
53 const char* APPLICATION_GAMES = "";
54 const char* APPLICATION_MAIL = "org.tizen.email";
55 const char* APPLICATION_MEDIAPLAYER = "org.tizen.music-player";
56 const char* APPLICATION_MESSAGING = "org.tizen.message";
57 const char* APPLICATION_PHONECALL = "org.tizen.dialer";
58 const char* APPLICATION_PHONECALL_CALLING = "org.tizen.call";
59 const char* APPLICATION_PICTURES = "org.tizen.gallery";
60 const char* APPLICATION_PICTURES_IMG_PATH = "org.tizen.image-viewer";
61 const char* APPLICATION_PROG_MANAGER = "org.tizen.taskmgr";
62 const char* APPLICATION_SETTINGS = "org.tizen.setting";
63 const char* APPLICATION_TASKS = "org.tizen.dailybriefing";
64 const char* APPLICATION_WIDGET_MANAGER = "org.tizen.wrt-test-ui";
65 const char* APPLICATION_WIDGET = "org.tizen.";
66 const char* APPLICATION_EMPTY = "";
68 const char* WIDGET_URI_PREFIX = "widget://";
70 const int SUCCESS_LAUNCHER = 0;
71 const int ERROR_LAUNCHER_INVALID_URI = 1;
72 const int ERROR_LAUNCHER_INVALID_PARAMETER = 2;
73 const int ERROR_LAUNCHER_EXECUTION_ERROR = 3;
76 namespace WrtPlugins {
78 std::map<Api::AppLauncher::ApplicationType,
79 std::string> AppLauncherManager::m_applicationTypesByPath;
80 std::map<Api::AppLauncher::ApplicationType,
81 std::string> AppLauncherManager::m_applicationTypesByName;
82 std::vector<std::string> AppLauncherManager::m_installedApplications;
83 std::vector<std::string> AppLauncherManager::m_installedApplicationsNames;
85 AppLauncherManager::AppLauncherManager()
88 static bool initialized = initializeApplicationList();
92 AppLauncherManager::~AppLauncherManager()
97 bool AppLauncherManager::initializeApplicationList()
100 m_applicationTypesByPath.insert(std::pair<ApplicationType,
102 APPLICATION_TYPE_ALARM,
104 m_applicationTypesByPath.insert(std::pair<ApplicationType,
106 APPLICATION_TYPE_BROWSER,
108 m_applicationTypesByPath.insert(std::pair<ApplicationType,
110 APPLICATION_TYPE_CALCULATOR,
112 m_applicationTypesByPath.insert(std::pair<ApplicationType,
114 APPLICATION_TYPE_CALENDAR,
116 m_applicationTypesByPath.insert(std::pair<ApplicationType,
118 APPLICATION_TYPE_CAMERA,
120 m_applicationTypesByPath.insert(std::pair<ApplicationType,
122 APPLICATION_TYPE_CONTACTS,
124 m_applicationTypesByPath.insert(std::pair<ApplicationType,
126 APPLICATION_TYPE_FILES,
128 m_applicationTypesByPath.insert(std::pair<ApplicationType,
130 APPLICATION_TYPE_GAMES,
132 m_applicationTypesByPath.insert(std::pair<ApplicationType,
134 APPLICATION_TYPE_MAIL,
136 m_applicationTypesByPath.insert(std::pair<ApplicationType,
138 APPLICATION_TYPE_MEDIAPLAYER,
140 m_applicationTypesByPath.insert(std::pair<ApplicationType,
142 APPLICATION_TYPE_MESSAGING,
144 m_applicationTypesByPath.insert(std::pair<ApplicationType,
146 APPLICATION_TYPE_PHONECALL,
148 m_applicationTypesByPath.insert(std::pair<ApplicationType,
150 APPLICATION_TYPE_PICTURES,
152 m_applicationTypesByPath.insert(std::pair<ApplicationType,
154 APPLICATION_TYPE_PROG_MANAGER,
156 m_applicationTypesByPath.insert(std::pair<ApplicationType,
158 APPLICATION_TYPE_SETTINGS,
160 m_applicationTypesByPath.insert(std::pair<ApplicationType,
162 APPLICATION_TYPE_TASKS,
164 m_applicationTypesByPath.insert(std::pair<ApplicationType,
166 APPLICATION_TYPE_WIDGET_MANAGER,
169 m_applicationTypesByName.insert(std::pair<ApplicationType,
171 APPLICATION_TYPE_ALARM,
173 m_applicationTypesByName.insert(std::pair<ApplicationType,
175 APPLICATION_TYPE_BROWSER,
177 m_applicationTypesByName.insert(std::pair<ApplicationType,
179 APPLICATION_TYPE_CALCULATOR,
181 m_applicationTypesByName.insert(std::pair<ApplicationType,
183 APPLICATION_TYPE_CALENDAR,
185 m_applicationTypesByName.insert(std::pair<ApplicationType,
187 APPLICATION_TYPE_CAMERA,
189 m_applicationTypesByName.insert(std::pair<ApplicationType,
191 APPLICATION_TYPE_CONTACTS,
193 m_applicationTypesByName.insert(std::pair<ApplicationType,
195 APPLICATION_TYPE_FILES,
197 m_applicationTypesByName.insert(std::pair<ApplicationType,
199 APPLICATION_TYPE_GAMES,
201 m_applicationTypesByName.insert(std::pair<ApplicationType,
203 APPLICATION_TYPE_MAIL,
205 m_applicationTypesByName.insert(std::pair<ApplicationType,
207 APPLICATION_TYPE_MEDIAPLAYER,
209 m_applicationTypesByName.insert(std::pair<ApplicationType,
211 APPLICATION_TYPE_MESSAGING,
213 m_applicationTypesByName.insert(std::pair<ApplicationType,
215 APPLICATION_TYPE_PHONECALL,
217 m_applicationTypesByName.insert(std::pair<ApplicationType,
219 APPLICATION_TYPE_PICTURES,
221 m_applicationTypesByName.insert(std::pair<ApplicationType,
223 APPLICATION_TYPE_PROG_MANAGER,
225 m_applicationTypesByName.insert(std::pair<ApplicationType,
227 APPLICATION_TYPE_SETTINGS,
229 m_applicationTypesByName.insert(std::pair<ApplicationType,
231 APPLICATION_TYPE_TASKS,
233 m_applicationTypesByName.insert(std::pair<ApplicationType,
235 APPLICATION_TYPE_WIDGET_MANAGER,
238 bool registered_application = false; // A variable that gets set if the
239 // current pkg_name is needed by WAC
240 // spec, needless of weather the
241 // package is visible or not.
243 unsigned int count = record_count(COUNT_MENU, &info);
244 LogDebug("number of registered applications: " << count);
246 DPL::ScopedFree<app_info> infoAll(static_cast<app_info*>(calloc(
251 if (!record_get(GET_MENU, infoAll.Get())) {
252 LogError("error during executing record_get() function");
255 for (unsigned int i = 0; i < count; i++) {
256 LogDebug("pkg_name " << infoAll.Get()[i].pkg_name);
257 LogDebug("app_path " << infoAll.Get()[i].app_path);
258 LogDebug("app_name " << infoAll.Get()[i].app_name);
259 registered_application = false;
260 if (infoAll.Get()[i].app_path == NULL ||
261 infoAll.Get()[i].app_name == NULL)
263 LogDebug("Not Registered.");
268 strncmp(APPLICATION_ALARM, infoAll.Get()[i].pkg_name,
271 m_applicationTypesByPath[APPLICATION_TYPE_ALARM] =
272 infoAll.Get()[i].app_path;
273 m_applicationTypesByName[APPLICATION_TYPE_ALARM] =
274 infoAll.Get()[i].app_name;
275 registered_application = true;
278 strncmp(APPLICATION_BROWSER, infoAll.Get()[i].pkg_name,
281 m_applicationTypesByPath[APPLICATION_TYPE_BROWSER] =
282 infoAll.Get()[i].app_path;
283 m_applicationTypesByName[APPLICATION_TYPE_BROWSER] =
284 infoAll.Get()[i].app_name;
285 registered_application = true;
288 strncmp(APPLICATION_CALCULATOR, infoAll.Get()[i].pkg_name,
291 m_applicationTypesByPath[APPLICATION_TYPE_CALCULATOR] =
292 infoAll.Get()[i].app_path;
293 m_applicationTypesByName[APPLICATION_TYPE_CALCULATOR] =
294 infoAll.Get()[i].app_name;
295 registered_application = true;
298 strncmp(APPLICATION_CALENDAR, infoAll.Get()[i].pkg_name,
301 m_applicationTypesByPath[APPLICATION_TYPE_CALENDAR] =
302 infoAll.Get()[i].app_path;
303 m_applicationTypesByName[APPLICATION_TYPE_CALENDAR] =
304 infoAll.Get()[i].app_name;
305 registered_application = true;
308 strncmp(APPLICATION_CAMERA, infoAll.Get()[i].pkg_name,
311 m_applicationTypesByPath[APPLICATION_TYPE_CAMERA] =
312 infoAll.Get()[i].app_path;
313 m_applicationTypesByName[APPLICATION_TYPE_CAMERA] =
314 infoAll.Get()[i].app_name;
315 registered_application = true;
318 strncmp(APPLICATION_CONTACTS, infoAll.Get()[i].pkg_name,
321 m_applicationTypesByPath[APPLICATION_TYPE_CONTACTS] =
322 infoAll.Get()[i].app_path;
323 m_applicationTypesByName[APPLICATION_TYPE_CONTACTS] =
324 infoAll.Get()[i].app_name;
325 registered_application = true;
328 strncmp(APPLICATION_FILES, infoAll.Get()[i].pkg_name,
331 m_applicationTypesByPath[APPLICATION_TYPE_FILES] =
332 infoAll.Get()[i].app_path;
333 m_applicationTypesByName[APPLICATION_TYPE_FILES] =
334 infoAll.Get()[i].app_name;
335 registered_application = true;
338 strncmp(APPLICATION_GAMES, infoAll.Get()[i].pkg_name,
341 m_applicationTypesByPath[APPLICATION_TYPE_GAMES] =
342 infoAll.Get()[i].app_path;
343 m_applicationTypesByName[APPLICATION_TYPE_GAMES] =
344 infoAll.Get()[i].app_name;
345 registered_application = true;
348 strncmp(APPLICATION_MAIL, infoAll.Get()[i].pkg_name,
351 m_applicationTypesByPath[APPLICATION_TYPE_MAIL] =
352 infoAll.Get()[i].app_path;
353 m_applicationTypesByName[APPLICATION_TYPE_MAIL] =
354 infoAll.Get()[i].app_name;
355 registered_application = true;
358 strncmp(APPLICATION_MEDIAPLAYER, infoAll.Get()[i].pkg_name,
361 m_applicationTypesByPath[APPLICATION_TYPE_MEDIAPLAYER] =
362 infoAll.Get()[i].app_path;
363 m_applicationTypesByName[APPLICATION_TYPE_MEDIAPLAYER] =
364 infoAll.Get()[i].app_name;
365 registered_application = true;
368 strncmp(APPLICATION_MESSAGING, infoAll.Get()[i].pkg_name,
371 m_applicationTypesByPath[APPLICATION_TYPE_MESSAGING] =
372 infoAll.Get()[i].app_path;
373 m_applicationTypesByName[APPLICATION_TYPE_MESSAGING] =
374 infoAll.Get()[i].app_name;
375 registered_application = true;
378 strncmp(APPLICATION_PHONECALL, infoAll.Get()[i].pkg_name,
381 m_applicationTypesByPath[APPLICATION_TYPE_PHONECALL] =
382 infoAll.Get()[i].app_path;
383 m_applicationTypesByName[APPLICATION_TYPE_PHONECALL] =
384 infoAll.Get()[i].app_name;
385 registered_application = true;
388 strncmp(APPLICATION_PICTURES, infoAll.Get()[i].pkg_name,
391 m_applicationTypesByPath[APPLICATION_TYPE_PICTURES] =
392 infoAll.Get()[i].app_path;
393 m_applicationTypesByName[APPLICATION_TYPE_PICTURES] =
394 infoAll.Get()[i].app_name;
395 registered_application = true;
398 strncmp(APPLICATION_PROG_MANAGER, infoAll.Get()[i].pkg_name,
401 m_applicationTypesByPath[APPLICATION_TYPE_PROG_MANAGER] =
402 infoAll.Get()[i].app_path;
403 m_applicationTypesByName[APPLICATION_TYPE_PROG_MANAGER] =
404 infoAll.Get()[i].app_name;
405 registered_application = true;
408 strncmp(APPLICATION_SETTINGS, infoAll.Get()[i].pkg_name,
411 m_applicationTypesByPath[APPLICATION_TYPE_SETTINGS] =
412 infoAll.Get()[i].app_path;
413 m_applicationTypesByName[APPLICATION_TYPE_SETTINGS] =
414 infoAll.Get()[i].app_name;
415 registered_application = true;
418 strncmp(APPLICATION_TASKS, infoAll.Get()[i].pkg_name,
421 m_applicationTypesByPath[APPLICATION_TYPE_TASKS] =
422 infoAll.Get()[i].app_path;
423 m_applicationTypesByName[APPLICATION_TYPE_TASKS] =
424 infoAll.Get()[i].app_name;
425 registered_application = true;
428 strncmp(APPLICATION_WIDGET_MANAGER, infoAll.Get()[i].pkg_name,
431 m_applicationTypesByPath[APPLICATION_TYPE_WIDGET_MANAGER] =
432 infoAll.Get()[i].app_path;
433 m_applicationTypesByName[APPLICATION_TYPE_WIDGET_MANAGER] =
434 infoAll.Get()[i].app_name;
435 registered_application = true;
437 if (infoAll.Get()[i].visible == 0 && registered_application ==
440 LogDebug("Not Registered.");
444 m_installedApplications.push_back(infoAll.Get()[i].app_path);
445 m_installedApplicationsNames.push_back(infoAll.Get()[i].app_name);
446 LogDebug("Registered.");
453 ApplicationType AppLauncherManager::getRegisteredApplicationType(
454 const std::string &name) const
457 std::map<ApplicationType, std::string>::const_iterator it;
458 for (it = m_applicationTypesByPath.begin();
459 it != m_applicationTypesByPath.end();
462 if (it->second == name) {
467 return APPLICATION_TYPE_UNDEFINED;
470 bool AppLauncherManager::isRegisteredApplication(const std::string &name) const
475 std::vector<std::string>::const_iterator pos =
476 find(m_installedApplications.begin(),
477 m_installedApplications.end(), name);
478 return pos != m_installedApplications.end();
481 bool AppLauncherManager::validateHttpAddress(const std::string &value) const
483 if (!pcrecpp::RE(HTTP_ADDRESS_PATTERN).FullMatch(value)) {
484 LogDebug("not valid paterrn of http address");
490 bool AppLauncherManager::isFilePath(const std::string &value) const
492 if (!pcrecpp::RE(FILE_ADDRESS_PATTERN).FullMatch(value)) {
498 bool AppLauncherManager::validateEmailAddress(const std::string &value) const
500 if (!pcrecpp::RE(EMAIL_PATTERN).FullMatch(value)) {
501 LogDebug("not valid paterrn of email address");
507 std::string AppLauncherManager::getRealPath(const std::string &path) const
511 Api::Filesystem::IPathPtr currentPath = Api::Filesystem::IPath::create(
513 return currentPath->getFullPath();
515 Catch(Commons::Exception)
517 LogError("invalid path");
519 return std::string();
522 std::string AppLauncherManager::getPathFromApplicationName(
523 const std::string &applicationName) const
525 if (0 == applicationName.find(WIDGET_URI_PREFIX) && std::string::npos !=
526 applicationName.find("?"))
528 //uri format is: widget://{widgetId}?wname={WidgetName}
529 LogDebug("found widget:// URI");
530 std::string uri = applicationName;
531 uri.erase(0, strlen(WIDGET_URI_PREFIX)); //remove widget://part
532 std::string widgetId = uri.substr(0, uri.find("?"));
533 uri.erase(0, widgetId.size() + 7); //remove widget id and "?wname="
534 // string, so uri contains only
536 std::string packageName = APPLICATION_WIDGET + widgetId;
538 "Widget id: " << widgetId << ", widget name: " << uri <<
539 ", package: " << packageName);
540 app_info info = { 0, };
541 strncpy(info.pkg_name, packageName.c_str(), NAME_LEN);
542 if (record_get(GET_ONE_RECORD_BY_PKG_NAME, &info)) {
543 if (info.app_path && info.app_name && uri == info.app_name) {
544 return std::string(info.app_path);
548 for (size_t i = 0; i < m_installedApplicationsNames.size(); ++i) {
549 if (m_installedApplicationsNames[i] == applicationName) {
550 return m_installedApplications[i];
553 return std::string();
556 std::string AppLauncherManager::getPathFromPackageName(
557 const std::string &packageName) const
559 app_info info = { 0, };
560 strncpy(info.pkg_name, packageName.c_str(), NAME_LEN);
561 if (record_get(GET_ONE_RECORD_BY_PKG_NAME, &info)) {
562 LogDebug("pkg_name " << info.pkg_name);
563 LogDebug("app_path " << info.app_path);
564 LogDebug("app_name " << info.app_name);
566 return std::string(info.app_path);
569 return std::string();
572 std::string AppLauncherManager::getPackageNameFromPath(const std::string &path)
575 app_info info = { 0, };
576 strncpy(info.app_path, path.c_str(), PATH_LEN);
577 if (record_get(GET_ONE_RECORD_BY_APP_PATH, &info)) {
578 LogDebug("pkg_name " << info.pkg_name);
579 LogDebug("app_path " << info.app_path);
580 LogDebug("app_name " << info.app_name);
582 return std::string(info.pkg_name);
585 return std::string();
588 int AppLauncherManager::launchApplicationFileInternal(
589 const std::string &uriParameter,
590 const std::vector<std::string> &applicationParams)
592 LogDebug("entered with uriParameter: '" << uriParameter << "'");
593 ApplicationType appType = getRegisteredApplicationType(uriParameter);
594 if (!isRegisteredApplication(uriParameter)) {
595 LogDebug("Its not registered application");
596 return ERROR_LAUNCHER_INVALID_URI;
598 //try to launch as package using aul
599 std::string packageName = getPackageNameFromPath(uriParameter);
600 if (!packageName.empty()) {
601 LogDebug("executing as package, package name " << packageName);
602 //check parameters for empty or extra spaces
603 std::vector<std::string> params;
604 std::vector<std::string>::const_iterator it;
605 for (it = applicationParams.begin();
606 it != applicationParams.end();
609 std::string param(Commons::String::trim(*it));
613 params.push_back(param);
616 if (params.size() > 0) {
617 if (appType == APPLICATION_TYPE_PHONECALL) {
618 //phone number is provided.
619 //replace package to make a call, not run application with this
622 packageName = APPLICATION_PHONECALL_CALLING;
623 kb = bundle_create();
625 return ERROR_LAUNCHER_EXECUTION_ERROR;
627 if (bundle_add(kb, "launch-type", "MO") < 0) { // "MO" : normal
632 return ERROR_LAUNCHER_EXECUTION_ERROR;
634 if (bundle_add(kb, "number", params.front().c_str()) < 0) {
636 return ERROR_LAUNCHER_EXECUTION_ERROR;
638 LogDebug("running with number: " << params.front());
639 } else if (appType == APPLICATION_TYPE_BROWSER) {
640 if (!validateHttpAddress(params.front())) {
641 return ERROR_LAUNCHER_INVALID_PARAMETER;
643 kb = bundle_create();
645 return ERROR_LAUNCHER_EXECUTION_ERROR;
647 if (bundle_add(kb, "url", params.front().c_str()) < 0) {
649 return ERROR_LAUNCHER_EXECUTION_ERROR;
651 LogDebug("running with url: " << params.front().c_str());
652 } else if (appType == APPLICATION_TYPE_MEDIAPLAYER) {
653 LogDebug("opening file: " << getRealPath(params.front()).c_str());
654 int result = aul_open_file(getRealPath(params.front()).c_str());
656 LogError("Cannot open file, launch application only");
658 return SUCCESS_LAUNCHER;
660 } else if (appType == APPLICATION_TYPE_FILES) {
662 if (stat(getRealPath(params.front()).c_str(), &sb) == -1) {
664 "The selected path does not exist: " <<
665 getRealPath(params.front()).c_str());
667 if (!S_ISDIR(sb.st_mode)) {
668 LogDebug("opening file: " << getRealPath(
669 params.front()).c_str());
670 int result = aul_open_file(getRealPath(
671 params.front()).c_str());
674 "Cannot open file, launch application only");
676 return SUCCESS_LAUNCHER;
679 kb = bundle_create();
681 return ERROR_LAUNCHER_EXECUTION_ERROR;
683 if (bundle_add(kb, "path",
684 getRealPath(params.front()).c_str()) <
688 return ERROR_LAUNCHER_EXECUTION_ERROR;
690 LogDebug("running with folder path: " <<
691 getRealPath(params.front()).c_str());
694 } else if (appType == APPLICATION_TYPE_PICTURES) {
695 //open photo with image path
696 //replace package to show only one picture with given image path
697 packageName = APPLICATION_PICTURES_IMG_PATH;
698 kb = bundle_create();
700 return ERROR_LAUNCHER_EXECUTION_ERROR;
702 if (bundle_add(kb, "View Mode", "SINGLE") < 0) {
704 return ERROR_LAUNCHER_EXECUTION_ERROR;
706 if (bundle_add(kb, "Path",
707 getRealPath(params.front()).c_str()) < 0)
710 return ERROR_LAUNCHER_EXECUTION_ERROR;
712 LogDebug("running with img file path: " <<
713 getRealPath(params.front()).c_str());
715 //TODO: add more parameters when needed
717 int result = aul_launch_app(packageName.c_str(), kb);
722 return SUCCESS_LAUNCHER;
724 LogError("aul_launch_app result " << result);
725 return ERROR_LAUNCHER_EXECUTION_ERROR;
727 return ERROR_LAUNCHER_EXECUTION_ERROR;
730 int AppLauncherManager::launchApplicationInternal(
731 const ApplicationUriType uriType,
732 const std::string &uriParameter,
733 const std::vector<std::string> &applicationParams)
736 "entered with uriType: " << uriType << ", uriParameter: " <<
738 if (APPLICATION_URI_TYPE_HTTP == uriType) {
739 std::string application =
740 m_applicationTypesByPath[APPLICATION_TYPE_BROWSER];
741 std::vector<std::string> params;
742 if (Commons::String::startsWith(uriParameter, "http://")) {
743 params.push_back(uriParameter);
744 } else if (!pcrecpp::RE(EMPTY_STRING_PATTERN).FullMatch(uriParameter))
746 params.push_back("http://" + uriParameter);
748 return launchApplicationFileInternal(application, params);
749 } else if (APPLICATION_URI_TYPE_HTTPS == uriType) {
750 std::string application =
751 m_applicationTypesByPath[APPLICATION_TYPE_BROWSER];
752 std::vector<std::string> params;
753 if (Commons::String::startsWith(uriParameter, "https://")) {
754 params.push_back(uriParameter);
755 } else if (!pcrecpp::RE(EMPTY_STRING_PATTERN).FullMatch(uriParameter))
757 params.push_back("https://" + uriParameter);
759 return launchApplicationFileInternal(application, params);
760 } else if (APPLICATION_URI_TYPE_TEL == uriType) {
761 std::string application =
762 m_applicationTypesByPath[APPLICATION_TYPE_PHONECALL];
763 std::vector<std::string> params;
764 params.push_back(uriParameter);
765 return launchApplicationFileInternal(application, params);
766 } else if (APPLICATION_URI_TYPE_MAILTO == uriType) {
767 std::string application =
768 m_applicationTypesByPath[APPLICATION_TYPE_MAIL];
769 std::vector<std::string> params;
770 params.push_back(uriParameter);
771 return launchApplicationFileInternal(application, params);
772 } else if (APPLICATION_URI_TYPE_SMS == uriType) {
773 std::string application =
774 m_applicationTypesByPath[APPLICATION_TYPE_MESSAGING];
775 std::vector<std::string> params;
776 params.push_back(uriParameter);
777 return launchApplicationFileInternal(application, params);
778 } else if (APPLICATION_URI_TYPE_FILE == uriType) {
779 return launchApplicationFileInternal(uriParameter, applicationParams);
780 } else if (APPLICATION_URI_TYPE_APPLICATION_BY_NAME == uriType) {
781 std::string application = getPathFromApplicationName(uriParameter);
782 return launchApplicationFileInternal(application, applicationParams);
784 return ERROR_LAUNCHER_INVALID_URI;
786 return SUCCESS_LAUNCHER;
789 std::string AppLauncherManager::getDefaultApplicationByMimeInternal(
790 const std::string &mime) const
792 LogDebug("entered with mime: " << mime);
793 const int bufferSize = 1024;
794 char buffer[bufferSize] = { 0 };
795 int result = aul_get_defapp_from_mime(mime.c_str(), buffer, bufferSize - 1);
796 if (AUL_R_OK == result) {
797 LogDebug("returning default application");
798 return std::string(buffer);
800 LogError("aul_get_defapp_from_mime failed, error code " << result);
801 Throw(Commons::PlatformException);
803 return std::string();
806 void AppLauncherManager::OnRequestReceived(
807 const EventGetDefaultApplicationPtr &event)
812 std::string result = getDefaultApplicationByMimeInternal(event->getMime());
813 event->setApplicationFullPath(result);
814 event->setExceptionCode(Commons::ExceptionCodes::None);
816 Catch(Commons::PlatformException)
818 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
822 void AppLauncherManager::OnRequestReceived(
823 const EventGetInstalledApplicationsPtr &event)
826 std::vector<std::string>::const_iterator it1;
827 for (it1 = m_installedApplications.begin();
828 it1 != m_installedApplications.end();
831 event->addApplicationFullPath(*it1);
833 for (it1 = m_installedApplicationsNames.begin();
834 it1 != m_installedApplicationsNames.end();
837 event->addApplicationName(*it1);
839 std::map<ApplicationType, std::string>::const_iterator it2;
840 for (it2 = m_applicationTypesByPath.begin();
841 it2 != m_applicationTypesByPath.end();
844 event->addApplicationTypeByPath(*it2);
846 for (it2 = m_applicationTypesByName.begin();
847 it2 != m_applicationTypesByName.end();
850 event->addApplicationTypeByName(*it2);
852 event->setExceptionCode(Commons::ExceptionCodes::None);
855 void AppLauncherManager::OnRequestReceived(
856 const EventLaunchApplicationPtr &event)
859 ApplicationUriType uriType = event->getApplicationUriType();
860 std::string uriParam = event->getApplicationUriParam();
861 std::vector<std::string> parameters = event->getApplicationParameters();
862 int result = launchApplicationInternal(uriType, uriParam, parameters);
863 if (result == SUCCESS_LAUNCHER) {
864 event->setExceptionCode(Commons::ExceptionCodes::None);
865 } else if (result == ERROR_LAUNCHER_INVALID_PARAMETER ||
866 result == ERROR_LAUNCHER_INVALID_URI)
868 event->setExceptionCode(
869 Commons::ExceptionCodes::InvalidArgumentException);
871 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);