@tokamakdev/platform-android-arm64 0.1.1-beta.143 → 0.1.1-beta.144
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.
- package/android-arm64/build/entrypoint +53 -82
- package/android-arm64/describer/Describe.kt +5 -3
- package/android-arm64/describer/Dispatch.kt +8 -11
- package/android-arm64/lib/TokamakRuntime/libtokamak.a +2 -2
- package/android-arm64/native-shell/app/TokamakApplication.kt +17 -11
- package/android-arm64/native-shell/app/TokamakPermissions.kt +1 -1
- package/android-arm64/native-shell/app/TokamakRuntime.kt +2 -7
- package/android-arm64/native-shell/app/TokamakWebChromeClient.kt +1 -5
- package/android-arm64/native-shell/app/TokamakWebViewClient.kt +1 -2
- package/android-arm64/native-shell/plugin/TokamakOwnerAuthentication.kt +27 -26
- package/android-arm64/native-shell/plugin/TokamakPlugin.kt +9 -4
- package/package.json +1 -1
|
@@ -10,6 +10,39 @@ agp_version=8.7.3
|
|
|
10
10
|
kotlin_version=2.1.0
|
|
11
11
|
coroutines_version=1.9.0
|
|
12
12
|
|
|
13
|
+
# The start of a Gradle project's settings.gradle: the repositories it
|
|
14
|
+
# resolves plugins and dependencies from.
|
|
15
|
+
gradle_repositories() {
|
|
16
|
+
cat <<'EOF'
|
|
17
|
+
pluginManagement {
|
|
18
|
+
repositories {
|
|
19
|
+
google()
|
|
20
|
+
mavenCentral()
|
|
21
|
+
gradlePluginPortal()
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
dependencyResolutionManagement {
|
|
25
|
+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
|
26
|
+
repositories {
|
|
27
|
+
google()
|
|
28
|
+
mavenCentral()
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
EOF
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
# The start of a Gradle project's build.gradle: the build tools its modules
|
|
35
|
+
# apply.
|
|
36
|
+
gradle_plugins() {
|
|
37
|
+
cat <<EOF
|
|
38
|
+
plugins {
|
|
39
|
+
id 'com.android.application' version '$agp_version' apply false
|
|
40
|
+
id 'com.android.library' version '$agp_version' apply false
|
|
41
|
+
id 'org.jetbrains.kotlin.android' version '$kotlin_version' apply false
|
|
42
|
+
}
|
|
43
|
+
EOF
|
|
44
|
+
}
|
|
45
|
+
|
|
13
46
|
# Describes the methods PLUGIN/android/Exports.kt exports into
|
|
14
47
|
# OUTPUT/description.json, with the dispatch that serves them,
|
|
15
48
|
# OUTPUT/Exports.generated.kt. A JVM unit test of the plugin, compiled with
|
|
@@ -31,29 +64,11 @@ describe() {
|
|
|
31
64
|
trap 'rm -rf "$temporary"' EXIT
|
|
32
65
|
local module=$temporary/plugin
|
|
33
66
|
mkdir -p "$module"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
gradlePluginPortal()
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
dependencyResolutionManagement {
|
|
43
|
-
repositories {
|
|
44
|
-
google()
|
|
45
|
-
mavenCentral()
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
rootProject.name = 'tokamak-describe'
|
|
49
|
-
include ':plugin'
|
|
50
|
-
EOF
|
|
51
|
-
cat > "$temporary/build.gradle" <<EOF
|
|
52
|
-
plugins {
|
|
53
|
-
id 'com.android.library' version '$agp_version' apply false
|
|
54
|
-
id 'org.jetbrains.kotlin.android' version '$kotlin_version' apply false
|
|
55
|
-
}
|
|
56
|
-
EOF
|
|
67
|
+
{
|
|
68
|
+
gradle_repositories
|
|
69
|
+
printf '%s\n' "rootProject.name = 'tokamak-describe'" "include ':plugin'"
|
|
70
|
+
} > "$temporary/settings.gradle"
|
|
71
|
+
gradle_plugins > "$temporary/build.gradle"
|
|
57
72
|
printf '%s\n' 'android.useAndroidX=true' > "$temporary/gradle.properties"
|
|
58
73
|
cat > "$module/build.gradle" <<EOF
|
|
59
74
|
plugins {
|
|
@@ -72,10 +87,6 @@ android {
|
|
|
72
87
|
defaultConfig {
|
|
73
88
|
minSdk $(<"$pack/build/min-sdk")
|
|
74
89
|
}
|
|
75
|
-
compileOptions {
|
|
76
|
-
sourceCompatibility JavaVersion.VERSION_17
|
|
77
|
-
targetCompatibility JavaVersion.VERSION_17
|
|
78
|
-
}
|
|
79
90
|
testOptions {
|
|
80
91
|
unitTests.returnDefaultValues = true
|
|
81
92
|
unitTests.all {
|
|
@@ -350,8 +361,12 @@ registry=$kotlin/TokamakPluginRegistry.kt
|
|
|
350
361
|
printf '%s\n\n%s\n%s\n' 'package com.tokamak.runtime' 'internal fun tokamakPlugins(app: TokamakApplication): List<TokamakPlugin> =' ' listOf(' > "$registry"
|
|
351
362
|
shopt -s nullglob
|
|
352
363
|
raw_names=" "
|
|
364
|
+
plugin_includes=
|
|
365
|
+
plugin_dependencies=
|
|
353
366
|
for plugin in "$input/plugins"/*/; do
|
|
354
367
|
plugin_id=$(basename "$plugin")
|
|
368
|
+
plugin_includes+="include ':plugins:$plugin_id'"$'\n'
|
|
369
|
+
plugin_dependencies+=" implementation project(':plugins:$plugin_id')"$'\n'
|
|
355
370
|
class=$(cat "$plugin/class" 2>/dev/null || true)
|
|
356
371
|
if [[ ! "$class" =~ $kotlin_class ]]; then
|
|
357
372
|
echo "plugin '$plugin_id' has invalid android class '$class'" >&2
|
|
@@ -409,52 +424,23 @@ for plugin in "$input/plugins"/*/; do
|
|
|
409
424
|
done
|
|
410
425
|
printf '%s\n' ' )' >> "$registry"
|
|
411
426
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
mavenCentral()
|
|
418
|
-
gradlePluginPortal()
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
dependencyResolutionManagement {
|
|
422
|
-
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
|
423
|
-
repositories {
|
|
424
|
-
google()
|
|
425
|
-
mavenCentral()
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
rootProject.name = 'tokamak'
|
|
429
|
-
include ':app', ':tokamak-plugin'
|
|
430
|
-
EOF
|
|
431
|
-
for plugin in "$input/plugins"/*/; do
|
|
432
|
-
printf "include ':plugins:%s'\n" "$(basename "$plugin")" >> "$project/settings.gradle"
|
|
433
|
-
done
|
|
427
|
+
{
|
|
428
|
+
gradle_repositories
|
|
429
|
+
printf '%s\n' "rootProject.name = 'tokamak'" "include ':app', ':tokamak-plugin'"
|
|
430
|
+
printf '%s' "$plugin_includes"
|
|
431
|
+
} > "$project/settings.gradle"
|
|
434
432
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
id 'com.android.library' version '$agp_version' apply false
|
|
439
|
-
id 'org.jetbrains.kotlin.android' version '$kotlin_version' apply false
|
|
440
|
-
}
|
|
433
|
+
{
|
|
434
|
+
gradle_plugins
|
|
435
|
+
cat <<EOF
|
|
441
436
|
|
|
442
437
|
subprojects {
|
|
443
|
-
plugins.
|
|
438
|
+
plugins.withType(com.android.build.gradle.api.AndroidBasePlugin) {
|
|
444
439
|
android {
|
|
445
440
|
compileSdk 35
|
|
446
441
|
defaultConfig {
|
|
447
442
|
minSdk $min_sdk
|
|
448
443
|
}
|
|
449
|
-
sourceSets {
|
|
450
|
-
main {
|
|
451
|
-
kotlin.srcDirs += 'src/main/kotlin'
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
compileOptions {
|
|
455
|
-
sourceCompatibility JavaVersion.VERSION_17
|
|
456
|
-
targetCompatibility JavaVersion.VERSION_17
|
|
457
|
-
}
|
|
458
444
|
}
|
|
459
445
|
}
|
|
460
446
|
plugins.withId('org.jetbrains.kotlin.android') {
|
|
@@ -470,6 +456,7 @@ subprojects {
|
|
|
470
456
|
}
|
|
471
457
|
}
|
|
472
458
|
EOF
|
|
459
|
+
} > "$project/build.gradle"
|
|
473
460
|
|
|
474
461
|
printf '%s\n' 'android.useAndroidX=true' > "$project/gradle.properties"
|
|
475
462
|
cat > "$project/app/build.gradle" <<EOF
|
|
@@ -480,11 +467,9 @@ plugins {
|
|
|
480
467
|
|
|
481
468
|
android {
|
|
482
469
|
namespace 'com.tokamak.runtime'
|
|
483
|
-
compileSdk 35
|
|
484
470
|
|
|
485
471
|
defaultConfig {
|
|
486
472
|
applicationId '$identifier'
|
|
487
|
-
minSdk $min_sdk
|
|
488
473
|
targetSdk 35
|
|
489
474
|
versionCode 1
|
|
490
475
|
versionName providers.gradleProperty('tokamak.version').get()
|
|
@@ -494,17 +479,6 @@ android {
|
|
|
494
479
|
ignoreAssetsPattern = ''
|
|
495
480
|
}
|
|
496
481
|
|
|
497
|
-
sourceSets {
|
|
498
|
-
main {
|
|
499
|
-
kotlin.srcDirs += 'src/main/kotlin'
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
compileOptions {
|
|
504
|
-
sourceCompatibility JavaVersion.VERSION_17
|
|
505
|
-
targetCompatibility JavaVersion.VERSION_17
|
|
506
|
-
}
|
|
507
|
-
|
|
508
482
|
lint {
|
|
509
483
|
checkOnly 'NewApi'
|
|
510
484
|
abortOnError true
|
|
@@ -526,10 +500,7 @@ dependencies {
|
|
|
526
500
|
implementation 'androidx.webkit:webkit:1.12.1'
|
|
527
501
|
implementation project(':tokamak-plugin')
|
|
528
502
|
EOF
|
|
529
|
-
|
|
530
|
-
printf " implementation project(':plugins:%s')\n" "$(basename "$plugin")" >> "$project/app/build.gradle"
|
|
531
|
-
done
|
|
532
|
-
printf '%s\n' '}' >> "$project/app/build.gradle"
|
|
503
|
+
printf '%s}\n' "$plugin_dependencies" >> "$project/app/build.gradle"
|
|
533
504
|
|
|
534
505
|
if [[ -n "$user_manifest" ]]; then
|
|
535
506
|
mkdir -p "$app/user"
|
|
@@ -50,6 +50,7 @@ internal class Export(
|
|
|
50
50
|
val doc: String,
|
|
51
51
|
val overflow: TokamakOverflow,
|
|
52
52
|
val parameters: List<KParameter>,
|
|
53
|
+
/** The call's result type, or the type of each value the stream sends. */
|
|
53
54
|
val returns: KType,
|
|
54
55
|
val suspends: Boolean,
|
|
55
56
|
)
|
|
@@ -83,7 +84,8 @@ private fun exports(exporter: TokamakExporter<TokamakPlugin>, plugin: KClass<*>)
|
|
|
83
84
|
if (export.kind == "stream" && method.isSuspend) {
|
|
84
85
|
throw DescribeError("${plugin.simpleName}.${method.name} returns its Flow without suspending")
|
|
85
86
|
}
|
|
86
|
-
|
|
87
|
+
val returns = if (export.kind == "stream") element(method.returnType, "${method.name}:") else method.returnType
|
|
88
|
+
Export(export.kind, method.name, export.doc, export.overflow, method.parameters.drop(1), returns, method.isSuspend)
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
/** The description of [exports] and [events], which records the data classes and enums they use in [types]. */
|
|
@@ -99,7 +101,7 @@ private fun description(exports: List<Export>, events: List<Event>, types: Types
|
|
|
99
101
|
}
|
|
100
102
|
when (export.kind) {
|
|
101
103
|
"call" -> put("returns", types.describe(export.returns, "$context result"))
|
|
102
|
-
"stream" -> put("returns", types.describe(
|
|
104
|
+
"stream" -> put("returns", types.describe(export.returns, "$context values"))
|
|
103
105
|
}
|
|
104
106
|
if (export.overflow == TokamakOverflow.DROP_OLDEST) put("overflow", "dropOldest")
|
|
105
107
|
}
|
|
@@ -135,7 +137,7 @@ private class Types {
|
|
|
135
137
|
val value: Any = when (classifier) {
|
|
136
138
|
String::class -> "string"
|
|
137
139
|
Boolean::class -> "boolean"
|
|
138
|
-
|
|
140
|
+
in NUMBERS -> "number"
|
|
139
141
|
Unit::class -> "void"
|
|
140
142
|
ByteArray::class -> "bytes"
|
|
141
143
|
Any::class -> "json"
|
|
@@ -33,7 +33,7 @@ internal fun dispatch(plugin: KClass<*>, exports: List<Export>, events: List<Eve
|
|
|
33
33
|
"is not supported",
|
|
34
34
|
),
|
|
35
35
|
)
|
|
36
|
-
val results = exports.filter { it.kind != "resource" }.map {
|
|
36
|
+
val results = exports.filter { it.kind != "resource" }.map { it.returns }
|
|
37
37
|
val parameters = exports.flatMap { export -> export.parameters.map { it.type } }
|
|
38
38
|
val classes = jsonClasses(parameters + results + events.flatMap { listOfNotNull(it.type, it.reply) })
|
|
39
39
|
val functions = requests.filter { it.isNotEmpty() }
|
|
@@ -89,7 +89,7 @@ private class Code(val packageName: String) {
|
|
|
89
89
|
val type = event.type.classifier as KClass<*>
|
|
90
90
|
"\"${event.name}\" -> encodeEvent(name, event, ${name(type)}::class) { ${encode(event.type, "it")} }"
|
|
91
91
|
}
|
|
92
|
-
return switch("override fun eventPayload(name: String, event: Any): ByteArray =", branches, "super.eventPayload(name, event)")
|
|
92
|
+
return switch("override fun eventPayload(name: String, event: Any): ByteArray =", "name", branches, "super.eventPayload(name, event)")
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
/** The decoding of the events' replies, or nothing when no event takes one. */
|
|
@@ -97,7 +97,7 @@ private class Code(val packageName: String) {
|
|
|
97
97
|
val branches = events.mapNotNull { event -> event.reply?.let { "\"${event.name}\" -> ${decode(it, "reply")}" } }
|
|
98
98
|
if (branches.isEmpty()) return emptyList()
|
|
99
99
|
imports += "com.tokamak.runtime.TokamakValue"
|
|
100
|
-
return switch("override fun eventReply(name: String, reply: TokamakValue): Any =", branches, "super.eventReply(name, reply)")
|
|
100
|
+
return switch("override fun eventReply(name: String, reply: TokamakValue): Any =", "name", branches, "super.eventReply(name, reply)")
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
/**
|
|
@@ -128,9 +128,7 @@ private class Code(val packageName: String) {
|
|
|
128
128
|
switch("override fun decodeValue(json: TokamakValue, type: KClass<*>): Any =", "type", decodes, "super.decodeValue(json, type)")
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
/** A function whose body switches on
|
|
132
|
-
private fun switch(signature: String, branches: List<String>, otherwise: String): List<String> = switch(signature, "name", branches, otherwise)
|
|
133
|
-
|
|
131
|
+
/** A function whose body switches on [subject], leaving others to [otherwise]. */
|
|
134
132
|
private fun switch(signature: String, subject: String, branches: List<String>, otherwise: String): List<String> =
|
|
135
133
|
listOf(" $signature", " when ($subject) {") + branches.map { " $it" } +
|
|
136
134
|
" else -> $otherwise" + " }"
|
|
@@ -145,7 +143,7 @@ private class Code(val packageName: String) {
|
|
|
145
143
|
lambda(label, start, call) { encode(export.returns, it) }
|
|
146
144
|
}
|
|
147
145
|
export.kind == "stream" -> {
|
|
148
|
-
val encoded = encode(export.returns
|
|
146
|
+
val encoded = encode(export.returns, "it")
|
|
149
147
|
val each = if (encoded == "it") "" else " { $encoded }"
|
|
150
148
|
use(label, call) { "collect(method, reply, $it)$each" }
|
|
151
149
|
}
|
|
@@ -355,10 +353,9 @@ private fun jsonClasses(types: List<KType>): Set<KClass<*>> {
|
|
|
355
353
|
private val RAW = setOf(TokamakPluginBody::class, ByteArray::class)
|
|
356
354
|
|
|
357
355
|
/** Kotlin's numeric types, which are JSON numbers. */
|
|
358
|
-
|
|
356
|
+
internal val NUMBERS = setOf(Int::class, Long::class, Short::class, Byte::class, Double::class, Float::class)
|
|
359
357
|
|
|
360
358
|
/** The types whose values are JSON, or bytes, as they are. */
|
|
361
|
-
private val SCALARS = setOf(
|
|
362
|
-
String::class, Boolean::class,
|
|
363
|
-
Any::class, JSONObject::class, JSONArray::class,
|
|
359
|
+
private val SCALARS = NUMBERS + setOf(
|
|
360
|
+
String::class, Boolean::class, Unit::class, ByteArray::class, Any::class, JSONObject::class, JSONArray::class,
|
|
364
361
|
)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/android-arm64/lib/TokamakRuntime/libtokamak.a
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 35412016 bytes
|
|
4
|
+
sha256: 1749e09d32b57be2080aab620f27ba87fd4711967e35dc7be41bb1eb5dd284d5
|
|
@@ -13,7 +13,9 @@ import androidx.lifecycle.ProcessLifecycleOwner
|
|
|
13
13
|
import java.io.File
|
|
14
14
|
import java.security.KeyStore
|
|
15
15
|
import java.util.concurrent.Executors
|
|
16
|
+
import kotlin.coroutines.resume
|
|
16
17
|
import kotlin.reflect.KClass
|
|
18
|
+
import kotlinx.coroutines.suspendCancellableCoroutine
|
|
17
19
|
|
|
18
20
|
private const val HOST_METADATA = "tokamak.host"
|
|
19
21
|
private const val DEV_ENDPOINT_METADATA = "tokamak.dev.endpoint"
|
|
@@ -123,10 +125,10 @@ class TokamakApplication : Application(), TokamakPlugins {
|
|
|
123
125
|
override fun wouldPrompt(permission: String): Boolean =
|
|
124
126
|
permissionRequests.wouldPrompt(permission)
|
|
125
127
|
|
|
126
|
-
override fun requestPermissions(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
override suspend fun requestPermissions(permissions: Set<String>): Map<String, Boolean> =
|
|
129
|
+
suspendCancellableCoroutine { continuation ->
|
|
130
|
+
permissionRequests.request(permissions) { continuation.resume(it) }
|
|
131
|
+
}
|
|
130
132
|
|
|
131
133
|
override fun emitBytes(name: String, payload: ByteArray, timeoutMillis: Long): ByteArray =
|
|
132
134
|
emitEvent("$id.android.$name", payload, timeoutMillis)
|
|
@@ -149,11 +151,8 @@ class TokamakApplication : Application(), TokamakPlugins {
|
|
|
149
151
|
|
|
150
152
|
private fun unregistered() = TokamakPluginError.typeError("$id has no android/Exports.kt")
|
|
151
153
|
|
|
152
|
-
override fun fetch(path: String, timeoutMillis: Long): ByteArray
|
|
153
|
-
|
|
154
|
-
val started = runtime
|
|
155
|
-
return started.fetch(path, deadline - SystemClock.elapsedRealtime())
|
|
156
|
-
}
|
|
154
|
+
override fun fetch(path: String, timeoutMillis: Long): ByteArray =
|
|
155
|
+
withRuntime(timeoutMillis) { runtime, remainingMillis -> runtime.fetch(path, remainingMillis) }
|
|
157
156
|
}
|
|
158
157
|
|
|
159
158
|
/** The activity to show UI in; throws `NeedsUIError` while the app is in the background. */
|
|
@@ -171,10 +170,17 @@ class TokamakApplication : Application(), TokamakPlugins {
|
|
|
171
170
|
* Delivers the event [name] with its encoded [payload] to the Worker's listeners and returns
|
|
172
171
|
* their encoded reply. Starts the runtime when it is not running. Blocks.
|
|
173
172
|
*/
|
|
174
|
-
private fun emitEvent(name: String, payload: ByteArray, timeoutMillis: Long): ByteArray
|
|
173
|
+
private fun emitEvent(name: String, payload: ByteArray, timeoutMillis: Long): ByteArray =
|
|
174
|
+
withRuntime(timeoutMillis) { runtime, remainingMillis -> runtime.emit(name, payload, remainingMillis) }
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Runs [operation] with the runtime, starting it when it is not running, and the part of
|
|
178
|
+
* [timeoutMillis] that starting it left, which is negative once none is left.
|
|
179
|
+
*/
|
|
180
|
+
private fun <T> withRuntime(timeoutMillis: Long, operation: (TokamakRuntime, Long) -> T): T {
|
|
175
181
|
val deadline = SystemClock.elapsedRealtime() + timeoutMillis
|
|
176
182
|
val started = runtime
|
|
177
|
-
return started
|
|
183
|
+
return operation(started, deadline - SystemClock.elapsedRealtime())
|
|
178
184
|
}
|
|
179
185
|
|
|
180
186
|
/** Records the app moving into or out of the foreground, once the runtime has started. */
|
|
@@ -73,6 +73,6 @@ internal class TokamakPermissions(private val app: TokamakApplication) {
|
|
|
73
73
|
|
|
74
74
|
private fun refused(): Set<String> = preferences.getStringSet(REFUSED, null).orEmpty()
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
fun isGranted(permission: String): Boolean =
|
|
77
77
|
app.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED
|
|
78
78
|
}
|
|
@@ -60,8 +60,7 @@ internal class TokamakRuntime private constructor(private val handle: Long) {
|
|
|
60
60
|
* The client certificate and PKCS#8 private key, both DER, to present for
|
|
61
61
|
* [host]. Null when tokamak cannot authenticate the connection.
|
|
62
62
|
*/
|
|
63
|
-
fun clientIdentity(host: String
|
|
64
|
-
nativeClientIdentity(handle, host, previousFailures)
|
|
63
|
+
fun clientIdentity(host: String): Array<ByteArray>? = nativeClientIdentity(handle, host)
|
|
65
64
|
|
|
66
65
|
companion object {
|
|
67
66
|
init {
|
|
@@ -176,10 +175,6 @@ internal class TokamakRuntime private constructor(private val handle: Long) {
|
|
|
176
175
|
private external fun nativeFetch(handle: Long, path: String, timeoutMillis: Long): ByteArray
|
|
177
176
|
|
|
178
177
|
@JvmStatic
|
|
179
|
-
private external fun nativeClientIdentity(
|
|
180
|
-
handle: Long,
|
|
181
|
-
host: String,
|
|
182
|
-
previousFailures: Int,
|
|
183
|
-
): Array<ByteArray>?
|
|
178
|
+
private external fun nativeClientIdentity(handle: Long, host: String): Array<ByteArray>?
|
|
184
179
|
}
|
|
185
180
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package com.tokamak.runtime
|
|
2
2
|
|
|
3
3
|
import android.Manifest
|
|
4
|
-
import android.content.pm.PackageManager
|
|
5
4
|
import android.webkit.PermissionRequest
|
|
6
5
|
import android.webkit.WebChromeClient
|
|
7
6
|
|
|
@@ -47,8 +46,5 @@ internal class TokamakWebChromeClient(
|
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
private fun missingPermissions(request: PermissionRequest): List<String> =
|
|
50
|
-
request.resources.map(RESOURCE_PERMISSIONS::getValue).filterNot(::isGranted)
|
|
51
|
-
|
|
52
|
-
private fun isGranted(permission: String): Boolean =
|
|
53
|
-
tokamak.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED
|
|
49
|
+
request.resources.map(RESOURCE_PERMISSIONS::getValue).filterNot(tokamak.permissionRequests::isGranted)
|
|
54
50
|
}
|
|
@@ -42,8 +42,7 @@ internal class TokamakWebViewClient(
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
override fun onReceivedClientCertRequest(view: WebView, request: ClientCertRequest) {
|
|
45
|
-
|
|
46
|
-
val identity = runtime.clientIdentity(request.host, 0)
|
|
45
|
+
val identity = runtime.clientIdentity(request.host)
|
|
47
46
|
if (identity == null) {
|
|
48
47
|
// The gateway requires a certificate, so proceeding without one
|
|
49
48
|
// ends the connection, which is the intended outcome.
|
|
@@ -4,6 +4,10 @@ import android.hardware.biometrics.BiometricManager
|
|
|
4
4
|
import android.hardware.biometrics.BiometricManager.Authenticators
|
|
5
5
|
import android.hardware.biometrics.BiometricPrompt
|
|
6
6
|
import android.os.CancellationSignal
|
|
7
|
+
import kotlin.coroutines.resume
|
|
8
|
+
import kotlin.coroutines.resumeWithException
|
|
9
|
+
import kotlinx.coroutines.CancellableContinuation
|
|
10
|
+
import kotlinx.coroutines.suspendCancellableCoroutine
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
13
|
* Throws unless the device owner can authenticate with [authenticators]: `NotSupportedError`
|
|
@@ -20,44 +24,41 @@ fun TokamakHost.requireOwnerAuthentication(authenticators: Int) {
|
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
26
|
* Shows the system prompt, titled [title], for the device owner to authenticate with
|
|
23
|
-
* [authenticators], authorising [crypto] when given
|
|
24
|
-
*
|
|
25
|
-
* on the main thread.
|
|
27
|
+
* [authenticators], authorising [crypto] when given, and returns once they do. Throws the failure
|
|
28
|
+
* otherwise, and `NeedsUIError` while the app is in the background. Call it on the main thread.
|
|
26
29
|
*/
|
|
27
|
-
fun TokamakHost.authenticateOwner(
|
|
30
|
+
suspend fun TokamakHost.authenticateOwner(
|
|
28
31
|
title: CharSequence,
|
|
29
32
|
authenticators: Int,
|
|
30
|
-
crypto: BiometricPrompt.CryptoObject
|
|
31
|
-
|
|
32
|
-
cancellation: CancellationSignal = CancellationSignal(),
|
|
33
|
-
succeeded: () -> Unit,
|
|
34
|
-
): () -> Unit {
|
|
35
|
-
cancellation.throwIfCanceled()
|
|
33
|
+
crypto: BiometricPrompt.CryptoObject? = null,
|
|
34
|
+
) {
|
|
36
35
|
val activity = requireForegroundActivity()
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
suspendCancellableCoroutine { continuation ->
|
|
37
|
+
val builder = BiometricPrompt.Builder(activity).setTitle(title).setAllowedAuthenticators(authenticators)
|
|
38
|
+
if ((authenticators and Authenticators.DEVICE_CREDENTIAL) == 0) {
|
|
39
|
+
builder.setNegativeButton(activity.getString(android.R.string.cancel), activity.mainExecutor) { _, _ ->
|
|
40
|
+
continuation.resumeWithException(TokamakPluginError("NotAllowedError", "Authentication was cancelled"))
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
val prompt = builder.build()
|
|
44
|
+
val cancellation = CancellationSignal()
|
|
45
|
+
continuation.invokeOnCancellation { cancellation.cancel() }
|
|
46
|
+
val callback = PromptCallback(continuation)
|
|
47
|
+
if (crypto == null) {
|
|
48
|
+
prompt.authenticate(cancellation, activity.mainExecutor, callback)
|
|
49
|
+
} else {
|
|
50
|
+
prompt.authenticate(crypto, cancellation, activity.mainExecutor, callback)
|
|
41
51
|
}
|
|
42
52
|
}
|
|
43
|
-
val prompt = builder.build()
|
|
44
|
-
val callback = PromptCallback(reply, succeeded)
|
|
45
|
-
if (crypto == null) {
|
|
46
|
-
prompt.authenticate(cancellation, activity.mainExecutor, callback)
|
|
47
|
-
} else {
|
|
48
|
-
prompt.authenticate(crypto, cancellation, activity.mainExecutor, callback)
|
|
49
|
-
}
|
|
50
|
-
return { cancellation.cancel() }
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
private class PromptCallback(
|
|
54
|
-
private val
|
|
55
|
-
private val succeeded: () -> Unit,
|
|
56
|
+
private val continuation: CancellableContinuation<Unit>,
|
|
56
57
|
) : BiometricPrompt.AuthenticationCallback() {
|
|
57
|
-
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) =
|
|
58
|
+
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) = continuation.resume(Unit)
|
|
58
59
|
|
|
59
60
|
override fun onAuthenticationError(code: Int, message: CharSequence) =
|
|
60
|
-
|
|
61
|
+
continuation.resumeWithException(TokamakPluginError(authenticationErrorName(code), message.toString()))
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
private fun authenticationErrorName(code: Int): String =
|
|
@@ -198,11 +198,10 @@ interface TokamakHost {
|
|
|
198
198
|
|
|
199
199
|
/**
|
|
200
200
|
* Asks the user for [permissions] in the app's activity once earlier requests finish, then
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
* the main thread; [callback] runs on the main thread.
|
|
201
|
+
* returns whether each is granted. Answers at once, without UI, when none would prompt; throws
|
|
202
|
+
* `NeedsUIError` when one would while the app is in the background. Call it on the main thread.
|
|
204
203
|
*/
|
|
205
|
-
fun requestPermissions(permissions: Set<String
|
|
204
|
+
suspend fun requestPermissions(permissions: Set<String>): Map<String, Boolean>
|
|
206
205
|
|
|
207
206
|
/**
|
|
208
207
|
* Delivers the plugin's event [name], which the Worker's listeners receive as
|
|
@@ -252,3 +251,9 @@ interface TokamakPlugins {
|
|
|
252
251
|
|
|
253
252
|
/** The plugin with [id] in the app this context belongs to, or null when the app does not include it. */
|
|
254
253
|
fun Context.tokamakPlugin(id: String): TokamakPlugin? = (applicationContext as TokamakPlugins).plugin(id)
|
|
254
|
+
|
|
255
|
+
/** The app's monochrome `drawable/tokamak_notification`, or its launcher icon, for a notification's small icon. */
|
|
256
|
+
fun Context.tokamakNotificationIcon(): Int =
|
|
257
|
+
resources.getIdentifier("tokamak_notification", "drawable", packageName).takeIf { it != 0 }
|
|
258
|
+
?: applicationInfo.icon.takeIf { it != 0 }
|
|
259
|
+
?: android.R.drawable.sym_def_app_icon
|