diff --git a/android/sdk/src/main/cpp/app/organicmaps/sdk/Framework.cpp b/android/sdk/src/main/cpp/app/organicmaps/sdk/Framework.cpp index 3a7917aa8..29ee2cb8e 100644 --- a/android/sdk/src/main/cpp/app/organicmaps/sdk/Framework.cpp +++ b/android/sdk/src/main/cpp/app/organicmaps/sdk/Framework.cpp @@ -1508,8 +1508,8 @@ JNIEXPORT void JNICALL Java_app_organicmaps_sdk_Framework_nativeGet3dMode(JNIEnv JNIEXPORT void JNICALL Java_app_organicmaps_sdk_Framework_nativeSetCustomMapDownloadUrl(JNIEnv * env, jclass, jstring url) { - std::string const nativeUrl = jni::ToNativeString(env, url); - GetPlatform().SetCustomMetaServerUrl(nativeUrl); + std::string nativeUrl = jni::ToNativeString(env, url); + GetPlatform().SetCustomMapServerUrl(nativeUrl); if (g_framework) { diff --git a/libs/platform/platform.cpp b/libs/platform/platform.cpp index 4018fad67..34065998b 100644 --- a/libs/platform/platform.cpp +++ b/libs/platform/platform.cpp @@ -155,16 +155,19 @@ std::string Platform::ReadPathForFile(std::string const & file, std::string sear "\nr: ", m_resourcesDir, "\ns: ", m_settingsDir)); } -void Platform::SetCustomMetaServerUrl(std::string const & url) +void Platform::SetCustomMapServerUrl(std::string & url) { - g_customMetaServerUrl = url; + strings::Trim(url); + m_customMapServerUrl = std::move(url); +} + +std::string const & Platform::CustomMapServerUrl() const +{ + return m_customMapServerUrl; } std::string Platform::MetaServerUrl() const { - if (!g_customMetaServerUrl.empty()) - return g_customMetaServerUrl; - return METASERVER_URL; } diff --git a/libs/platform/platform.hpp b/libs/platform/platform.hpp index e0001b50a..a514b05cf 100644 --- a/libs/platform/platform.hpp +++ b/libs/platform/platform.hpp @@ -268,8 +268,9 @@ public: /// @return integer version in yyMMdd format. int32_t IntVersion() const; - /// Set custom meta server url to allow user-defined download servers - void SetCustomMetaServerUrl(std::string const & url); + /// Set custom map server url to allow user-defined download servers + void SetCustomMapServerUrl(std::string & url); + std::string const & CustomMapServerUrl() const; /// @return url for clients to download maps std::string MetaServerUrl() const; @@ -342,6 +343,8 @@ private: void ShutdownThreads(); void GetSystemFontNames(FilesList & res) const; + + std::string m_customMapServerUrl; }; std::string DebugPrint(Platform::EError err); diff --git a/libs/storage/map_files_downloader.cpp b/libs/storage/map_files_downloader.cpp index 1ca0e68fd..58c6eea29 100644 --- a/libs/storage/map_files_downloader.cpp +++ b/libs/storage/map_files_downloader.cpp @@ -156,6 +156,26 @@ std::string GetAcceptLanguage() MetaConfig MapFilesDownloader::LoadMetaConfig() { Platform & pl = GetPlatform(); + std::optional metaConfig; + + std::string const customServer = pl.CustomMapServerUrl(); + + if (!customServer.empty()) + { + LOG(LINFO, ("Using custom map server URL:", customServer)); + + // Reuse default meta settings (timeouts, other endpoints) and override servers + metaConfig = downloader::ParseMetaConfig(pl.DefaultUrlsJSON()); + CHECK(metaConfig, ()); + + metaConfig->m_serversList.clear(); + metaConfig->m_serversList.push_back(customServer); + + LOG(LINFO, ("Got servers list (custom server):", metaConfig->m_serversList)); + CHECK(!metaConfig->m_serversList.empty(), ()); + return *metaConfig; + } + std::string const metaServerUrl = pl.MetaServerUrl(); std::string httpResult; @@ -170,7 +190,7 @@ MetaConfig MapFilesDownloader::LoadMetaConfig() request.RunHttpRequest(httpResult); } - std::optional metaConfig = downloader::ParseMetaConfig(httpResult); + metaConfig = downloader::ParseMetaConfig(httpResult); if (!metaConfig) { metaConfig = downloader::ParseMetaConfig(pl.DefaultUrlsJSON());