diff options
author | Chris Loer <chris.loer@gmail.com> | 2018-10-16 14:43:48 -0700 |
---|---|---|
committer | Chris Loer <chris.loer@mapbox.com> | 2018-10-17 12:53:24 -0700 |
commit | 3f98d6a8219237967f87b5a096afefc74605d460 (patch) | |
tree | 6aef35f6030edb5576bae06f585ef628222701a6 /platform/android/src | |
parent | 5a45976b7c72e9a9e1a43d57e5482b1dd9c1e98e (diff) | |
download | qtlocation-mapboxgl-3f98d6a8219237967f87b5a096afefc74605d460.tar.gz |
[android] Add OfflineManager.putResourceForURL
Useful for pre-warming the ambient cache
Diffstat (limited to 'platform/android/src')
-rw-r--r-- | platform/android/src/offline/offline_manager.cpp | 28 | ||||
-rw-r--r-- | platform/android/src/offline/offline_manager.hpp | 8 |
2 files changed, 35 insertions, 1 deletions
diff --git a/platform/android/src/offline/offline_manager.cpp b/platform/android/src/offline/offline_manager.cpp index c6432f766a..07e10d4c81 100644 --- a/platform/android/src/offline/offline_manager.cpp +++ b/platform/android/src/offline/offline_manager.cpp @@ -121,7 +121,8 @@ void OfflineManager::registerNative(jni::JNIEnv& env) { METHOD(&OfflineManager::setOfflineMapboxTileCountLimit, "setOfflineMapboxTileCountLimit"), METHOD(&OfflineManager::listOfflineRegions, "listOfflineRegions"), METHOD(&OfflineManager::createOfflineRegion, "createOfflineRegion"), - METHOD(&OfflineManager::mergeOfflineRegions, "mergeOfflineRegions")); + METHOD(&OfflineManager::mergeOfflineRegions, "mergeOfflineRegions"), + METHOD(&OfflineManager::putResourceWithUrl, "putResourceWithUrl")); } // OfflineManager::ListOfflineRegionsCallback // @@ -201,5 +202,30 @@ void OfflineManager::MergeOfflineRegionsCallback::onMerge(jni::JNIEnv& env, callback.Call(env, method, jregions); } +void OfflineManager::putResourceWithUrl(jni::JNIEnv& env, + const jni::String& url_, + const jni::Array<jni::jbyte>& arr, + jlong modified, + jlong expires, + const jni::String& eTag_) { + auto url = jni::Make<std::string>(env, url_); + auto data = std::make_shared<std::string>(arr.Length(env), char()); + jni::GetArrayRegion(env, *arr, 0, data->size(), reinterpret_cast<jbyte*>(&(*data)[0])); + mbgl::Resource resource(mbgl::Resource::Kind::Unknown, url); + mbgl::Response response; + response.data = data; + if (eTag_) { + response.etag = jni::Make<std::string>(env, eTag_); + } + if (modified > 0) { + response.modified = Timestamp(mbgl::Seconds(modified)); + } + if (expires > 0) { + response.expires = Timestamp(mbgl::Seconds(expires)); + } + + fileSource.put(resource, response); +} + } // namespace android } // namespace mbgl diff --git a/platform/android/src/offline/offline_manager.hpp b/platform/android/src/offline/offline_manager.hpp index b2ebc63a63..52c9ab70a0 100644 --- a/platform/android/src/offline/offline_manager.hpp +++ b/platform/android/src/offline/offline_manager.hpp @@ -75,6 +75,14 @@ public: const jni::String&, const jni::Object<MergeOfflineRegionsCallback>&); + void putResourceWithUrl(jni::JNIEnv&, + const jni::String& url, + const jni::Array<jni::jbyte>& data, + jlong modified, + jlong expires, + const jni::String& eTag); + + private: mbgl::DefaultFileSource& fileSource; }; |