@tokamakdev/platform-android-arm64 0.1.1-beta.50 → 0.1.1-beta.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
Binary file
|
|
@@ -38,8 +38,8 @@ class TokamakApplication : Application(), TokamakHost {
|
|
|
38
38
|
requireNotNull(metadata()?.getString(HOST_METADATA)) { "$HOST_METADATA is required" }
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
override fun
|
|
42
|
-
runtime.
|
|
41
|
+
override fun call(name: String, body: String, timeoutMillis: Long): String =
|
|
42
|
+
runtime.call(name, body, timeoutMillis)
|
|
43
43
|
|
|
44
44
|
override fun plugin(id: String): TokamakPlugin? = plugins[id]
|
|
45
45
|
|
|
@@ -50,7 +50,7 @@ class TokamakApplication : Application(), TokamakHost {
|
|
|
50
50
|
return if (!endpoint.isNullOrEmpty() && !sessionToken.isNullOrEmpty()) {
|
|
51
51
|
TokamakRuntime.startDevelopment(stateDir(), appHost, endpoint, sessionToken)
|
|
52
52
|
} else {
|
|
53
|
-
TokamakRuntime.start(unpackApp(), stateDir(), appHost)
|
|
53
|
+
TokamakRuntime.start(unpackApp(), stateDir(), storageDir(), appHost)
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -59,8 +59,8 @@ class TokamakApplication : Application(), TokamakHost {
|
|
|
59
59
|
|
|
60
60
|
/** Copy the packaged app out of the APK once per install, so the runtime can read it as files. */
|
|
61
61
|
private fun unpackApp(): File {
|
|
62
|
-
val app = File(
|
|
63
|
-
val unpacked = File(
|
|
62
|
+
val app = File(noBackupFilesDir, "tokamak/app")
|
|
63
|
+
val unpacked = File(noBackupFilesDir, "tokamak/app.installed")
|
|
64
64
|
val installed = packageManager.getPackageInfo(packageName, 0).lastUpdateTime.toString()
|
|
65
65
|
if (unpacked.isFile && unpacked.readText() == installed) return app
|
|
66
66
|
app.deleteRecursively()
|
|
@@ -82,5 +82,16 @@ class TokamakApplication : Application(), TokamakHost {
|
|
|
82
82
|
for (entry in entries) copyAsset("$source/$entry", File(destination, entry))
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
/** Runtime state, which backups leave out. */
|
|
86
|
+
private fun stateDir(): File = File(noBackupFilesDir, "tokamak/state").apply { mkdirs() }
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Stores behind storage bindings, which Auto Backup includes. tokamak keeps nothing else in the
|
|
90
|
+
* files directory, so everything else under `tokamak` there is removed.
|
|
91
|
+
*/
|
|
92
|
+
private fun storageDir(): File {
|
|
93
|
+
val root = File(filesDir, "tokamak")
|
|
94
|
+
root.listFiles()?.filter { it.name != "storage" }?.forEach { it.deleteRecursively() }
|
|
95
|
+
return File(root, "storage").apply { mkdirs() }
|
|
96
|
+
}
|
|
86
97
|
}
|
|
@@ -15,12 +15,11 @@ internal class TokamakRuntime private constructor(private val handle: Long) {
|
|
|
15
15
|
fun resume() = nativeResume(handle)
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
* [timeoutMillis] passes
|
|
20
|
-
* no such handler.
|
|
18
|
+
* Posts the JSON [body] to the Worker's `/tokamak/<name>` endpoint, blocking until it
|
|
19
|
+
* responds 200 or [timeoutMillis] passes, and returns the response body.
|
|
21
20
|
*/
|
|
22
|
-
fun
|
|
23
|
-
|
|
21
|
+
fun call(name: String, body: String, timeoutMillis: Long): String =
|
|
22
|
+
nativeCall(handle, name, body, timeoutMillis)
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
25
|
* The authority a server certificate for [host] must chain to, or null
|
|
@@ -41,8 +40,13 @@ internal class TokamakRuntime private constructor(private val handle: Long) {
|
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
/** Start the runtime, throwing when it cannot serve the app. */
|
|
44
|
-
fun start(
|
|
45
|
-
|
|
43
|
+
fun start(
|
|
44
|
+
packagedDir: File,
|
|
45
|
+
stateDir: File,
|
|
46
|
+
storageDir: File,
|
|
47
|
+
host: String,
|
|
48
|
+
): TokamakRuntime =
|
|
49
|
+
TokamakRuntime(nativeStart(packagedDir.path, stateDir.path, storageDir.path, host))
|
|
46
50
|
|
|
47
51
|
/** Start the runtime against a host development server. */
|
|
48
52
|
fun startDevelopment(
|
|
@@ -54,7 +58,12 @@ internal class TokamakRuntime private constructor(private val handle: Long) {
|
|
|
54
58
|
TokamakRuntime(nativeStartDevelopment(stateDir.path, host, endpoint, sessionToken))
|
|
55
59
|
|
|
56
60
|
@JvmStatic
|
|
57
|
-
private external fun nativeStart(
|
|
61
|
+
private external fun nativeStart(
|
|
62
|
+
packagedDir: String,
|
|
63
|
+
stateDir: String,
|
|
64
|
+
storageDir: String,
|
|
65
|
+
host: String,
|
|
66
|
+
): Long
|
|
58
67
|
|
|
59
68
|
@JvmStatic
|
|
60
69
|
private external fun nativeStartDevelopment(
|
|
@@ -77,12 +86,12 @@ internal class TokamakRuntime private constructor(private val handle: Long) {
|
|
|
77
86
|
private external fun nativeResume(handle: Long)
|
|
78
87
|
|
|
79
88
|
@JvmStatic
|
|
80
|
-
private external fun
|
|
89
|
+
private external fun nativeCall(
|
|
81
90
|
handle: Long,
|
|
82
|
-
|
|
83
|
-
|
|
91
|
+
name: String,
|
|
92
|
+
body: String,
|
|
84
93
|
timeoutMillis: Long,
|
|
85
|
-
): String
|
|
94
|
+
): String
|
|
86
95
|
|
|
87
96
|
@JvmStatic
|
|
88
97
|
private external fun nativeServerAuthority(handle: Long, host: String): ByteArray?
|
|
@@ -52,12 +52,11 @@ interface TokamakHost {
|
|
|
52
52
|
val activity: Activity?
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* off the main thread; throws when the handler fails or runs longer than [timeoutMillis].
|
|
55
|
+
* Posts the JSON [body] to the Worker's `/tokamak/<name>` endpoint and returns the
|
|
56
|
+
* response body. Starts the runtime when it is not running. Blocks, so call it off the main
|
|
57
|
+
* thread; throws unless the Worker responds 200 within [timeoutMillis].
|
|
59
58
|
*/
|
|
60
|
-
fun
|
|
59
|
+
fun call(name: String, body: String, timeoutMillis: Long): String
|
|
61
60
|
|
|
62
61
|
/** The plugin with [id], or null when the app does not include it. */
|
|
63
62
|
fun plugin(id: String): TokamakPlugin?
|