summaryrefslogtreecommitdiff
path: root/src/components/application_manager/src/application_manager_impl.cc
diff options
context:
space:
mode:
authorJackLivio <jack@livio.io>2019-03-01 15:00:38 -0500
committerGitHub <noreply@github.com>2019-03-01 15:00:38 -0500
commitfc9f7d13c0e03caee9e196a636815e791213ad66 (patch)
tree1ab8631036aaa75a335797e9efae07eba0413e05 /src/components/application_manager/src/application_manager_impl.cc
parentbc6cec5d29ff36b7092112dc1ea69ccd4d92acc3 (diff)
downloadsdl_core-fc9f7d13c0e03caee9e196a636815e791213ad66.tar.gz
Get Icon URL Request (#2823)
* Fix regex command for reading paths post port number * Add Icon URL to policies * Create Icon Request and save to icon folder. * Fixes for get icon url * Fix unit tests * Send Icon_url request after PTU * Address comments * Address Comments
Diffstat (limited to 'src/components/application_manager/src/application_manager_impl.cc')
-rw-r--r--src/components/application_manager/src/application_manager_impl.cc162
1 files changed, 159 insertions, 3 deletions
diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc
index 9903342ae1..a9ae2e5ca7 100644
--- a/src/components/application_manager/src/application_manager_impl.cc
+++ b/src/components/application_manager/src/application_manager_impl.cc
@@ -73,6 +73,7 @@
#include "policy/usage_statistics/counter.h"
#include "utils/custom_string.h"
#include <time.h>
+#include <boost/filesystem.hpp>
namespace {
int get_rand_from_range(uint32_t from = 0, int to = RAND_MAX) {
@@ -240,6 +241,13 @@ DataAccessor<ApplicationSet> ApplicationManagerImpl::applications() const {
return accessor;
}
+DataAccessor<AppsWaitRegistrationSet>
+ApplicationManagerImpl::pending_applications() const {
+ DataAccessor<AppsWaitRegistrationSet> accessor(
+ apps_to_register_, apps_to_register_list_lock_ptr_);
+ return accessor;
+}
+
ApplicationSharedPtr ApplicationManagerImpl::application(
uint32_t app_id) const {
AppIdPredicate finder(app_id);
@@ -261,6 +269,13 @@ ApplicationSharedPtr ApplicationManagerImpl::application_by_policy_id(
return FindApp(accessor, finder);
}
+ApplicationSharedPtr ApplicationManagerImpl::pending_application_by_policy_id(
+ const std::string& policy_app_id) const {
+ PolicyAppIdPredicate finder(policy_app_id);
+ DataAccessor<AppsWaitRegistrationSet> accessor = pending_applications();
+ return FindPendingApp(accessor, finder);
+}
+
bool ActiveAppPredicate(const ApplicationSharedPtr app) {
return app ? app->IsFullscreen() : false;
}
@@ -808,6 +823,60 @@ void ApplicationManagerImpl::OnHMIStartedCooperation() {
RefreshCloudAppInformation();
}
+std::string ApplicationManagerImpl::PolicyIDByIconUrl(const std::string url) {
+ sync_primitives::AutoLock lock(app_icon_map_lock_ptr_);
+ for (auto& x : app_icon_map_) {
+ auto policy_id = x.first;
+ std::string icon_url = GetPolicyHandler().GetIconUrl(policy_id);
+ if (icon_url == url) {
+ LOG4CXX_DEBUG(logger_, "Matched icon url: " << url);
+ x.second.pending_request = false;
+ return policy_id;
+ }
+ }
+ return std::string("");
+}
+
+void ApplicationManagerImpl::SetIconFileFromSystemRequest(
+ const std::string policy_id) {
+ app_icon_map_lock_ptr_.Acquire();
+ auto app_icon_it = app_icon_map_.find(policy_id);
+ if (app_icon_it != app_icon_map_.end()) {
+ app_icon_map_.erase(app_icon_it);
+ }
+ app_icon_map_lock_ptr_.Release();
+
+ // Find pending application and set icon path
+ auto app = pending_application_by_policy_id(policy_id);
+ if (!app) {
+ return;
+ }
+ const std::string app_icon_dir(settings_.app_icons_folder());
+ const std::string full_icon_path(app_icon_dir + "/" + policy_id);
+ if (file_system::FileExists(full_icon_path)) {
+ LOG4CXX_DEBUG(logger_, "Set Icon Path: " << full_icon_path);
+ AppFile file;
+ file.is_persistent = true;
+ file.is_download_complete = true;
+ file.file_name = full_icon_path;
+
+ std::string icon_url = GetPolicyHandler().GetIconUrl(policy_id);
+ std::string extension = boost::filesystem::extension(icon_url);
+ if (extension == "bmp" || extension == "BMP") {
+ file.file_type = mobile_apis::FileType::GRAPHIC_BMP;
+ } else if (extension == "JPEG" || extension == "jpeg" ||
+ extension == "JPG" || extension == "jpg") {
+ file.file_type = mobile_apis::FileType::GRAPHIC_JPEG;
+ } else {
+ file.file_type = mobile_apis::FileType::GRAPHIC_PNG;
+ }
+
+ app->AddFile(file);
+ app->set_app_icon_path(full_icon_path);
+ }
+ SendUpdateAppList();
+}
+
void ApplicationManagerImpl::DisconnectCloudApp(ApplicationSharedPtr app) {
std::string endpoint;
std::string certificate;
@@ -857,6 +926,7 @@ void ApplicationManagerImpl::RefreshCloudAppInformation() {
// Store old device map and clear the current map
pending_device_map_lock_ptr_->Acquire();
+ app_icon_map_lock_ptr_.Acquire();
std::map<std::string, std::string> old_device_map = pending_device_map_;
pending_device_map_ = std::map<std::string, std::string>();
// Create a device for each newly enabled cloud app
@@ -868,9 +938,9 @@ void ApplicationManagerImpl::RefreshCloudAppInformation() {
auth_token,
cloud_transport_type,
hybrid_app_preference);
-
+ auto policy_id = *enabled_it;
pending_device_map_.insert(
- std::pair<std::string, std::string>(endpoint, *enabled_it));
+ std::pair<std::string, std::string>(endpoint, policy_id));
// Determine which endpoints were disabled by erasing all enabled apps from
// the old device list
auto old_device_it = old_device_map.find(endpoint);
@@ -880,8 +950,34 @@ void ApplicationManagerImpl::RefreshCloudAppInformation() {
// If the device was disconnected, this will reinitialize the device
connection_handler().AddCloudAppDevice(
- *enabled_it, endpoint, cloud_transport_type);
+ policy_id, endpoint, cloud_transport_type);
+
+ // Look for app icon url data and add to app_icon_url_map
+ std::string url = GetPolicyHandler().GetIconUrl(policy_id);
+
+ if (url.empty()) {
+ LOG4CXX_DEBUG(logger_, "No Icon Url for cloud app");
+ continue;
+ }
+
+ auto app_icon_it = app_icon_map_.find(policy_id);
+ if (app_icon_it != app_icon_map_.end()) {
+ LOG4CXX_DEBUG(logger_, "Cloud App Already Exists in Icon Map");
+ continue;
+ }
+
+ const std::string app_icon_dir(settings_.app_icons_folder());
+ const std::string full_icon_path(app_icon_dir + "/" + policy_id);
+ if (!file_system::FileExists(full_icon_path)) {
+ int icon_map_size = app_icon_map_.size();
+ AppIconInfo icon_info(endpoint, false);
+ LOG4CXX_DEBUG(logger_,
+ "Inserting cloud app into icon map: " << icon_map_size);
+ app_icon_map_.insert(
+ std::pair<std::string, AppIconInfo>(policy_id, icon_info));
+ }
}
+ app_icon_map_lock_ptr_.Release();
pending_device_map_lock_ptr_->Release();
int removed_app_count = 0;
@@ -3660,7 +3756,15 @@ void ApplicationManagerImpl::OnPTUFinished(const bool ptu_result) {
if (!ptu_result) {
return;
}
+
RefreshCloudAppInformation();
+
+ auto app_id = policy_handler_->GetAppIdForSending();
+ auto app = application(app_id);
+ if (app) {
+ SendGetIconUrlNotifications(app->app_id(), app);
+ }
+
auto on_app_policy_updated = [](plugin_manager::RPCPlugin& plugin) {
plugin.OnPolicyEvent(plugin_manager::kApplicationPolicyUpdated);
};
@@ -3703,6 +3807,58 @@ void ApplicationManagerImpl::SendDriverDistractionState(
}
}
+void ApplicationManagerImpl::SendGetIconUrlNotifications(
+ const uint32_t connection_key, ApplicationSharedPtr application) {
+ LOG4CXX_AUTO_TRACE(logger_);
+ std::vector<std::string> enabled_apps;
+ GetPolicyHandler().GetEnabledCloudApps(enabled_apps);
+ std::vector<std::string>::iterator enabled_it = enabled_apps.begin();
+ std::vector<std::string>::iterator enabled_end = enabled_apps.end();
+ sync_primitives::AutoLock lock(app_icon_map_lock_ptr_);
+ for (; enabled_it != enabled_end; ++enabled_it) {
+ auto app_icon_it = app_icon_map_.find(*enabled_it);
+ if (app_icon_it == app_icon_map_.end()) {
+ LOG4CXX_WARN(logger_, "Could not find cloud app in icon map");
+ continue;
+ }
+
+ std::string endpoint = app_icon_it->second.endpoint;
+ bool pending_request = app_icon_it->second.pending_request;
+
+ if (pending_request) {
+ LOG4CXX_DEBUG(logger_, "Cloud app has already sent request");
+ continue;
+ }
+
+ std::string url = GetPolicyHandler().GetIconUrl(*enabled_it);
+
+ if (url.empty()) {
+ LOG4CXX_DEBUG(logger_, "No Icon Url for cloud app");
+ continue;
+ }
+
+ LOG4CXX_DEBUG(logger_, "Creating Get Icon Request");
+
+ smart_objects::SmartObjectSPtr message =
+ std::make_shared<smart_objects::SmartObject>(
+ smart_objects::SmartType_Map);
+ (*message)[strings::params][strings::function_id] =
+ mobile_apis::FunctionID::OnSystemRequestID;
+ (*message)[strings::params][strings::connection_key] = connection_key;
+ (*message)[strings::params][strings::message_type] =
+ mobile_apis::messageType::notification;
+ (*message)[strings::params][strings::protocol_version] =
+ application->protocol_version();
+ (*message)[strings::msg_params][strings::request_type] =
+ mobile_apis::RequestType::ICON_URL;
+ (*message)[strings::msg_params][strings::url] = url;
+
+ app_icon_it->second.pending_request = true;
+
+ rpc_service_->ManageMobileCommand(message, commands::Command::SOURCE_SDL);
+ }
+}
+
protocol_handler::MajorProtocolVersion
ApplicationManagerImpl::SupportedSDLVersion() const {
LOG4CXX_AUTO_TRACE(logger_);