diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 9 | ||||
-rw-r--r-- | Readme.md | 7 | ||||
-rw-r--r-- | WORKSPACE | 14 | ||||
-rw-r--r-- | app/java/AndroidManifest.xml | 41 | ||||
-rw-r--r-- | app/java/BUILD | 14 | ||||
-rw-r--r-- | app/java/res/layout/main.xml | 29 | ||||
-rw-r--r-- | app/java/res/values/dimens.xml | 4 | ||||
-rw-r--r-- | app/java/res/values/strings.xml | 10 | ||||
-rw-r--r-- | app/java/src/DNSService.java | 33 | ||||
-rw-r--r-- | app/java/src/MainActivity.java | 68 | ||||
-rw-r--r-- | shell.nix | 31 |
12 files changed, 261 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a6ef824 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bazel-* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9003dc3 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +build: app/java/src/*.java + bazel build //app/java:dnsproxy + +watch: + ibazel build //app/java:dnsproxy + +install: + adb install bazel-bin/app/java/dnsproxy.apk + #bazel mobile-install //app/java:dnsproxy diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..804c469 --- /dev/null +++ b/Readme.md @@ -0,0 +1,7 @@ +- https://github.com/IngoZenz/personaldnsfilter/blob/master/app/src/main/java/dnsfilter/android/DNSFilterService.java +- https://android.googlesource.com/platform/development/+/master/samples/ToyVpn/src/com/example/android/toyvpn/ToyVpnService.java +- https://developer.android.com/guide/components/services#StartingAService +- https://developer.android.com/guide/components/services#Foreground +- https://stackoverflow.com/questions/600207/how-to-check-if-a-service-is-running-on-android +- https://www.vogella.com/tutorials/AndroidServices/article.html#communication-with-services +- https://github.com/googlecodelabs/bazel-android-intro/blob/master/sample/mediarecorder/java/com/example/android/mediarecorder/MainActivity.java diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 0000000..24b7050 --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,14 @@ +# Load the Android build rules +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +http_archive( + name = "build_bazel_rules_android", + urls = ["https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip"], + sha256 = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806", + strip_prefix = "rules_android-0.1.1", +) + +# Configure Android SDK Path +load("@build_bazel_rules_android//android:rules.bzl", "android_sdk_repository") +android_sdk_repository( + name = "androidsdk", +) diff --git a/app/java/AndroidManifest.xml b/app/java/AndroidManifest.xml new file mode 100644 index 0000000..ef81463 --- /dev/null +++ b/app/java/AndroidManifest.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<manifest + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + package="org.pihole.dnsproxy" + android:versionCode="1" + android:versionName="1.0" +> + <uses-sdk + android:minSdkVersion="16" + android:targetSdkVersion="28" + /> + + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> + <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> + <uses-permission android:name="android.permission.INTERNET" /> + + <application + android:usesCleartextTraffic="true" + > + <service + android:name=".DNSService" + android:permission="android.permission.BIND_VPN_SERVICE" + > + <intent-filter> + <action android:name="android.net.VpnService" /> + </intent-filter> + </service> + + <activity + android:name=".MainActivity" + android:label="@string/label" + android:screenOrientation="portrait" + > + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> +</manifest> diff --git a/app/java/BUILD b/app/java/BUILD new file mode 100644 index 0000000..c19473f --- /dev/null +++ b/app/java/BUILD @@ -0,0 +1,14 @@ +load("@build_bazel_rules_android//android:rules.bzl", "android_library", "android_binary") + +android_library( + name = "main", + srcs = glob(["src/*.java"]), + manifest = "AndroidManifest.xml", + resource_files = glob(["res/**"]), +) + +android_binary( + name = "dnsproxy", + manifest = "AndroidManifest.xml", + deps = [":main"], +) diff --git a/app/java/res/layout/main.xml b/app/java/res/layout/main.xml new file mode 100644 index 0000000..4a644b6 --- /dev/null +++ b/app/java/res/layout/main.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<FrameLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingRight="@dimen/activity_horizontal_margin" + android:paddingTop="@dimen/activity_vertical_margin" + android:paddingBottom="@dimen/activity_vertical_margin" + android:orientation="vertical" + tools:context=".MainActivity" +> + + <TextureView + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:id="@+id/surface_view" + /> + + <Button + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:id="@+id/button_start" + android:layout_gravity="center" + android:onClick="onStartClick" + android:text="@string/btnStart" + /> +</FrameLayout> diff --git a/app/java/res/values/dimens.xml b/app/java/res/values/dimens.xml new file mode 100644 index 0000000..fe991af --- /dev/null +++ b/app/java/res/values/dimens.xml @@ -0,0 +1,4 @@ +<resources> + <dimen name="activity_horizontal_margin">16dp</dimen> + <dimen name="activity_vertical_margin">16dp</dimen> +</resources> diff --git a/app/java/res/values/strings.xml b/app/java/res/values/strings.xml new file mode 100644 index 0000000..beab6c5 --- /dev/null +++ b/app/java/res/values/strings.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="label"> + Pihole DNS Proxy + </string> + + <string name="btnStart"> + Start Proxy + </string> +</resources> diff --git a/app/java/src/DNSService.java b/app/java/src/DNSService.java new file mode 100644 index 0000000..4f760a5 --- /dev/null +++ b/app/java/src/DNSService.java @@ -0,0 +1,33 @@ +package org.pihole.dnsproxy; + +import android.app.AlertDialog; +import android.app.Service; + +import android.content.Intent; + +import android.net.VpnService; + +public class DNSService extends VpnService { + + private static boolean isRunning = false; + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + //VpnService.prepare(); + + DNSService.isRunning = true; + + return Service.START_STICKY; + } + + @Override + public void onDestroy() { + DNSService.isRunning = false; + super.onDestroy(); + } + + public static boolean isRunning() + { + return DNSService.isRunning; + } +} diff --git a/app/java/src/MainActivity.java b/app/java/src/MainActivity.java new file mode 100644 index 0000000..9fd99f6 --- /dev/null +++ b/app/java/src/MainActivity.java @@ -0,0 +1,68 @@ +package org.pihole.dnsproxy; + +import android.app.Activity; +import android.app.AlertDialog; + +import android.content.Intent; + +import android.net.VpnService; + +import android.os.Bundle; + +import android.view.TextureView; +import android.view.View; + +import android.widget.Button; +import android.widget.Toast; + +public class MainActivity extends Activity { + + private Button buttonStart; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + + this.buttonStart = (Button) findViewById(R.id.button_start); + this.buttonStart.setText(DNSService.isRunning() ? "Stop" : "Start"); + } + + @Override + public void onResume() { + super.onResume(); + this.buttonStart.setText("on RESSSSUME"); + } + + @Override + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {} + + public void onStartClick(View view) { + Intent intent = VpnService.prepare(this); + if (intent != null) { + startActivityForResult(intent, 0); + } + //Intent intent = new Intent(this, DNSService.class); + + if (!DNSService.isRunning()) { + startService(intent); + + new AlertDialog.Builder(this) + .setTitle("PROXY START") + .setMessage("BRRR") + .show(); + Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show(); + this.buttonStart.setText("Stop"); + } + else { + stopService(intent); + + new AlertDialog.Builder(this) + .setTitle("PROXY STOP") + .setMessage("RRRB") + .show(); + Toast.makeText(this, "service stopping", Toast.LENGTH_SHORT).show(); + this.buttonStart.setText("Start"); + } + } +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..767fb3d --- /dev/null +++ b/shell.nix @@ -0,0 +1,31 @@ +with (import <nixpkgs> { + config.android_sdk.accept_license = true; +}); +let + jdk = jdk11; + android_composition = androidenv.composeAndroidPackages { + platformVersions = ["28"]; + }; + #androidsdk = androidenv.androidPkgs_9_0.androidsdk; + androidsdk = android_composition.androidsdk; +in +mkShell rec { + buildInputs = [ + jdk + androidsdk + #android-studio + bazel + python2 + bazel-watcher + java-language-server + ]; + + JAVA_HOME = jdk.home; + ANDROID_SDK_ROOT = "${androidsdk}/libexec/android-sdk"; + ANDROID_NDK_ROOT = "${ANDROID_SDK_ROOT}/ndk-bundle"; + ANDROID_HOME = "${ANDROID_SDK_ROOT}"; + + shellHook = '' + echo ":lua require('lspconfig').java_language_server.setup { cmd = { '${java-language-server}/share/java/java-language-server/lang_server_linux.sh' } }" + ''; +} |