[core] Allow overriding map metaserver URL and reset downloader cache

- Add custom meta server API.
- Implement override.
- Add reset hook and implement reset.
- Expose reset from Storage.
- Let JNI set URL and reset cache.

Signed-off-by: NoelClick <dev@noel.click>
This commit is contained in:
NoelClick
2025-11-15 19:05:12 -08:00
committed by jeanbaptisteC
parent 4973f4fed2
commit 29c363a581
6 changed files with 47 additions and 0 deletions

View File

@@ -1505,6 +1505,22 @@ JNIEXPORT void JNICALL Java_app_organicmaps_sdk_Framework_nativeGet3dMode(JNIEnv
env->SetBooleanField(result, buildingsField, buildings);
}
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);
if (g_framework)
{
frm()->GetStorage().ResetMapDownloadMetaConfig();
}
else
{
LOG(LINFO, ("nativeSetCustomMapDownloadUrl: framework not created yet, skipping ResetMapDownloadMetaConfig"));
}
}
JNIEXPORT void JNICALL Java_app_organicmaps_sdk_Framework_nativeSetAutoZoomEnabled(JNIEnv * env, jclass,
jboolean enabled)
{

View File

@@ -49,6 +49,11 @@ bool GetFileTypeChecked(std::string const & path, Platform::EFileType & type)
}
} // namespace
namespace
{
std::string g_customMetaServerUrl;
} // namespace
// static
Platform::EError Platform::ErrnoToError()
{
@@ -150,8 +155,16 @@ std::string Platform::ReadPathForFile(std::string const & file, std::string sear
"\nr: ", m_resourcesDir, "\ns: ", m_settingsDir));
}
void Platform::SetCustomMetaServerUrl(std::string const & url)
{
g_customMetaServerUrl = url;
}
std::string Platform::MetaServerUrl() const
{
if (!g_customMetaServerUrl.empty())
return g_customMetaServerUrl;
return METASERVER_URL;
}

View File

@@ -268,6 +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);
/// @return url for clients to download maps
std::string MetaServerUrl() const;

View File

@@ -190,4 +190,10 @@ void MapFilesDownloader::GetMetaConfig(MetaConfigCallback const & callback)
callback(LoadMetaConfig());
}
void MapFilesDownloader::ResetMetaConfig()
{
m_serversList.clear();
m_isMetaConfigRequested = false;
}
} // namespace storage

View File

@@ -66,6 +66,9 @@ public:
void SetDownloadingPolicy(DownloadingPolicy * policy);
void SetDataVersion(int64_t version) { m_dataVersion = version; }
/// Reset after changes, e.g. map download URL.
void ResetMetaConfig();
/// @name Legacy functions for Android resources downloading routine (initial World download).
/// @{
void EnsureMetaConfigReady(std::function<void()> && callback);

View File

@@ -585,6 +585,12 @@ public:
void RestoreDownloadQueue();
void ResetMapDownloadMetaConfig()
{
if (m_downloader)
m_downloader->ResetMetaConfig();
}
protected:
void OnFinishDownloading();