@blotch/angular-lynx-native 22.3.1 → 22.3.3
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/README.md +47 -15
- package/dist/android/project.d.ts +114 -1
- package/dist/android/project.d.ts.map +1 -1
- package/dist/android/project.js +440 -5
- package/dist/eject.d.ts +15 -1
- package/dist/eject.d.ts.map +1 -1
- package/dist/eject.js +14 -2
- package/dist/features.d.ts +70 -0
- package/dist/features.d.ts.map +1 -0
- package/dist/features.js +115 -0
- package/dist/files.d.ts +24 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +41 -0
- package/dist/generate.d.ts +34 -3
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +78 -19
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -2
- package/dist/ios/build.d.ts.map +1 -1
- package/dist/ios/build.js +8 -2
- package/dist/ios/frameworks.d.ts +6 -5
- package/dist/ios/frameworks.d.ts.map +1 -1
- package/dist/ios/frameworks.js +46 -15
- package/dist/ios/project.d.ts +192 -11
- package/dist/ios/project.d.ts.map +1 -1
- package/dist/ios/project.js +823 -33
- package/dist/options.d.ts +208 -1
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +154 -0
- package/dist/permissions.d.ts +18 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +79 -4
- package/dist/plugins.d.ts +245 -0
- package/dist/plugins.d.ts.map +1 -0
- package/dist/plugins.js +1244 -0
- package/package.json +1 -1
- package/templates/android/README.md +46 -5
- package/templates/android/angular-lynx.properties +2 -0
- package/templates/android/app/build.gradle.kts +78 -11
- package/templates/android/app/src/main/AndroidManifest.xml +19 -3
- package/templates/android/app/src/main/java/dev/angularlynx/shell/AngularLynxPlugins.kt +13 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/AudioRecorderModule.kt +520 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BarcodeScannerModule.kt +144 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BiometricsModule.kt +433 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BitmapPresenter.kt +98 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BitmapRendererContext.kt +175 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BluetoothModule.kt +1288 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/CalendarModule.kt +127 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/Canvas2DContext.kt +1557 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/Canvas2DOps.kt +63 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasFilter.kt +357 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasUI.kt +4 -3
- package/templates/android/app/src/main/java/dev/angularlynx/shell/EdgeToEdgeOverlay.kt +24 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/EngineThreadHint.kt +156 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/FilePickerModule.kt +263 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/GeolocationModule.kt +557 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/HapticsModule.kt +82 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/HostElementUI.kt +331 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ImagePickerModule.kt +143 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ImagePipeline.kt +83 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/MainActivity.kt +523 -9
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ModuleBytes.kt +58 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/MotionModule.kt +332 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/NetworkStatus.kt +121 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/NfcModule.kt +274 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/PermissionRequests.kt +35 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/PhotoLibraryModule.kt +355 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShareTargetModule.kt +234 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellApplication.kt +7 -8
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellModule.kt +58 -4
- package/templates/android/app/src/main/java/dev/angularlynx/shell/StoreReviewModule.kt +66 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/SystemFontFamilies.kt +68 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/TrackingModule.kt +74 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/VideoFrameTarget.kt +429 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/VideoUI.kt +676 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLContext.kt +128 -13
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLModule.kt +493 -65
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WifiModule.kt +429 -0
- package/templates/android/app/src/main/res/values/biometrics.xml +9 -0
- package/templates/android/app/src/main/res/values/share_target.xml +11 -0
- package/templates/android/app/src/main/res/xml/backup_rules.xml +5 -3
- package/templates/android/app/src/main/res/xml/data_extraction_rules.xml +6 -3
- package/templates/android/app/src/main/res/xml/share_paths.xml +7 -2
- package/templates/android/build.gradle.kts +1 -1
- package/templates/android/gradle/wrapper/gradle-wrapper.properties +2 -2
- package/templates/ios/App/AngularLynxBitmapRendererContext.m +188 -0
- package/templates/ios/App/AngularLynxCanvas2DContext.m +2467 -0
- package/templates/ios/App/AngularLynxCanvas2DOps.h +61 -0
- package/templates/ios/App/AngularLynxPlugins.swift +22 -0
- package/templates/ios/App/AngularLynxVideo.h +37 -0
- package/templates/ios/App/AngularLynxVideo.m +435 -0
- package/templates/ios/App/AngularLynxWebGL.h +69 -7
- package/templates/ios/App/AngularLynxWebGL.m +538 -29
- package/templates/ios/App/AngularLynxWebGLContext.m +148 -46
- package/templates/ios/App/AnimationFrameRate.swift +66 -0
- package/templates/ios/App/AppDelegate.swift +37 -3
- package/templates/ios/App/AppleSignInButton.swift +106 -0
- package/templates/ios/App/AppleSignInModule.swift +222 -0
- package/templates/ios/App/AudioRecorderModule.swift +433 -0
- package/templates/ios/App/BarcodeScannerModule.swift +284 -0
- package/templates/ios/App/BiometricsModule.swift +256 -0
- package/templates/ios/App/BluetoothModule.swift +1086 -0
- package/templates/ios/App/CalendarModule.swift +158 -0
- package/templates/ios/App/FilePickerModule.swift +240 -0
- package/templates/ios/App/GeolocationModule.swift +455 -0
- package/templates/ios/App/HapticsModule.swift +90 -0
- package/templates/ios/App/HostElementUI.swift +270 -0
- package/templates/ios/App/ImagePickerModule.swift +160 -1
- package/templates/ios/App/Info.plist +2 -0
- package/templates/ios/App/LynxViewController.swift +274 -9
- package/templates/ios/App/MotionModule.swift +430 -0
- package/templates/ios/App/NetworkStatus.swift +41 -0
- package/templates/ios/App/NfcModule.swift +346 -0
- package/templates/ios/App/PhotoLibraryModule.swift +169 -0
- package/templates/ios/App/ShareTargetModule.swift +150 -0
- package/templates/ios/App/ShellModule.swift +17 -0
- package/templates/ios/App/StoreReviewModule.swift +61 -0
- package/templates/ios/App/TrackingModule.swift +121 -0
- package/templates/ios/App/WifiModule.swift +237 -0
- package/templates/ios/App/XElementRegistry.swift +13 -3
- package/templates/ios/ShareExtension/Info.plist +42 -0
- package/templates/ios/ShareExtension/ShareViewController.swift +387 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
package dev.angularlynx.shell
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.content.Intent
|
|
5
|
+
import android.net.Uri
|
|
6
|
+
import android.os.Build
|
|
7
|
+
import android.os.Handler
|
|
8
|
+
import android.os.Looper
|
|
9
|
+
import android.provider.OpenableColumns
|
|
10
|
+
import android.util.Base64
|
|
11
|
+
import android.util.Log
|
|
12
|
+
import android.webkit.MimeTypeMap
|
|
13
|
+
import com.lynx.jsbridge.LynxMethod
|
|
14
|
+
import com.lynx.jsbridge.LynxModule
|
|
15
|
+
import com.lynx.react.bridge.Callback
|
|
16
|
+
import com.lynx.react.bridge.JavaOnlyArray
|
|
17
|
+
import com.lynx.react.bridge.JavaOnlyMap
|
|
18
|
+
import java.io.ByteArrayOutputStream
|
|
19
|
+
import java.io.IOException
|
|
20
|
+
import java.io.InputStream
|
|
21
|
+
import java.util.concurrent.Executors
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The native module behind the runtime's `LynxShareTarget`, which calls it as
|
|
25
|
+
* `NativeModules.AngularLynxShareTarget` (from the background thread, where
|
|
26
|
+
* NativeModules lives). iOS's shell has one of the same name.
|
|
27
|
+
*
|
|
28
|
+
* angular.json's `shareTarget` puts `ACTION_SEND` and `ACTION_SEND_MULTIPLE`
|
|
29
|
+
* intent filters for its MIME types on MainActivity, so the app is in other
|
|
30
|
+
* apps' share sheets. A share may start the app, so the activity can't hand
|
|
31
|
+
* it straight to the Angular app: it leaves it here ([receive]), and the
|
|
32
|
+
* runtime takes it when it's ready, at startup and each time it hears the
|
|
33
|
+
* `angularLynxShare` global event. A share waits for as long as that takes,
|
|
34
|
+
* so the one that started the app isn't lost, and none is handled twice.
|
|
35
|
+
*
|
|
36
|
+
* The shared files are read as soon as the share arrives: the app may read
|
|
37
|
+
* another app's `content://` URI only while the activity it was granted to
|
|
38
|
+
* is alive. `take` calls back with `{ shares }`: each `{ title?, text?, url?,
|
|
39
|
+
* files: [{ base64, name, type }] }` since the last call, oldest first.
|
|
40
|
+
*
|
|
41
|
+
* The generator leaves this file, and the lines in MainActivity that hand it
|
|
42
|
+
* the intents and register it, out of an app whose angular.json has no
|
|
43
|
+
* `shareTarget`.
|
|
44
|
+
*/
|
|
45
|
+
class ShareTargetModule(context: Context, param: Any?) : LynxModule(context, param) {
|
|
46
|
+
@LynxMethod
|
|
47
|
+
fun take(callback: Callback) {
|
|
48
|
+
val shares = JavaOnlyArray()
|
|
49
|
+
for (share in takeWaiting()) {
|
|
50
|
+
shares.pushMap(share)
|
|
51
|
+
}
|
|
52
|
+
callback.invoke(JavaOnlyMap.from(mapOf("shares" to shares)))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
companion object {
|
|
56
|
+
const val NAME = "AngularLynxShareTarget"
|
|
57
|
+
|
|
58
|
+
// The global event that says a share is waiting. It carries nothing:
|
|
59
|
+
// the listener answers by taking them.
|
|
60
|
+
const val EVENT = "angularLynxShare"
|
|
61
|
+
|
|
62
|
+
private const val TAG = "AngularLynxShareTarget"
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The most bytes of files one share hands the app, all its files
|
|
66
|
+
* together: 20 MiB, as LynxFilePicker's FILE_PICKER_MAX_BYTES. They
|
|
67
|
+
* travel to JavaScript as base64, held several times over on the
|
|
68
|
+
* way, so a file that would take a share past it is left out.
|
|
69
|
+
*/
|
|
70
|
+
private const val MAX_BYTES = 20L * 1024 * 1024
|
|
71
|
+
|
|
72
|
+
/** An absolute link, which a share of a page carries as its text. */
|
|
73
|
+
private val LINK = Regex("^[a-zA-Z][a-zA-Z0-9+.-]*://\\S+$")
|
|
74
|
+
|
|
75
|
+
private val worker = Executors.newSingleThreadExecutor()
|
|
76
|
+
private val main = Handler(Looper.getMainLooper())
|
|
77
|
+
|
|
78
|
+
// The activity leaves them on the worker thread, and Lynx calls
|
|
79
|
+
// modules off it.
|
|
80
|
+
private val waiting = mutableListOf<JavaOnlyMap>()
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Tells the runtime a share is waiting: set by the activity that's
|
|
84
|
+
* current, and called on the main thread once a share's files are
|
|
85
|
+
* read. A share is read on a worker thread, and Android may replace
|
|
86
|
+
* the activity that received it meanwhile, as on a rotation, so
|
|
87
|
+
* the event goes through the activity current then, rather than
|
|
88
|
+
* the one that started the read. Without one, the runtime takes
|
|
89
|
+
* the share as it next starts.
|
|
90
|
+
*/
|
|
91
|
+
@Volatile
|
|
92
|
+
var arrived: (() -> Unit)? = null
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Leaves the share `intent` carries for the runtime to take, and
|
|
96
|
+
* calls [arrived] once it's waiting. Returns whether the intent was
|
|
97
|
+
* a share.
|
|
98
|
+
*/
|
|
99
|
+
fun receive(context: Context, intent: Intent): Boolean {
|
|
100
|
+
if (intent.action != Intent.ACTION_SEND && intent.action != Intent.ACTION_SEND_MULTIPLE) {
|
|
101
|
+
return false
|
|
102
|
+
}
|
|
103
|
+
val accepted = context.resources.getStringArray(R.array.angular_lynx_share_mime_types).toList()
|
|
104
|
+
val subject = intent.getStringExtra(Intent.EXTRA_SUBJECT) ?: intent.getStringExtra(Intent.EXTRA_TITLE)
|
|
105
|
+
val text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT)?.toString()
|
|
106
|
+
val streams = streams(intent)
|
|
107
|
+
val resolver = context.applicationContext.contentResolver
|
|
108
|
+
// Reading a large photo takes a moment: off the main thread. The
|
|
109
|
+
// grant to read the URIs lasts as long as the activity, which
|
|
110
|
+
// this outlives only if the person leaves at once.
|
|
111
|
+
worker.execute {
|
|
112
|
+
val share = mutableMapOf<String, Any>()
|
|
113
|
+
if (subject != null) share["title"] = subject
|
|
114
|
+
// Android shares a link as text (Chrome sends its page's URL
|
|
115
|
+
// as text/plain): a text that is one link is the share's url,
|
|
116
|
+
// for an app that takes links.
|
|
117
|
+
val trimmed = text?.trim()
|
|
118
|
+
if (trimmed != null && LINK.matches(trimmed) && accepts(accepted, "text/uri-list")) {
|
|
119
|
+
share["url"] = trimmed
|
|
120
|
+
} else if (!text.isNullOrEmpty() && accepts(accepted, "text/plain")) {
|
|
121
|
+
share["text"] = text
|
|
122
|
+
}
|
|
123
|
+
val files = JavaOnlyArray()
|
|
124
|
+
var remaining = MAX_BYTES
|
|
125
|
+
for (uri in streams) {
|
|
126
|
+
val type = resolver.getType(uri) ?: typeFromName(uri) ?: "application/octet-stream"
|
|
127
|
+
if (!accepts(accepted, type)) continue
|
|
128
|
+
val bytes = try {
|
|
129
|
+
resolver.openInputStream(uri)?.use { readAtMost(it, remaining) }
|
|
130
|
+
} catch (error: IOException) {
|
|
131
|
+
Log.w(TAG, "Couldn't read $uri", error)
|
|
132
|
+
null
|
|
133
|
+
} catch (error: SecurityException) {
|
|
134
|
+
Log.w(TAG, "Not allowed to read $uri", error)
|
|
135
|
+
null
|
|
136
|
+
} ?: continue
|
|
137
|
+
if (bytes.size > remaining) {
|
|
138
|
+
Log.w(TAG, "Left out $uri: the share is over ${MAX_BYTES / 1024 / 1024} MiB")
|
|
139
|
+
continue
|
|
140
|
+
}
|
|
141
|
+
remaining -= bytes.size
|
|
142
|
+
files.pushMap(
|
|
143
|
+
JavaOnlyMap.from(
|
|
144
|
+
mapOf(
|
|
145
|
+
"base64" to Base64.encodeToString(bytes, Base64.NO_WRAP),
|
|
146
|
+
"name" to (displayName(context, uri) ?: uri.lastPathSegment ?: "file"),
|
|
147
|
+
"type" to type,
|
|
148
|
+
),
|
|
149
|
+
),
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
// Nothing the app takes, such as text for an app that takes
|
|
153
|
+
// only photos: there's nothing to hand over.
|
|
154
|
+
if (files.size == 0 && !share.containsKey("text") && !share.containsKey("url")) {
|
|
155
|
+
return@execute
|
|
156
|
+
}
|
|
157
|
+
share["files"] = files
|
|
158
|
+
synchronized(waiting) { waiting.add(JavaOnlyMap.from(share)) }
|
|
159
|
+
main.post { arrived?.invoke() }
|
|
160
|
+
}
|
|
161
|
+
return true
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private fun takeWaiting(): List<JavaOnlyMap> =
|
|
165
|
+
synchronized(waiting) {
|
|
166
|
+
val taken = waiting.toList()
|
|
167
|
+
waiting.clear()
|
|
168
|
+
taken
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** The files a share carries: one for ACTION_SEND, a list for ACTION_SEND_MULTIPLE. */
|
|
172
|
+
@Suppress("DEPRECATION")
|
|
173
|
+
private fun streams(intent: Intent): List<Uri> {
|
|
174
|
+
if (intent.action == Intent.ACTION_SEND_MULTIPLE) {
|
|
175
|
+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
176
|
+
intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM, Uri::class.java)
|
|
177
|
+
} else {
|
|
178
|
+
intent.getParcelableArrayListExtra<Uri>(Intent.EXTRA_STREAM)
|
|
179
|
+
} ?: emptyList()
|
|
180
|
+
}
|
|
181
|
+
val uri = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
182
|
+
intent.getParcelableExtra(Intent.EXTRA_STREAM, Uri::class.java)
|
|
183
|
+
} else {
|
|
184
|
+
intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)
|
|
185
|
+
}
|
|
186
|
+
return listOfNotNull(uri)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Whether angular.json's `shareTarget.mimeTypes` takes [type]: the
|
|
191
|
+
* type itself, a wildcard for its subtype, or the wildcard for
|
|
192
|
+
* every type. The intent filters already chose, but a share's own
|
|
193
|
+
* type is often broader than each of its files', such as the
|
|
194
|
+
* wildcard for a photo and a PDF together.
|
|
195
|
+
*/
|
|
196
|
+
private fun accepts(accepted: List<String>, type: String): Boolean {
|
|
197
|
+
val mime = type.lowercase()
|
|
198
|
+
val major = mime.substringBefore('/')
|
|
199
|
+
return accepted.any { it == "*/*" || it == mime || it == "$major/*" }
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private fun typeFromName(uri: Uri): String? =
|
|
203
|
+
uri.lastPathSegment?.substringAfterLast('.', "")?.takeIf { it.isNotEmpty() }?.let {
|
|
204
|
+
MimeTypeMap.getSingleton().getMimeTypeFromExtension(it.lowercase())
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** The file's name, such as `photo.jpg`, as its provider gives it. */
|
|
208
|
+
private fun displayName(context: Context, uri: Uri): String? =
|
|
209
|
+
try {
|
|
210
|
+
context.contentResolver.query(uri, arrayOf(OpenableColumns.DISPLAY_NAME), null, null, null)?.use {
|
|
211
|
+
if (it.moveToFirst() && !it.isNull(0)) it.getString(0) else null
|
|
212
|
+
}
|
|
213
|
+
} catch (_: Exception) {
|
|
214
|
+
null
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* The stream's bytes, up to [limit] and one more: a result longer
|
|
219
|
+
* than [limit] says the file is over it, without reading the rest.
|
|
220
|
+
*/
|
|
221
|
+
private fun readAtMost(input: InputStream, limit: Long): ByteArray {
|
|
222
|
+
val output = ByteArrayOutputStream()
|
|
223
|
+
val buffer = ByteArray(64 * 1024)
|
|
224
|
+
while (output.size() <= limit) {
|
|
225
|
+
val left = limit - output.size()
|
|
226
|
+
val wanted = if (left >= buffer.size) buffer.size else (left + 1).toInt()
|
|
227
|
+
val read = input.read(buffer, 0, wanted)
|
|
228
|
+
if (read < 0) break
|
|
229
|
+
output.write(buffer, 0, read)
|
|
230
|
+
}
|
|
231
|
+
return output.toByteArray()
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
@@ -4,14 +4,12 @@ import android.app.Application
|
|
|
4
4
|
import android.content.ComponentCallbacks2
|
|
5
5
|
import android.content.pm.ApplicationInfo
|
|
6
6
|
import com.facebook.drawee.backends.pipeline.Fresco
|
|
7
|
-
import com.facebook.imagepipeline.core.ImagePipelineConfig
|
|
8
|
-
import com.facebook.imagepipeline.memory.PoolConfig
|
|
9
|
-
import com.facebook.imagepipeline.memory.PoolFactory
|
|
10
7
|
import com.lynx.service.http.LynxHttpService
|
|
11
8
|
import com.lynx.service.image.LynxImageService
|
|
12
9
|
import com.lynx.service.log.LynxLogService
|
|
13
10
|
import com.lynx.tasm.LynxEnv
|
|
14
11
|
import com.lynx.tasm.base.LLog
|
|
12
|
+
import com.lynx.tasm.behavior.shadow.text.TypefaceCache
|
|
15
13
|
import com.lynx.tasm.service.LynxServiceCenter
|
|
16
14
|
|
|
17
15
|
/**
|
|
@@ -26,11 +24,7 @@ class ShellApplication : Application() {
|
|
|
26
24
|
// LynxImageService draws <image> through Fresco, which must be
|
|
27
25
|
// initialized first. Fresco also understands asset:/// URIs natively,
|
|
28
26
|
// which is how bundled images are loaded (see AssetMediaResourceFetcher).
|
|
29
|
-
|
|
30
|
-
Fresco.initialize(
|
|
31
|
-
this,
|
|
32
|
-
ImagePipelineConfig.newBuilder(this).setPoolFactory(pools).build(),
|
|
33
|
-
)
|
|
27
|
+
Fresco.initialize(this, imagePipelineConfig(this))
|
|
34
28
|
LynxServiceCenter.inst().registerService(LynxImageService.getInstance())
|
|
35
29
|
LynxServiceCenter.inst().registerService(LynxLogService)
|
|
36
30
|
LynxServiceCenter.inst().registerService(LynxHttpService)
|
|
@@ -39,6 +33,11 @@ class ShellApplication : Application() {
|
|
|
39
33
|
// its loaders to the LynxView it builds.
|
|
40
34
|
LynxEnv.inst().init(this, null, null, null)
|
|
41
35
|
|
|
36
|
+
// Android's own font families (`monospace`, `serif`...), which Lynx
|
|
37
|
+
// doesn't find by itself (SystemFontFamilies.kt). Before the first
|
|
38
|
+
// LynxView, so its first text finds them.
|
|
39
|
+
TypefaceCache.addLazyProvider(SystemFontFamilies)
|
|
40
|
+
|
|
42
41
|
// Lynx's libraries are built for release, where Lynx logs at INFO: a
|
|
43
42
|
// line for every touch, flush, layout, event listener and main-thread
|
|
44
43
|
// module call, each a call from native code back into Java and an
|
|
@@ -3,6 +3,10 @@ package dev.angularlynx.shell
|
|
|
3
3
|
import android.content.Context
|
|
4
4
|
import android.os.Handler
|
|
5
5
|
import android.os.Looper
|
|
6
|
+
import android.os.SystemClock
|
|
7
|
+
import android.os.Trace
|
|
8
|
+
import android.util.Log
|
|
9
|
+
import androidx.core.os.HandlerCompat
|
|
6
10
|
import com.lynx.jsbridge.LynxMethod
|
|
7
11
|
import com.lynx.jsbridge.LynxModule
|
|
8
12
|
import com.lynx.tasm.LynxEnv
|
|
@@ -16,10 +20,13 @@ import com.lynx.tasm.LynxEnv
|
|
|
16
20
|
* gesture starts whether the app will handle it (predictive back shows a
|
|
17
21
|
* different animation either way). The Angular app can't answer in time, so it
|
|
18
22
|
* tells us ahead of time instead: it enables the back handler while the Router
|
|
19
|
-
* has somewhere to go back to
|
|
23
|
+
* has somewhere to go back to, or something open on top (a popover) takes
|
|
24
|
+
* back. While enabled, back presses become an
|
|
20
25
|
* `angularLynxBack` global event; while disabled (the default, and whenever the
|
|
21
26
|
* runtime doesn't know about this module) Android's default back behavior
|
|
22
|
-
* applies, which leaves the app.
|
|
27
|
+
* applies, which leaves the app. While enabled, the predictive back gesture
|
|
28
|
+
* also arrives as it goes, as `angularLynxBackGesture` global events, so a
|
|
29
|
+
* stack in the app can move its page with the finger.
|
|
23
30
|
*
|
|
24
31
|
* `collectGarbage` runs a full collection of the main thread's JavaScript
|
|
25
32
|
* heap. PrimJS, which runs it, collects as the app runs, but those collections
|
|
@@ -40,12 +47,40 @@ import com.lynx.tasm.LynxEnv
|
|
|
40
47
|
* `am start -W`'s callers) read as time to full display. It's called on the
|
|
41
48
|
* thread the runtime calls from, Lynx's engine thread: the system takes it
|
|
42
49
|
* from any thread, and a post to the UI thread would add a wait to the moment
|
|
43
|
-
* it marks.
|
|
50
|
+
* it marks. Each call also logs `Fully Drawn at <ns> ns` (below).
|
|
51
|
+
*
|
|
52
|
+
* `markEvent(name)` marks any other moment the app names, as an instant
|
|
53
|
+
* section of that name in a system trace (`Trace.beginSection`, ended at
|
|
54
|
+
* once), which Perfetto and Android Studio's profiler show on the thread
|
|
55
|
+
* that called it: the start of the work a profile is about, for example.
|
|
56
|
+
* Every call marks. The benchmark apps mark `MountStart` as their mount
|
|
57
|
+
* screen starts building (`benchmarks/SPEC.md`); the iOS shell's is an
|
|
58
|
+
* `os_signpost` event that Instruments shows.
|
|
59
|
+
*
|
|
60
|
+
* Both also log a line under this module's name, `Mark <name> at <ns> ns`
|
|
61
|
+
* and `Fully Drawn at <ns> ns`, with `SystemClock.elapsedRealtimeNanos()`
|
|
62
|
+
* at the call. logcat shows neither trace sections nor when the app called
|
|
63
|
+
* reportFullyDrawn: its own `Fully drawn` line gives a time from the
|
|
64
|
+
* launch's start, or from the first frame for a call before it, on no clock
|
|
65
|
+
* a mark shares. The benchmark harness (`android_launch.py`) reads the two
|
|
66
|
+
* lines to time a mount screen from its `MountStart` to its fully drawn call,
|
|
67
|
+
* as the iOS harness does with the two signposts. The clock is in the
|
|
68
|
+
* message, rather than taken from logcat's timestamps, because those are
|
|
69
|
+
* wall-clock time, which an emulator steps when it syncs with its host.
|
|
44
70
|
*/
|
|
45
71
|
class ShellModule(context: Context, param: Any?) : LynxModule(context, param) {
|
|
46
72
|
private val host = param as Host
|
|
47
73
|
private val main = Handler(Looper.getMainLooper())
|
|
48
74
|
|
|
75
|
+
// The UI thread's queue for hideSplashScreen, whose messages don't wait
|
|
76
|
+
// behind a frame's sync barrier. While the splash screen is up, its
|
|
77
|
+
// pre-draw check cancels each frame and schedules the next, and each
|
|
78
|
+
// schedule puts a sync barrier in the UI thread's queue that holds back
|
|
79
|
+
// every ordinary message until that frame runs. So a hide posted to
|
|
80
|
+
// `main` ran only after the next frame had been canceled once more, and
|
|
81
|
+
// the screen came a frame later than it could: 8 ms at 120 Hz.
|
|
82
|
+
private val beforeNextFrame = HandlerCompat.createAsync(Looper.getMainLooper())
|
|
83
|
+
|
|
49
84
|
interface Host {
|
|
50
85
|
fun setBackHandlerEnabled(enabled: Boolean)
|
|
51
86
|
fun hideSplashScreen()
|
|
@@ -59,12 +94,26 @@ class ShellModule(context: Context, param: Any?) : LynxModule(context, param) {
|
|
|
59
94
|
|
|
60
95
|
@LynxMethod
|
|
61
96
|
fun hideSplashScreen() {
|
|
62
|
-
|
|
97
|
+
beforeNextFrame.post { host.hideSplashScreen() }
|
|
63
98
|
}
|
|
64
99
|
|
|
65
100
|
@LynxMethod
|
|
66
101
|
fun reportFullyDrawn() {
|
|
102
|
+
// Read before the call, which is the moment it marks: the system's
|
|
103
|
+
// own bookkeeping comes after.
|
|
104
|
+
val at = SystemClock.elapsedRealtimeNanos()
|
|
67
105
|
host.markFullyDrawn()
|
|
106
|
+
Log.i(NAME, "Fully Drawn at $at ns")
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// On the calling thread, as reportFullyDrawn is, so the mark lands at the
|
|
110
|
+
// moment it marks. A trace section's name is at most 127 characters.
|
|
111
|
+
@LynxMethod
|
|
112
|
+
fun markEvent(name: String) {
|
|
113
|
+
val at = SystemClock.elapsedRealtimeNanos()
|
|
114
|
+
Trace.beginSection(name.take(127))
|
|
115
|
+
Trace.endSection()
|
|
116
|
+
Log.i(NAME, "Mark $name at $at ns")
|
|
68
117
|
}
|
|
69
118
|
|
|
70
119
|
@LynxMethod
|
|
@@ -76,6 +125,11 @@ class ShellModule(context: Context, param: Any?) : LynxModule(context, param) {
|
|
|
76
125
|
const val NAME = "AngularLynxShell"
|
|
77
126
|
const val BACK_EVENT = "angularLynxBack"
|
|
78
127
|
|
|
128
|
+
// Android's predictive back gesture as it goes (see MainActivity's
|
|
129
|
+
// backHandler): it starts, moves, or is canceled. One that ends in
|
|
130
|
+
// back sends BACK_EVENT, as a press does.
|
|
131
|
+
const val BACK_GESTURE_EVENT = "angularLynxBackGesture"
|
|
132
|
+
|
|
79
133
|
// Lynx's MemoryPressureLevel values, from a package the app doesn't
|
|
80
134
|
// compile against.
|
|
81
135
|
const val MEMORY_PRESSURE_MODERATE = 1
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
package dev.angularlynx.shell
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.os.Handler
|
|
6
|
+
import android.os.Looper
|
|
7
|
+
import android.util.Log
|
|
8
|
+
import com.google.android.play.core.review.ReviewManagerFactory
|
|
9
|
+
import com.lynx.jsbridge.LynxMethod
|
|
10
|
+
import com.lynx.jsbridge.LynxModule
|
|
11
|
+
import com.lynx.react.bridge.Callback
|
|
12
|
+
import com.lynx.react.bridge.JavaOnlyMap
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The native module behind the runtime's `LynxStoreReview`, which calls it as
|
|
16
|
+
* `NativeModules.AngularLynxStoreReview` (from the background thread, where
|
|
17
|
+
* NativeModules lives). MainActivity registers it with itself as the param:
|
|
18
|
+
* Google Play shows the rating prompt over it.
|
|
19
|
+
*
|
|
20
|
+
* `request` asks Play's In-App Review API for a review flow and launches it,
|
|
21
|
+
* then calls back once with `{}`. Play decides whether the prompt shows, and
|
|
22
|
+
* doesn't say: it has a quota per person, shows nothing until the account
|
|
23
|
+
* has installed the app from Play (an internal test track or internal app
|
|
24
|
+
* sharing will do), and fails
|
|
25
|
+
* where the phone has no Play Store. None of that is something the app can
|
|
26
|
+
* act on, so a failure is logged and calls back the same `{}`.
|
|
27
|
+
*
|
|
28
|
+
* The generator leaves this file, the lines in MainActivity that register it
|
|
29
|
+
* and Play's review library out of an app whose angular.json doesn't set
|
|
30
|
+
* `storeReview`.
|
|
31
|
+
*/
|
|
32
|
+
class StoreReviewModule(context: Context, param: Any?) : LynxModule(context, param) {
|
|
33
|
+
private val activity = param as Activity
|
|
34
|
+
private val main = Handler(Looper.getMainLooper())
|
|
35
|
+
|
|
36
|
+
// Lynx calls modules off the main thread. Play's tasks call their
|
|
37
|
+
// listeners on the main thread, and the flow is launched from there too,
|
|
38
|
+
// over the activity.
|
|
39
|
+
@LynxMethod
|
|
40
|
+
fun request(callback: Callback) {
|
|
41
|
+
main.post {
|
|
42
|
+
val done = { callback.invoke(JavaOnlyMap()) }
|
|
43
|
+
try {
|
|
44
|
+
val manager = ReviewManagerFactory.create(activity)
|
|
45
|
+
manager.requestReviewFlow().addOnCompleteListener { request ->
|
|
46
|
+
if (!request.isSuccessful || activity.isFinishing) {
|
|
47
|
+
Log.w(TAG, "Google Play has no review flow for the app", request.exception)
|
|
48
|
+
done()
|
|
49
|
+
return@addOnCompleteListener
|
|
50
|
+
}
|
|
51
|
+
// Completes once the prompt has closed, or at once when
|
|
52
|
+
// Play chose not to show it.
|
|
53
|
+
manager.launchReviewFlow(activity, request.result).addOnCompleteListener { done() }
|
|
54
|
+
}
|
|
55
|
+
} catch (error: RuntimeException) {
|
|
56
|
+
Log.w(TAG, "Google Play's review flow failed", error)
|
|
57
|
+
done()
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
companion object {
|
|
63
|
+
const val NAME = "AngularLynxStoreReview"
|
|
64
|
+
private const val TAG = "AngularLynxStoreReview"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
package dev.angularlynx.shell
|
|
2
|
+
|
|
3
|
+
import android.graphics.Typeface
|
|
4
|
+
import android.os.Build
|
|
5
|
+
import com.lynx.tasm.behavior.shadow.text.TypefaceCache
|
|
6
|
+
import java.util.Locale
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Lets `font-family` name Android's own font families, as a browser does:
|
|
10
|
+
* `monospace`, `serif`, `sans-serif`, the other CSS generic families Android
|
|
11
|
+
* has a font for, and the families in the system's fonts.xml
|
|
12
|
+
* (`sans-serif-condensed`, `serif-monospace`, `casual`...).
|
|
13
|
+
*
|
|
14
|
+
* Lynx on Android finds a family only in the providers the host app
|
|
15
|
+
* registers and in the app's `@font-face` rules (TypefaceCache.getTypeface,
|
|
16
|
+
* then FontFaceManager); neither asks Android for its system families, so
|
|
17
|
+
* `font-family: Menlo, monospace` (the build plugin's rule for `<code>`)
|
|
18
|
+
* drew the default font. iOS finds installed fonts by name itself.
|
|
19
|
+
*
|
|
20
|
+
* Lynx walks the list a family at a time, so a name Android doesn't have
|
|
21
|
+
* must return null here, letting Lynx try the app's `@font-face` rules and
|
|
22
|
+
* then the next family in the list. Lynx asks the providers before the
|
|
23
|
+
* `@font-face` rules, so an app's `@font-face` named after one of these
|
|
24
|
+
* families loses to the system's. A browser treats unquoted generic names the
|
|
25
|
+
* same way, and Lynx drops the quotes that would tell the two apart.
|
|
26
|
+
*/
|
|
27
|
+
object SystemFontFamilies : TypefaceCache.LazyProvider {
|
|
28
|
+
// CSS's generic families, and the Android family each draws in, with
|
|
29
|
+
// `system-ui` in the system font as Chrome draws it. Android has no
|
|
30
|
+
// family for `fantasy`, `math` or `emoji` (emoji come from the fallback
|
|
31
|
+
// fonts whatever the family), and Chrome doesn't know Safari's `ui-*`
|
|
32
|
+
// families, so those fall through to the next family in the list.
|
|
33
|
+
private val NAMED_FAMILIES = mapOf(
|
|
34
|
+
"serif" to "serif",
|
|
35
|
+
"sans-serif" to "sans-serif",
|
|
36
|
+
"monospace" to "monospace",
|
|
37
|
+
"cursive" to "cursive",
|
|
38
|
+
"system-ui" to "sans-serif",
|
|
39
|
+
// fonts.xml's aliases of `sans-serif`. Android hands back the default
|
|
40
|
+
// Typeface itself for them, which the check below can't tell from a
|
|
41
|
+
// name it doesn't have, so they're named here: `Arial, monospace`
|
|
42
|
+
// draws Arial's alias, as Chrome on Android does.
|
|
43
|
+
"arial" to "sans-serif",
|
|
44
|
+
"helvetica" to "sans-serif",
|
|
45
|
+
"tahoma" to "sans-serif",
|
|
46
|
+
"verdana" to "sans-serif",
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
// Lynx calls this from TypefaceCache, which caches each family and style
|
|
50
|
+
// it returns, so a family is looked up once. `style` is Typeface's style
|
|
51
|
+
// (NORMAL, BOLD, ITALIC or BOLD_ITALIC), from the text's font-weight and
|
|
52
|
+
// font-style.
|
|
53
|
+
override fun getTypeface(fontFamily: String, style: Int): Typeface? {
|
|
54
|
+
// CSS family names ignore case; Android's are all lowercase.
|
|
55
|
+
val family = fontFamily.lowercase(Locale.ROOT)
|
|
56
|
+
NAMED_FAMILIES[family]?.let { return Typeface.create(it, style) }
|
|
57
|
+
|
|
58
|
+
// Any other family in fonts.xml. Typeface.create(name) gives back
|
|
59
|
+
// Typeface.DEFAULT itself for a name it doesn't have, from Android 9;
|
|
60
|
+
// before it, that isn't promised, so earlier versions find only the
|
|
61
|
+
// generic families (returning the default there would stop Lynx at a
|
|
62
|
+
// family the system doesn't have and skip the rest of the list).
|
|
63
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) return null
|
|
64
|
+
val typeface = Typeface.create(family, Typeface.NORMAL)
|
|
65
|
+
if (typeface === Typeface.DEFAULT) return null
|
|
66
|
+
return Typeface.create(typeface, style)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
package dev.angularlynx.shell
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.util.Log
|
|
5
|
+
import com.google.android.gms.ads.identifier.AdvertisingIdClient
|
|
6
|
+
import com.google.android.gms.common.GooglePlayServicesNotAvailableException
|
|
7
|
+
import com.lynx.jsbridge.LynxMethod
|
|
8
|
+
import com.lynx.jsbridge.LynxModule
|
|
9
|
+
import com.lynx.react.bridge.Callback
|
|
10
|
+
import com.lynx.react.bridge.JavaOnlyMap
|
|
11
|
+
import java.util.concurrent.Executors
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The native module behind the runtime's `LynxTracking`, which calls it as
|
|
15
|
+
* `NativeModules.AngularLynxTracking` (from the background thread, where
|
|
16
|
+
* NativeModules lives). MainActivity registers it without a param.
|
|
17
|
+
*
|
|
18
|
+
* Android has no tracking prompt: an app that declares the AD_ID permission
|
|
19
|
+
* (angular.json's `permissions.tracking` does) reads the advertising ID from
|
|
20
|
+
* Google Play services. The person can still opt out of personalized ads, or
|
|
21
|
+
* delete the ID (Android 12 and later), in the phone's Settings, and the ID
|
|
22
|
+
* then reads as zeros. Google Play's policy says to respect that, so
|
|
23
|
+
* `status` and `request` both call back with `{ status }`:
|
|
24
|
+
*
|
|
25
|
+
* - `authorized`: the ID is there, and the person hasn't opted out.
|
|
26
|
+
* - `denied`: they have opted out, or deleted it.
|
|
27
|
+
* - `unsupported`: the phone has no Google Play services, so there's no ID.
|
|
28
|
+
*
|
|
29
|
+
* Asking Play services blocks on a binder call, so it runs on a worker
|
|
30
|
+
* thread of the module's own, not on Lynx's.
|
|
31
|
+
*
|
|
32
|
+
* The generator leaves this file, the lines in MainActivity that register it
|
|
33
|
+
* and Play's advertising ID library out of an app whose angular.json doesn't
|
|
34
|
+
* set `permissions.tracking`.
|
|
35
|
+
*/
|
|
36
|
+
class TrackingModule(context: Context, @Suppress("UNUSED_PARAMETER") param: Any?) :
|
|
37
|
+
LynxModule(context, param) {
|
|
38
|
+
private val appContext = context.applicationContext
|
|
39
|
+
|
|
40
|
+
@LynxMethod
|
|
41
|
+
fun status(callback: Callback) = answer(callback)
|
|
42
|
+
|
|
43
|
+
// There's nothing to ask: Android shows no prompt, so a request answers
|
|
44
|
+
// what status does.
|
|
45
|
+
@LynxMethod
|
|
46
|
+
fun request(callback: Callback) = answer(callback)
|
|
47
|
+
|
|
48
|
+
private fun answer(callback: Callback) {
|
|
49
|
+
worker.execute {
|
|
50
|
+
val status = try {
|
|
51
|
+
if (AdvertisingIdClient.getAdvertisingIdInfo(appContext).isLimitAdTrackingEnabled) {
|
|
52
|
+
"denied"
|
|
53
|
+
} else {
|
|
54
|
+
"authorized"
|
|
55
|
+
}
|
|
56
|
+
} catch (error: GooglePlayServicesNotAvailableException) {
|
|
57
|
+
"unsupported"
|
|
58
|
+
} catch (error: Exception) {
|
|
59
|
+
// Play services couldn't be reached (an IOException), is out
|
|
60
|
+
// of date (GooglePlayServicesRepairableException), or failed
|
|
61
|
+
// otherwise: there's no ID to read now.
|
|
62
|
+
Log.w(TAG, "Couldn't read the advertising ID", error)
|
|
63
|
+
"unsupported"
|
|
64
|
+
}
|
|
65
|
+
callback.invoke(JavaOnlyMap().apply { putString("status", status) })
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
companion object {
|
|
70
|
+
const val NAME = "AngularLynxTracking"
|
|
71
|
+
private const val TAG = "AngularLynxTracking"
|
|
72
|
+
private val worker = Executors.newSingleThreadExecutor()
|
|
73
|
+
}
|
|
74
|
+
}
|