@blotch/angular-lynx-native 22.3.2 → 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 +8 -2
- package/dist/android/project.d.ts +27 -3
- package/dist/android/project.d.ts.map +1 -1
- package/dist/android/project.js +80 -9
- package/dist/eject.d.ts.map +1 -1
- package/dist/eject.js +1 -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 +17 -2
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +68 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/ios/project.d.ts +21 -2
- package/dist/ios/project.d.ts.map +1 -1
- package/dist/ios/project.js +58 -2
- package/dist/options.d.ts +68 -0
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +27 -0
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +18 -3
- 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 +12 -4
- package/templates/android/app/build.gradle.kts +27 -9
- package/templates/android/app/src/main/AndroidManifest.xml +5 -0
- 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/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/GeolocationModule.kt +557 -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 +153 -9
- package/templates/android/app/src/main/java/dev/angularlynx/shell/NetworkStatus.kt +121 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/PermissionRequests.kt +10 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/PhotoLibraryModule.kt +203 -16
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellApplication.kt +1 -8
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellModule.kt +11 -1
- package/templates/android/app/src/main/res/xml/share_paths.xml +7 -2
- package/templates/ios/App/AngularLynxPlugins.swift +22 -0
- package/templates/ios/App/AnimationFrameRate.swift +66 -0
- package/templates/ios/App/AppDelegate.swift +3 -1
- package/templates/ios/App/AudioRecorderModule.swift +433 -0
- package/templates/ios/App/GeolocationModule.swift +455 -0
- package/templates/ios/App/HostElementUI.swift +270 -0
- package/templates/ios/App/ImagePickerModule.swift +160 -1
- package/templates/ios/App/LynxViewController.swift +66 -5
- package/templates/ios/App/NetworkStatus.swift +41 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
package dev.angularlynx.shell
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.os.Build
|
|
5
|
+
import android.os.PerformanceHintManager
|
|
6
|
+
import android.os.SystemClock
|
|
7
|
+
import android.util.Log
|
|
8
|
+
import android.view.MotionEvent
|
|
9
|
+
import androidx.annotation.RequiresApi
|
|
10
|
+
import java.io.File
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Tells Android, at every touch, that Lynx's engine thread has work coming.
|
|
14
|
+
*
|
|
15
|
+
* The engine thread runs the whole Angular app, layout and Lynx's animator
|
|
16
|
+
* (see MainActivity's thread strategy), and it works in bursts: nothing while
|
|
17
|
+
* the app is still, then a tap's handler, a navigation and a page to build,
|
|
18
|
+
* all at once. Android's scheduler sizes a thread's core and that core's
|
|
19
|
+
* frequency from how busy the thread has been, so each burst starts on a
|
|
20
|
+
* core that's slow, and most are over before the scheduler has caught up. On
|
|
21
|
+
* a Pixel 9 Pro Fold a push ran at an average of 1.2 GHz on a phone whose
|
|
22
|
+
* cores reach 3.1, and took 44 ms from the tap's handler to the page's first
|
|
23
|
+
* render. The UI thread and RenderThread don't have this problem: Android
|
|
24
|
+
* keeps a performance hint session for them itself.
|
|
25
|
+
*
|
|
26
|
+
* This is one for the engine thread. A session takes a target for a piece of
|
|
27
|
+
* the thread's work and reports of how long the work took, and the system
|
|
28
|
+
* gives the thread faster cores while the reports run over the target.
|
|
29
|
+
* Nothing here can time the engine thread's work, so the target is a frame
|
|
30
|
+
* and each report says the last work took two, at the moments its longest
|
|
31
|
+
* work starts: a finger going down, moving and lifting. With it the same
|
|
32
|
+
* push took 22 ms. The reports stop when the touches do, and the system
|
|
33
|
+
* lets the thread back down by itself.
|
|
34
|
+
*
|
|
35
|
+
* Android 12 and later. A phone whose system has no such sessions gives
|
|
36
|
+
* none ([PerformanceHintManager.createHintSession] returns null), and the
|
|
37
|
+
* touches then do nothing.
|
|
38
|
+
*/
|
|
39
|
+
@RequiresApi(Build.VERSION_CODES.S)
|
|
40
|
+
class EngineThreadHint(context: Context) {
|
|
41
|
+
private val manager = context.getSystemService(PerformanceHintManager::class.java)
|
|
42
|
+
|
|
43
|
+
// Made at the first touch that finds the engine thread: Lynx starts it
|
|
44
|
+
// with the first LynxView, after the activity is made.
|
|
45
|
+
private var session: PerformanceHintManager.Session? = null
|
|
46
|
+
|
|
47
|
+
// Whether a session was asked for and refused, so it isn't asked for at
|
|
48
|
+
// every touch.
|
|
49
|
+
private var unsupported = false
|
|
50
|
+
|
|
51
|
+
// When the last report was made, in SystemClock.uptimeMillis().
|
|
52
|
+
private var reportedAt = 0L
|
|
53
|
+
|
|
54
|
+
// When the engine thread was last looked for and not found, in
|
|
55
|
+
// SystemClock.uptimeMillis(), or null when it hasn't been missed. Looking
|
|
56
|
+
// reads every thread's name in /proc on the UI thread, so a miss holds
|
|
57
|
+
// the next look off for SEARCH_INTERVAL_MILLIS: a thread that's late is
|
|
58
|
+
// still found, a second at most after it starts, and one that never
|
|
59
|
+
// comes (a Lynx that names it differently) costs a look a second, not
|
|
60
|
+
// one at every touch.
|
|
61
|
+
private var missedAt: Long? = null
|
|
62
|
+
|
|
63
|
+
// The least time between two reports while a finger moves: the system
|
|
64
|
+
// reads a session's reports no more often than this.
|
|
65
|
+
private val moveInterval =
|
|
66
|
+
(manager?.preferredUpdateRateNanos ?: 0L).coerceAtLeast(0L) / NANOS_PER_MILLISECOND
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Reports for a touch `event` the activity is about to dispatch: always
|
|
70
|
+
* for a finger going down or lifting, where a press, a tap or a swipe's
|
|
71
|
+
* end starts the engine thread's work, and for a move no more often than
|
|
72
|
+
* the system reads reports, for the handlers a drag runs. Reporting only
|
|
73
|
+
* when a finger goes down pushed a page as fast, but over a scroll of
|
|
74
|
+
* a long list the engine thread then ran 10% longer, for no measurable
|
|
75
|
+
* saving in energy.
|
|
76
|
+
*/
|
|
77
|
+
fun touched(event: MotionEvent) {
|
|
78
|
+
val now = SystemClock.uptimeMillis()
|
|
79
|
+
when (event.actionMasked) {
|
|
80
|
+
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN, MotionEvent.ACTION_UP -> {}
|
|
81
|
+
MotionEvent.ACTION_MOVE -> if (now - reportedAt < moveInterval) return
|
|
82
|
+
else -> return
|
|
83
|
+
}
|
|
84
|
+
val session = session ?: open(now) ?: return
|
|
85
|
+
reportedAt = now
|
|
86
|
+
try {
|
|
87
|
+
session.reportActualWorkDuration(REPORTED_NANOS)
|
|
88
|
+
} catch (error: RuntimeException) {
|
|
89
|
+
// The session's threads are gone, or the system dropped it: start
|
|
90
|
+
// again at the next touch.
|
|
91
|
+
Log.w(TAG, "Engine thread hint: report failed", error)
|
|
92
|
+
close()
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Ends the session, with the activity. */
|
|
97
|
+
fun close() {
|
|
98
|
+
session?.close()
|
|
99
|
+
session = null
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private fun open(now: Long): PerformanceHintManager.Session? {
|
|
103
|
+
if (unsupported || manager == null) return null
|
|
104
|
+
if (missedAt?.let { now - it < SEARCH_INTERVAL_MILLIS } == true) return null
|
|
105
|
+
val threads = engineThreads()
|
|
106
|
+
if (threads.isEmpty()) {
|
|
107
|
+
missedAt = now
|
|
108
|
+
return null
|
|
109
|
+
}
|
|
110
|
+
session = try {
|
|
111
|
+
manager.createHintSession(threads, TARGET_NANOS)
|
|
112
|
+
} catch (error: RuntimeException) {
|
|
113
|
+
Log.w(TAG, "Engine thread hint: no session", error)
|
|
114
|
+
null
|
|
115
|
+
}
|
|
116
|
+
unsupported = session == null
|
|
117
|
+
return session
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The ids of the process's threads Lynx named as its engine thread
|
|
122
|
+
* (`Lynx_TASM`, or `Lynx_TASM1` and up when it keeps several), read from
|
|
123
|
+
* /proc: Lynx starts the thread itself, in native code, and has no call
|
|
124
|
+
* that gives its id.
|
|
125
|
+
*/
|
|
126
|
+
private fun engineThreads(): IntArray =
|
|
127
|
+
(File("/proc/self/task").listFiles() ?: emptyArray())
|
|
128
|
+
.filter { task ->
|
|
129
|
+
try {
|
|
130
|
+
File(task, "comm").readText().startsWith(ENGINE_THREAD_NAME)
|
|
131
|
+
} catch (_: java.io.IOException) {
|
|
132
|
+
// The thread ended between the listing and the read.
|
|
133
|
+
false
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
.mapNotNull { it.name.toIntOrNull() }
|
|
137
|
+
.toIntArray()
|
|
138
|
+
|
|
139
|
+
private companion object {
|
|
140
|
+
const val TAG = "AngularLynxShell"
|
|
141
|
+
|
|
142
|
+
// Lynx's name for the thread, in its task runners' StartTASMThread().
|
|
143
|
+
const val ENGINE_THREAD_NAME = "Lynx_TASM"
|
|
144
|
+
const val NANOS_PER_MILLISECOND = 1_000_000L
|
|
145
|
+
|
|
146
|
+
// The least time between two looks for an engine thread that wasn't
|
|
147
|
+
// there.
|
|
148
|
+
const val SEARCH_INTERVAL_MILLIS = 1_000L
|
|
149
|
+
|
|
150
|
+
// A frame at 120 Hz, and two of them. What matters is that the
|
|
151
|
+
// report is over the target: on the Pixel a report of twice the
|
|
152
|
+
// target and one of twelve times it sped a push up alike.
|
|
153
|
+
const val TARGET_NANOS = 8_333_333L
|
|
154
|
+
const val REPORTED_NANOS = 2 * TARGET_NANOS
|
|
155
|
+
}
|
|
156
|
+
}
|