summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--android/LICENSE_ASSETBRIDGE23
-rw-r--r--android/cpp/JNI.cpp7
-rw-r--r--android/cpp/NativeMapView.hpp2
-rw-r--r--android/java/.gitignore3
-rw-r--r--android/java/lib/src/main/java/com/arieslabs/assetbridge/Assetbridge.java107
-rw-r--r--android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java12
-rw-r--r--android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java6
-rw-r--r--platform/android/cache_database_data.cpp3
-rw-r--r--platform/default/http_request_baton_curl.cpp11
10 files changed, 167 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index 0a1bc56e83..783d348d9e 100644
--- a/Makefile
+++ b/Makefile
@@ -87,6 +87,9 @@ android:
$(MAKE) -C build/android BUILDTYPE=$(BUILDTYPE) V=$(V) androidapp && \
mkdir -p android/java/lib/src/main/jniLibs/armeabi-v7a && \
cp build/android/out/$(BUILDTYPE)/lib.target/libmapbox-gl.so android/java/lib/src/main/jniLibs/armeabi-v7a/libmapbox-gl.so && \
+ mkdir -p android/java/lib/src/main/assets && \
+ cp build/android/out/$(BUILDTYPE)/ca-bundle.crt android/java/lib/src/main/assets/ca-bundle.crt && \
+ cp -r build/android/out/$(BUILDTYPE)/styles android/java/lib/src/main/assets/styles && \
cd android/java && \
./gradlew build
@@ -154,7 +157,7 @@ clean: clear_xcode_cache
-rm -rf ./macosx/build/
-rm -rf ./config.gypi ./config-ios.gypi ./config-android.gypi
-rm -rf ./android/java/build ./android/java/app/build ./android/java/lib/build
- -rm -rf ./android/java/lib/src/main/jniLibs
+ -rm -rf ./android/java/lib/src/main/jniLibs ./android/java/lib/src/main/assets
distclean: clean
-rm -rf ./mason_packages
diff --git a/android/LICENSE_ASSETBRIDGE b/android/LICENSE_ASSETBRIDGE
new file mode 100644
index 0000000000..09d4125bcf
--- /dev/null
+++ b/android/LICENSE_ASSETBRIDGE
@@ -0,0 +1,23 @@
+Copyright (c) 2013 Steve Havelka
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
diff --git a/android/cpp/JNI.cpp b/android/cpp/JNI.cpp
index 44ecea0b4a..d664ef1ade 100644
--- a/android/cpp/JNI.cpp
+++ b/android/cpp/JNI.cpp
@@ -20,6 +20,8 @@
namespace mbgl {
namespace android {
+std::string cache_path;
+
jmethodID on_map_changed_id = nullptr;
jclass lon_lat_class = nullptr;
@@ -140,8 +142,9 @@ using namespace mbgl::android;
// TODO: wrap C++ exceptions?
// TODO: wrap other sorts of exceptions? eg coffee catch
-jlong JNICALL nativeCreate(JNIEnv* env, jobject obj, jstring style_url, jstring api_key) {
+jlong JNICALL nativeCreate(JNIEnv* env, jobject obj, jstring cache_path_, jstring style_url, jstring api_key) {
LOG_VERBOSE("nativeCreate");
+ cache_path = std_string_from_jstring(env, cache_path_);
NativeMapView* native_map_view = new NativeMapView(env, obj, std_string_from_jstring(env, style_url), std_string_from_jstring(env, api_key));
if (native_map_view == nullptr) {
throw_error(env, "Unable to create NativeMapView.");
@@ -684,7 +687,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
// NOTE: if you get java.lang.UnsatisfiedLinkError you likely forgot to set the size of the array correctly (too large)
std::array<JNINativeMethod, 50> methods = {{ // Can remove the extra brace in C++14
- { "nativeCreate", "(Ljava/lang/String;Ljava/lang/String;)J", reinterpret_cast<void*>(&nativeCreate) },
+ { "nativeCreate", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)J", reinterpret_cast<void*>(&nativeCreate) },
{ "nativeDestroy", "(J)V", reinterpret_cast<void*>(&nativeDestroy) },
{ "nativeInitializeDisplay", "(J)V", reinterpret_cast<void*>(&nativeInitializeDisplay) },
{ "nativeTerminateDisplay", "(J)V", reinterpret_cast<void*>(&nativeTerminateDisplay) },
diff --git a/android/cpp/NativeMapView.hpp b/android/cpp/NativeMapView.hpp
index a3081e2ed6..459ef9343e 100644
--- a/android/cpp/NativeMapView.hpp
+++ b/android/cpp/NativeMapView.hpp
@@ -14,6 +14,8 @@
namespace mbgl {
namespace android {
+extern std::string cache_path;
+
extern jmethodID on_map_changed_id;
extern jclass lon_lat_class;
diff --git a/android/java/.gitignore b/android/java/.gitignore
index 478d786980..7c3a4c469a 100644
--- a/android/java/.gitignore
+++ b/android/java/.gitignore
@@ -10,5 +10,8 @@ build/
*/build/
*.so
+# Lib assets
+lib/src/main/assets/
+
# Local settings
local.properties
diff --git a/android/java/lib/src/main/java/com/arieslabs/assetbridge/Assetbridge.java b/android/java/lib/src/main/java/com/arieslabs/assetbridge/Assetbridge.java
new file mode 100644
index 0000000000..e322d1c613
--- /dev/null
+++ b/android/java/lib/src/main/java/com/arieslabs/assetbridge/Assetbridge.java
@@ -0,0 +1,107 @@
+package com.arieslabs.assetbridge;
+
+import android.content.Context;
+import android.content.res.AssetManager;
+import android.util.Log;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+
+
+public class Assetbridge {
+ /*static {
+ System.loadLibrary("assetbridge");
+ }*/
+
+
+ // unpack
+ public static void unpack(Context c) {
+
+ try {
+ // first let's get the temp directory
+ String tmpdir = c.getCacheDir().getPath();
+
+ // now we need the assetmanager
+ AssetManager am = c.getAssets();
+ String[] assets = am.list("");
+
+ // iterate on the files...
+ for(String asset : assets) {
+ copyAssetFolder(am, asset, tmpdir + "/" + asset);
+ }
+
+ // last, set the ASSETDIR environment variable for the C
+ // parts of the procee
+ //setassetdir(c.getCacheDir().getPath());
+
+ } catch (IOException e) {
+ Log.e("Assetbridge", "Can't unpack assets from APK", e);
+ }
+
+ }
+
+
+ public static void copyAssetFolder(AssetManager am, String src, String dest)
+ throws IOException{
+
+ InputStream srcIS = null;
+ File destfh;
+
+ // this is the only way we can tell if this is a file or a
+ // folder - we have to open the asset, and if the open fails,
+ // it's a folder...
+ boolean isDir = false;
+ try {
+ srcIS = am.open(src);
+ } catch (FileNotFoundException e) {
+ isDir = true;
+ }
+
+ // either way, we'll use the dest as a File
+ destfh = new File(dest);
+
+ // and now, depending on ..
+ if(isDir) {
+
+ // If the directory doesn't yet exist, create it
+ if( !destfh.exists() ){
+ destfh.mkdir();
+ }
+
+ // list the assets in the directory...
+ String assets[] = am.list(src);
+
+ // and copy them all using same.
+ for(String asset : assets) {
+ copyAssetFolder(am, src + "/" + asset, dest + "/" + asset);
+ }
+
+ } else {
+
+ int count, buffer_len = 2048;
+ byte[] data = new byte[buffer_len];
+
+ // copy the file from the assets subsystem to the filesystem
+ FileOutputStream destOS = new FileOutputStream(destfh);
+
+ //copy the file content in bytes
+ while( (count = srcIS.read(data, 0, buffer_len)) != -1) {
+ destOS.write(data, 0, count);
+ }
+
+ // and close the two files
+ srcIS.close();
+ destOS.close();
+
+ }
+ }
+
+
+ // the native method to set the environment variable
+ //public static native void setassetdir(String s);
+}
diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java
index f76750c5c2..1bd092c736 100644
--- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java
+++ b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java
@@ -27,6 +27,7 @@ import android.widget.ZoomButtonsController;
import com.almeros.android.multitouch.gesturedetectors.RotateGestureDetector;
import com.almeros.android.multitouch.gesturedetectors.TwoFingerGestureDetector;
+import com.arieslabs.assetbridge.Assetbridge;
// Custom view that shows a Map
// Based on SurfaceView as we use OpenGL ES to render
@@ -118,12 +119,19 @@ public class MapView extends SurfaceView {
return;
}
+ // Get the cache path
+ String cachePath = context.getCacheDir().getPath();
+
+ // Extract the asset files
+ Assetbridge.unpack(context);
+
// Load the map style and API key
- mStyleUrl = "https://mapbox.github.io/mapbox-gl-styles/styles/bright-v6.json";
+ //mStyleUrl = "https://mapbox.github.io/mapbox-gl-styles/styles/bright-v6.json";
+ mStyleUrl = "file://" + cachePath + "/styles/styles/bright-v6.json";
mApiKey = "pk.eyJ1IjoibGpiYWRlIiwiYSI6IlJSQ0FEZ2MifQ.7mE4aOegldh3595AG9dxpQ";
// Create the NativeMapView
- mNativeMapView = new NativeMapView(this, mStyleUrl, mApiKey);
+ mNativeMapView = new NativeMapView(this, cachePath, mStyleUrl, mApiKey);
// Load the attributes
TypedArray typedArray = context.obtainStyledAttributes(attrs,
diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java
index 5aa692e2af..5be250cf9a 100644
--- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java
+++ b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java
@@ -37,11 +37,11 @@ class NativeMapView {
// Constructors
//
- public NativeMapView(MapView mapView, String styleUrl, String apiKey) {
+ public NativeMapView(MapView mapView, String cachePath, String styleUrl, String apiKey) {
mMapView = mapView;
// Create the NativeMapView
- mNativeMapViewPtr = nativeCreate(styleUrl, apiKey);
+ mNativeMapViewPtr = nativeCreate(cachePath, styleUrl, apiKey);
}
//
@@ -359,7 +359,7 @@ class NativeMapView {
super.finalize();
}
- private native long nativeCreate(String styleUrl, String apiKey);
+ private native long nativeCreate(String cachePath, String styleUrl, String apiKey);
private native void nativeDestroy(long nativeMapViewPtr);
diff --git a/platform/android/cache_database_data.cpp b/platform/android/cache_database_data.cpp
index e1765efcdc..61c4efc15b 100644
--- a/platform/android/cache_database_data.cpp
+++ b/platform/android/cache_database_data.cpp
@@ -1,4 +1,5 @@
#include <mbgl/platform/platform.hpp>
+#include "../../android/cpp/NativeMapView.hpp"
namespace mbgl {
namespace platform {
@@ -6,7 +7,7 @@ namespace platform {
// Returns the path to the default cache database on this system.
std::string defaultCacheDatabase() {
// TODO need to use get cache dir from java
- return "/data/data/com.mapbox.mapboxgl.app/mbgl-cache.db";
+ return mbgl::android::cache_path + "/mbgl-cache.db";
}
}
diff --git a/platform/default/http_request_baton_curl.cpp b/platform/default/http_request_baton_curl.cpp
index 4b967c6c1b..8ca7781594 100644
--- a/platform/default/http_request_baton_curl.cpp
+++ b/platform/default/http_request_baton_curl.cpp
@@ -3,6 +3,7 @@
#include <mbgl/util/std.hpp>
#include <mbgl/util/ptr.hpp>
#include <mbgl/util/time.hpp>
+#include "../../android/cpp/NativeMapView.hpp"
#include <uv.h>
#include <curl/curl.h>
@@ -404,11 +405,15 @@ void start_request(void *const ptr) {
baton->response = std::make_unique<Response>();
}
+#ifndef __ANDROID__
+ std::string ca_path = "ca-bundle.crt";
+#else
+ std::string ca_path = mbgl::android::cache_path + "/ca-bundle.crt";
+#endif
+
// Carry on the shared pointer in the private information of the CURL handle.
curl_easy_setopt(handle, CURLOPT_PRIVATE, context.release());
- // FIXME temp work around
- curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0);
- //curl_easy_setopt(handle, CURLOPT_CAINFO, "ca-bundle.crt");
+ curl_easy_setopt(handle, CURLOPT_CAINFO, ca_path.c_str());
curl_easy_setopt(handle, CURLOPT_URL, baton->path.c_str());
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, curl_write_cb);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &baton->response->data);