Better lifetimes still in the Java code, and turn on some strict vm policy messages.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4414 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
59b2ffaf95
commit
d96b836bef
@ -41,10 +41,14 @@ public class MainActivity extends Activity {
|
|||||||
WebView web_view;
|
WebView web_view;
|
||||||
String base_url;
|
String base_url;
|
||||||
Process process;
|
Process process;
|
||||||
WatchService watcher;
|
Thread thread;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
|
||||||
|
.detectLeakedClosableObjects()
|
||||||
|
.penaltyLog()
|
||||||
|
.build());
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
@ -55,8 +59,7 @@ public class MainActivity extends Activity {
|
|||||||
Log.w("tildefriends", String.format("getPackageResourcePath() is %s", getPackageResourcePath().toString()));
|
Log.w("tildefriends", String.format("getPackageResourcePath() is %s", getPackageResourcePath().toString()));
|
||||||
Log.w("tildefriends", String.format("os.arch is %s", arch));
|
Log.w("tildefriends", String.format("os.arch is %s", arch));
|
||||||
|
|
||||||
try {
|
try (ZipInputStream zip = new ZipInputStream(new BufferedInputStream(new FileInputStream(getPackageResourcePath().toString())))) {
|
||||||
ZipInputStream zip = new ZipInputStream(new BufferedInputStream(new FileInputStream(getPackageResourcePath().toString())));
|
|
||||||
ZipEntry entry = null;
|
ZipEntry entry = null;
|
||||||
String lookup = String.format("bin/%s/tildefriends", arch);
|
String lookup = String.format("bin/%s/tildefriends", arch);
|
||||||
Log.w("tildefriends", "Looking for " + lookup);
|
Log.w("tildefriends", "Looking for " + lookup);
|
||||||
@ -71,7 +74,6 @@ public class MainActivity extends Activity {
|
|||||||
}
|
}
|
||||||
out.close();
|
out.close();
|
||||||
new File(getFilesDir().toString() + "/tildefriends").setExecutable(true);
|
new File(getFilesDir().toString() + "/tildefriends").setExecutable(true);
|
||||||
} finally {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zip.closeEntry();
|
zip.closeEntry();
|
||||||
@ -89,12 +91,11 @@ public class MainActivity extends Activity {
|
|||||||
|
|
||||||
MainActivity activity = this;
|
MainActivity activity = this;
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
thread = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
|
||||||
Log.w("tildefriends", "Watching for changes in: " + getFilesDir().toString());
|
Log.w("tildefriends", "Watching for changes in: " + getFilesDir().toString());
|
||||||
watcher = FileSystems.getDefault().newWatchService();
|
try (WatchService watcher = FileSystems.getDefault().newWatchService()) {
|
||||||
Paths.get(getFilesDir().toString()).register(
|
Paths.get(getFilesDir().toString()).register(
|
||||||
watcher,
|
watcher,
|
||||||
StandardWatchEventKinds.ENTRY_CREATE,
|
StandardWatchEventKinds.ENTRY_CREATE,
|
||||||
@ -108,8 +109,6 @@ public class MainActivity extends Activity {
|
|||||||
activity.runOnUiThread(() -> {
|
activity.runOnUiThread(() -> {
|
||||||
web_view.loadUrl(base_url);
|
web_view.loadUrl(base_url);
|
||||||
});
|
});
|
||||||
watcher.close();
|
|
||||||
watcher = null;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,7 +123,8 @@ public class MainActivity extends Activity {
|
|||||||
Log.w("tildefriends", "InterruptedException: " + e.toString());
|
Log.w("tildefriends", "InterruptedException: " + e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
});
|
||||||
|
thread.start();
|
||||||
|
|
||||||
String exe = getFilesDir().toString() + "/tildefriends";
|
String exe = getFilesDir().toString() + "/tildefriends";
|
||||||
ProcessBuilder builder = new ProcessBuilder(exe, "run", "-z", getPackageResourcePath().toString(), "-a", "out_http_port_file=" + port_file_path, "-p", "0");
|
ProcessBuilder builder = new ProcessBuilder(exe, "run", "-z", getPackageResourcePath().toString(), "-a", "out_http_port_file=" + port_file_path, "-p", "0");
|
||||||
@ -237,21 +237,12 @@ public class MainActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int read_port(String path) {
|
private int read_port(String path) {
|
||||||
BufferedReader reader = null;
|
try (BufferedReader reader = new BufferedReader(new FileReader(path))) {
|
||||||
try {
|
|
||||||
reader = new BufferedReader(new FileReader(path));
|
|
||||||
return Integer.parseInt(reader.readLine());
|
return Integer.parseInt(reader.readLine());
|
||||||
} catch (java.io.FileNotFoundException e) {
|
} catch (java.io.FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (java.io.IOException e) {
|
} catch (java.io.IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (reader != null) {
|
|
||||||
reader.close();
|
|
||||||
}
|
|
||||||
} catch (java.io.IOException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user