summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
authorJackLivio <jack@livio.io>2017-05-12 09:18:20 -0400
committerGitHub <noreply@github.com>2017-05-12 09:18:20 -0400
commitaaeafb7b96e1bec140e94fe7f31e6f9922402dd7 (patch)
tree5b83b804f63a97015871361c1246bffc23b61b1a /src/components
parent962a63d5d66bc9252c8b0fd46c12d3830b1f1354 (diff)
parentacfcca4334380d770afd43aef88809971aa14d52 (diff)
downloadsdl_core-aaeafb7b96e1bec140e94fe7f31e6f9922402dd7.tar.gz
Merge pull request #1478 from LitvinenkoIra/fix/cycling_urls_refactoring
Fix SDL omits one of the URLs during retry sequence
Diffstat (limited to 'src/components')
-rw-r--r--src/components/application_manager/include/application_manager/policies/policy_handler.h11
-rw-r--r--src/components/application_manager/src/policies/policy_handler.cc49
-rw-r--r--src/components/application_manager/test/policy_handler_test.cc11
-rw-r--r--src/components/include/policy/policy_external/policy/policy_manager.h20
-rw-r--r--src/components/include/policy/policy_regular/policy/policy_manager.h20
-rw-r--r--src/components/include/policy/policy_regular/policy/policy_types.h20
-rw-r--r--src/components/include/test/policy/policy_external/policy/mock_policy_manager.h4
-rw-r--r--src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h4
-rw-r--r--src/components/policy/policy_external/include/policy/policy_manager_impl.h12
-rw-r--r--src/components/policy/policy_external/include/policy/policy_types.h20
-rw-r--r--src/components/policy/policy_external/src/policy_manager_impl.cc45
-rw-r--r--src/components/policy/policy_regular/include/policy/policy_manager.h486
-rw-r--r--src/components/policy/policy_regular/include/policy/policy_manager_impl.h12
-rw-r--r--src/components/policy/policy_regular/src/policy_manager_impl.cc42
14 files changed, 241 insertions, 515 deletions
diff --git a/src/components/application_manager/include/application_manager/policies/policy_handler.h b/src/components/application_manager/include/application_manager/policies/policy_handler.h
index 7aca49a96a..ea69b9fb7e 100644
--- a/src/components/application_manager/include/application_manager/policies/policy_handler.h
+++ b/src/components/application_manager/include/application_manager/policies/policy_handler.h
@@ -570,6 +570,17 @@ class PolicyHandler : public PolicyHandlerInterface,
application_manager::ApplicationManager& application_manager_;
friend class AppPermissionDelegate;
+ /**
+ * @brief Checks if the application with the given policy
+ * application id is registered or it is default id
+ * @param app_idx Application idx from EndpointUrls vector
+ * @param urls EndpointUrls vector
+ * @return TRUE if the vector with URLs with given idx is not empty
+ * and is related to a registered application or these are default URLs,
+ * otherwise FALSE
+ */
+ bool IsUrlAppIdValid(const uint32_t app_idx, const EndpointUrls& urls) const;
+
DISALLOW_COPY_AND_ASSIGN(PolicyHandler);
};
diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc
index 9336c6199e..ab09bbc23c 100644
--- a/src/components/application_manager/src/policies/policy_handler.cc
+++ b/src/components/application_manager/src/policies/policy_handler.cc
@@ -484,6 +484,12 @@ void PolicyHandler::GetAvailableApps(std::queue<std::string>& apps) {
}
}
+struct SmartObjectToInt {
+ int operator()(const smart_objects::SmartObject& item) const {
+ return item.asInt();
+ }
+};
+
StatusNotifier PolicyHandler::AddApplication(
const std::string& application_id) {
POLICY_LIB_CHECK(utils::MakeShared<utils::CallNothing>());
@@ -1366,32 +1372,12 @@ void PolicyHandler::OnSnapshotCreated(const BinaryMessage& pt_string) {
return;
}
- static size_t current_app = 0;
- static size_t current_url = 0;
- if (current_url >= urls.at(current_app).url.size()) {
- ApplicationSharedPtr app;
- current_url = 0;
-
- bool is_default = false;
- bool is_registered = false;
- bool has_urls = false;
- bool valid_app_found = false;
- do {
- if (++current_app >= urls.size()) {
- current_app = 0;
- }
- const std::string& app_id = urls.at(current_app).app_id;
- app = application_manager_.application_by_policy_id(app_id);
-
- is_default = (app_id == policy::kDefaultId);
- is_registered = (app && app->IsRegistered());
- has_urls = !urls.at(current_app).url.empty();
- valid_app_found = (is_default || (is_registered && has_urls));
- } while (!valid_app_found);
+ AppIdURL app_url = policy_manager_->GetNextUpdateUrl(urls);
+ while (!IsUrlAppIdValid(app_url.first, urls)) {
+ app_url = policy_manager_->GetNextUpdateUrl(urls);
}
-
- SendMessageToSDK(pt_string, urls.at(current_app).url.at(current_url));
- current_url++;
+ const std::string& url = urls[app_url.first].url[app_url.second];
+ SendMessageToSDK(pt_string, url);
#endif // PROPRIETARY_MODE
// reset update required false
OnUpdateRequestSentToMobile();
@@ -1819,4 +1805,17 @@ void PolicyHandler::Add(const std::string& app_id,
policy_manager_->Add(app_id, type, timespan_seconds);
}
+bool PolicyHandler::IsUrlAppIdValid(const uint32_t app_idx,
+ const EndpointUrls& urls) const {
+ const EndpointData& app_data = urls[app_idx];
+ const std::vector<std::string> app_urls = app_data.url;
+ const ApplicationSharedPtr app =
+ application_manager_.application_by_policy_id(app_data.app_id);
+
+ const bool is_registered = (app && (app->IsRegistered()));
+ const bool is_default = (app_data.app_id == policy::kDefaultId);
+ const bool is_empty_urls = app_urls.empty();
+
+ return ((is_registered && !is_empty_urls) || is_default);
+}
} // namespace policy
diff --git a/src/components/application_manager/test/policy_handler_test.cc b/src/components/application_manager/test/policy_handler_test.cc
index 4f80f2e464..36e7343442 100644
--- a/src/components/application_manager/test/policy_handler_test.cc
+++ b/src/components/application_manager/test/policy_handler_test.cc
@@ -85,6 +85,8 @@ using ::testing::DoAll;
using ::testing::SetArgReferee;
using ::testing::Mock;
+const std::string kDummyData = "some_data";
+
class PolicyHandlerTest : public ::testing::Test {
public:
PolicyHandlerTest()
@@ -1349,14 +1351,20 @@ TEST_F(PolicyHandlerTest, OnSnapshotCreated_UrlAdded) {
EnablePolicyAndPolicyManagerMock();
BinaryMessage msg;
EndpointUrls test_data;
- EndpointData data("some_data");
+ EndpointData data(kDummyData);
test_data.push_back(data);
+ ApplicationSharedPtr mock_app;
#ifdef PROPRIETARY_MODE
ExtendedPolicyExpectations();
#else
+ AppIdURL next_app_url = std::make_pair(0, 0);
EXPECT_CALL(*mock_policy_manager_, GetUpdateUrls("0x07", _))
.WillRepeatedly(SetArgReferee<1>(test_data));
+ EXPECT_CALL(*mock_policy_manager_, GetNextUpdateUrl(_))
+ .WillOnce(Return(next_app_url));
+ EXPECT_CALL(app_manager_, application_by_policy_id(_))
+ .WillOnce(Return(mock_app));
EXPECT_CALL(app_manager_, connection_handler())
.WillOnce(ReturnRef(conn_handler));
EXPECT_CALL(conn_handler, get_session_observer())
@@ -1372,6 +1380,7 @@ TEST_F(PolicyHandlerTest, OnSnapshotCreated_UrlAdded) {
EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(kPolicyAppId_));
#endif // PROPRIETARY_MODE
+ EXPECT_CALL(*mock_policy_manager_, OnUpdateStarted());
policy_handler_.OnSnapshotCreated(msg);
}
#endif // EXTERNAL_PROPRIETARY_MODE
diff --git a/src/components/include/policy/policy_external/policy/policy_manager.h b/src/components/include/policy/policy_external/policy/policy_manager.h
index 7d5bbb5e52..6028a1674e 100644
--- a/src/components/include/policy/policy_external/policy/policy_manager.h
+++ b/src/components/include/policy/policy_external/policy/policy_manager.h
@@ -481,6 +481,26 @@ class PolicyManager : public usage_statistics::StatisticsManager {
virtual const PolicySettings& get_settings() const = 0;
+ /**
+ * @brief Finds the next URL that must be sent on OnSystemRequest retry
+ * @param urls vector of vectors that contain urls for each application
+ * @return Pair of policy application id and application url id from the
+ * urls vector
+ */
+ virtual AppIdURL GetNextUpdateUrl(const EndpointUrls& urls) = 0;
+
+ /**
+ * @brief Checks if there is existing URL in the EndpointUrls vector with
+ * index saved in the policy manager and if not, it moves to the next
+ * application index
+ * @param rs contains the application index and url index from the
+ * urls vector that are to be sent on the next OnSystemRequest
+ * @param urls vector of vectors that contain urls for each application
+ * @return Pair of application index and url index
+ */
+ virtual AppIdURL RetrySequenceUrl(const struct RetrySequenceURL& rs,
+ const EndpointUrls& urls) const = 0;
+
protected:
/**
* Checks is PT exceeded IgnitionCycles
diff --git a/src/components/include/policy/policy_regular/policy/policy_manager.h b/src/components/include/policy/policy_regular/policy/policy_manager.h
index 0bd72faaae..fcdf48e8cf 100644
--- a/src/components/include/policy/policy_regular/policy/policy_manager.h
+++ b/src/components/include/policy/policy_regular/policy/policy_manager.h
@@ -457,6 +457,26 @@ class PolicyManager : public usage_statistics::StatisticsManager {
virtual const PolicySettings& get_settings() const = 0;
+ /**
+ * @brief Finds the next URL that must be sent on OnSystemRequest retry
+ * @param urls vector of vectors that contain urls for each application
+ * @return Pair of policy application id and application url id from the
+ * urls vector
+ */
+ virtual AppIdURL GetNextUpdateUrl(const EndpointUrls& urls) = 0;
+
+ /**
+ * @brief Checks if there is existing URL in the EndpointUrls vector with
+ * index saved in the policy manager and if not, it moves to the next
+ * application index
+ * @param rs contains the application index and url index from the
+ * urls vector that are to be sent on the next OnSystemRequest
+ * @param urls vector of vectors that contain urls for each application
+ * @return Pair of application index and url index
+ */
+ virtual AppIdURL RetrySequenceUrl(const struct RetrySequenceURL& rs,
+ const EndpointUrls& urls) const = 0;
+
protected:
/**
* Checks is PT exceeded IgnitionCycles
diff --git a/src/components/include/policy/policy_regular/policy/policy_types.h b/src/components/include/policy/policy_regular/policy/policy_types.h
index b3843f8889..dbd910d62d 100644
--- a/src/components/include/policy/policy_regular/policy/policy_types.h
+++ b/src/components/include/policy/policy_regular/policy/policy_types.h
@@ -313,6 +313,26 @@ struct MetaInfo {
std::string language;
};
+/**
+ * @brief The index of the application, the index of its URL
+ * and the policy application id from the Endpoints vector
+ * that will be sent on the next OnSystemRequest retry sequence
+ */
+struct RetrySequenceURL {
+ uint32_t app_idx_;
+ uint32_t url_idx_;
+ std::string policy_app_id_;
+ RetrySequenceURL(uint32_t app, uint32_t url, const std::string& app_id)
+ : app_idx_(app), url_idx_(url), policy_app_id_(app_id) {}
+ RetrySequenceURL() : app_idx_(0), url_idx_(0) {}
+};
+
+/**
+ * @brief Index of the application, index of its URL
+ * from the Endpoints vector
+ */
+typedef std::pair<uint32_t, uint32_t> AppIdURL;
+
} // namespace policy
#endif // SRC_COMPONENTS_INCLUDE_POLICY_POLICY_TYPES_H_
diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h
index 0140efddf5..30c1496495 100644
--- a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h
+++ b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h
@@ -182,6 +182,10 @@ class MockPolicyManager : public PolicyManager {
int32_t timespan_seconds));
MOCK_CONST_METHOD0(get_settings, const PolicySettings&());
MOCK_METHOD1(set_settings, void(const PolicySettings* get_settings));
+ MOCK_METHOD1(GetNextUpdateUrl, AppIdURL(const EndpointUrls& urls));
+ MOCK_CONST_METHOD2(RetrySequenceUrl,
+ AppIdURL(const struct RetrySequenceURL&,
+ const EndpointUrls& urls));
};
} // namespace policy_manager_test
} // namespace components
diff --git a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h
index 638f33399c..16e647dfba 100644
--- a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h
+++ b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h
@@ -184,6 +184,10 @@ class MockPolicyManager : public PolicyManager {
MOCK_CONST_METHOD0(get_settings, const PolicySettings&());
MOCK_METHOD1(set_settings, void(const PolicySettings* get_settings));
MOCK_CONST_METHOD0(GetLockScreenIconUrl, std::string());
+ MOCK_METHOD1(GetNextUpdateUrl, AppIdURL(const EndpointUrls& urls));
+ MOCK_CONST_METHOD2(RetrySequenceUrl,
+ AppIdURL(const struct RetrySequenceURL&,
+ const EndpointUrls& urls));
};
} // namespace policy_manager_test
diff --git a/src/components/policy/policy_external/include/policy/policy_manager_impl.h b/src/components/policy/policy_external/include/policy/policy_manager_impl.h
index 55b5ab1212..2d64a5a4e1 100644
--- a/src/components/policy/policy_external/include/policy/policy_manager_impl.h
+++ b/src/components/policy/policy_external/include/policy/policy_manager_impl.h
@@ -205,6 +205,11 @@ class PolicyManagerImpl : public PolicyManager {
const PolicySettings& get_settings() const OVERRIDE;
+ AppIdURL GetNextUpdateUrl(const EndpointUrls& urls) OVERRIDE;
+
+ AppIdURL RetrySequenceUrl(const struct RetrySequenceURL& rs,
+ const EndpointUrls& urls) const OVERRIDE;
+
protected:
virtual utils::SharedPtr<policy_table::Table> Parse(
const BinaryMessage& pt_content);
@@ -335,6 +340,13 @@ class PolicyManagerImpl : public PolicyManager {
const PolicySettings* settings_;
friend struct CheckAppPolicy;
+
+ /**
+ * @brief Pair of app index and url index from Endpoints vector
+ * that contains all application URLs
+ */
+ RetrySequenceURL retry_sequence_url_;
+ friend struct ProccessAppGroups;
};
} // namespace policy
diff --git a/src/components/policy/policy_external/include/policy/policy_types.h b/src/components/policy/policy_external/include/policy/policy_types.h
index e0f7d89ae9..a0eefda555 100644
--- a/src/components/policy/policy_external/include/policy/policy_types.h
+++ b/src/components/policy/policy_external/include/policy/policy_types.h
@@ -364,6 +364,26 @@ struct MetaInfo {
std::string language;
};
+/**
+ * @brief The index of the application, the index of its URL
+ * and the policy application id from the Endpoints vector
+ * that will be sent on the next OnSystemRequest retry sequence
+ */
+struct RetrySequenceURL {
+ uint32_t app_idx_;
+ uint32_t url_idx_;
+ std::string policy_app_id_;
+ RetrySequenceURL(uint32_t app, uint32_t url, const std::string& app_id)
+ : app_idx_(app), url_idx_(url), policy_app_id_(app_id) {}
+ RetrySequenceURL() : app_idx_(0), url_idx_(0) {}
+};
+
+/**
+ * @brief Index of the application, index of its URL
+ * from the Endpoints vector
+ */
+typedef std::pair<uint32_t, uint32_t> AppIdURL;
+
} // namespace policy
#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TYPES_H_
diff --git a/src/components/policy/policy_external/src/policy_manager_impl.cc b/src/components/policy/policy_external/src/policy_manager_impl.cc
index 68602db712..423691796c 100644
--- a/src/components/policy/policy_external/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_external/src/policy_manager_impl.cc
@@ -66,7 +66,8 @@ PolicyManagerImpl::PolicyManagerImpl()
, cache_(new CacheManager)
, retry_sequence_timeout_(60)
, retry_sequence_index_(0)
- , ignition_check(true) {}
+ , ignition_check(true)
+ , retry_sequence_url_(0, 0, "") {}
PolicyManagerImpl::PolicyManagerImpl(bool in_memory)
: PolicyManager()
@@ -74,7 +75,8 @@ PolicyManagerImpl::PolicyManagerImpl(bool in_memory)
, cache_(new CacheManager(in_memory))
, retry_sequence_timeout_(60)
, retry_sequence_index_(0)
- , ignition_check(true) {}
+ , ignition_check(true)
+ , retry_sequence_url_(0, 0, "") {}
void PolicyManagerImpl::set_listener(PolicyListener* listener) {
listener_ = listener;
@@ -1190,6 +1192,45 @@ void PolicyManagerImpl::SetDecryptedCertificate(
cache_->SetDecryptedCertificate(certificate);
}
+AppIdURL PolicyManagerImpl::GetNextUpdateUrl(const EndpointUrls& urls) {
+ LOG4CXX_AUTO_TRACE(logger_);
+
+ const AppIdURL next_app_url = RetrySequenceUrl(retry_sequence_url_, urls);
+
+ retry_sequence_url_.url_idx_ = next_app_url.second + 1;
+ retry_sequence_url_.app_idx_ = next_app_url.first;
+ retry_sequence_url_.policy_app_id_ = urls[next_app_url.first].app_id;
+
+ return next_app_url;
+}
+
+AppIdURL PolicyManagerImpl::RetrySequenceUrl(const struct RetrySequenceURL& rs,
+ const EndpointUrls& urls) const {
+ uint32_t url_idx = rs.url_idx_;
+ uint32_t app_idx = rs.app_idx_;
+ const std::string& app_id = rs.policy_app_id_;
+
+ if (urls.size() <= app_idx) {
+ // Index of current application doesn't exist any more due to app(s)
+ // unregistration
+ url_idx = 0;
+ app_idx = 0;
+ } else if (urls[app_idx].app_id != app_id) {
+ // Index of current application points to another one due to app(s)
+ // registration/unregistration
+ url_idx = 0;
+ } else if (url_idx >= urls[app_idx].url.size()) {
+ // Index of current application is OK, but all of its URL are sent,
+ // move to the next application
+ url_idx = 0;
+ if (++app_idx >= urls.size()) {
+ app_idx = 0;
+ }
+ }
+
+ return std::make_pair(app_idx, url_idx);
+}
+
/**
* @brief The CallStatusChange class notify update manager aboun new application
*/
diff --git a/src/components/policy/policy_regular/include/policy/policy_manager.h b/src/components/policy/policy_regular/include/policy/policy_manager.h
deleted file mode 100644
index 0bd72faaae..0000000000
--- a/src/components/policy/policy_regular/include/policy/policy_manager.h
+++ /dev/null
@@ -1,486 +0,0 @@
-/*
- Copyright (c) 2016, Ford Motor Company
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-
- Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following
- disclaimer in the documentation and/or other materials provided with the
- distribution.
-
- Neither the name of the Ford Motor Company nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_POLICY_MANAGER_H_
-#define SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_POLICY_MANAGER_H_
-
-#include <vector>
-#include <cstdint>
-
-#include "utils/callable.h"
-#include "policy/policy_types.h"
-#include "policy/policy_listener.h"
-#include "policy/usage_statistics/statistics_manager.h"
-
-namespace policy {
-class PolicySettings;
-typedef utils::SharedPtr<utils::Callable> StatusNotifier;
-
-class PolicyManager : public usage_statistics::StatisticsManager {
- public:
- virtual ~PolicyManager() {}
-
- virtual void set_listener(PolicyListener* listener) = 0;
-
- /**
- * Inits Policy Table
- * @param file_name Path to preloaded PT file
- * @return true if successfully
- */
- virtual bool InitPT(const std::string& file_name,
- const PolicySettings* settings) = 0;
-
- /**
- * @brief Updates Policy Table from binary message received from
- * mobile device. Saves to Policy Table diff between Policy Table
- * sent in snapshot and received Policy Table.
- * @param file name of file with update policy table
- * @param pt_content PTU as binary string
- * @return bool Success of operation
- */
- virtual bool LoadPT(const std::string& file,
- const BinaryMessage& pt_content) = 0;
-
- /**
- * Resets Policy Table
- * @param file_name Path to preloaded PT file
- * @return true if successfully
- */
- virtual bool ResetPT(const std::string& file_name) = 0;
-
- /**
- * @brief GetLockScreenIcon allows to obtain lock screen icon url;
- *
- * @return url which point to the resourse where lock screen icon could be
- *obtained.
- */
- virtual std::string GetLockScreenIconUrl() const = 0;
-
- /**
- * @brief Gets all URLs for sending PTS to from PT itself.
- * @param service_type Service specifies user of URL
- * @return vector of urls
- */
- virtual void GetUpdateUrls(const std::string& service_type,
- EndpointUrls& out_end_points) = 0;
- virtual void GetUpdateUrls(const uint32_t service_type,
- EndpointUrls& out_end_points) = 0;
-
- /**
- * @brief PTU is needed, for this PTS has to be formed and sent.
- */
- virtual bool RequestPTUpdate() = 0;
-
- /**
- * @brief Check if specified RPC for specified application
- * has permission to be executed in specified HMI Level
- * and also its permitted params.
- * @param app_id Id of application provided during registration
- * @param hmi_level Current HMI Level of application
- * @param rpc Name of RPC
- * @param CheckPermissionResult containing flag if HMI Level is allowed
- * and list of allowed params.
- */
- virtual void CheckPermissions(const PTString& app_id,
- const PTString& hmi_level,
- const PTString& rpc,
- const RPCParams& rpc_params,
- CheckPermissionResult& result) = 0;
-
- /**
- * @brief Clear all record of user consents. Used during Factory Reset.
- * @return bool Success of operation
- */
- virtual bool ResetUserConsent() = 0;
-
- /**
- * @brief Returns current status of policy table for HMI
- * @return Current status of policy table
- */
- virtual std::string GetPolicyTableStatus() const = 0;
-
- /**
- * Checks is PT exceeded kilometers
- * @param kilometers current kilometers at odometer
- * @return true if exceeded
- */
- virtual void KmsChanged(int kilometers) = 0;
-
- /**
- * Increments counter of ignition cycles
- */
- virtual void IncrementIgnitionCycles() = 0;
-
- /**
- * @brief ExchangeByUserRequest
- */
- virtual std::string ForcePTExchange() = 0;
-
- /**
- * Resets retry sequence
- */
- virtual void ResetRetrySequence() = 0;
-
- /**
- * Gets timeout to wait before next retry updating PT
- * If timeout is equal to zero then the retry sequence is not need.
- * @return timeout in seconds
- */
- virtual uint32_t NextRetryTimeout() = 0;
-
- /**
- * Gets timeout to wait until receive response
- * @return timeout in seconds
- */
- virtual uint32_t TimeoutExchangeMSec() = 0;
-
- /**
- * @brief List of timeouts in seconds between retries
- * when attempt to update PT fails
- * @return List of delays between attempts.
- */
- virtual const std::vector<int> RetrySequenceDelaysSeconds() = 0;
-
- /**
- * Handler of exceeding timeout of exchanging policy table
- */
- virtual void OnExceededTimeout() = 0;
-
- /**
- * @brief Handler of PTS sending out
- */
- virtual void OnUpdateStarted() = 0;
-
- /**
- * @brief Check user consent for mobile device data connection
- * @param device_id Unique device identifier
- * @return status of device consent
- */
- virtual DeviceConsent GetUserConsentForDevice(
- const std::string& device_id) const = 0;
-
- /**
- * @brief Get user consent for application
- * @param device_id Device id
- * @param policy_app_id Unique application id
- * @param permissions Array of functional groups permissions
- */
- virtual void GetUserConsentForApp(
- const std::string& device_id,
- const std::string& policy_app_id,
- std::vector<FunctionalGroupPermission>& permissions) = 0;
-
- /**
- * @brief Set user consent for mobile device data connection
- * @param device_id Unique device identifier
- * @param is_allowed User consent for usage device data connection
- */
- virtual void SetUserConsentForDevice(const std::string& device_id,
- bool is_allowed) = 0;
-
- /**
- * @brief Update Application Policies as reaction
- * on User allowing/disallowing device this app is running on.
- */
- virtual bool ReactOnUserDevConsentForApp(const std::string app_id,
- bool is_device_allowed) = 0;
- /**
- * Sets counter value that passed for receiving PT UPdate.
- */
- virtual void PTUpdatedAt(Counters counter, int value) = 0;
-
- /**
- * @brief Retrieves data from app_policies about app on its registration:
- * @param app_id - id of registered app
- * @param app_types Section on HMI where app can appear (Navigation, Phone
- * etc)
- * @param nicknames Synonyms for application
- */
- virtual bool GetInitialAppData(const std::string& application_id,
- StringArray* nicknames = NULL,
- StringArray* app_hmi_types = NULL) = 0;
-
- /**
- * @brief Add's device to policy table
- * @param device_id Device mac address
- * @param connection_type Device connection type
- */
- virtual void AddDevice(const std::string& device_id,
- const std::string& connection_type) = 0;
-
- /**
- * @brief Stores device parameters received during application registration
- * to policy table
- * @param device_id Device mac address
- * @param device_info Received device parameters
- */
- virtual void SetDeviceInfo(const std::string& device_id,
- const DeviceInfo& device_info) = 0;
-
- /**
- * @brief Set user consent for application functional groups
- * @param permissions User-defined application group pemissions.
- * The permissions is not const reference because it may contains
- * valid data as well as invalid. So we will remove all invalid data
- * from this structure.
- */
- virtual void SetUserConsentForApp(const PermissionConsent& permissions) = 0;
-
- /**
- * @brief Get default HMI level for application
- * @param policy_app_id Unique application id
- * @param default_hmi Default HMI level for application or empty, if value
- * was not set
- * @return true, if succedeed, otherwise - false
- */
- virtual bool GetDefaultHmi(const std::string& policy_app_id,
- std::string* default_hmi) const = 0;
-
- /**
- * @brief Get priority for application
- * @param policy_app_id Unique application id
- * @param priority Priority for application or empty, if value was not set
- * @return true, if succedeed, otherwise - false
- */
- virtual bool GetPriority(const std::string& policy_app_id,
- std::string* priority) const = 0;
-
- /**
- * @brief Get user friendly messages for given RPC messages and language
- * @param message_codes RPC message codes
- * @param language Language
- * @return Array of structs with appropriate message parameters
- */
- virtual std::vector<UserFriendlyMessage> GetUserFriendlyMessages(
- const std::vector<std::string>& message_code,
- const std::string& language) = 0;
-
- /**
- * Checks if the application is revoked
- * @param app_id application id
- * @return true if application is revoked
- */
- virtual bool IsApplicationRevoked(const std::string& app_id) const = 0;
-
- /**
- * @brief Get resulting RPCs permissions for application which started on
- * specific device
- * @param device_id Device id
- * @param policy_app_id Unique application id
- * @param permissions Array of functional groups permissions
- */
- virtual void GetPermissionsForApp(
- const std::string& device_id,
- const std::string& policy_app_id,
- std::vector<FunctionalGroupPermission>& permissions) = 0;
-
- /**
- * @brief Gets specific application permissions changes since last policy
- * table update
- * @param policy_app_id Unique application id
- * @return Permissions changes
- */
- virtual AppPermissions GetAppPermissionsChanges(
- const std::string& policy_app_id) = 0;
-
- virtual void RemovePendingPermissionChanges(const std::string& app_id) = 0;
-
- /**
- * @brief Return device id, which hosts specific application
- * @param Application id, which is required to update device id
- */
- virtual std::string& GetCurrentDeviceId(
- const std::string& policy_app_id) const = 0;
-
- /**
- * @brief Set current system language
- * @param language Language
- */
- virtual void SetSystemLanguage(const std::string& language) = 0;
-
- /**
- * @brief Set data from GetSystemInfo response to policy table
- * @param ccpu_version CCPU version
- * @param wers_country_code WERS country code
- * @param language System language
- */
- virtual void SetSystemInfo(const std::string& ccpu_version,
- const std::string& wers_country_code,
- const std::string& language) = 0;
-
- /**
- * @brief Send OnPermissionsUpdated for choosen application
- * @param application_id
- */
- virtual void SendNotificationOnPermissionsUpdated(
- const std::string& application_id) = 0;
-
- /**
- * Marks device as upaired
- * @param device_id id device
- */
- virtual void MarkUnpairedDevice(const std::string& device_id) = 0;
-
- /**
- * @brief Adds, application to the db or update existed one
- * run PTU if policy update is necessary for application.
- * @param Application id assigned by Ford to the application
- * @return function that will notify update manager about new application
- */
- virtual StatusNotifier AddApplication(const std::string& application_id) = 0;
-
- /**
- * @brief Removes unpaired device records and related records from DB
- * @param device_ids List of device_id, which should be removed
- * @return true, if succedeed, otherwise - false
- */
- virtual bool CleanupUnpairedDevices() = 0;
-
- /**
- * @brief Check if app can keep context.
- */
- virtual bool CanAppKeepContext(const std::string& app_id) const = 0;
-
- /**
- * @brief Check if app can steal focus.
- */
- virtual bool CanAppStealFocus(const std::string& app_id) const = 0;
-
- /**
- * @brief Runs necessary operations, which is depends on external system
- * state, e.g. getting system-specific parameters which are need to be
- * filled into policy table
- */
- virtual void OnSystemReady() = 0;
-
- /**
- * @brief GetNotificationNumber
- * @param priority
- * @return
- */
- virtual uint32_t GetNotificationsNumber(
- const std::string& priority) const = 0;
-
- /**
- * @brief Allows to update Vehicle Identification Number in policy table.
- * @param new value for the parameter.
- */
- virtual void SetVINValue(const std::string& value) = 0;
-
- /**
- * @brief Checks, if application has policy assigned w/o data consent
- * @param policy_app_id Unique application id
- * @return true, if policy assigned w/o data consent, otherwise -false
- */
- virtual bool IsPredataPolicy(const std::string& policy_app_id) const = 0;
-
- /**
- * Returns heart beat timeout
- * @param app_id application id
- * @return if timeout was set then value in milliseconds greater zero
- * otherwise heart beat for specific application isn't set
- */
- virtual uint32_t HeartBeatTimeout(const std::string& app_id) const = 0;
-
- /**
- * @brief SaveUpdateStatusRequired alows to save update status.
- */
- virtual void SaveUpdateStatusRequired(bool is_update_needed) = 0;
-
- /**
- * @brief Handler on applications search started
- */
- virtual void OnAppsSearchStarted() = 0;
-
- /**
- * @brief Handler on applications search completed
- */
- virtual void OnAppsSearchCompleted() = 0;
- /**
- * @brief Gets request types for application
- * @param policy_app_id Unique application id
- * @return request_types Request types of application
- */
- virtual const std::vector<std::string> GetAppRequestTypes(
- const std::string policy_app_id) const = 0;
-
- /**
- * @brief Get information about vehicle
- */
- virtual const VehicleInfo GetVehicleInfo() const = 0;
-
- /**
- * @brief OnAppRegisteredOnMobile alows to handle event when application were
- * succesfully registered on mobile device.
- * It will send OnAppPermissionSend notification and will try to start PTU.
- *
- * @param application_id registered application.
- */
- virtual void OnAppRegisteredOnMobile(const std::string& application_id) = 0;
-
- /**
- * @brief RetrieveCertificate Allows to obtain certificate in order
- * to start secure connection.
- *
- * @return The certificate in PKCS#7 format.
- */
- virtual std::string RetrieveCertificate() const = 0;
-
- virtual const PolicySettings& get_settings() const = 0;
-
- protected:
- /**
- * Checks is PT exceeded IgnitionCycles
- * @return true if exceeded
- */
- virtual bool ExceededIgnitionCycles() = 0;
-
- /**
- * Checks is PT exceeded days
- * @return true if exceeded
- */
- virtual bool ExceededDays() = 0;
-
- /**
- * @brief StartPTExchange allows to start PTU. The function will check
- * if one is required and starts the update flow in only case when previous
- * condition is true.
- */
- virtual void StartPTExchange() = 0;
-};
-
-} // namespace policy
-
-extern "C" policy::PolicyManager* CreateManager();
-extern "C" void DeleteManager(policy::PolicyManager*);
-
-#endif // SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_POLICY_MANAGER_H_
diff --git a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h
index c7773d7728..fec05e0724 100644
--- a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h
+++ b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h
@@ -202,6 +202,11 @@ class PolicyManagerImpl : public PolicyManager {
virtual std::string RetrieveCertificate() const OVERRIDE;
+ AppIdURL GetNextUpdateUrl(const EndpointUrls& urls) OVERRIDE;
+
+ AppIdURL RetrySequenceUrl(const struct RetrySequenceURL& rs,
+ const EndpointUrls& urls) const OVERRIDE;
+
protected:
#ifdef USE_HMI_PTU_DECRYPTION
virtual utils::SharedPtr<policy_table::Table> Parse(
@@ -347,6 +352,13 @@ class PolicyManagerImpl : public PolicyManager {
const PolicySettings* settings_;
friend struct CheckAppPolicy;
+ friend struct ProccessAppGroups;
+
+ /**
+ * @brief Pair of app index and url index from Endpoints vector
+ * that contains all application URLs
+ */
+ RetrySequenceURL retry_sequence_url_;
};
} // namespace policy
diff --git a/src/components/policy/policy_regular/src/policy_manager_impl.cc b/src/components/policy/policy_regular/src/policy_manager_impl.cc
index 8c3fbe5178..9aac892300 100644
--- a/src/components/policy/policy_regular/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc
@@ -76,7 +76,8 @@ PolicyManagerImpl::PolicyManagerImpl()
, timer_retry_sequence_("Retry sequence timer",
new timer::TimerTaskImpl<PolicyManagerImpl>(
this, &PolicyManagerImpl::RetrySequence))
- , ignition_check(true) {}
+ , ignition_check(true)
+ , retry_sequence_url_(0, 0, "") {}
void PolicyManagerImpl::set_listener(PolicyListener* listener) {
listener_ = listener;
@@ -899,6 +900,45 @@ std::string PolicyManagerImpl::RetrieveCertificate() const {
return cache_->GetCertificate();
}
+AppIdURL PolicyManagerImpl::GetNextUpdateUrl(const EndpointUrls& urls) {
+ LOG4CXX_AUTO_TRACE(logger_);
+
+ const AppIdURL next_app_url = RetrySequenceUrl(retry_sequence_url_, urls);
+
+ retry_sequence_url_.url_idx_ = next_app_url.second + 1;
+ retry_sequence_url_.app_idx_ = next_app_url.first;
+ retry_sequence_url_.policy_app_id_ = urls[next_app_url.first].app_id;
+
+ return next_app_url;
+}
+
+AppIdURL PolicyManagerImpl::RetrySequenceUrl(const struct RetrySequenceURL& rs,
+ const EndpointUrls& urls) const {
+ uint32_t url_idx = rs.url_idx_;
+ uint32_t app_idx = rs.app_idx_;
+ const std::string& app_id = rs.policy_app_id_;
+
+ if (urls.size() <= app_idx) {
+ // Index of current application doesn't exist any more due to app(s)
+ // unregistration
+ url_idx = 0;
+ app_idx = 0;
+ } else if (urls[app_idx].app_id != app_id) {
+ // Index of current application points to another one due to app(s)
+ // registration/unregistration
+ url_idx = 0;
+ } else if (url_idx >= urls[app_idx].url.size()) {
+ // Index of current application is OK, but all of its URL are sent,
+ // move to the next application
+ url_idx = 0;
+ if (++app_idx >= urls.size()) {
+ app_idx = 0;
+ }
+ }
+
+ return std::make_pair(app_idx, url_idx);
+}
+
class CallStatusChange : public utils::Callable {
public:
CallStatusChange(UpdateStatusManager& upd_manager,