-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * @file AppLauncherManager.cpp
- * @author Lukasz Marek (l.marek@samsung.com)
- * @author Yujie Zeng (yj.zeng@samsung.com)
- * @version 0.1
- */
-
-#include <algorithm>
-#include <vector>
-#include <pcrecpp.h>
-#include <menu_db.h>
-#include <aul.h>
-#include <bundle.h>
-#include <dpl/scoped_free.h>
-#include <dpl/log/log.h>
-#include <commons/StringUtils.h>
-#include <Filesystem/Manager.h>
-#include "AppLauncherManager.h"
-
-using namespace WrtPlugins::Api;
-using namespace WrtPlugins::Api::AppLauncher;
-
-namespace {
-const char* EMPTY_STRING_PATTERN = "^\\s*$";
-const char* EMAIL_PATTERN = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+$";
-//According to RFC1738,any character is possible in http address
-const char* HTTP_ADDRESS_PATTERN = "^(http(s)?://)?\\w+.*$";
-const char* FILE_ADDRESS_PATTERN = "^.*\\..*$";
-
-const char* APPLICATION_ALARM = "org.tizen.clock"; // alarm has been
- // included in clock app
-const char* APPLICATION_BROWSER = "org.tizen.browser";
-const char* APPLICATION_CALCULATOR = "org.tizen.calculator";
-const char* APPLICATION_CALENDAR = "org.tizen.efl-calendar";
-const char* APPLICATION_CAMERA = "org.tizen.camera-app";
-const char* APPLICATION_CONTACTS = "org.tizen.contacts";
-const char* APPLICATION_FILES = "org.tizen.myfile";
-const char* APPLICATION_GAMES = "";
-const char* APPLICATION_MAIL = "org.tizen.email";
-const char* APPLICATION_MEDIAPLAYER = "org.tizen.music-player";
-const char* APPLICATION_MESSAGING = "org.tizen.message";
-const char* APPLICATION_PHONECALL = "org.tizen.dialer";
-const char* APPLICATION_PHONECALL_CALLING = "org.tizen.call";
-const char* APPLICATION_PICTURES = "org.tizen.gallery";
-const char* APPLICATION_PICTURES_IMG_PATH = "org.tizen.image-viewer";
-const char* APPLICATION_PROG_MANAGER = "org.tizen.taskmgr";
-const char* APPLICATION_SETTINGS = "org.tizen.setting";
-const char* APPLICATION_TASKS = "org.tizen.dailybriefing";
-const char* APPLICATION_WIDGET_MANAGER = "org.tizen.wrt-test-ui";
-const char* APPLICATION_WIDGET = "org.tizen.";
-const char* APPLICATION_EMPTY = "";
-
-const char* WIDGET_URI_PREFIX = "widget://";
-
-const int SUCCESS_LAUNCHER = 0;
-const int ERROR_LAUNCHER_INVALID_URI = 1;
-const int ERROR_LAUNCHER_INVALID_PARAMETER = 2;
-const int ERROR_LAUNCHER_EXECUTION_ERROR = 3;
-}
-
-namespace WrtPlugins {
-namespace Platform {
-std::map<Api::AppLauncher::ApplicationType,
- std::string> AppLauncherManager::m_applicationTypesByPath;
-std::map<Api::AppLauncher::ApplicationType,
- std::string> AppLauncherManager::m_applicationTypesByName;
-std::vector<std::string> AppLauncherManager::m_installedApplications;
-std::vector<std::string> AppLauncherManager::m_installedApplicationsNames;
-
-AppLauncherManager::AppLauncherManager()
-{
- LogDebug("entered");
- static bool initialized = initializeApplicationList();
- (void) initialized;
-}
-
-AppLauncherManager::~AppLauncherManager()
-{
- LogDebug("entered");
-}
-
-bool AppLauncherManager::initializeApplicationList()
-{
- //application paths
- m_applicationTypesByPath.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_ALARM,
- APPLICATION_EMPTY));
- m_applicationTypesByPath.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_BROWSER,
- APPLICATION_EMPTY));
- m_applicationTypesByPath.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_CALCULATOR,
- APPLICATION_EMPTY));
- m_applicationTypesByPath.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_CALENDAR,
- APPLICATION_EMPTY));
- m_applicationTypesByPath.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_CAMERA,
- APPLICATION_EMPTY));
- m_applicationTypesByPath.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_CONTACTS,
- APPLICATION_EMPTY));
- m_applicationTypesByPath.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_FILES,
- APPLICATION_EMPTY));
- m_applicationTypesByPath.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_GAMES,
- APPLICATION_EMPTY));
- m_applicationTypesByPath.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_MAIL,
- APPLICATION_EMPTY));
- m_applicationTypesByPath.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_MEDIAPLAYER,
- APPLICATION_EMPTY));
- m_applicationTypesByPath.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_MESSAGING,
- APPLICATION_EMPTY));
- m_applicationTypesByPath.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_PHONECALL,
- APPLICATION_EMPTY));
- m_applicationTypesByPath.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_PICTURES,
- APPLICATION_EMPTY));
- m_applicationTypesByPath.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_PROG_MANAGER,
- APPLICATION_EMPTY));
- m_applicationTypesByPath.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_SETTINGS,
- APPLICATION_EMPTY));
- m_applicationTypesByPath.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_TASKS,
- APPLICATION_EMPTY));
- m_applicationTypesByPath.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_WIDGET_MANAGER,
- APPLICATION_EMPTY));
- //application names
- m_applicationTypesByName.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_ALARM,
- APPLICATION_EMPTY));
- m_applicationTypesByName.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_BROWSER,
- APPLICATION_EMPTY));
- m_applicationTypesByName.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_CALCULATOR,
- APPLICATION_EMPTY));
- m_applicationTypesByName.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_CALENDAR,
- APPLICATION_EMPTY));
- m_applicationTypesByName.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_CAMERA,
- APPLICATION_EMPTY));
- m_applicationTypesByName.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_CONTACTS,
- APPLICATION_EMPTY));
- m_applicationTypesByName.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_FILES,
- APPLICATION_EMPTY));
- m_applicationTypesByName.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_GAMES,
- APPLICATION_EMPTY));
- m_applicationTypesByName.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_MAIL,
- APPLICATION_EMPTY));
- m_applicationTypesByName.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_MEDIAPLAYER,
- APPLICATION_EMPTY));
- m_applicationTypesByName.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_MESSAGING,
- APPLICATION_EMPTY));
- m_applicationTypesByName.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_PHONECALL,
- APPLICATION_EMPTY));
- m_applicationTypesByName.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_PICTURES,
- APPLICATION_EMPTY));
- m_applicationTypesByName.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_PROG_MANAGER,
- APPLICATION_EMPTY));
- m_applicationTypesByName.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_SETTINGS,
- APPLICATION_EMPTY));
- m_applicationTypesByName.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_TASKS,
- APPLICATION_EMPTY));
- m_applicationTypesByName.insert(std::pair<ApplicationType,
- std::string>(
- APPLICATION_TYPE_WIDGET_MANAGER,
- APPLICATION_EMPTY));
-
- 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.
- app_info info = {};
- unsigned int count = record_count(COUNT_MENU, &info);
- LogDebug("number of registered applications: " << count);
-
- DPL::ScopedFree<app_info> infoAll(static_cast<app_info*>(calloc(
- count,
- sizeof(
- app_info))));
- if (infoAll.Get()) {
- if (!record_get(GET_MENU, infoAll.Get())) {
- LogError("error during executing record_get() function");
- return false;
- }
- for (unsigned int i = 0; i < count; i++) {
- LogDebug("pkg_name " << infoAll.Get()[i].pkg_name);
- LogDebug("app_path " << infoAll.Get()[i].app_path);
- LogDebug("app_name " << infoAll.Get()[i].app_name);
- registered_application = false;
- if (infoAll.Get()[i].app_path == NULL ||
- infoAll.Get()[i].app_name == NULL)
- {
- LogDebug("Not Registered.");
- LogDebug("-----");
- continue;
- }
- if (0 ==
- strncmp(APPLICATION_ALARM, infoAll.Get()[i].pkg_name,
- NAME_LEN))
- {
- m_applicationTypesByPath[APPLICATION_TYPE_ALARM] =
- infoAll.Get()[i].app_path;
- m_applicationTypesByName[APPLICATION_TYPE_ALARM] =
- infoAll.Get()[i].app_name;
- registered_application = true;
- }
- if (0 ==
- strncmp(APPLICATION_BROWSER, infoAll.Get()[i].pkg_name,
- NAME_LEN))
- {
- m_applicationTypesByPath[APPLICATION_TYPE_BROWSER] =
- infoAll.Get()[i].app_path;
- m_applicationTypesByName[APPLICATION_TYPE_BROWSER] =
- infoAll.Get()[i].app_name;
- registered_application = true;
- }
- if (0 ==
- strncmp(APPLICATION_CALCULATOR, infoAll.Get()[i].pkg_name,
- NAME_LEN))
- {
- m_applicationTypesByPath[APPLICATION_TYPE_CALCULATOR] =
- infoAll.Get()[i].app_path;
- m_applicationTypesByName[APPLICATION_TYPE_CALCULATOR] =
- infoAll.Get()[i].app_name;
- registered_application = true;
- }
- if (0 ==
- strncmp(APPLICATION_CALENDAR, infoAll.Get()[i].pkg_name,
- NAME_LEN))
- {
- m_applicationTypesByPath[APPLICATION_TYPE_CALENDAR] =
- infoAll.Get()[i].app_path;
- m_applicationTypesByName[APPLICATION_TYPE_CALENDAR] =
- infoAll.Get()[i].app_name;
- registered_application = true;
- }
- if (0 ==
- strncmp(APPLICATION_CAMERA, infoAll.Get()[i].pkg_name,
- NAME_LEN))
- {
- m_applicationTypesByPath[APPLICATION_TYPE_CAMERA] =
- infoAll.Get()[i].app_path;
- m_applicationTypesByName[APPLICATION_TYPE_CAMERA] =
- infoAll.Get()[i].app_name;
- registered_application = true;
- }
- if (0 ==
- strncmp(APPLICATION_CONTACTS, infoAll.Get()[i].pkg_name,
- NAME_LEN))
- {
- m_applicationTypesByPath[APPLICATION_TYPE_CONTACTS] =
- infoAll.Get()[i].app_path;
- m_applicationTypesByName[APPLICATION_TYPE_CONTACTS] =
- infoAll.Get()[i].app_name;
- registered_application = true;
- }
- if (0 ==
- strncmp(APPLICATION_FILES, infoAll.Get()[i].pkg_name,
- NAME_LEN))
- {
- m_applicationTypesByPath[APPLICATION_TYPE_FILES] =
- infoAll.Get()[i].app_path;
- m_applicationTypesByName[APPLICATION_TYPE_FILES] =
- infoAll.Get()[i].app_name;
- registered_application = true;
- }
- if (0 ==
- strncmp(APPLICATION_GAMES, infoAll.Get()[i].pkg_name,
- NAME_LEN))
- {
- m_applicationTypesByPath[APPLICATION_TYPE_GAMES] =
- infoAll.Get()[i].app_path;
- m_applicationTypesByName[APPLICATION_TYPE_GAMES] =
- infoAll.Get()[i].app_name;
- registered_application = true;
- }
- if (0 ==
- strncmp(APPLICATION_MAIL, infoAll.Get()[i].pkg_name,
- NAME_LEN))
- {
- m_applicationTypesByPath[APPLICATION_TYPE_MAIL] =
- infoAll.Get()[i].app_path;
- m_applicationTypesByName[APPLICATION_TYPE_MAIL] =
- infoAll.Get()[i].app_name;
- registered_application = true;
- }
- if (0 ==
- strncmp(APPLICATION_MEDIAPLAYER, infoAll.Get()[i].pkg_name,
- NAME_LEN))
- {
- m_applicationTypesByPath[APPLICATION_TYPE_MEDIAPLAYER] =
- infoAll.Get()[i].app_path;
- m_applicationTypesByName[APPLICATION_TYPE_MEDIAPLAYER] =
- infoAll.Get()[i].app_name;
- registered_application = true;
- }
- if (0 ==
- strncmp(APPLICATION_MESSAGING, infoAll.Get()[i].pkg_name,
- NAME_LEN))
- {
- m_applicationTypesByPath[APPLICATION_TYPE_MESSAGING] =
- infoAll.Get()[i].app_path;
- m_applicationTypesByName[APPLICATION_TYPE_MESSAGING] =
- infoAll.Get()[i].app_name;
- registered_application = true;
- }
- if (0 ==
- strncmp(APPLICATION_PHONECALL, infoAll.Get()[i].pkg_name,
- NAME_LEN))
- {
- m_applicationTypesByPath[APPLICATION_TYPE_PHONECALL] =
- infoAll.Get()[i].app_path;
- m_applicationTypesByName[APPLICATION_TYPE_PHONECALL] =
- infoAll.Get()[i].app_name;
- registered_application = true;
- }
- if (0 ==
- strncmp(APPLICATION_PICTURES, infoAll.Get()[i].pkg_name,
- NAME_LEN))
- {
- m_applicationTypesByPath[APPLICATION_TYPE_PICTURES] =
- infoAll.Get()[i].app_path;
- m_applicationTypesByName[APPLICATION_TYPE_PICTURES] =
- infoAll.Get()[i].app_name;
- registered_application = true;
- }
- if (0 ==
- strncmp(APPLICATION_PROG_MANAGER, infoAll.Get()[i].pkg_name,
- NAME_LEN))
- {
- m_applicationTypesByPath[APPLICATION_TYPE_PROG_MANAGER] =
- infoAll.Get()[i].app_path;
- m_applicationTypesByName[APPLICATION_TYPE_PROG_MANAGER] =
- infoAll.Get()[i].app_name;
- registered_application = true;
- }
- if (0 ==
- strncmp(APPLICATION_SETTINGS, infoAll.Get()[i].pkg_name,
- NAME_LEN))
- {
- m_applicationTypesByPath[APPLICATION_TYPE_SETTINGS] =
- infoAll.Get()[i].app_path;
- m_applicationTypesByName[APPLICATION_TYPE_SETTINGS] =
- infoAll.Get()[i].app_name;
- registered_application = true;
- }
- if (0 ==
- strncmp(APPLICATION_TASKS, infoAll.Get()[i].pkg_name,
- NAME_LEN))
- {
- m_applicationTypesByPath[APPLICATION_TYPE_TASKS] =
- infoAll.Get()[i].app_path;
- m_applicationTypesByName[APPLICATION_TYPE_TASKS] =
- infoAll.Get()[i].app_name;
- registered_application = true;
- }
- if (0 ==
- strncmp(APPLICATION_WIDGET_MANAGER, infoAll.Get()[i].pkg_name,
- NAME_LEN))
- {
- m_applicationTypesByPath[APPLICATION_TYPE_WIDGET_MANAGER] =
- infoAll.Get()[i].app_path;
- m_applicationTypesByName[APPLICATION_TYPE_WIDGET_MANAGER] =
- infoAll.Get()[i].app_name;
- registered_application = true;
- }
- if (infoAll.Get()[i].visible == 0 && registered_application ==
- false)
- {
- LogDebug("Not Registered.");
- LogDebug("-----");
- continue;
- }
- m_installedApplications.push_back(infoAll.Get()[i].app_path);
- m_installedApplicationsNames.push_back(infoAll.Get()[i].app_name);
- LogDebug("Registered.");
- LogDebug("-----");
- }
- }
- return true;
-}
-
-ApplicationType AppLauncherManager::getRegisteredApplicationType(
- const std::string &name) const
-{
- if (!name.empty()) {
- std::map<ApplicationType, std::string>::const_iterator it;
- for (it = m_applicationTypesByPath.begin();
- it != m_applicationTypesByPath.end();
- ++it)
- {
- if (it->second == name) {
- return it->first;
- }
- }
- }
- return APPLICATION_TYPE_UNDEFINED;
-}
-
-bool AppLauncherManager::isRegisteredApplication(const std::string &name) const
-{
- if (name.empty()) {
- return false;
- }
- std::vector<std::string>::const_iterator pos =
- find(m_installedApplications.begin(),
- m_installedApplications.end(), name);
- return pos != m_installedApplications.end();
-}
-
-bool AppLauncherManager::validateHttpAddress(const std::string &value) const
-{
- if (!pcrecpp::RE(HTTP_ADDRESS_PATTERN).FullMatch(value)) {
- LogDebug("not valid paterrn of http address");
- return false;
- }
- return true;
-}
-
-bool AppLauncherManager::isFilePath(const std::string &value) const
-{
- if (!pcrecpp::RE(FILE_ADDRESS_PATTERN).FullMatch(value)) {
- return false;
- }
- return true;
-}
-
-bool AppLauncherManager::validateEmailAddress(const std::string &value) const
-{
- if (!pcrecpp::RE(EMAIL_PATTERN).FullMatch(value)) {
- LogDebug("not valid paterrn of email address");
- return false;
- }
- return true;
-}
-
-std::string AppLauncherManager::getRealPath(const std::string &path) const
-{
- Try
- {
- Api::Filesystem::IPathPtr currentPath = Api::Filesystem::IPath::create(
- path);
- return currentPath->getFullPath();
- }
- Catch(Commons::Exception)
- {
- LogError("invalid path");
- }
- return std::string();
-}
-
-std::string AppLauncherManager::getPathFromApplicationName(
- const std::string &applicationName) const
-{
- if (0 == applicationName.find(WIDGET_URI_PREFIX) && std::string::npos !=
- applicationName.find("?"))
- {
- //uri format is: widget://{widgetId}?wname={WidgetName}
- LogDebug("found widget:// URI");
- std::string uri = applicationName;
- uri.erase(0, strlen(WIDGET_URI_PREFIX)); //remove widget://part
- std::string widgetId = uri.substr(0, uri.find("?"));
- uri.erase(0, widgetId.size() + 7); //remove widget id and "?wname="
- // string, so uri contains only
- // widget name now
- std::string packageName = APPLICATION_WIDGET + widgetId;
- LogDebug(
- "Widget id: " << widgetId << ", widget name: " << uri <<
- ", package: " << packageName);
- app_info info = { 0, };
- strncpy(info.pkg_name, packageName.c_str(), NAME_LEN);
- if (record_get(GET_ONE_RECORD_BY_PKG_NAME, &info)) {
- if (info.app_path && info.app_name && uri == info.app_name) {
- return std::string(info.app_path);
- }
- }
- }
- for (size_t i = 0; i < m_installedApplicationsNames.size(); ++i) {
- if (m_installedApplicationsNames[i] == applicationName) {
- return m_installedApplications[i];
- }
- }
- return std::string();
-}
-
-std::string AppLauncherManager::getPathFromPackageName(
- const std::string &packageName) const
-{
- app_info info = { 0, };
- strncpy(info.pkg_name, packageName.c_str(), NAME_LEN);
- if (record_get(GET_ONE_RECORD_BY_PKG_NAME, &info)) {
- LogDebug("pkg_name " << info.pkg_name);
- LogDebug("app_path " << info.app_path);
- LogDebug("app_name " << info.app_name);
- if (info.app_path) {
- return std::string(info.app_path);
- }
- }
- return std::string();
-}
-
-std::string AppLauncherManager::getPackageNameFromPath(const std::string &path)
-const
-{
- app_info info = { 0, };
- strncpy(info.app_path, path.c_str(), PATH_LEN);
- if (record_get(GET_ONE_RECORD_BY_APP_PATH, &info)) {
- LogDebug("pkg_name " << info.pkg_name);
- LogDebug("app_path " << info.app_path);
- LogDebug("app_name " << info.app_name);
- if (info.app_path) {
- return std::string(info.pkg_name);
- }
- }
- return std::string();
-}
-
-int AppLauncherManager::launchApplicationFileInternal(
- const std::string &uriParameter,
- const std::vector<std::string> &applicationParams)
-{
- LogDebug("entered with uriParameter: '" << uriParameter << "'");
- ApplicationType appType = getRegisteredApplicationType(uriParameter);
- if (!isRegisteredApplication(uriParameter)) {
- LogDebug("Its not registered application");
- return ERROR_LAUNCHER_INVALID_URI;
- }
- //try to launch as package using aul
- std::string packageName = getPackageNameFromPath(uriParameter);
- if (!packageName.empty()) {
- LogDebug("executing as package, package name " << packageName);
- //check parameters for empty or extra spaces
- std::vector<std::string> params;
- std::vector<std::string>::const_iterator it;
- for (it = applicationParams.begin();
- it != applicationParams.end();
- ++it)
- {
- std::string param(Commons::String::trim(*it));
- if (param.empty()) {
- continue;
- }
- params.push_back(param);
- }
- bundle *kb = NULL;
- if (params.size() > 0) {
- if (appType == APPLICATION_TYPE_PHONECALL) {
- //phone number is provided.
- //replace package to make a call, not run application with this
- // functionality
-
- packageName = APPLICATION_PHONECALL_CALLING;
- kb = bundle_create();
- if (!kb) {
- return ERROR_LAUNCHER_EXECUTION_ERROR;
- }
- if (bundle_add(kb, "launch-type", "MO") < 0) { // "MO" : normal
- // call,
- // "EMERGENCY" :
- // emergency call
- bundle_free(kb);
- return ERROR_LAUNCHER_EXECUTION_ERROR;
- }
- if (bundle_add(kb, "number", params.front().c_str()) < 0) {
- bundle_free(kb);
- return ERROR_LAUNCHER_EXECUTION_ERROR;
- }
- LogDebug("running with number: " << params.front());
- } else if (appType == APPLICATION_TYPE_BROWSER) {
- if (!validateHttpAddress(params.front())) {
- return ERROR_LAUNCHER_INVALID_PARAMETER;
- }
- kb = bundle_create();
- if (!kb) {
- return ERROR_LAUNCHER_EXECUTION_ERROR;
- }
- if (bundle_add(kb, "url", params.front().c_str()) < 0) {
- bundle_free(kb);
- return ERROR_LAUNCHER_EXECUTION_ERROR;
- }
- LogDebug("running with url: " << params.front().c_str());
- } else if (appType == APPLICATION_TYPE_MEDIAPLAYER) {
- LogDebug("opening file: " << getRealPath(params.front()).c_str());
- int result = aul_open_file(getRealPath(params.front()).c_str());
- if (result < 0) {
- LogError("Cannot open file, launch application only");
- } else {
- return SUCCESS_LAUNCHER;
- }
- } else if (appType == APPLICATION_TYPE_FILES) {
- struct stat sb;
- if (stat(getRealPath(params.front()).c_str(), &sb) == -1) {
- LogError(
- "The selected path does not exist: " <<
- getRealPath(params.front()).c_str());
- } else {
- if (!S_ISDIR(sb.st_mode)) {
- LogDebug("opening file: " << getRealPath(
- params.front()).c_str());
- int result = aul_open_file(getRealPath(
- params.front()).c_str());
- if (result < 0) {
- LogError(
- "Cannot open file, launch application only");
- } else {
- return SUCCESS_LAUNCHER;
- }
- } else {
- kb = bundle_create();
- if (!kb) {
- return ERROR_LAUNCHER_EXECUTION_ERROR;
- }
- if (bundle_add(kb, "path",
- getRealPath(params.front()).c_str()) <
- 0)
- {
- bundle_free(kb);
- return ERROR_LAUNCHER_EXECUTION_ERROR;
- }
- LogDebug("running with folder path: " <<
- getRealPath(params.front()).c_str());
- }
- }
- } else if (appType == APPLICATION_TYPE_PICTURES) {
- //open photo with image path
- //replace package to show only one picture with given image path
- packageName = APPLICATION_PICTURES_IMG_PATH;
- kb = bundle_create();
- if (!kb) {
- return ERROR_LAUNCHER_EXECUTION_ERROR;
- }
- if (bundle_add(kb, "View Mode", "SINGLE") < 0) {
- bundle_free(kb);
- return ERROR_LAUNCHER_EXECUTION_ERROR;
- }
- if (bundle_add(kb, "Path",
- getRealPath(params.front()).c_str()) < 0)
- {
- bundle_free(kb);
- return ERROR_LAUNCHER_EXECUTION_ERROR;
- }
- LogDebug("running with img file path: " <<
- getRealPath(params.front()).c_str());
- }
- //TODO: add more parameters when needed
- }
- int result = aul_launch_app(packageName.c_str(), kb);
- if (kb) {
- bundle_free(kb);
- }
- if (result > 0) {
- return SUCCESS_LAUNCHER;
- }
- LogError("aul_launch_app result " << result);
- return ERROR_LAUNCHER_EXECUTION_ERROR;
- }
- return ERROR_LAUNCHER_EXECUTION_ERROR;
-}
-
-int AppLauncherManager::launchApplicationInternal(
- const ApplicationUriType uriType,
- const std::string &uriParameter,
- const std::vector<std::string> &applicationParams)
-{
- LogDebug(
- "entered with uriType: " << uriType << ", uriParameter: " <<
- uriParameter);
- if (APPLICATION_URI_TYPE_HTTP == uriType) {
- std::string application =
- m_applicationTypesByPath[APPLICATION_TYPE_BROWSER];
- std::vector<std::string> params;
- if (Commons::String::startsWith(uriParameter, "http://")) {
- params.push_back(uriParameter);
- } else if (!pcrecpp::RE(EMPTY_STRING_PATTERN).FullMatch(uriParameter))
- {
- params.push_back("http://" + uriParameter);
- }
- return launchApplicationFileInternal(application, params);
- } else if (APPLICATION_URI_TYPE_HTTPS == uriType) {
- std::string application =
- m_applicationTypesByPath[APPLICATION_TYPE_BROWSER];
- std::vector<std::string> params;
- if (Commons::String::startsWith(uriParameter, "https://")) {
- params.push_back(uriParameter);
- } else if (!pcrecpp::RE(EMPTY_STRING_PATTERN).FullMatch(uriParameter))
- {
- params.push_back("https://" + uriParameter);
- }
- return launchApplicationFileInternal(application, params);
- } else if (APPLICATION_URI_TYPE_TEL == uriType) {
- std::string application =
- m_applicationTypesByPath[APPLICATION_TYPE_PHONECALL];
- std::vector<std::string> params;
- params.push_back(uriParameter);
- return launchApplicationFileInternal(application, params);
- } else if (APPLICATION_URI_TYPE_MAILTO == uriType) {
- std::string application =
- m_applicationTypesByPath[APPLICATION_TYPE_MAIL];
- std::vector<std::string> params;
- params.push_back(uriParameter);
- return launchApplicationFileInternal(application, params);
- } else if (APPLICATION_URI_TYPE_SMS == uriType) {
- std::string application =
- m_applicationTypesByPath[APPLICATION_TYPE_MESSAGING];
- std::vector<std::string> params;
- params.push_back(uriParameter);
- return launchApplicationFileInternal(application, params);
- } else if (APPLICATION_URI_TYPE_FILE == uriType) {
- return launchApplicationFileInternal(uriParameter, applicationParams);
- } else if (APPLICATION_URI_TYPE_APPLICATION_BY_NAME == uriType) {
- std::string application = getPathFromApplicationName(uriParameter);
- return launchApplicationFileInternal(application, applicationParams);
- } else {
- return ERROR_LAUNCHER_INVALID_URI;
- }
- return SUCCESS_LAUNCHER;
-}
-
-std::string AppLauncherManager::getDefaultApplicationByMimeInternal(
- const std::string &mime) const
-{
- LogDebug("entered with mime: " << mime);
- const int bufferSize = 1024;
- char buffer[bufferSize] = { 0 };
- int result = aul_get_defapp_from_mime(mime.c_str(), buffer, bufferSize - 1);
- if (AUL_R_OK == result) {
- LogDebug("returning default application");
- return std::string(buffer);
- } else {
- LogError("aul_get_defapp_from_mime failed, error code " << result);
- Throw(Commons::PlatformException);
- }
- return std::string();
-}
-
-void AppLauncherManager::OnRequestReceived(
- const EventGetDefaultApplicationPtr &event)
-{
- LogDebug("entered");
- Try
- {
- std::string result = getDefaultApplicationByMimeInternal(event->getMime());
- event->setApplicationFullPath(result);
- event->setExceptionCode(Commons::ExceptionCodes::None);
- }
- Catch(Commons::PlatformException)
- {
- event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
- }
-}
-
-void AppLauncherManager::OnRequestReceived(
- const EventGetInstalledApplicationsPtr &event)
-{
- LogDebug("entered");
- std::vector<std::string>::const_iterator it1;
- for (it1 = m_installedApplications.begin();
- it1 != m_installedApplications.end();
- ++it1)
- {
- event->addApplicationFullPath(*it1);
- }
- for (it1 = m_installedApplicationsNames.begin();
- it1 != m_installedApplicationsNames.end();
- ++it1)
- {
- event->addApplicationName(*it1);
- }
- std::map<ApplicationType, std::string>::const_iterator it2;
- for (it2 = m_applicationTypesByPath.begin();
- it2 != m_applicationTypesByPath.end();
- ++it2)
- {
- event->addApplicationTypeByPath(*it2);
- }
- for (it2 = m_applicationTypesByName.begin();
- it2 != m_applicationTypesByName.end();
- ++it2)
- {
- event->addApplicationTypeByName(*it2);
- }
- event->setExceptionCode(Commons::ExceptionCodes::None);
-}
-
-void AppLauncherManager::OnRequestReceived(
- const EventLaunchApplicationPtr &event)
-{
- LogDebug("entered");
- ApplicationUriType uriType = event->getApplicationUriType();
- std::string uriParam = event->getApplicationUriParam();
- std::vector<std::string> parameters = event->getApplicationParameters();
- int result = launchApplicationInternal(uriType, uriParam, parameters);
- if (result == SUCCESS_LAUNCHER) {
- event->setExceptionCode(Commons::ExceptionCodes::None);
- } else if (result == ERROR_LAUNCHER_INVALID_PARAMETER ||
- result == ERROR_LAUNCHER_INVALID_URI)
- {
- event->setExceptionCode(
- Commons::ExceptionCodes::InvalidArgumentException);
- } else {
- event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
- }
-}
-}
-}