-
Notifications
You must be signed in to change notification settings - Fork 6
feat: implement network type detection using JNI #729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7deda27
feat: implement macOS network type detection using JNI
aanorbel 2764513
register gradle tasks
aanorbel ee2f5dd
chore: update build scripts
aanorbel 3214dd2
fix: update JavaExec task to set library path and clean up exception …
aanorbel 7e68ff9
refactor: rename MacOsNetworkTypeFinder to DesktopNetworkTypeFinder a…
aanorbel 464a025
chore: add support for linux platform
aanorbel 6db3b4e
chore: add support for windows network finder
aanorbel 19894fb
chore: add workflow for building networkfinder in ci
aanorbel 01747fc
chore: add workflow for building networkfinder in ci
aanorbel c4432a8
chore: add workflow for building networkfinder in ci
aanorbel 912270c
chore: update windows path for headers
aanorbel 02acf69
update build flow
aanorbel 9141d75
refactor: update interface type checks to use boolean return values
aanorbel a273eed
chore: update .gitignore to include networktypefinder build artifacts
aanorbel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,54 @@ | ||
name: Build NetworkTypeFinder JNI Bridge | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'composeApp/src/desktopMain/c/**' | ||
- '.github/workflows/build-networktypefinder.yml' | ||
- 'composeApp/src/desktopMain/Makefile' | ||
pull_request: | ||
paths: | ||
- 'composeApp/src/desktopMain/c/**' | ||
- '.github/workflows/build-networktypefinder.yml' | ||
- 'composeApp/src/desktopMain/Makefile' | ||
|
||
jobs: | ||
build: | ||
name: Build on ${{ matrix.os }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
defaults: | ||
run: | ||
working-directory: composeApp/src/desktopMain | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Java | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '17' | ||
|
||
- name: Install dependencies (Linux) | ||
if: runner.os == 'Linux' | ||
run: sudo apt-get update && sudo apt-get install -y clang make | ||
|
||
- name: Install dependencies (macOS) | ||
if: runner.os == 'macOS' | ||
run: brew install llvm make | ||
|
||
- name: Install dependencies (Windows) | ||
if: runner.os == 'Windows' | ||
run: choco install llvm make | ||
|
||
- name: Build NetworkTypeFinder | ||
run: make all | ||
|
||
- name: Upload built library | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: networktypefinder-${{ matrix.os }} | ||
path: composeApp/src/desktopMain/build/ |
This file contains hidden or 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
This file contains hidden or 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
4 changes: 2 additions & 2 deletions
4
composeApp/src/commonMain/composeResources/drawable/.gitignore
This file contains hidden or 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
|
||
logo_probe.xml | ||
ooni_logo.xml | ||
ooni_logo.xml | ||
logo_probe.xml |
This file contains hidden or 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
ic_launcher_monochrome.xml | ||
ic_launcher_foreground.xml | ||
notification_icon.xml | ||
ic_launcher_monochrome.xml | ||
notification_icon.xml |
This file contains hidden or 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,81 @@ | ||
# Makefile for NetworkTypeFinder JNI Bridge | ||
|
||
# Variables | ||
COMPILER = clang | ||
FILES = c/NetworkTypeFinder.m | ||
LIBRARY_NAME = networktypefinder | ||
LIBRARY_FILE_MAC = lib$(LIBRARY_NAME).dylib | ||
LIBRARY_FILE_LINUX = lib$(LIBRARY_NAME).so | ||
JAVA_HOME ?= $(shell java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home' | awk '{print $$3}') | ||
|
||
# Detect platform | ||
UNAME_S := $(shell uname -s) | ||
|
||
ifeq ($(UNAME_S),Darwin) | ||
PLATFORM_TARGET := macos | ||
LIBRARY_FILE := $(LIBRARY_FILE_MAC) | ||
else ifeq ($(UNAME_S),Linux) | ||
PLATFORM_TARGET := linux | ||
LIBRARY_FILE := $(LIBRARY_FILE_LINUX) | ||
else ifeq ($(OS),Windows_NT) | ||
PLATFORM_TARGET := windows | ||
LIBRARY_FILE := $(LIBRARY_NAME).dll | ||
else | ||
PLATFORM_TARGET := unknown | ||
LIBRARY_FILE := | ||
endif | ||
|
||
# Default target: build only for detected platform | ||
all: $(PLATFORM_TARGET) | ||
|
||
macos: | ||
@echo "Compiling Objective-C code to a dynamic library for macOS..." | ||
@mkdir -p build | ||
$(COMPILER) -dynamiclib -o build/$(LIBRARY_FILE_MAC) $(FILES) -framework Foundation -framework SystemConfiguration -framework CoreFoundation -framework Network -framework CFNetwork -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/darwin | ||
@echo "Library created at build/$(LIBRARY_FILE_MAC)" | ||
|
||
linux: | ||
@echo "Compiling Objective-C code to a dynamic library for Linux..." | ||
@mkdir -p build | ||
$(COMPILER) -shared -fPIC -o build/$(LIBRARY_FILE_LINUX) $(FILES) -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux | ||
@echo "Library created at build/$(LIBRARY_FILE_LINUX)" | ||
|
||
windows: | ||
@echo "Compiling Objective-C code to a dynamic library for Windows..." | ||
@mkdir -p build | ||
$(COMPILER) -shared -m64 -o build\\$(LIBRARY_NAME).dll $(FILES) '-I$(JAVA_HOME)\\include' '-I$(JAVA_HOME)\\include\\win32' -lws2_32 -liphlpapi | ||
@echo "Library created at build/$(LIBRARY_NAME).dll" | ||
|
||
# Install the library to system path | ||
install: all | ||
@echo "Installing library to system path..." | ||
ifeq ($(PLATFORM_TARGET),macos) | ||
cp build/$(LIBRARY_FILE_MAC) $(HOME)/Library/Java/Extensions | ||
else ifeq ($(PLATFORM_TARGET),linux) | ||
sudo cp build/$(LIBRARY_FILE_LINUX) /usr/lib/ | ||
else ifeq ($(PLATFORM_TARGET),windows) | ||
copy build\\$(LIBRARY_NAME).dll %JAVA_HOME%\\bin | ||
else | ||
@echo "Unknown platform, not installing." | ||
endif | ||
@echo "Library installed" | ||
|
||
clean: | ||
@echo "Cleaning build artifacts..." | ||
rm -rf build | ||
@echo "Clean complete" | ||
|
||
help: | ||
@echo "NetworkTypeFinder JNI Bridge Makefile" | ||
@echo "" | ||
@echo "Targets:" | ||
@echo " all (default): Compile Objective-C code to a dynamic library for the current platform" | ||
@echo " install: Install the library to system path for the current platform" | ||
@echo " clean: Clean build artifacts" | ||
@echo " help: Show this help message" | ||
@echo "" | ||
@echo "Example usage:" | ||
@echo " make all # Compile the library for your platform" | ||
@echo " make install # Install the library for your platform" | ||
|
||
.PHONY: all macos linux windows install clean help |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or 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,15 @@ | ||
#ifndef NetworkTypeFinder_h | ||
#define NetworkTypeFinder_h | ||
|
||
#include <jni.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
JNIEXPORT jstring JNICALL Java_org_ooni_engine_MacOsNetworkTypeFinder_getNetworkType(JNIEnv *env, jobject obj); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not just
MacOs
right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes