Compare commits
15 Commits
v0.0.20
...
b8cd1232be
Author | SHA1 | Date | |
---|---|---|---|
b8cd1232be | |||
a518ab07f4 | |||
9e5a1ee975 | |||
95bf3f0316 | |||
d69dd513bc | |||
525cdf571a | |||
9cfe0a8804 | |||
50b54599ef | |||
ed6bef6d24 | |||
71268636df | |||
568729ecd6 | |||
9139725be6 | |||
969a8da6bf
|
|||
2338b26329 | |||
d4df206740 |
26
.fdroid.yml
Normal file
26
.fdroid.yml
Normal file
@ -0,0 +1,26 @@
|
||||
License: MIT
|
||||
|
||||
AutoName: tildefriends
|
||||
|
||||
RepoType: git
|
||||
Repo: https://dev.tildefriends.net/cory/tildefriends.git
|
||||
|
||||
Categories: Internet
|
||||
|
||||
Builds:
|
||||
- versionName: 0.0.21-wip
|
||||
versionCode: 22
|
||||
commit: 9e5a1ee9758281a93521cacd9cd396e0c3763072
|
||||
subdir: src/android
|
||||
submodules: true
|
||||
scanignore:
|
||||
- deps/libuv/docs/src/static/diagrams.key/Index.zip
|
||||
androidupdate:
|
||||
- no
|
||||
build:
|
||||
- mkdir bin/
|
||||
- ANDROID_SDK=$$SDK$$ ANDROID_NDK=$$NDK$$ make -C ../../ -j`nproc` out/apk/TildeFriends-arm-release.unsigned.apk
|
||||
ndk: 26.3.11579264
|
||||
|
||||
AutoUpdateMode: None
|
||||
UpdateCheckMode: Tags
|
82
GNUmakefile
82
GNUmakefile
@ -3,12 +3,13 @@
|
||||
MAKEFLAGS += --warn-undefined-variables
|
||||
MAKEFLAGS += --no-builtin-rules
|
||||
|
||||
VERSION_CODE := 20
|
||||
VERSION_NUMBER := 0.0.20
|
||||
VERSION_NAME := They gave you a small cup.
|
||||
VERSION_CODE := 22
|
||||
VERSION_NUMBER := 0.0.21-wip
|
||||
VERSION_NAME := Psst. Look behind you.
|
||||
|
||||
SQLITE_URL := https://www.sqlite.org/2024/sqlite-amalgamation-3460000.zip
|
||||
LIBUV_URL := https://dist.libuv.org/dist/v1.48.0/libuv-v1.48.0.tar.gz
|
||||
BUNDLETOOL_URL := https://github.com/google/bundletool/releases/download/1.17.0/bundletool-all-1.17.0.jar
|
||||
|
||||
PROJECT = tildefriends
|
||||
BUILD_DIR ?= out
|
||||
@ -16,6 +17,7 @@ UNAME_S := $(shell uname -s)
|
||||
UNAME_M := $(shell uname -m)
|
||||
|
||||
ANDROID_SDK ?= ~/Android/Sdk
|
||||
BUNDLETOOL = out/bundletool.jar
|
||||
|
||||
HAVE_WIN := 0
|
||||
|
||||
@ -150,9 +152,10 @@ ANDROID_RELEASE_TARGETS := $(filter-out $(DEBUG_TARGETS),$(ANDROID_TARGETS))
|
||||
NONANDROID_RELEASE_TARGETS := $(filter-out $(ANDROID_ARM64_TARGETS),$(RELEASE_TARGETS))
|
||||
NONANDROID_TARGETS := $(filter-out $(ANDROID_TARGETS),$(ALL_TARGETS))
|
||||
NONMACOS_TARGETS := $(filter-out $(MACOS_TARGETS) $(IOS_TARGETS) $(IOSSIM_TARGETS),$(ALL_TARGETS))
|
||||
DEADSTRIP_TARGETS := $(filter-out $(ANDROID_TARGETS),$(NONMACOS_TARGETS))
|
||||
|
||||
$(NONANDROID_TARGETS): CFLAGS += -fno-omit-frame-pointer
|
||||
$(filter-out $(ANDROID_TARGETS) $(WINDOWS_TARGETS),$(ALL_TARGETS)): LDFLAGS += -rdynamic
|
||||
$(filter-out $(WINDOWS_TARGETS),$(ALL_TARGETS)): LDFLAGS += -rdynamic
|
||||
$(ANDROID_TARGETS): CFLAGS += \
|
||||
--sysroot $(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/sysroot \
|
||||
-fPIC \
|
||||
@ -205,7 +208,7 @@ $(ANDROID_X86_TARGETS): LDFLAGS += -Ldeps/openssl/android/x86/usr/local/lib
|
||||
$(ANDROID_X86_64_TARGETS): CFLAGS += -Ideps/openssl/android/x86_64/usr/local/include
|
||||
$(ANDROID_X86_64_TARGETS): LDFLAGS += -Ldeps/openssl/android/x86_64/usr/local/lib
|
||||
$(NONMACOS_TARGETS): CFLAGS += -Wno-cast-function-type
|
||||
$(NONMACOS_TARGETS): LDFLAGS += -Wl,--gc-sections
|
||||
$(DEADSTRIP_TARGETS): LDFLAGS += -Wl,--gc-sections
|
||||
$(IOS_TARGETS): CFLAGS += -mios-version-min=9.0 -Ideps/openssl/ios/ios64-xcrun/usr/local/include
|
||||
$(IOS_TARGETS): LDFLAGS += -Ldeps/openssl/ios/ios64-xcrun/usr/local/lib
|
||||
$(IOSSIM_TARGETS): CFLAGS += -Ideps/openssl/ios/iossimulator-xcrun/usr/local/include
|
||||
@ -616,7 +619,7 @@ $(IOS_TARGETS) $(IOSSIM_TARGETS): LDFLAGS += \
|
||||
|
||||
unix: debug release
|
||||
win: windebug winrelease
|
||||
all: $(BUILD_TYPES) default.nix
|
||||
all: $(BUILD_TYPES)
|
||||
.PHONY: all win unix
|
||||
|
||||
ALL_APP_OBJS := \
|
||||
@ -673,10 +676,6 @@ src/android/AndroidManifest.xml : $(firstword $(MAKEFILE_LIST))
|
||||
-e 's/android:targetSdkVersion="[[:digit:]]*"/android:targetSdkVersion="$(ANDROID_TARGET_SDK_VERSION)"/' \
|
||||
$@
|
||||
|
||||
default.nix : $(firstword $(MAKEFILE_LIST))
|
||||
@echo "[version] $@"
|
||||
@sed -i -e 's/version = ".*";/version = "$(VERSION_NUMBER)";/' $@
|
||||
|
||||
# Android support.
|
||||
out/res/layout_activity_main.xml.flat: src/android/res/layout/activity_main.xml
|
||||
@mkdir -p $(dir $@)
|
||||
@ -702,7 +701,7 @@ $(CLASS_FILES) &: $(JAVA_FILES)
|
||||
out/apk/classes.dex: $(CLASS_FILES)
|
||||
@mkdir -p $(dir $@)
|
||||
@echo "[d8] $@"
|
||||
@$(ANDROID_BUILD_TOOLS)/d8 --$(BUILD_TYPE) --lib $(ANDROID_PLATFORM)/android.jar --output $(dir $@) out/classes/com/unprompted/tildefriends/*.class
|
||||
@$(ANDROID_BUILD_TOOLS)/d8 --lib $(ANDROID_PLATFORM)/android.jar --output $(dir $@) out/classes/com/unprompted/tildefriends/*.class
|
||||
|
||||
PACKAGE_DIRS := \
|
||||
apps/ \
|
||||
@ -723,13 +722,51 @@ out/apk/TildeFriends-arm-release.unsigned.apk: out/apk/classes.dex out/androidre
|
||||
out/apk/TildeFriends-x86-debug.unsigned.apk: out/apk/classes.dex out/androiddebug-x86_64/tildefriends out/androiddebug-x86/tildefriends $(RAW_FILES) out/apk/res.apk
|
||||
out/apk/TildeFriends-x86-release.unsigned.apk: out/apk/classes.dex out/androidrelease-x86_64/tildefriends out/androidrelease-x86/tildefriends $(RAW_FILES) out/apk/res.apk
|
||||
|
||||
$(BUNDLETOOL):
|
||||
@echo [curl] $(BUNDLETOOL_URL) TO $@
|
||||
@curl -q -L --create-dirs -o $@ $(BUNDLETOOL_URL)
|
||||
|
||||
out/TildeFriends.aab: out/apk/classes.dex $(filter-out %debug%, $(ANDROID_TARGETS)) $(RAW_FILES) out/apk/res.apk src/android/AndroidManifest.xml $(BUNDLETOOL)
|
||||
@rm -rf out/aab/staging/
|
||||
@mkdir -p out/aab/staging
|
||||
@$(ANDROID_BUILD_TOOLS)/aapt2 link --proto-format -o out/aab/temporary.apk -I $(ANDROID_PLATFORM)/android.jar --manifest src/android/AndroidManifest.xml -R out/res/layout_activity_main.xml.flat -R out/res/drawable_icon.xml.flat --auto-add-overlay
|
||||
@unzip out/aab/temporary.apk -d out/aab/staging/
|
||||
@mkdir -p out/aab/staging/root/deps
|
||||
@mkdir -p out/aab/staging/classes
|
||||
@mkdir -p out/aab/staging/dex
|
||||
@mkdir -p out/aab/staging/manifest
|
||||
@mv out/aab/staging/AndroidManifest.xml out/aab/staging/manifest/AndroidManifest.xml
|
||||
@cp out/apk/classes.dex out/aab/staging/dex/
|
||||
@rm -fv out/base.zip
|
||||
@cp -r out/apk-arm-release/lib/ out/aab/staging/
|
||||
@cp -r out/apk-x86-release/lib/ out/aab/staging/
|
||||
@cp -r apps/ out/aab/staging/root/
|
||||
@rm -rf out/aab/staging/root/apps/welcome*
|
||||
@cp -r core/ out/aab/staging/root/
|
||||
@cp -r deps/prettier/ out/aab/staging/root/deps/
|
||||
@cp -r deps/lit/ out/aab/staging/root/deps/
|
||||
@cp -r deps/codemirror/ out/aab/staging/root/deps/
|
||||
@cd out/aab/staging/; zip -r ../base.zip *; cd ../../../
|
||||
@java -jar $(BUNDLETOOL) build-bundle --overwrite --config=src/android/BundleConfig.json --modules=out/aab/base.zip --output=$@
|
||||
@jarsigner -keystore .keys/android.jks $@ androidKey -storepass android
|
||||
|
||||
aab: out/TildeFriends.aab
|
||||
.PHONY: aab
|
||||
|
||||
out/TildeFriends.apks: out/TildeFriends.aab $(BUNDLETOOL)
|
||||
@java -jar $(BUNDLETOOL) build-apks --bundle out/TildeFriends.aab --overwrite --output $@ --ks .keys/android.jks --ks-key-alias androidKey --ks-pass pass:android
|
||||
|
||||
aabgo: out/TildeFriends.apks $(BUNDLETOOL)
|
||||
@java -jar $(BUNDLETOOL) install-apks --apks out/TildeFriends.apks
|
||||
@adb shell am start com.unprompted.tildefriends/.TildeFriendsActivity
|
||||
|
||||
out/apk/TildeFriends-arm-%.unsigned.apk:
|
||||
@mkdir -p $(dir $@) out/apk-arm-$(BUILD_TYPE)/lib/arm64-v8a/ out/apk-arm-$(BUILD_TYPE)/lib/armeabi-v7a/
|
||||
@echo "[aapt] $@"
|
||||
@cp out/android$(BUILD_TYPE)/tildefriends out/apk-arm-$(BUILD_TYPE)/lib/arm64-v8a/tildefriends.so
|
||||
@cp out/android$(BUILD_TYPE)-armv7a/tildefriends out/apk-arm-$(BUILD_TYPE)/lib/armeabi-v7a/tildefriends.so
|
||||
@$(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk-arm-$(BUILD_TYPE)/lib/arm64-v8a/tildefriends.so
|
||||
@$(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk-arm-$(BUILD_TYPE)/lib/armeabi-v7a/tildefriends.so
|
||||
@cp out/android$(BUILD_TYPE)/tildefriends out/apk-arm-$(BUILD_TYPE)/lib/arm64-v8a/libtildefriends.so
|
||||
@cp out/android$(BUILD_TYPE)-armv7a/tildefriends out/apk-arm-$(BUILD_TYPE)/lib/armeabi-v7a/libtildefriends.so
|
||||
@$(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk-arm-$(BUILD_TYPE)/lib/arm64-v8a/libtildefriends.so
|
||||
@$(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk-arm-$(BUILD_TYPE)/lib/armeabi-v7a/libtildefriends.so
|
||||
@cp out/apk/res.apk $@.zip
|
||||
@cp out/apk/classes.dex out/apk-arm-$(BUILD_TYPE)/
|
||||
@cd out/apk-arm-$(BUILD_TYPE) && zip -u ../../$@.zip -q -9 -r . && cd ../../
|
||||
@ -739,10 +776,10 @@ out/apk/TildeFriends-arm-%.unsigned.apk:
|
||||
out/apk/TildeFriends-x86-%.unsigned.apk:
|
||||
@mkdir -p $(dir $@) out/apk-x86-$(BUILD_TYPE)/lib/x86_64/ out/apk-x86-$(BUILD_TYPE)/lib/x86/
|
||||
@echo "[aapt] $@"
|
||||
@cp out/android$(BUILD_TYPE)-x86_64/tildefriends out/apk-x86-$(BUILD_TYPE)/lib/x86_64/tildefriends.so
|
||||
@cp out/android$(BUILD_TYPE)-x86/tildefriends out/apk-x86-$(BUILD_TYPE)/lib/x86/tildefriends.so
|
||||
@$(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk-x86-$(BUILD_TYPE)/lib/x86_64/tildefriends.so
|
||||
@$(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk-x86-$(BUILD_TYPE)/lib/x86/tildefriends.so
|
||||
@cp out/android$(BUILD_TYPE)-x86_64/tildefriends out/apk-x86-$(BUILD_TYPE)/lib/x86_64/libtildefriends.so
|
||||
@cp out/android$(BUILD_TYPE)-x86/tildefriends out/apk-x86-$(BUILD_TYPE)/lib/x86/libtildefriends.so
|
||||
@$(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk-x86-$(BUILD_TYPE)/lib/x86_64/libtildefriends.so
|
||||
@$(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk-x86-$(BUILD_TYPE)/lib/x86/libtildefriends.so
|
||||
@cp out/apk/res.apk $@.zip
|
||||
@cp out/apk/classes.dex out/apk-x86-$(BUILD_TYPE)/
|
||||
@cd out/apk-x86-$(BUILD_TYPE) && zip -u ../../$@.zip -q -9 -r . && cd ../../
|
||||
@ -761,6 +798,11 @@ out/%.zopfli.apk: out/%.apk
|
||||
release-apk: out/TildeFriends-arm-release.zopfli.apk out/TildeFriends-x86-release.zopfli.apk
|
||||
.PHONY: release-apk
|
||||
|
||||
apkgo: out/TildeFriends-arm-debug.apk
|
||||
@adb install -r $<
|
||||
@adb shell am start com.unprompted.tildefriends/.TildeFriendsActivity
|
||||
.PHONY: apkgo
|
||||
|
||||
releaseapkgo: out/TildeFriends-arm-release.apk
|
||||
@adb install -r $<
|
||||
@adb shell am start com.unprompted.tildefriends/.TildeFriendsActivity
|
||||
@ -862,7 +904,7 @@ clean:
|
||||
rm -rf $(BUILD_DIR)
|
||||
.PHONY: clean
|
||||
|
||||
dist: release-apk iosrelease-ipa $(if $(HAVE_WIN), out/winrelease/tildefriends.standalone.exe) default.nix
|
||||
dist: release-apk iosrelease-ipa $(if $(HAVE_WIN), out/winrelease/tildefriends.standalone.exe)
|
||||
@echo [archive] dist/tildefriends-$(VERSION_NUMBER).tar.xz
|
||||
@rm -rf out/tildefriends-$(VERSION_NUMBER)
|
||||
@mkdir -p dist/ out/tildefriends-$(VERSION_NUMBER)
|
||||
|
@ -25,6 +25,14 @@
|
||||
max-height: 100%;
|
||||
"
|
||||
>
|
||||
<noscript>
|
||||
<div class="w3-container">
|
||||
<div class="w3-panel w3-red w3-padding w3-card-4">
|
||||
<h1>TildeFriends requires JavaScript.</h1>
|
||||
<p>It looks like JavaScript is disabled or unsupported. This isn't going to work.</p>
|
||||
</div>
|
||||
</div>
|
||||
</noscript>
|
||||
<tf-navigation></tf-navigation>
|
||||
<div id="content" class="hbox" style="flex: 1 0; overflow: auto">
|
||||
<div
|
||||
|
@ -28,7 +28,7 @@ pkgs.stdenv.mkDerivation rec {
|
||||
owner = "cory";
|
||||
repo = "tildefriends";
|
||||
rev = "v${version}";
|
||||
hash = "sha256-ttqL2wz06Jvn2f6kKIAGpF0nSSle+g4nSlj4jL0D+Fk=";
|
||||
hash = "sha256-q7PQS/OnfPyU74FBsTmuwWn+G8XTJ11ulvTxf1sgUQk=";
|
||||
fetchSubmodules = true;
|
||||
};
|
||||
|
||||
|
@ -1,15 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.unprompted.tildefriends"
|
||||
android:versionCode="20"
|
||||
android:versionName="0.0.20">
|
||||
android:versionCode="22"
|
||||
android:versionName="0.0.21-wip">
|
||||
<uses-sdk android:minSdkVersion="24" android:targetSdkVersion="34"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<application
|
||||
android:label="Tilde Friends"
|
||||
android:usesCleartextTraffic="true"
|
||||
android:debuggable="true"
|
||||
android:extractNativeLibs="true">
|
||||
android:debuggable="false">
|
||||
<meta-data android:name="android.max_aspect" android:value="2.1"/>
|
||||
<activity
|
||||
android:name=".TildeFriendsActivity"
|
||||
@ -21,5 +20,10 @@
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<service
|
||||
android:name=".TildeFriendsSandboxService"
|
||||
android:exported="false"
|
||||
android:isolatedProcess="true"
|
||||
android:process=":sandbox"/>
|
||||
</application>
|
||||
</manifest>
|
||||
|
5
src/android/BundleConfig.json
Normal file
5
src/android/BundleConfig.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"optimizations" : {
|
||||
"uncompress_native_libraries" : {}
|
||||
}
|
||||
}
|
6
src/android/build.xml
Normal file
6
src/android/build.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<project>
|
||||
<target name="clean"></target>
|
||||
<target name="release">
|
||||
<echo>Creating ../../../out/apk/TildeFriends-arm-release.unsigned.apk for release.</echo>
|
||||
</target>
|
||||
</project>
|
@ -3,15 +3,18 @@ package com.unprompted.tildefriends;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.DownloadManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.os.Environment;
|
||||
import android.os.IBinder;
|
||||
import android.os.Parcel;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.RemoteException;
|
||||
import android.os.StrictMode;
|
||||
import android.os.SystemClock;
|
||||
import android.os.strictmode.Violation;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
@ -29,19 +32,13 @@ import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebResourceRequest;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.InputStream;
|
||||
import java.lang.Process;
|
||||
import java.lang.Thread;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardWatchEventKinds;
|
||||
@ -51,17 +48,30 @@ import java.nio.file.WatchService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class TildeFriendsActivity extends Activity {
|
||||
static TildeFriendsActivity s_activity;
|
||||
TildeFriendsWebView web_view;
|
||||
String base_url;
|
||||
Process process;
|
||||
String port_file_path;
|
||||
Thread thread;
|
||||
Thread server_thread;
|
||||
ServiceConnection service_connection;
|
||||
|
||||
private ValueCallback<Uri[]> upload_message;
|
||||
private final static int FILECHOOSER_RESULT = 1;
|
||||
private float touch_down_y;
|
||||
|
||||
static {
|
||||
Log.w("tildefriends", "Calling system.loadLibrary().");
|
||||
System.loadLibrary("tildefriends");
|
||||
Log.w("tildefriends", "system.loadLibrary() completed.");
|
||||
}
|
||||
|
||||
public static native int tf_server_main(String files_dir, String apk_path, String out_port_file_path);
|
||||
public static native int tf_sandbox_main(int pipe_fd);
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
s_activity = this;
|
||||
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
|
||||
.detectLeakedClosableObjects()
|
||||
.penaltyLog()
|
||||
@ -76,7 +86,7 @@ public class TildeFriendsActivity extends Activity {
|
||||
Log.w("tildefriends", String.format("getPackageResourcePath() is %s", getPackageResourcePath().toString()));
|
||||
Log.w("tildefriends", String.format("nativeLibraryDir is %s", getApplicationInfo().nativeLibraryDir));
|
||||
|
||||
String port_file_path = getFilesDir().toString() + "/port.txt";
|
||||
port_file_path = getFilesDir().toString() + "/port.txt";
|
||||
new File(port_file_path).delete();
|
||||
base_url = "http://127.0.0.1:12345/";
|
||||
|
||||
@ -134,17 +144,15 @@ public class TildeFriendsActivity extends Activity {
|
||||
thread.start();
|
||||
|
||||
set_status("Starting server...");
|
||||
String exe = getApplicationInfo().nativeLibraryDir + "/tildefriends.so";
|
||||
ProcessBuilder builder = new ProcessBuilder(exe, "run", "-z", getPackageResourcePath().toString(), "-a", "out_http_port_file=" + port_file_path, "-p", "0");
|
||||
Log.w("tildefriends", "files = " + getFilesDir().toString());
|
||||
Log.w("tildefriends", "exe = " + exe);
|
||||
builder.directory(getFilesDir());
|
||||
builder.inheritIO();
|
||||
try {
|
||||
process = builder.start();
|
||||
} catch (java.io.IOException e) {
|
||||
Log.w("tildefriends", "IOException starting process: " + e.toString());
|
||||
}
|
||||
server_thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.w("tildefriends", "Calling tf_server_main.");
|
||||
int result = tf_server_main(getFilesDir().toString(), getPackageResourcePath().toString(), port_file_path);
|
||||
Log.w("tildefriends", "tf_server_main returned " + result + ".");
|
||||
}
|
||||
});
|
||||
server_thread.start();
|
||||
|
||||
web_view.getSettings().setJavaScriptEnabled(true);
|
||||
web_view.getSettings().setDatabaseEnabled(true);
|
||||
@ -266,13 +274,8 @@ public class TildeFriendsActivity extends Activity {
|
||||
@Override
|
||||
protected void onDestroy()
|
||||
{
|
||||
if (process != null) {
|
||||
Log.w("tildefriends", "Killing process.");
|
||||
process.destroyForcibly();
|
||||
Log.w("tildefriends", "Process killed.");
|
||||
process = null;
|
||||
}
|
||||
super.onDestroy();
|
||||
s_activity = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -374,4 +377,49 @@ public class TildeFriendsActivity extends Activity {
|
||||
web_view.setVisibility(View.VISIBLE);
|
||||
text_view.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public static void start_sandbox(int pipe_fd) {
|
||||
Log.w("tildefriends", "starting service with fd: " + pipe_fd);
|
||||
Intent intent = new Intent(s_activity, TildeFriendsSandboxService.class);
|
||||
s_activity.service_connection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onBindingDied(ComponentName name) {
|
||||
Log.w("tildefriends", "onBindingDied");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNullBinding(ComponentName name) {
|
||||
Log.w("tildefriends", "onNullBinding");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder binder) {
|
||||
Log.w("tildefriends", "onServiceConnected");
|
||||
Parcel data = Parcel.obtain();
|
||||
ParcelFileDescriptor pfd = ParcelFileDescriptor.adoptFd(pipe_fd);
|
||||
data.writeParcelable(pfd, 0);
|
||||
try {
|
||||
binder.transact(TildeFriendsSandboxService.START_CALL, data, null, IBinder.FLAG_ONEWAY);
|
||||
} catch (RemoteException e) {
|
||||
Log.w("tildefriends", "RemoteException");
|
||||
} finally {
|
||||
data.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
Log.w("tildefriends", "onServiceDisconnected");
|
||||
}
|
||||
};
|
||||
s_activity.bindService(intent, s_activity.service_connection, BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
public static void stop_sandbox() {
|
||||
Log.w("tildefriends", "stop_sandbox");
|
||||
if (s_activity.service_connection != null) {
|
||||
s_activity.unbindService(s_activity.service_connection);
|
||||
s_activity.service_connection = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
package com.unprompted.tildefriends;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
import android.os.Parcel;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.util.Log;
|
||||
|
||||
public class TildeFriendsSandboxService extends Service {
|
||||
public static final int START_CALL = IBinder.FIRST_CALL_TRANSACTION;
|
||||
|
||||
Thread thread;
|
||||
|
||||
public int onStartCommand(Intent intent, int flags, int start_id) {
|
||||
Log.w("tildefriends", "TildeFriendsSandboxService: onStartCommand");
|
||||
return super.onStartCommand(intent, flags, start_id);
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
Log.w("tildefriends", "TildeFriendsSandboxService: onDestroy");
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private void start_thread(int pipe_fd) {
|
||||
thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.w("tildefriends", "Calling tf_sandbox_main.");
|
||||
int result = TildeFriendsActivity.tf_sandbox_main(pipe_fd);
|
||||
Log.w("tildefriends", "tf_sandbox_main returned " + result + ".");
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return new Binder() {
|
||||
@Override
|
||||
protected boolean onTransact(int code, Parcel data, Parcel reply, int flags) {
|
||||
if (code == START_CALL) {
|
||||
ParcelFileDescriptor pfd = data.readParcelable(ParcelFileDescriptor.class.getClassLoader(), ParcelFileDescriptor.class);
|
||||
if (pfd != null) {
|
||||
Log.w("tildefriends", "fd is " + pfd.getFd());
|
||||
start_thread(pfd.detachFd());
|
||||
try {
|
||||
pfd.close();
|
||||
} catch (java.io.IOException e) {
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ package com.unprompted.tildefriends;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
|
||||
public class TildeFriendsWebView extends android.webkit.WebView {
|
||||
boolean overscrolledY = false;
|
||||
|
145
src/main.c
145
src/main.c
@ -34,6 +34,10 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#include "jni.h"
|
||||
#endif
|
||||
|
||||
#if !defined(_countof)
|
||||
#define _countof(a) ((int)(sizeof((a)) / sizeof(*(a))))
|
||||
#endif
|
||||
@ -603,14 +607,16 @@ static int _tf_command_run(const char* file, int argc, char* argv[])
|
||||
static int _tf_command_sandbox(const char* file, int argc, char* argv[])
|
||||
{
|
||||
bool show_usage = false;
|
||||
int fd = STDIN_FILENO;
|
||||
|
||||
while (!show_usage)
|
||||
{
|
||||
static const struct option k_options[] = {
|
||||
{ "fd", required_argument, NULL, 'f' },
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ 0 },
|
||||
};
|
||||
int c = getopt_long(argc, argv, "h", k_options, NULL);
|
||||
int c = getopt_long(argc, argv, "f:h", k_options, NULL);
|
||||
if (c == -1)
|
||||
{
|
||||
break;
|
||||
@ -622,6 +628,9 @@ static int _tf_command_sandbox(const char* file, int argc, char* argv[])
|
||||
default:
|
||||
show_usage = true;
|
||||
break;
|
||||
case 'f':
|
||||
fd = atoi(optarg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -630,6 +639,7 @@ static int _tf_command_sandbox(const char* file, int argc, char* argv[])
|
||||
tf_printf("\nUsage: %s sandbox [options]\n\n", file);
|
||||
tf_printf("options:\n");
|
||||
tf_printf(" -h, --help Show this usage information.\n");
|
||||
tf_printf(" -f, --fd File descriptor with which to communicate with parent process.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@ -637,7 +647,7 @@ static int _tf_command_sandbox(const char* file, int argc, char* argv[])
|
||||
prctl(PR_SET_PDEATHSIG, SIGHUP);
|
||||
#endif
|
||||
tf_task_t* task = tf_task_create();
|
||||
tf_task_configure_from_fd(task, STDIN_FILENO);
|
||||
tf_task_configure_from_fd(task, fd);
|
||||
_shed_privileges();
|
||||
/* The caller will trigger tf_task_activate with a message. */
|
||||
tf_task_run(task);
|
||||
@ -685,10 +695,6 @@ static void _startup(int argc, char* argv[])
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
setenv("UV_USE_IO_URING", "0", 1);
|
||||
#endif
|
||||
|
||||
tf_mem_startup(tracking);
|
||||
g_backtrace_state = backtrace_create_state(argv[0], 0, _backtrace_error, NULL);
|
||||
|
||||
@ -716,7 +722,7 @@ static void _startup(int argc, char* argv[])
|
||||
{
|
||||
if (
|
||||
#if !defined(_WIN32)
|
||||
signal(SIGSYS, _error_handler) == SIG_ERR ||
|
||||
signal(SIGSYS, _error_handler) == SIG_ERR || signal(SIGABRT, _error_handler) == SIG_ERR ||
|
||||
#endif
|
||||
signal(SIGSEGV, _error_handler) == SIG_ERR)
|
||||
{
|
||||
@ -726,6 +732,131 @@ static void _startup(int argc, char* argv[])
|
||||
}
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
static JNIEnv* s_jni_env;
|
||||
|
||||
static void _tf_service_start(int pipe_fd)
|
||||
{
|
||||
tf_printf("_tf_service_start\n");
|
||||
jclass c = (*s_jni_env)->FindClass(s_jni_env, "com/unprompted/tildefriends/TildeFriendsActivity");
|
||||
jmethodID start_sandbox = (*s_jni_env)->GetStaticMethodID(s_jni_env, c, "start_sandbox", "(I)V");
|
||||
(*s_jni_env)->CallStaticVoidMethod(s_jni_env, c, start_sandbox, pipe_fd);
|
||||
}
|
||||
|
||||
static void _tf_service_stop()
|
||||
{
|
||||
tf_printf("_tf_service_stop\n");
|
||||
jclass c = (*s_jni_env)->FindClass(s_jni_env, "com/unprompted/tildefriends/TildeFriendsActivity");
|
||||
jmethodID stop_sandbox = (*s_jni_env)->GetStaticMethodID(s_jni_env, c, "stop_sandbox", "()V");
|
||||
(*s_jni_env)->CallStaticVoidMethod(s_jni_env, c, stop_sandbox);
|
||||
}
|
||||
|
||||
static jint _tf_server_main(JNIEnv* env, jobject this_object, jstring files_dir, jstring apk_path, jstring out_port_file_path)
|
||||
{
|
||||
s_jni_env = env;
|
||||
|
||||
tf_printf("This is tf_server_main main.\n");
|
||||
_startup(0, (char*[]) { NULL });
|
||||
tf_printf("That was startup.\n");
|
||||
|
||||
const char* files = (*env)->GetStringUTFChars(env, files_dir, NULL);
|
||||
const char* apk = (*env)->GetStringUTFChars(env, apk_path, NULL);
|
||||
const char* out_port_file = (*env)->GetStringUTFChars(env, out_port_file_path, NULL);
|
||||
|
||||
tf_printf("FILES = %s\n", files);
|
||||
tf_printf("APK = %s\n", apk);
|
||||
tf_printf("OUT_PORT = %s\n", out_port_file);
|
||||
|
||||
int result = uv_chdir(files);
|
||||
if (result)
|
||||
{
|
||||
tf_printf("uv_chdir: %s\n", uv_strerror(result));
|
||||
}
|
||||
|
||||
size_t port_file_arg_length = strlen(out_port_file) + strlen("out_http_port_file=") + 1;
|
||||
char* port_file_arg = alloca(port_file_arg_length);
|
||||
snprintf(port_file_arg, port_file_arg_length, "out_http_port_file=%s", out_port_file);
|
||||
|
||||
const char* args[] = {
|
||||
"run",
|
||||
"-z",
|
||||
apk,
|
||||
"-a",
|
||||
port_file_arg,
|
||||
"-p",
|
||||
"0",
|
||||
};
|
||||
|
||||
tf_task_set_android_service_callbacks(_tf_service_start, _tf_service_stop);
|
||||
result = _tf_command_run(apk, _countof(args), (char**)args);
|
||||
tf_task_set_android_service_callbacks(NULL, NULL);
|
||||
|
||||
(*env)->ReleaseStringUTFChars(env, files_dir, files);
|
||||
(*env)->ReleaseStringUTFChars(env, apk_path, apk);
|
||||
(*env)->ReleaseStringUTFChars(env, out_port_file_path, out_port_file);
|
||||
|
||||
tf_printf("tf_server_main finished with %d.", result);
|
||||
|
||||
s_jni_env = NULL;
|
||||
return result;
|
||||
}
|
||||
|
||||
static jint _tf_sandbox_main(JNIEnv* env, jobject this_object, int pipe_fd)
|
||||
{
|
||||
s_jni_env = env;
|
||||
|
||||
tf_printf("This is tf_sandbox_main main (fd=%d).\n", pipe_fd);
|
||||
_startup(0, (char*[]) { NULL });
|
||||
tf_printf("That was startup.\n");
|
||||
|
||||
char fd[32] = { 0 };
|
||||
snprintf(fd, sizeof(fd), "%d", pipe_fd);
|
||||
const char* args[] = {
|
||||
"sandbox",
|
||||
"-f",
|
||||
fd,
|
||||
};
|
||||
|
||||
int result = _tf_command_sandbox(NULL, _countof(args), (char**)args);
|
||||
|
||||
tf_printf("tf_sandbox_main finished with %d.", result);
|
||||
|
||||
s_jni_env = NULL;
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
||||
{
|
||||
tf_printf("JNI_Onload called.\n");
|
||||
JNIEnv* env;
|
||||
if ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) != JNI_OK)
|
||||
{
|
||||
tf_printf("Failed to get JNI environment.\n");
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
tf_printf("Finding class.\n");
|
||||
jclass c = (*env)->FindClass(env, "com/unprompted/tildefriends/TildeFriendsActivity");
|
||||
if (!c)
|
||||
{
|
||||
tf_printf("Failed to find TildeFriendsActivity class.\n");
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
tf_printf("Registering method.\n");
|
||||
static const JNINativeMethod methods[] = {
|
||||
{ "tf_server_main", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I", _tf_server_main },
|
||||
{ "tf_sandbox_main", "(I)I", _tf_sandbox_main },
|
||||
};
|
||||
int result = (*env)->RegisterNatives(env, c, methods, (int)_countof(methods));
|
||||
if (result != JNI_OK)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
tf_printf("Done.\n");
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
_startup(argc, argv);
|
||||
|
19
src/task.c
19
src/task.c
@ -50,6 +50,9 @@
|
||||
static JSClassID _import_class_id;
|
||||
static int _count;
|
||||
|
||||
static tf_android_start_service_t* s_android_start_service;
|
||||
static tf_android_stop_service_t* s_android_stop_service;
|
||||
|
||||
extern struct backtrace_state* g_backtrace_state;
|
||||
|
||||
typedef struct _export_record_t export_record_t;
|
||||
@ -2160,3 +2163,19 @@ static JSValue _tf_task_pokeSandbox(JSContext* context, JSValueConst this_val, i
|
||||
#endif
|
||||
return JS_NewInt32(context, WEXITSTATUS(result));
|
||||
}
|
||||
|
||||
void tf_task_set_android_service_callbacks(tf_android_start_service_t* start_service, tf_android_stop_service_t* stop_service)
|
||||
{
|
||||
s_android_start_service = start_service;
|
||||
s_android_stop_service = stop_service;
|
||||
}
|
||||
|
||||
tf_android_start_service_t* tf_task_get_android_start_service()
|
||||
{
|
||||
return s_android_start_service;
|
||||
}
|
||||
|
||||
tf_android_stop_service_t* tf_task_get_android_stop_service()
|
||||
{
|
||||
return s_android_stop_service;
|
||||
}
|
||||
|
31
src/task.h
31
src/task.h
@ -333,4 +333,35 @@ char* tf_task_get_debug(tf_task_t* task);
|
||||
*/
|
||||
char* tf_task_get_hitches(tf_task_t* task);
|
||||
|
||||
/**
|
||||
** A callback used to start an Android service.
|
||||
** @param pipe_fd A file descriptor with which to communicate with the invoking
|
||||
** task.
|
||||
*/
|
||||
typedef void(tf_android_start_service_t)(int pipe_fd);
|
||||
|
||||
/**
|
||||
** A callback used to stop an Android service.
|
||||
*/
|
||||
typedef void(tf_android_stop_service_t)();
|
||||
|
||||
/**
|
||||
** Set Android service callbacks.
|
||||
** @param start_service Start service callback.
|
||||
** @param stop_service Stop service callback.
|
||||
*/
|
||||
void tf_task_set_android_service_callbacks(tf_android_start_service_t* start_service, tf_android_stop_service_t* stop_service);
|
||||
|
||||
/**
|
||||
** Get the callback registered for starting an Android service.
|
||||
** @return the callback.
|
||||
*/
|
||||
tf_android_start_service_t* tf_task_get_android_start_service();
|
||||
|
||||
/**
|
||||
** Get the callback registered for stopping an Android service.
|
||||
** @return the callback.
|
||||
*/
|
||||
tf_android_stop_service_t* tf_task_get_android_stop_service();
|
||||
|
||||
/** @} */
|
||||
|
@ -122,10 +122,11 @@ static JSValue _taskstub_create(JSContext* context, JSValueConst this_val, int a
|
||||
char arg1[] = "sandbox";
|
||||
char* command_argv[] = { _executable, arg1, 0 };
|
||||
|
||||
tf_android_start_service_t* start_service = tf_task_get_android_start_service();
|
||||
JSValue result = JS_NULL;
|
||||
if (tf_task_get_one_proc(parent))
|
||||
if (tf_task_get_one_proc(parent) || start_service)
|
||||
{
|
||||
uv_os_sock_t fds[2];
|
||||
uv_os_sock_t fds[2] = { 0 };
|
||||
int pipe_result = uv_socketpair(SOCK_STREAM, 0, fds, 0, 0);
|
||||
if (pipe_result)
|
||||
{
|
||||
@ -133,7 +134,7 @@ static JSValue _taskstub_create(JSContext* context, JSValueConst this_val, int a
|
||||
}
|
||||
|
||||
uv_pipe_t* pipe = tf_packetstream_get_pipe(stub->_stream);
|
||||
memset(pipe, 0, sizeof(*pipe));
|
||||
*pipe = (uv_pipe_t) { 0 };
|
||||
pipe_result = uv_pipe_init(tf_task_get_loop(parent), pipe, 1);
|
||||
if (pipe_result != 0)
|
||||
{
|
||||
@ -145,8 +146,16 @@ static JSValue _taskstub_create(JSContext* context, JSValueConst this_val, int a
|
||||
tf_printf("uv_pipe_open failed: %s\n", uv_strerror(pipe_result));
|
||||
}
|
||||
|
||||
uv_thread_t* thread = tf_malloc(sizeof(uv_thread_t));
|
||||
uv_thread_create(thread, _tf_taskstub_run_sandbox_thread, (void*)(intptr_t)fds[1]);
|
||||
if (start_service)
|
||||
{
|
||||
start_service(fds[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* XXX: This is a leak. */
|
||||
uv_thread_t* thread = tf_malloc(sizeof(uv_thread_t));
|
||||
uv_thread_create(thread, _tf_taskstub_run_sandbox_thread, (void*)(intptr_t)fds[1]);
|
||||
}
|
||||
|
||||
tf_packetstream_set_on_receive(stub->_stream, tf_task_on_receive_packet, stub);
|
||||
tf_packetstream_start(stub->_stream);
|
||||
@ -443,7 +452,15 @@ JSValue tf_taskstub_kill(tf_taskstub_t* stub)
|
||||
JSValue result = JS_UNDEFINED;
|
||||
if (!tf_task_get_one_proc(stub->_owner))
|
||||
{
|
||||
uv_process_kill(&stub->_process, SIGKILL);
|
||||
tf_android_stop_service_t* stop_service = tf_task_get_android_stop_service();
|
||||
if (stop_service)
|
||||
{
|
||||
stop_service();
|
||||
}
|
||||
else
|
||||
{
|
||||
uv_process_kill(&stub->_process, SIGKILL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,2 +1,2 @@
|
||||
#define VERSION_NUMBER "0.0.20"
|
||||
#define VERSION_NAME "They gave you a small cup."
|
||||
#define VERSION_NUMBER "0.0.21-wip"
|
||||
#define VERSION_NAME "Psst. Look behind you."
|
||||
|
Reference in New Issue
Block a user