So close. We can do it without the .so.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4214 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2023-03-11 03:47:01 +00:00
parent f74f4f6da9
commit 2a3b1a1e33
2 changed files with 49 additions and 18 deletions

View File

@ -9,8 +9,16 @@ import android.os.SystemClock;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import java.lang.Process;
import java.lang.Thread;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.BufferedInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -20,8 +28,41 @@ public class MainActivity extends Activity {
WebView web = (WebView)findViewById(R.id.web);
Log.w("tildefriends", String.format("getFilesDir() is %s", getFilesDir().toString()));
Log.w("tildefriends", String.format("getPackageResourcePath() is %s", getPackageResourcePath().toString()));
Log.w("tildefriends", String.format("getPackageCodePath() is %s", getPackageCodePath().toString()));
setFilesPath(getFilesDir().toString(), getPackageResourcePath().toString());
try {
ZipInputStream zip = new ZipInputStream(new BufferedInputStream(new FileInputStream(getPackageResourcePath().toString())));
ZipEntry entry = null;
while ((entry = zip.getNextEntry()) != null) {
if (entry.getName().equals("lib/arm64-v8a/tildefriends")) {
FileOutputStream out = new FileOutputStream(getFilesDir().toString().concat("/tildefriends"));
byte[] buffer = new byte[32768];
int count;
while ((count = zip.read(buffer)) != -1) {
out.write(buffer, 0, count);
}
out.close();
new File(getFilesDir().toString() + "/tildefriends").setExecutable(true);
}
zip.closeEntry();
}
} catch (java.io.FileNotFoundException e) {
Log.w("tildefriends", "FileNotFoundException extracting executable");
Log.w("tildefriends", e.toString());
} catch (java.io.IOException e) {
Log.w("tildefriends", "IOException extracting executable");
Log.w("tildefriends", e.toString());
}
ProcessBuilder builder = new ProcessBuilder(getFilesDir().toString() + "/tildefriends", "run", "-z", getPackageResourcePath().toString());
Log.w("tildefriends", "files = " + getFilesDir().toString());
builder.directory(getFilesDir());
builder.inheritIO();
try {
builder.start();
} catch (java.io.IOException e) {
Log.w("tildefriends", "IOException starting process: " + e.toString());
}
try {
Thread.sleep(1000);
} catch (java.lang.InterruptedException e) {
@ -43,8 +84,6 @@ public class MainActivity extends Activity {
web.loadUrl("http://127.0.0.1:12345/~core/apps/");
}
public native void setFilesPath(String files_path, String apk_path);
static {
System.loadLibrary("tildefriends");
}