summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2019-10-04 11:56:26 +0300
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2019-10-04 13:18:23 +0300
commit198e3453394ccb2b1f7db72d1858cfd18e302a1e (patch)
treedaff6ffd927fe6aa904b07970da91f869fe2fdc0
parent946b9d22818c76325ce6f5bf4804494f461f2c0a (diff)
downloadqtlocation-mapboxgl-198e3453394ccb2b1f7db72d1858cfd18e302a1e.tar.gz
[android] Check if Mapbox instance exists before creating default file source
This check is needed for mbgl-benchmark target, as it does not require Mapbox instance, nor Android asset manager.
-rw-r--r--platform/android/src/file_source.cpp11
-rw-r--r--platform/android/src/mapbox.cpp6
-rw-r--r--platform/android/src/mapbox.hpp1
3 files changed, 15 insertions, 3 deletions
diff --git a/platform/android/src/file_source.cpp b/platform/android/src/file_source.cpp
index 234d8d9758..a002d6616f 100644
--- a/platform/android/src/file_source.cpp
+++ b/platform/android/src/file_source.cpp
@@ -17,9 +17,14 @@ namespace mbgl {
std::shared_ptr<FileSource> FileSource::createPlatformFileSource(const ResourceOptions& options) {
auto env{android::AttachEnv()};
- auto assetManager = android::Mapbox::getAssetManager(*env);
- auto fileSource = std::make_shared<DefaultFileSource>(options.cachePath(),
- std::make_unique<AssetManagerFileSource>(*env, assetManager));
+ std::shared_ptr<DefaultFileSource> fileSource;
+ if (android::Mapbox::hasInstance(*env)) {
+ auto assetManager = android::Mapbox::getAssetManager(*env);
+ fileSource = std::make_shared<DefaultFileSource>(options.cachePath(),
+ std::make_unique<AssetManagerFileSource>(*env, assetManager));
+ } else {
+ fileSource = std::make_shared<DefaultFileSource>(options.cachePath(), options.assetPath());
+ }
fileSource->setAccessToken(options.accessToken());
return fileSource;
}
diff --git a/platform/android/src/mapbox.cpp b/platform/android/src/mapbox.cpp
index c835518b42..5246739cf6 100644
--- a/platform/android/src/mapbox.cpp
+++ b/platform/android/src/mapbox.cpp
@@ -9,6 +9,12 @@ jni::Local<jni::Object<AssetManager>> Mapbox::getAssetManager(jni::JNIEnv& env)
return javaClass.Call(env, method);
}
+jboolean Mapbox::hasInstance(jni::JNIEnv& env) {
+ static auto& javaClass = jni::Class<Mapbox>::Singleton(env);
+ auto method = javaClass.GetStaticMethod<jboolean()>(env, "hasInstance");
+ return javaClass.Call(env, method);
+}
+
void Mapbox::registerNative(jni::JNIEnv& env) {
jni::Class<Mapbox>::Singleton(env);
}
diff --git a/platform/android/src/mapbox.hpp b/platform/android/src/mapbox.hpp
index 2d9a657fa1..813f5bf174 100644
--- a/platform/android/src/mapbox.hpp
+++ b/platform/android/src/mapbox.hpp
@@ -10,6 +10,7 @@ namespace android {
class Mapbox {
public:
static constexpr auto Name() { return "com/mapbox/mapboxsdk/Mapbox"; };
+ static jboolean hasInstance(jni::JNIEnv&);
static jni::Local<jni::Object<AssetManager>> getAssetManager(jni::JNIEnv&);
static void registerNative(jni::JNIEnv&);
};