[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.
This commit is contained in:
Alexander Shalamov
2019-10-04 11:56:26 +03:00
parent 946b9d2281
commit 198e345339
3 changed files with 15 additions and 3 deletions

View File

@@ -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;
}