This repository has been archived by the owner on Mar 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit dd841f0
Showing
11 changed files
with
309 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
BasedOnStyle: LLVM | ||
AllowShortIfStatementsOnASingleLine: true | ||
IndentWidth: 4 | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.DS_Store | ||
measurement_kit-jni-libs-v*.tar.bz2 | ||
measurement_kit-jni-v*.tar.bz2 | ||
measurement_kit-jni-v*.tar.bz2.asc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
PHONIES += check dist download-and-verify help jni-libs jni-libs-no-unpack | ||
PHONIES += unpack unpack-clean | ||
.PHONY: $(PHONIES) | ||
|
||
GPG2 = gpg2 | ||
NDK_BUILD = ndk-build | ||
WGET = wget | ||
|
||
BASEURL = https://github.com/measurement-kit/measurement-kit/releases/download | ||
VERSION = v0.1.0-beta.2 | ||
TAG = 5-ge0eb44b | ||
INPUT = measurement_kit-jni-$(VERSION)-$(TAG).tar.bz2 | ||
OVERSION = $$(git describe --tags) | ||
OUTPUT = measurement_kit-jni-libs-$(OVERSION).tar.bz2 | ||
|
||
ABIS = arm64-v8a armeabi armeabi-v7a mips mips64 x86 x86_64 | ||
|
||
help: | ||
@printf "Targets:\n" | ||
@for TARGET in `grep ^PHONIES Makefile|sed 's/^PHONIES += //'`; do \ | ||
if echo $$TARGET|grep -qv ^_; then \ | ||
printf " - $$TARGET\n"; \ | ||
fi; \ | ||
done | ||
|
||
dist: jni-libs | ||
@echo "Creating $(OUTPUT)..." | ||
@tar -cjf $(OUTPUT) java jniLibs | ||
|
||
jni-libs: unpack jni-libs-no-unpack | ||
|
||
jni-libs-no-unpack: | ||
$(NDK_BUILD) NDK_LIBS_OUT=./jniLibs | ||
|
||
unpack: unpack-clean download-and-verify | ||
@echo "Unpack $(INPUT) inside jni" | ||
@tar xf $(INPUT) | ||
|
||
unpack-clean: | ||
@echo "Cleanup jni dirs: $(ABIS)" | ||
@for ABI in $(ABIS); do \ | ||
rm -rf jni/$$ABI/*; \ | ||
done | ||
|
||
download-and-verify: check $(INPUT) $(INPUT).asc | ||
$(GPG2) --verify $(INPUT).asc | ||
|
||
check: | ||
@if [ -z "$$(which $(GPG2))" ]; then \ | ||
echo "FATAL: install $(GPG2) or make sure it's in PATH" 1>&2; \ | ||
exit 1; \ | ||
fi | ||
@echo "Using $(GPG2): $$(which $(GPG2))" | ||
@if [ -z "$$(which $(NDK_BUILD))" ]; then \ | ||
echo "FATAL: install $(NDK_BUILD) or make sure it's in PATH" 1>&2; \ | ||
exit 1; \ | ||
fi | ||
@echo "Using $(NDK_BUILD): $$(which $(NDK_BUILD))" | ||
@if [ -z "$$(which $(WGET))" ]; then \ | ||
echo "FATAL: install $(WGET) or make sure it's in PATH" 1>&2; \ | ||
exit 1; \ | ||
fi | ||
@echo "Using $(WGET): $$(which $(WGET))" | ||
|
||
$(INPUT): | ||
$(WGET) -q $(BASEURL)/$(VERSION)/$(INPUT) | ||
|
||
$(INPUT).asc: | ||
$(WGET) -q $(BASEURL)/$(VERSION)/$(INPUT).asc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Measurement Kit JNI Libs | ||
|
||
This repository contains Measurement Kit Java native interface (JNI). It | ||
also contains the code to generate Measurement Kit JNI libs. | ||
|
||
The `Makefile` file allows you to cross-compile JNI libs suitable for being | ||
used by Android applications. | ||
|
||
To see all the available targets, just type: | ||
|
||
``` | ||
make | ||
``` | ||
|
||
To generate a tarball containing the Java files and the corresponding | ||
compiled libraries, type: | ||
|
||
``` | ||
make dist | ||
``` | ||
|
||
This will download the latest Measurement Kit binaries from GitHub, verify | ||
them with GnuPG, cross-compile the JNI code and statically link it with the | ||
downloaded binaries, package a tarball suitable for distribution. | ||
|
||
The version number of the tarball will be the version downloaded from | ||
GitHub, plus the abbreviated reference of the current HEAD. | ||
|
||
A Unix environment is assumed. You need to have the following executables | ||
in your PATH: | ||
|
||
- git | ||
- wget | ||
- ndk-build | ||
- gpg2 | ||
|
||
Git, wget, and gpg2 could be installed using your distributions package | ||
manager. As regards ndk-build, [there are instructions to install it inside | ||
Measurement Kit repository](https://github.com/measurement-kit/measurement-kit/tree/master/mobile/android#installing-the-ndk). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Part of measurement-kit <https://measurement-kit.github.io/>. | ||
// Measurement-kit is free software. See AUTHORS and LICENSE for more | ||
// information on the copying conditions. | ||
|
||
package io.github.measurement_kit.jni.sync; | ||
|
||
/** | ||
* Allows to run OONI tests. | ||
*/ | ||
class OONI { | ||
|
||
/** | ||
* Runs OONI dns-injection test. | ||
* @param backend Address (and optionally port) of backend. | ||
* @param inputPath Path of input file to use. | ||
* @param verbose Whether to run in verbose mode. | ||
* @param logPath Path of log file to use. | ||
* @return Path of test report file. | ||
*/ | ||
public static native String dnsInjection(String backend, | ||
String inputPath, | ||
boolean verbose, | ||
String logPath); | ||
|
||
/** | ||
* Runs OONI http-invalid-request-line test. | ||
* @param backend URL of backend. | ||
* @param verbose Whether to run in verbose mode. | ||
* @param logPath Path of log file to use. | ||
* @return Path of test report file. | ||
*/ | ||
public static native String httpInvalidRequestLine(String backend, | ||
boolean verbose, | ||
String logPath); | ||
|
||
/** | ||
* Runs OONI tcp-connect test. | ||
* @param port Port to use. | ||
* @param inputPath Path of input file to use. | ||
* @param verbose Whether to run in verbose mode. | ||
* @param logPath Path of log file to use. | ||
* @return Path of test report file. | ||
*/ | ||
public static native String tcpConnect(String port, | ||
String inputPath, | ||
boolean verbose, | ||
String logPath); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
LOCAL_PATH := $(call my-dir) | ||
|
||
include $(CLEAR_VARS) | ||
LOCAL_MODULE := libevent | ||
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libevent.a | ||
include $(PREBUILT_STATIC_LIBRARY) | ||
|
||
include $(CLEAR_VARS) | ||
LOCAL_MODULE := libevent_pthreads | ||
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libevent_pthreads.a | ||
include $(PREBUILT_STATIC_LIBRARY) | ||
|
||
include $(CLEAR_VARS) | ||
LOCAL_MODULE := libjansson | ||
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libjansson.a | ||
include $(PREBUILT_STATIC_LIBRARY) | ||
|
||
include $(CLEAR_VARS) | ||
LOCAL_MODULE := libmeasurement_kit | ||
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libmeasurement_kit.a | ||
include $(PREBUILT_STATIC_LIBRARY) | ||
|
||
include $(CLEAR_VARS) | ||
LOCAL_MODULE := libyaml-cpp | ||
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libyaml-cpp.a | ||
include $(PREBUILT_STATIC_LIBRARY) | ||
|
||
include $(CLEAR_VARS) | ||
LOCAL_LDLIBS := -llog -latomic | ||
LOCAL_STATIC_LIBRARIES := measurement_kit event event_pthreads jansson \ | ||
maxminddb yaml-cpp | ||
LOCAL_MODULE := measurement_kit_jni | ||
LOCAL_SRC_FILES := measurement_kit_jni.cpp | ||
APP_PLATFORM := android-21 | ||
LOCAL_CPPFLAGS += -I jni/$(TARGET_ARCH_ABI)/include -std=c++11 | ||
include $(BUILD_SHARED_LIBRARY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
APP_ABI := all | ||
APP_PLATFORM := android-21 | ||
NDK_TOOLCHAIN_VERSION := clang | ||
APP_STL := c++_static | ||
APP_CPPFLAGS += -fexceptions -frtti |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Part of measurement-kit <https://measurement-kit.github.io/>. | ||
// Measurement-kit is free software. See AUTHORS and LICENSE for more | ||
// information on the copying conditions. | ||
|
||
#include <jni.h> | ||
#include <measurement_kit/ooni.hpp> | ||
#include <string> | ||
#include "io_github_measurement_kit_jni_sync_OONI.h" | ||
|
||
static std::string jstring_to_cxxstring(JNIEnv *env, jstring source) { | ||
const char *ptr = env->GetStringUTFChars(source, nullptr); | ||
if (ptr == nullptr) throw std::bad_alloc(); | ||
std::string copy = ptr; | ||
env->ReleaseStringUTFChars(source, ptr); | ||
return copy; | ||
} | ||
|
||
JNIEXPORT jstring JNICALL | ||
Java_io_github_measurement_1kit_jni_sync_OONI_dnsInjection( | ||
JNIEnv *env, jclass /*clazz*/, jstring backend, jstring inputPath, | ||
jboolean /*verbose*/, jstring logPath) { | ||
try { | ||
mk::ooni::DnsInjectionTest() | ||
.set_backend(jstring_to_cxxstring(env, backend)) | ||
.set_input_file_path(jstring_to_cxxstring(env, inputPath)) | ||
.set_verbose() | ||
.run(); | ||
} catch (...) { | ||
// XXX suppress | ||
} | ||
return nullptr; | ||
} | ||
|
||
JNIEXPORT jstring JNICALL | ||
Java_io_github_measurement_1kit_jni_sync_OONI_httpInvalidRequestLine( | ||
JNIEnv *env, jclass /*clazz*/, jstring backend, jboolean /*verbose*/, | ||
jstring logPath) { | ||
try { | ||
mk::ooni::HttpInvalidRequestLineTest() | ||
.set_backend(jstring_to_cxxstring(env, backend)) | ||
.set_verbose() | ||
.run(); | ||
} catch (...) { | ||
// XXX suppress | ||
} | ||
return nullptr; | ||
} | ||
|
||
JNIEXPORT jstring JNICALL | ||
Java_io_github_measurement_1kit_jni_sync_OONI_tcpConnect( | ||
JNIEnv *env, jclass /*clazz*/, jstring port, jstring inputPath, | ||
jboolean verbose, jstring logPath) { | ||
try { | ||
mk::ooni::TcpConnectTest() | ||
.set_port(jstring_to_cxxstring(env, port)) | ||
.set_input_file_path(jstring_to_cxxstring(env, inputPath)) | ||
.set_verbose() | ||
.run(); | ||
} catch (...) { | ||
// XXX suppress | ||
} | ||
return nullptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* |