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 included in clock app
46 const char* APPLICATION_BROWSER = "org.tizen.browser";
47 const char* APPLICATION_CALCULATOR = "org.tizen.calculator";
48 const char* APPLICATION_CALENDAR = "org.tizen.efl-calendar";
49 const char* APPLICATION_CAMERA = "org.tizen.camera-app";
50 const char* APPLICATION_CONTACTS = "org.tizen.contacts";
51 const char* APPLICATION_FILES = "org.tizen.myfile";
52 const char* APPLICATION_GAMES = "";
53 const char* APPLICATION_MAIL = "org.tizen.email";
54 const char* APPLICATION_MEDIAPLAYER = "org.tizen.music-player";
55 const char* APPLICATION_MESSAGING = "org.tizen.message";
56 const char* APPLICATION_PHONECALL = "org.tizen.dialer";
57 const char* APPLICATION_PHONECALL_CALLING = "org.tizen.call";
58 const char* APPLICATION_PICTURES = "org.tizen.gallery";
59 const char* APPLICATION_PICTURES_IMG_PATH = "org.tizen.image-viewer";
60 const char* APPLICATION_PROG_MANAGER = "org.tizen.taskmgr";
61 const char* APPLICATION_SETTINGS = "org.tizen.setting";
62 const char* APPLICATION_TASKS = "org.tizen.dailybriefing";
63 const char* APPLICATION_WIDGET_MANAGER = "org.tizen.wrt-test-ui";
64 const char* APPLICATION_WIDGET = "org.tizen.";
65 const char* APPLICATION_EMPTY = "";
67 const char* WIDGET_URI_PREFIX = "widget://";
69 const int SUCCESS_LAUNCHER = 0;
70 const int ERROR_LAUNCHER_INVALID_URI = 1;
71 const int ERROR_LAUNCHER_INVALID_PARAMETER = 2;
72 const int ERROR_LAUNCHER_EXECUTION_ERROR = 3;
75 namespace WrtPlugins {
77 std::map<Api::AppLauncher::ApplicationType,
78 std::string> AppLauncherManager::m_applicationTypesByPath;
79 std::map<Api::AppLauncher::ApplicationType,
80 std::string> AppLauncherManager::m_applicationTypesByName;
81 std::vector<std::string> AppLauncherManager::m_installedApplications;
82 std::vector<std::string> AppLauncherManager::m_installedApplicationsNames;
84 AppLauncherManager::AppLauncherManager()
87 static bool initialized = initializeApplicationList();
91 AppLauncherManager::~AppLauncherManager()
96 bool AppLauncherManager::initializeApplicationList()
99 m_applicationTypesByPath.insert(std::pair<ApplicationType,
101 APPLICATION_TYPE_ALARM,
103 m_applicationTypesByPath.insert(std::pair<ApplicationType,
105 APPLICATION_TYPE_BROWSER,
107 m_applicationTypesByPath.insert(std::pair<ApplicationType,
109 APPLICATION_TYPE_CALCULATOR,
111 m_applicationTypesByPath.insert(std::pair<ApplicationType,
113 APPLICATION_TYPE_CALENDAR,
115 m_applicationTypesByPath.insert(std::pair<ApplicationType,
117 APPLICATION_TYPE_CAMERA,
119 m_applicationTypesByPath.insert(std::pair<ApplicationType,
121 APPLICATION_TYPE_CONTACTS,
123 m_applicationTypesByPath.insert(std::pair<ApplicationType,
125 APPLICATION_TYPE_FILES,
127 m_applicationTypesByPath.insert(std::pair<ApplicationType,
129 APPLICATION_TYPE_GAMES,
131 m_applicationTypesByPath.insert(std::pair<ApplicationType,
133 APPLICATION_TYPE_MAIL,
135 m_applicationTypesByPath.insert(std::pair<ApplicationType,
137 APPLICATION_TYPE_MEDIAPLAYER,
139 m_applicationTypesByPath.insert(std::pair<ApplicationType,
141 APPLICATION_TYPE_MESSAGING,
143 m_applicationTypesByPath.insert(std::pair<ApplicationType,
145 APPLICATION_TYPE_PHONECALL,
147 m_applicationTypesByPath.insert(std::pair<ApplicationType,
149 APPLICATION_TYPE_PICTURES,
151 m_applicationTypesByPath.insert(std::pair<ApplicationType,
153 APPLICATION_TYPE_PROG_MANAGER,
155 m_applicationTypesByPath.insert(std::pair<ApplicationType,
157 APPLICATION_TYPE_SETTINGS,
159 m_applicationTypesByPath.insert(std::pair<ApplicationType,
161 APPLICATION_TYPE_TASKS,
163 m_applicationTypesByPath.insert(std::pair<ApplicationType,
165 APPLICATION_TYPE_WIDGET_MANAGER,
168 m_applicationTypesByName.insert(std::pair<ApplicationType,
170 APPLICATION_TYPE_ALARM,
172 m_applicationTypesByName.insert(std::pair<ApplicationType,
174 APPLICATION_TYPE_BROWSER,
176 m_applicationTypesByName.insert(std::pair<ApplicationType,
178 APPLICATION_TYPE_CALCULATOR,
180 m_applicationTypesByName.insert(std::pair<ApplicationType,
182 APPLICATION_TYPE_CALENDAR,
184 m_applicationTypesByName.insert(std::pair<ApplicationType,
186 APPLICATION_TYPE_CAMERA,
188 m_applicationTypesByName.insert(std::pair<ApplicationType,
190 APPLICATION_TYPE_CONTACTS,
192 m_applicationTypesByName.insert(std::pair<ApplicationType,
194 APPLICATION_TYPE_FILES,
196 m_applicationTypesByName.insert(std::pair<ApplicationType,
198 APPLICATION_TYPE_GAMES,
200 m_applicationTypesByName.insert(std::pair<ApplicationType,
202 APPLICATION_TYPE_MAIL,
204 m_applicationTypesByName.insert(std::pair<ApplicationType,
206 APPLICATION_TYPE_MEDIAPLAYER,
208 m_applicationTypesByName.insert(std::pair<ApplicationType,
210 APPLICATION_TYPE_MESSAGING,
212 m_applicationTypesByName.insert(std::pair<ApplicationType,
214 APPLICATION_TYPE_PHONECALL,
216 m_applicationTypesByName.insert(std::pair<ApplicationType,
218 APPLICATION_TYPE_PICTURES,
220 m_applicationTypesByName.insert(std::pair<ApplicationType,
222 APPLICATION_TYPE_PROG_MANAGER,
224 m_applicationTypesByName.insert(std::pair<ApplicationType,
226 APPLICATION_TYPE_SETTINGS,
228 m_applicationTypesByName.insert(std::pair<ApplicationType,
230 APPLICATION_TYPE_TASKS,
232 m_applicationTypesByName.insert(std::pair<ApplicationType,
234 APPLICATION_TYPE_WIDGET_MANAGER,
237 bool registered_application = false; // A variable that gets set if the current pkg_name is needed by WAC spec, needless of weather the package is visible or not.
239 unsigned int count = record_count(COUNT_MENU, &info);
240 LogDebug("number of registered applications: " << count);
242 DPL::ScopedFree<app_info> infoAll(static_cast<app_info*>(calloc(
247 if (!record_get(GET_MENU, infoAll.Get())) {
248 LogError("error during executing record_get() function");
251 for (unsigned int i = 0; i < count; i++) {
252 LogDebug("pkg_name " << infoAll.Get()[i].pkg_name);
253 LogDebug("app_path " << infoAll.Get()[i].app_path);
254 LogDebug("app_name " << infoAll.Get()[i].app_name);
255 registered_application = false;
256 if (infoAll.Get()[i].app_path == NULL ||
257 infoAll.Get()[i].app_name == NULL) {
258 LogDebug("Not Registered.");
263 strncmp(APPLICATION_ALARM, infoAll.Get()[i].pkg_name,
265 m_applicationTypesByPath[APPLICATION_TYPE_ALARM] =
266 infoAll.Get()[i].app_path;
267 m_applicationTypesByName[APPLICATION_TYPE_ALARM] =
268 infoAll.Get()[i].app_name;
269 registered_application = true;
272 strncmp(APPLICATION_BROWSER, infoAll.Get()[i].pkg_name,
274 m_applicationTypesByPath[APPLICATION_TYPE_BROWSER] =
275 infoAll.Get()[i].app_path;
276 m_applicationTypesByName[APPLICATION_TYPE_BROWSER] =
277 infoAll.Get()[i].app_name;
278 registered_application = true;
281 strncmp(APPLICATION_CALCULATOR, infoAll.Get()[i].pkg_name,
283 m_applicationTypesByPath[APPLICATION_TYPE_CALCULATOR] =
284 infoAll.Get()[i].app_path;
285 m_applicationTypesByName[APPLICATION_TYPE_CALCULATOR] =
286 infoAll.Get()[i].app_name;
287 registered_application = true;
290 strncmp(APPLICATION_CALENDAR, infoAll.Get()[i].pkg_name,
292 m_applicationTypesByPath[APPLICATION_TYPE_CALENDAR] =
293 infoAll.Get()[i].app_path;
294 m_applicationTypesByName[APPLICATION_TYPE_CALENDAR] =
295 infoAll.Get()[i].app_name;
296 registered_application = true;
299 strncmp(APPLICATION_CAMERA, infoAll.Get()[i].pkg_name,
301 m_applicationTypesByPath[APPLICATION_TYPE_CAMERA] =
302 infoAll.Get()[i].app_path;
303 m_applicationTypesByName[APPLICATION_TYPE_CAMERA] =
304 infoAll.Get()[i].app_name;
305 registered_application = true;
308 strncmp(APPLICATION_CONTACTS, infoAll.Get()[i].pkg_name,
310 m_applicationTypesByPath[APPLICATION_TYPE_CONTACTS] =
311 infoAll.Get()[i].app_path;
312 m_applicationTypesByName[APPLICATION_TYPE_CONTACTS] =
313 infoAll.Get()[i].app_name;
314 registered_application = true;
317 strncmp(APPLICATION_FILES, infoAll.Get()[i].pkg_name,
319 m_applicationTypesByPath[APPLICATION_TYPE_FILES] =
320 infoAll.Get()[i].app_path;
321 m_applicationTypesByName[APPLICATION_TYPE_FILES] =
322 infoAll.Get()[i].app_name;
323 registered_application = true;
326 strncmp(APPLICATION_GAMES, infoAll.Get()[i].pkg_name,
328 m_applicationTypesByPath[APPLICATION_TYPE_GAMES] =
329 infoAll.Get()[i].app_path;
330 m_applicationTypesByName[APPLICATION_TYPE_GAMES] =
331 infoAll.Get()[i].app_name;
332 registered_application = true;
335 strncmp(APPLICATION_MAIL, infoAll.Get()[i].pkg_name,
337 m_applicationTypesByPath[APPLICATION_TYPE_MAIL] =
338 infoAll.Get()[i].app_path;
339 m_applicationTypesByName[APPLICATION_TYPE_MAIL] =
340 infoAll.Get()[i].app_name;
341 registered_application = true;
344 strncmp(APPLICATION_MEDIAPLAYER, infoAll.Get()[i].pkg_name,
346 m_applicationTypesByPath[APPLICATION_TYPE_MEDIAPLAYER] =
347 infoAll.Get()[i].app_path;
348 m_applicationTypesByName[APPLICATION_TYPE_MEDIAPLAYER] =
349 infoAll.Get()[i].app_name;
350 registered_application = true;
353 strncmp(APPLICATION_MESSAGING, infoAll.Get()[i].pkg_name,
355 m_applicationTypesByPath[APPLICATION_TYPE_MESSAGING] =
356 infoAll.Get()[i].app_path;
357 m_applicationTypesByName[APPLICATION_TYPE_MESSAGING] =
358 infoAll.Get()[i].app_name;
359 registered_application = true;
362 strncmp(APPLICATION_PHONECALL, infoAll.Get()[i].pkg_name,
364 m_applicationTypesByPath[APPLICATION_TYPE_PHONECALL] =
365 infoAll.Get()[i].app_path;
366 m_applicationTypesByName[APPLICATION_TYPE_PHONECALL] =
367 infoAll.Get()[i].app_name;
368 registered_application = true;
371 strncmp(APPLICATION_PICTURES, infoAll.Get()[i].pkg_name,
373 m_applicationTypesByPath[APPLICATION_TYPE_PICTURES] =
374 infoAll.Get()[i].app_path;
375 m_applicationTypesByName[APPLICATION_TYPE_PICTURES] =
376 infoAll.Get()[i].app_name;
377 registered_application = true;
380 strncmp(APPLICATION_PROG_MANAGER, infoAll.Get()[i].pkg_name,
382 m_applicationTypesByPath[APPLICATION_TYPE_PROG_MANAGER] =
383 infoAll.Get()[i].app_path;
384 m_applicationTypesByName[APPLICATION_TYPE_PROG_MANAGER] =
385 infoAll.Get()[i].app_name;
386 registered_application = true;
389 strncmp(APPLICATION_SETTINGS, infoAll.Get()[i].pkg_name,
391 m_applicationTypesByPath[APPLICATION_TYPE_SETTINGS] =
392 infoAll.Get()[i].app_path;
393 m_applicationTypesByName[APPLICATION_TYPE_SETTINGS] =
394 infoAll.Get()[i].app_name;
395 registered_application = true;
398 strncmp(APPLICATION_TASKS, infoAll.Get()[i].pkg_name,
400 m_applicationTypesByPath[APPLICATION_TYPE_TASKS] =
401 infoAll.Get()[i].app_path;
402 m_applicationTypesByName[APPLICATION_TYPE_TASKS] =
403 infoAll.Get()[i].app_name;
404 registered_application = true;
407 strncmp(APPLICATION_WIDGET_MANAGER, infoAll.Get()[i].pkg_name,
409 m_applicationTypesByPath[APPLICATION_TYPE_WIDGET_MANAGER] =
410 infoAll.Get()[i].app_path;
411 m_applicationTypesByName[APPLICATION_TYPE_WIDGET_MANAGER] =
412 infoAll.Get()[i].app_name;
413 registered_application = true;
415 if (infoAll.Get()[i].visible == 0 && registered_application ==
417 LogDebug("Not Registered.");
421 m_installedApplications.push_back(infoAll.Get()[i].app_path);
422 m_installedApplicationsNames.push_back(infoAll.Get()[i].app_name);
423 LogDebug("Registered.");
430 ApplicationType AppLauncherManager::getRegisteredApplicationType(
431 const std::string &name) const
434 std::map<ApplicationType, std::string>::const_iterator it;
435 for (it = m_applicationTypesByPath.begin();
436 it != m_applicationTypesByPath.end();
438 if (it->second == name) {
443 return APPLICATION_TYPE_UNDEFINED;
446 bool AppLauncherManager::isRegisteredApplication(const std::string &name) const
451 std::vector<std::string>::const_iterator pos =
452 find(m_installedApplications.begin(),
453 m_installedApplications.end(), name);
454 return pos != m_installedApplications.end();
457 bool AppLauncherManager::validateHttpAddress(const std::string &value) const
459 if (!pcrecpp::RE(HTTP_ADDRESS_PATTERN).FullMatch(value)) {
460 LogDebug("not valid paterrn of http address");
466 bool AppLauncherManager::isFilePath(const std::string &value) const
468 if (!pcrecpp::RE(FILE_ADDRESS_PATTERN).FullMatch(value)) {
474 bool AppLauncherManager::validateEmailAddress(const std::string &value) const
476 if (!pcrecpp::RE(EMAIL_PATTERN).FullMatch(value)) {
477 LogDebug("not valid paterrn of email address");
483 std::string AppLauncherManager::getRealPath(const std::string &path) const
487 Api::Filesystem::IPathPtr currentPath = Api::Filesystem::IPath::create(
489 return currentPath->getFullPath();
491 Catch(Commons::Exception)
493 LogError("invalid path");
495 return std::string();
498 std::string AppLauncherManager::getPathFromApplicationName(
499 const std::string &applicationName) const
501 if (0 == applicationName.find(WIDGET_URI_PREFIX) && std::string::npos !=
502 applicationName.find("?")) {
503 //uri format is: widget://{widgetId}?wname={WidgetName}
504 LogDebug("found widget:// URI");
505 std::string uri = applicationName;
506 uri.erase(0, strlen(WIDGET_URI_PREFIX)); //remove widget://part
507 std::string widgetId = uri.substr(0, uri.find("?"));
508 uri.erase(0, widgetId.size() + 7); //remove widget id and "?wname=" string, so uri contains only widget name now
509 std::string packageName = APPLICATION_WIDGET + widgetId;
511 "Widget id: " << widgetId << ", widget name: " << uri <<
512 ", package: " << packageName);
513 app_info info = { 0, };
514 strncpy(info.pkg_name, packageName.c_str(), NAME_LEN);
515 if (record_get(GET_ONE_RECORD_BY_PKG_NAME, &info)) {
516 if (info.app_path && info.app_name && uri == info.app_name) {
517 return std::string(info.app_path);
521 for (size_t i = 0; i < m_installedApplicationsNames.size(); ++i) {
522 if (m_installedApplicationsNames[i] == applicationName) {
523 return m_installedApplications[i];
526 return std::string();
529 std::string AppLauncherManager::getPathFromPackageName(
530 const std::string &packageName) const
532 app_info info = { 0, };
533 strncpy(info.pkg_name, packageName.c_str(), NAME_LEN);
534 if (record_get(GET_ONE_RECORD_BY_PKG_NAME, &info)) {
535 LogDebug("pkg_name " << info.pkg_name);
536 LogDebug("app_path " << info.app_path);
537 LogDebug("app_name " << info.app_name);
539 return std::string(info.app_path);
542 return std::string();
545 std::string AppLauncherManager::getPackageNameFromPath(const std::string &path)
548 app_info info = { 0, };
549 strncpy(info.app_path, path.c_str(), PATH_LEN);
550 if (record_get(GET_ONE_RECORD_BY_APP_PATH, &info)) {
551 LogDebug("pkg_name " << info.pkg_name);
552 LogDebug("app_path " << info.app_path);
553 LogDebug("app_name " << info.app_name);
555 return std::string(info.pkg_name);
558 return std::string();
561 int AppLauncherManager::launchApplicationFileInternal(
562 const std::string &uriParameter,
563 const std::vector<std::string> &applicationParams)
565 LogDebug("entered with uriParameter: '" << uriParameter << "'");
566 ApplicationType appType = getRegisteredApplicationType(uriParameter);
567 if (!isRegisteredApplication(uriParameter)) {
568 LogDebug("Its not registered application");
569 return ERROR_LAUNCHER_INVALID_URI;
571 //try to launch as package using aul
572 std::string packageName = getPackageNameFromPath(uriParameter);
573 if (!packageName.empty()) {
574 LogDebug("executing as package, package name " << packageName);
575 //check parameters for empty or extra spaces
576 std::vector<std::string> params;
577 std::vector<std::string>::const_iterator it;
578 for (it = applicationParams.begin();
579 it != applicationParams.end();
581 std::string param(Commons::String::trim(*it));
585 params.push_back(param);
588 if (params.size() > 0) {
589 if (appType == APPLICATION_TYPE_PHONECALL) {
590 //phone number is provided.
591 //replace package to make a call, not run application with this functionality
593 packageName = APPLICATION_PHONECALL_CALLING;
594 kb = bundle_create();
596 return ERROR_LAUNCHER_EXECUTION_ERROR;
598 if (bundle_add(kb, "launch-type", "MO") < 0) { // "MO" : normal call, "EMERGENCY" : emergency call
600 return ERROR_LAUNCHER_EXECUTION_ERROR;
602 if (bundle_add(kb, "number", params.front().c_str()) < 0) {
604 return ERROR_LAUNCHER_EXECUTION_ERROR;
606 LogDebug("running with number: " << params.front());
607 } else if (appType == APPLICATION_TYPE_BROWSER) {
608 if (!validateHttpAddress(params.front())) {
609 return ERROR_LAUNCHER_INVALID_PARAMETER;
611 kb = bundle_create();
613 return ERROR_LAUNCHER_EXECUTION_ERROR;
615 if (bundle_add(kb, "url", params.front().c_str()) < 0) {
617 return ERROR_LAUNCHER_EXECUTION_ERROR;
619 LogDebug("running with url: " << params.front().c_str());
620 } else if (appType == APPLICATION_TYPE_MEDIAPLAYER) {
621 LogDebug("opening file: " << getRealPath(params.front()).c_str());
622 int result = aul_open_file(getRealPath(params.front()).c_str());
624 LogError("Cannot open file, launch application only");
626 return SUCCESS_LAUNCHER;
628 } else if (appType == APPLICATION_TYPE_FILES) {
630 if (stat(getRealPath(params.front()).c_str(), &sb) == -1) {
632 "The selected path does not exist: " <<
633 getRealPath(params.front()).c_str());
635 if (!S_ISDIR(sb.st_mode)) {
636 LogDebug("opening file: " << getRealPath(
637 params.front()).c_str());
638 int result = aul_open_file(getRealPath(
639 params.front()).c_str());
642 "Cannot open file, launch application only");
644 return SUCCESS_LAUNCHER;
647 kb = bundle_create();
649 return ERROR_LAUNCHER_EXECUTION_ERROR;
651 if (bundle_add(kb, "path",
652 getRealPath(params.front()).c_str()) <
655 return ERROR_LAUNCHER_EXECUTION_ERROR;
657 LogDebug("running with folder path: " <<
658 getRealPath(params.front()).c_str());
661 } else if (appType == APPLICATION_TYPE_PICTURES) {
662 //open photo with image path
663 //replace package to show only one picture with given image path
664 packageName = APPLICATION_PICTURES_IMG_PATH;
665 kb = bundle_create();
667 return ERROR_LAUNCHER_EXECUTION_ERROR;
669 if (bundle_add(kb, "View Mode", "SINGLE") < 0) {
671 return ERROR_LAUNCHER_EXECUTION_ERROR;
673 if (bundle_add(kb, "Path",
674 getRealPath(params.front()).c_str()) < 0) {
676 return ERROR_LAUNCHER_EXECUTION_ERROR;
678 LogDebug("running with img file path: " <<
679 getRealPath(params.front()).c_str());
681 //TODO: add more parameters when needed
683 int result = aul_launch_app(packageName.c_str(), kb);
688 return SUCCESS_LAUNCHER;
690 LogError("aul_launch_app result " << result);
691 return ERROR_LAUNCHER_EXECUTION_ERROR;
693 return ERROR_LAUNCHER_EXECUTION_ERROR;
696 int AppLauncherManager::launchApplicationInternal(
697 const ApplicationUriType uriType,
698 const std::string &uriParameter,
699 const std::vector<std::string> &applicationParams)
702 "entered with uriType: " << uriType << ", uriParameter: " <<
704 if (APPLICATION_URI_TYPE_HTTP == uriType) {
705 std::string application =
706 m_applicationTypesByPath[APPLICATION_TYPE_BROWSER];
707 std::vector<std::string> params;
708 if (Commons::String::startsWith(uriParameter, "http://")) {
709 params.push_back(uriParameter);
710 } else if (!pcrecpp::RE(EMPTY_STRING_PATTERN).FullMatch(uriParameter))
712 params.push_back("http://" + uriParameter);
714 return launchApplicationFileInternal(application, params);
715 } else if (APPLICATION_URI_TYPE_HTTPS == uriType) {
716 std::string application =
717 m_applicationTypesByPath[APPLICATION_TYPE_BROWSER];
718 std::vector<std::string> params;
719 if (Commons::String::startsWith(uriParameter, "https://")) {
720 params.push_back(uriParameter);
721 } else if (!pcrecpp::RE(EMPTY_STRING_PATTERN).FullMatch(uriParameter))
723 params.push_back("https://" + uriParameter);
725 return launchApplicationFileInternal(application, params);
726 } else if (APPLICATION_URI_TYPE_TEL == uriType) {
727 std::string application =
728 m_applicationTypesByPath[APPLICATION_TYPE_PHONECALL];
729 std::vector<std::string> params;
730 params.push_back(uriParameter);
731 return launchApplicationFileInternal(application, params);
732 } else if (APPLICATION_URI_TYPE_MAILTO == uriType) {
733 std::string application =
734 m_applicationTypesByPath[APPLICATION_TYPE_MAIL];
735 std::vector<std::string> params;
736 params.push_back(uriParameter);
737 return launchApplicationFileInternal(application, params);
738 } else if (APPLICATION_URI_TYPE_SMS == uriType) {
739 std::string application =
740 m_applicationTypesByPath[APPLICATION_TYPE_MESSAGING];
741 std::vector<std::string> params;
742 params.push_back(uriParameter);
743 return launchApplicationFileInternal(application, params);
744 } else if (APPLICATION_URI_TYPE_FILE == uriType) {
745 return launchApplicationFileInternal(uriParameter, applicationParams);
746 } else if (APPLICATION_URI_TYPE_APPLICATION_BY_NAME == uriType) {
747 std::string application = getPathFromApplicationName(uriParameter);
748 return launchApplicationFileInternal(application, applicationParams);
750 return ERROR_LAUNCHER_INVALID_URI;
752 return SUCCESS_LAUNCHER;
755 std::string AppLauncherManager::getDefaultApplicationByMimeInternal(
756 const std::string &mime) const
758 LogDebug("entered with mime: " << mime);
759 const int bufferSize = 1024;
760 char buffer[bufferSize] = { 0 };
761 int result = aul_get_defapp_from_mime(mime.c_str(), buffer, bufferSize - 1);
762 if (AUL_R_OK == result) {
763 LogDebug("returning default application");
764 return std::string(buffer);
766 LogError("aul_get_defapp_from_mime failed, error code " << result);
767 Throw(Commons::PlatformException);
769 return std::string();
772 void AppLauncherManager::OnRequestReceived(
773 const EventGetDefaultApplicationPtr &event)
778 std::string result = getDefaultApplicationByMimeInternal(event->getMime());
779 event->setApplicationFullPath(result);
780 event->setExceptionCode(Commons::ExceptionCodes::None);
782 Catch(Commons::PlatformException)
784 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
788 void AppLauncherManager::OnRequestReceived(
789 const EventGetInstalledApplicationsPtr &event)
792 std::vector<std::string>::const_iterator it1;
793 for (it1 = m_installedApplications.begin();
794 it1 != m_installedApplications.end();
796 event->addApplicationFullPath(*it1);
798 for (it1 = m_installedApplicationsNames.begin();
799 it1 != m_installedApplicationsNames.end();
801 event->addApplicationName(*it1);
803 std::map<ApplicationType, std::string>::const_iterator it2;
804 for (it2 = m_applicationTypesByPath.begin();
805 it2 != m_applicationTypesByPath.end();
807 event->addApplicationTypeByPath(*it2);
809 for (it2 = m_applicationTypesByName.begin();
810 it2 != m_applicationTypesByName.end();
812 event->addApplicationTypeByName(*it2);
814 event->setExceptionCode(Commons::ExceptionCodes::None);
817 void AppLauncherManager::OnRequestReceived(
818 const EventLaunchApplicationPtr &event)
821 ApplicationUriType uriType = event->getApplicationUriType();
822 std::string uriParam = event->getApplicationUriParam();
823 std::vector<std::string> parameters = event->getApplicationParameters();
824 int result = launchApplicationInternal(uriType, uriParam, parameters);
825 if (result == SUCCESS_LAUNCHER) {
826 event->setExceptionCode(Commons::ExceptionCodes::None);
827 } else if (result == ERROR_LAUNCHER_INVALID_PARAMETER ||
828 result == ERROR_LAUNCHER_INVALID_URI) {
829 event->setExceptionCode(
830 Commons::ExceptionCodes::InvalidArgumentException);
832 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);