summaryrefslogtreecommitdiff
path: root/src/components/config_profile
diff options
context:
space:
mode:
authorFrank Ronneburg <fronneburg@xevo.com>2018-04-05 03:21:41 +0900
committerfronneburg <fronneburg@xevo.com>2018-04-04 14:28:44 -0700
commit8af8e7142f33b00fb29f35e30f0811c519460e03 (patch)
treeb3c06edd7dcfb61693dcbde10c39b3d419bb5d48 /src/components/config_profile
parent926e8db70ceae88a4b11a028d9c37abbee9208e9 (diff)
downloadsdl_core-8af8e7142f33b00fb29f35e30f0811c519460e03.tar.gz
Merge pull request #229 in NAR/sdl-core from feat/disable_resumption_before_secondary_transport_2 to feature/Ford-WiFi
* commit 'bfe8579a831b873c8d0c1f950d46498ed3939a90': Enable retrying resumption after secondary transport is established Disable or limit resumption based on availability of high-bandwidth transport Add TransportRequiredForResumption and LowBandwidthTransportResumptionLevel sections in .ini file Update ReadStringContainer() Add required DeviceType enums Conflicts: src/components/include/test/application_manager/mock_application_manager.h src/components/include/transport_manager/transport_adapter/transport_adapter.h src/components/transport_manager/src/transport_adapter/transport_adapter_impl.cc
Diffstat (limited to 'src/components/config_profile')
-rw-r--r--src/components/config_profile/include/config_profile/profile.h57
-rw-r--r--src/components/config_profile/src/profile.cc244
-rw-r--r--src/components/config_profile/test/profile_test.cc45
3 files changed, 332 insertions, 14 deletions
diff --git a/src/components/config_profile/include/config_profile/profile.h b/src/components/config_profile/include/config_profile/profile.h
index e3f65b5a0f..a10559c90a 100644
--- a/src/components/config_profile/include/config_profile/profile.h
+++ b/src/components/config_profile/include/config_profile/profile.h
@@ -37,6 +37,7 @@
#include <string>
#include <vector>
#include <list>
+#include <map>
#include "utils/macro.h"
#include "protocol_handler/protocol_handler_settings.h"
#include "connection_handler/connection_handler_settings.h"
@@ -546,13 +547,17 @@ class Profile : public protocol_handler::ProtocolHandlerSettings,
* @param pKey The key whose value needs to be read out
* @param out_result Pointer to bool value for result reading Section
* (could be NULL)
+ * @param allow_empty If true, then out_result will be true when the value
+ * contains an empty string.
+ * If false, then out_result will be false in such case.
*
* @return container of values or empty continer
* if could not read the value out of the profile
*/
std::vector<std::string> ReadStringContainer(const char* const pSection,
const char* const pKey,
- bool* out_result) const;
+ bool* out_result,
+ bool allow_empty = false) const;
/**
* @brief Reads an container of hex int values from the profile,
* which handle as "0x01, 0xA0, 0XFF"
@@ -644,6 +649,33 @@ class Profile : public protocol_handler::ProtocolHandlerSettings,
uint16_t open_attempt_timeout_ms_resumption_db() const;
/**
+ * @brief Returns "transport required for resumption" map
+ *
+ * Keys of the map are AppHMIType strings, i.e. "DEFAULT", "COMMUNICATION",
+ * "MEDIA", and so on. The map may contain a special key "EMPTY_APP" for apps
+ * that does not specify any AppHMIType.
+ */
+ const std::map<std::string, std::vector<std::string> >&
+ transport_required_for_resumption_map() const OVERRIDE;
+
+ /**
+ * @brief Returns HMI level for resumption of a NAVIGATION app
+ */
+ const std::string& navigation_lowbandwidth_resumption_level() const OVERRIDE;
+
+ /**
+ * @brief Returns HMI level for resumption of a PROJECTION app
+ */
+ const std::string& projection_lowbandwidth_resumption_level() const OVERRIDE;
+
+ /**
+ * @brief Returns HMI level for resumption of a media app
+ *
+ * Note: this is not for AppHMIType = MEDIA.
+ */
+ const std::string& mediaapp_lowbandwidth_resumption_level() const OVERRIDE;
+
+ /**
* @brief Returns wait time after device connection
* before app launch request
*/
@@ -740,13 +772,29 @@ class Profile : public protocol_handler::ProtocolHandlerSettings,
* @param pKey The key whose value needs to be read out
*
* @return FALSE if could not read the value out of the profile
- * (then the value is not changed)
+ * (then the value is not changed) or the value was empty
*/
bool ReadValue(std::string* value,
const char* const pSection,
const char* const pKey) const;
/**
+ * @brief Reads a string value from the profile
+ *
+ * This is same as ReadValue(), except that this method will accept an empty
+ * string.
+ *
+ * @param value The value to return
+ * @param pSection The section to read the value in
+ * @param pKey The key whose value needs to be read out
+ *
+ * @return TRUE if the value is read, FALSE if the value is not found
+ */
+ bool ReadValueEmpty(std::string* value,
+ const char* const pSection,
+ const char* const pKey) const;
+
+ /**
* @brief Reads a boolean value from the profile
*
* @param value The value to return
@@ -946,6 +994,11 @@ class Profile : public protocol_handler::ProtocolHandlerSettings,
bool use_db_for_resumption_;
uint16_t attempts_to_open_resumption_db_;
uint16_t open_attempt_timeout_ms_resumption_db_;
+ std::map<std::string, std::vector<std::string> >
+ transport_required_for_resumption_map_;
+ std::string navigation_lowbandwidth_resumption_level_;
+ std::string projection_lowbandwidth_resumption_level_;
+ std::string mediaapps_lowbandwidth_resumption_level_;
uint16_t app_launch_wait_time_;
uint16_t app_launch_max_retry_attempt_;
uint16_t app_launch_retry_wait_time_;
diff --git a/src/components/config_profile/src/profile.cc b/src/components/config_profile/src/profile.cc
index 95ec94510f..ccf9e60ab8 100644
--- a/src/components/config_profile/src/profile.cc
+++ b/src/components/config_profile/src/profile.cc
@@ -90,6 +90,10 @@ const char* kResumptionSection = "Resumption";
const char* kAppLaunchSection = "AppLaunch";
const char* kMultipleTransportsSection = "MultipleTransports";
const char* kServicesMapSection = "ServicesMap";
+const char* kTransportRequiredForResumptionSection =
+ "TransportRequiredForResumption";
+const char* kLowBandwidthTransportResumptionLevelSection =
+ "LowBandwidthTransportResumptionLevel";
const char* kSDLVersionKey = "SDLVersion";
const char* kHmiCapabilitiesKey = "HMICapabilities";
@@ -223,6 +227,53 @@ const char* kSecondaryTransportForUSBKey = "SecondaryTransportForUSB";
const char* kSecondaryTransportForWiFiKey = "SecondaryTransportForWiFi";
const char* kAudioServiceTransportsKey = "AudioServiceTransports";
const char* kVideoServiceTransportsKey = "VideoServiceTransports";
+
+const char* kDefaultTransportRequiredForResumptionKey =
+ "DefaultTransportRequiredForResumption";
+const char* kAppHMITypeDefault = "DEFAULT";
+const char* kCommunicationTransportRequiredForResumptionKey =
+ "CommunicationTransportRequiredForResumption";
+const char* kAppHMITypeCommunication = "COMMUNICATION";
+const char* kMediaTransportRequiredForResumptionKey =
+ "MediaTransportRequiredForResumption";
+const char* kAppHMITypeMedia = "MEDIA";
+const char* kMessagingTransportRequiredForResumptionKey =
+ "MessagingTransportRequiredForResumption";
+const char* kAppHMITypeMessaging = "MESSAGING";
+const char* kNavigationTransportRequiredForResumptionKey =
+ "NavigationTransportRequiredForResumption";
+const char* kAppHMITypeNavigation = "NAVIGATION";
+const char* kInformationTransportRequiredForResumptionKey =
+ "InformationTransportRequiredForResumption";
+const char* kAppHMITypeInformation = "INFORMATION";
+const char* kSocialTransportRequiredForResumptionKey =
+ "SocialTransportRequiredForResumption";
+const char* kAppHMITypeSocial = "SOCIAL";
+const char* kBackgroundProcessTransportRequiredForResumptionKey =
+ "BackgroundProcessTransportRequiredForResumption";
+const char* kAppHMITypeBackgroundProcess = "BACKGROUND_PROCESS";
+const char* kTestingTransportRequiredForResumptionKey =
+ "TestingTransportRequiredForResumption";
+const char* kAppHMITypeTesting = "TESTING";
+const char* kSystemTransportRequiredForResumptionKey =
+ "SystemTransportRequiredForResumption";
+const char* kAppHMITypeSystem = "SYSTEM";
+const char* kProjectionTransportRequiredForResumptionKey =
+ "ProjectionTransportRequiredForResumption";
+const char* kAppHMITypeProjection = "PROJECTION";
+const char* kRemoteControlTransportRequiredForResumptionKey =
+ "RemoteControlTransportRequiredForResumption";
+const char* kAppHMITypeRemoteControl = "REMOTE_CONTROL";
+const char* kEmptyAppTransportRequiredForResumptionKey =
+ "EmptyAppTransportRequiredForResumption";
+const char* kAppHMITypeEmptyApp = "EMPTY_APP";
+const char* kNavigationLowBandwidthResumptionLevelKey =
+ "NavigationLowBandwidthResumptionLevel";
+const char* kProjectionLowBandwidthResumptionLevelKey =
+ "ProjectionLowBandwidthResumptionLevel";
+const char* kMediaLowBandwidthResumptionLevelKey =
+ "MediaLowBandwidthResumptionLevel";
+
#ifdef WEB_HMI
const char* kDefaultLinkToWebHMI = "HMI/index.html";
#endif // WEB_HMI
@@ -322,6 +373,7 @@ const uint32_t kDefaultAppTransportChangeTimerAddition = 0u;
const std::string kAllowedSymbols =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_.-";
const bool kDefaultMultipleTransportsEnabled = true;
+const char* kDefaultLowBandwidthResumptionLevel = "NONE";
} // namespace
namespace profile {
@@ -414,6 +466,12 @@ Profile::Profile()
, attempts_to_open_resumption_db_(kDefaultAttemptsToOpenResumptionDB)
, open_attempt_timeout_ms_resumption_db_(
kDefaultOpenAttemptTimeoutMsResumptionDB)
+ , navigation_lowbandwidth_resumption_level_(
+ kDefaultLowBandwidthResumptionLevel)
+ , projection_lowbandwidth_resumption_level_(
+ kDefaultLowBandwidthResumptionLevel)
+ , mediaapps_lowbandwidth_resumption_level_(
+ kDefaultLowBandwidthResumptionLevel)
, app_launch_wait_time_(kDefaultAppLaunchWaitTime)
, app_launch_max_retry_attempt_(kDefaultAppLaunchMaxRetryAttempt)
, app_launch_retry_wait_time_(kDefaultAppLaunchRetryWaitTime)
@@ -915,6 +973,23 @@ uint16_t Profile::open_attempt_timeout_ms_resumption_db() const {
return open_attempt_timeout_ms_resumption_db_;
}
+const std::map<std::string, std::vector<std::string> >&
+Profile::transport_required_for_resumption_map() const {
+ return transport_required_for_resumption_map_;
+}
+
+const std::string& Profile::navigation_lowbandwidth_resumption_level() const {
+ return navigation_lowbandwidth_resumption_level_;
+}
+
+const std::string& Profile::projection_lowbandwidth_resumption_level() const {
+ return projection_lowbandwidth_resumption_level_;
+}
+
+const std::string& Profile::mediaapp_lowbandwidth_resumption_level() const {
+ return mediaapps_lowbandwidth_resumption_level_;
+}
+
const uint16_t Profile::app_launch_max_retry_attempt() const {
return app_launch_max_retry_attempt_;
}
@@ -1891,6 +1966,86 @@ void Profile::UpdateValues() {
kOpenAttemptTimeoutMsResumptionDBKey,
kResumptionSection);
+ { // read parameters from TransportRequiredForResumption section
+ struct KeyPair {
+ const char* ini_key_name;
+ const char* map_key_name;
+ } keys[] = {
+ {kDefaultTransportRequiredForResumptionKey, kAppHMITypeDefault},
+ {kCommunicationTransportRequiredForResumptionKey,
+ kAppHMITypeCommunication},
+ {kMediaTransportRequiredForResumptionKey, kAppHMITypeMedia},
+ {kMessagingTransportRequiredForResumptionKey, kAppHMITypeMessaging},
+ {kNavigationTransportRequiredForResumptionKey, kAppHMITypeNavigation},
+ {kInformationTransportRequiredForResumptionKey, kAppHMITypeInformation},
+ {kSocialTransportRequiredForResumptionKey, kAppHMITypeSocial},
+ {kBackgroundProcessTransportRequiredForResumptionKey,
+ kAppHMITypeBackgroundProcess},
+ {kTestingTransportRequiredForResumptionKey, kAppHMITypeTesting},
+ {kSystemTransportRequiredForResumptionKey, kAppHMITypeSystem},
+ {kProjectionTransportRequiredForResumptionKey, kAppHMITypeProjection},
+ {kRemoteControlTransportRequiredForResumptionKey,
+ kAppHMITypeRemoteControl},
+ {kEmptyAppTransportRequiredForResumptionKey, kAppHMITypeEmptyApp},
+ {NULL, NULL}};
+ struct KeyPair* entry = keys;
+
+ while (entry->ini_key_name != NULL) {
+ bool exist = false;
+ std::vector<std::string> transport_list =
+ ReadStringContainer(kTransportRequiredForResumptionSection,
+ entry->ini_key_name,
+ &exist,
+ true);
+ if (exist) {
+ transport_required_for_resumption_map_[entry->map_key_name] =
+ transport_list;
+
+ std::stringstream ss;
+ for (std::vector<std::string>::iterator it = transport_list.begin();
+ it != transport_list.end();
+ ++it) {
+ if (it != transport_list.begin()) {
+ ss << ", ";
+ }
+ ss << *it;
+ }
+ LOG_UPDATED_VALUE(ss.str(),
+ entry->ini_key_name,
+ kTransportRequiredForResumptionSection);
+ }
+ entry++;
+ }
+ }
+
+ // Read parameters from LowBandwidthTransportResumptionLevel section
+ ReadStringValue(&navigation_lowbandwidth_resumption_level_,
+ kDefaultLowBandwidthResumptionLevel,
+ kLowBandwidthTransportResumptionLevelSection,
+ kNavigationLowBandwidthResumptionLevelKey);
+
+ LOG_UPDATED_VALUE(navigation_lowbandwidth_resumption_level_,
+ kNavigationLowBandwidthResumptionLevelKey,
+ kLowBandwidthTransportResumptionLevelSection);
+
+ ReadStringValue(&projection_lowbandwidth_resumption_level_,
+ kDefaultLowBandwidthResumptionLevel,
+ kLowBandwidthTransportResumptionLevelSection,
+ kProjectionLowBandwidthResumptionLevelKey);
+
+ LOG_UPDATED_VALUE(projection_lowbandwidth_resumption_level_,
+ kProjectionLowBandwidthResumptionLevelKey,
+ kLowBandwidthTransportResumptionLevelSection);
+
+ ReadStringValue(&mediaapps_lowbandwidth_resumption_level_,
+ kDefaultLowBandwidthResumptionLevel,
+ kLowBandwidthTransportResumptionLevelSection,
+ kMediaLowBandwidthResumptionLevelKey);
+
+ LOG_UPDATED_VALUE(mediaapps_lowbandwidth_resumption_level_,
+ kMediaLowBandwidthResumptionLevelKey,
+ kLowBandwidthTransportResumptionLevelSection);
+
// Read parameters from App Launch section
ReadUIntValue(&app_launch_wait_time_,
kDefaultAppLaunchWaitTime,
@@ -1976,14 +2131,46 @@ void Profile::UpdateValues() {
LOG_UPDATED_BOOL_VALUE(
multiple_transports_enabled_, kMultipleTransportsEnabledKey, kMultipleTransportsSection);
- // Secondary Transports
- secondary_transports_for_bluetooth_ = ReadStringContainer(kMultipleTransportsSection, kSecondaryTransportForBluetoothKey, NULL);
- secondary_transports_for_usb_ = ReadStringContainer(kMultipleTransportsSection, kSecondaryTransportForUSBKey, NULL);
- secondary_transports_for_wifi_ = ReadStringContainer(kMultipleTransportsSection, kSecondaryTransportForWiFiKey, NULL);
-
- // Services Map
- audio_service_transports_ = ReadStringContainer(kServicesMapSection, kAudioServiceTransportsKey, NULL);
- video_service_transports_ = ReadStringContainer(kServicesMapSection, kVideoServiceTransportsKey, NULL);
+ { // Secondary Transports and ServicesMap
+ struct KeyPair {
+ std::vector<std::string> *ini_vector;
+ const char* ini_section_name;
+ const char* ini_key_name;
+ } keys[] = {
+ {&secondary_transports_for_bluetooth_, kMultipleTransportsSection, kSecondaryTransportForBluetoothKey},
+ {&secondary_transports_for_usb_, kMultipleTransportsSection, kSecondaryTransportForUSBKey},
+ {&secondary_transports_for_wifi_, kMultipleTransportsSection, kSecondaryTransportForWiFiKey},
+ {&audio_service_transports_, kServicesMapSection, kAudioServiceTransportsKey},
+ {&video_service_transports_, kServicesMapSection, kVideoServiceTransportsKey},
+ {NULL, NULL, NULL}};
+ struct KeyPair* entry = keys;
+
+ while (entry->ini_vector != NULL) {
+ bool exist = false;
+ std::vector<std::string> profile_entry =
+ ReadStringContainer(entry->ini_section_name,
+ entry->ini_key_name,
+ &exist,
+ true);
+ if (exist) {
+ *entry->ini_vector = profile_entry;
+
+ std::stringstream ss;
+ for (std::vector<std::string>::iterator it = profile_entry.begin();
+ it != profile_entry.end();
+ ++it) {
+ if (it != profile_entry.begin()) {
+ ss << ", ";
+ }
+ ss << *it;
+ }
+ LOG_UPDATED_VALUE(ss.str(),
+ entry->ini_key_name,
+ entry->ini_section_name);
+ }
+ entry++;
+ }
+ }
}
bool Profile::ReadValue(bool* value,
@@ -2023,6 +2210,22 @@ bool Profile::ReadValue(std::string* value,
return ret;
}
+bool Profile::ReadValueEmpty(std::string* value,
+ const char* const pSection,
+ const char* const pKey) const {
+ DCHECK(value);
+ bool ret = false;
+
+ char buf[INI_LINE_LEN + 1];
+ *buf = '\0';
+ if (0 != ini_read_value(config_file_name_.c_str(), pSection, pKey, buf)) {
+ *value = buf;
+ ret = true;
+ }
+
+ return ret;
+}
+
bool Profile::ReadStringValue(std::string* value,
const char* default_value,
const char* const pSection,
@@ -2081,6 +2284,18 @@ namespace {
int32_t hex_to_int(const std::string& value) {
return static_cast<int32_t>(strtol(value.c_str(), NULL, 16));
}
+
+std::string trim_string(const std::string& str) {
+ const char* delims = " \t";
+
+ size_t start = str.find_first_not_of(delims);
+ if (std::string::npos == start) {
+ return std::string();
+ }
+ size_t end = str.find_last_not_of(delims);
+
+ return str.substr(start, end - start + 1);
+}
}
std::vector<int> Profile::ReadIntContainer(const char* const pSection,
@@ -2098,9 +2313,15 @@ std::vector<int> Profile::ReadIntContainer(const char* const pSection,
std::vector<std::string> Profile::ReadStringContainer(
const char* const pSection,
const char* const pKey,
- bool* out_result) const {
+ bool* out_result,
+ bool allow_empty) const {
std::string string;
- const bool result = ReadValue(&string, pSection, pKey);
+ bool result;
+ if (allow_empty) {
+ result = ReadValueEmpty(&string, pSection, pKey);
+ } else {
+ result = ReadValue(&string, pSection, pKey);
+ }
if (out_result)
*out_result = result;
std::vector<std::string> value_container;
@@ -2110,8 +2331,7 @@ std::vector<std::string> Profile::ReadStringContainer(
while (iss) {
if (!getline(iss, temp_str, ','))
break;
- value_container.push_back(temp_str);
- LOG_UPDATED_VALUE(temp_str, pKey, pSection);
+ value_container.push_back(trim_string(temp_str));
}
}
return value_container;
diff --git a/src/components/config_profile/test/profile_test.cc b/src/components/config_profile/test/profile_test.cc
index e7d62f4740..f1527c996b 100644
--- a/src/components/config_profile/test/profile_test.cc
+++ b/src/components/config_profile/test/profile_test.cc
@@ -694,6 +694,30 @@ TEST_F(ProfileTest, CheckStringContainer) {
EXPECT_EQ(diag_mode, element_mode);
}
+TEST_F(ProfileTest, CheckStringContainerEmpty) {
+ // Set new config file
+ profile_.set_config_file_name("smartDeviceLink_test.ini");
+ EXPECT_EQ("smartDeviceLink_test.ini", profile_.config_file_name());
+
+ bool isread = false;
+ std::vector<std::string> output_list =
+ profile_.ReadStringContainer("MAIN", "AppConfigFolder", &isread);
+ EXPECT_FALSE(isread);
+ EXPECT_TRUE(output_list.empty());
+
+ isread = false;
+ std::vector<std::string> output_list2 =
+ profile_.ReadStringContainer("MAIN", "AppConfigFolder", &isread, true);
+ EXPECT_TRUE(isread);
+ EXPECT_TRUE(output_list2.empty());
+
+ isread = false;
+ std::vector<std::string> output_list3 =
+ profile_.ReadStringContainer("MAIN", "DoesNotExistKey", &isread, true);
+ EXPECT_FALSE(isread);
+ EXPECT_TRUE(output_list2.empty());
+}
+
#ifdef ENABLE_SECURITY
TEST_F(ProfileTest, CheckIntContainerInSecurityData) {
// Set new config file
@@ -724,6 +748,27 @@ TEST_F(ProfileTest, CheckIntContainerInSecurityData) {
}
#endif
+TEST_F(ProfileTest, CheckEmptyValue) {
+ // Set new config file
+ profile_.set_config_file_name("smartDeviceLink_test.ini");
+ EXPECT_EQ("smartDeviceLink_test.ini", profile_.config_file_name());
+
+ bool isread = false;
+ std::string output;
+
+ // specify a key with empty value
+ bool ret = profile_.ReadValue(&output, "MAIN", "AppConfigFolder");
+ EXPECT_FALSE(ret);
+
+ std::string output2 = "abc";
+ ret = profile_.ReadValueEmpty(&output2, "MAIN", "AppConfigFolder");
+ EXPECT_TRUE(ret);
+ EXPECT_EQ(output2, "");
+
+ ret = profile_.ReadValueEmpty(&output2, "MAIN", "DoesNotExistKey");
+ EXPECT_FALSE(ret);
+}
+
} // namespace profile_test
} // namespace components
} // namespace test