@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,429 @@
|
|
|
1
|
+
package dev.angularlynx.shell
|
|
2
|
+
|
|
3
|
+
// angular-lynx:wifi-read
|
|
4
|
+
import android.Manifest
|
|
5
|
+
import android.content.pm.PackageManager
|
|
6
|
+
import android.location.LocationManager
|
|
7
|
+
import android.net.wifi.WifiManager
|
|
8
|
+
import androidx.core.content.ContextCompat
|
|
9
|
+
import androidx.core.location.LocationManagerCompat
|
|
10
|
+
// /angular-lynx:wifi-read
|
|
11
|
+
import android.content.Context
|
|
12
|
+
// angular-lynx:wifi-join
|
|
13
|
+
import android.net.ConnectivityManager
|
|
14
|
+
import android.net.Network
|
|
15
|
+
import android.net.NetworkCapabilities
|
|
16
|
+
import android.net.NetworkRequest
|
|
17
|
+
import android.net.wifi.WifiNetworkSpecifier
|
|
18
|
+
import android.net.wifi.WifiNetworkSuggestion
|
|
19
|
+
import android.os.Build
|
|
20
|
+
import com.lynx.react.bridge.ReadableMap
|
|
21
|
+
// /angular-lynx:wifi-join
|
|
22
|
+
import android.os.Handler
|
|
23
|
+
import android.os.Looper
|
|
24
|
+
import com.lynx.jsbridge.LynxMethod
|
|
25
|
+
import com.lynx.jsbridge.LynxModule
|
|
26
|
+
import com.lynx.react.bridge.Callback
|
|
27
|
+
import com.lynx.react.bridge.JavaOnlyMap
|
|
28
|
+
|
|
29
|
+
// cspell:words BSSID
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The native module behind the runtime's `LynxWifi`, which calls it as
|
|
33
|
+
* `NativeModules.AngularLynxWifi` (from the background thread, where
|
|
34
|
+
* NativeModules lives). MainActivity registers it with its [PermissionHost] as the param. Every
|
|
35
|
+
* method calls back once, with its answer or `{ error, message }`.
|
|
36
|
+
*
|
|
37
|
+
* - `currentNetwork` calls back with `{ ssid, bssid }` from `WifiManager`, or
|
|
38
|
+
* `{ none: true }` off Wi-Fi. Android gives the network's name only to an
|
|
39
|
+
* app with `ACCESS_FINE_LOCATION`, while Location is on, so it first asks
|
|
40
|
+
* the person for their location through MainActivity's prompt (the
|
|
41
|
+
* [PermissionHost] MainActivity registers the module with), and answers
|
|
42
|
+
* `denied` only once they've refused.
|
|
43
|
+
* - `join` with `joinOnce` asks for the network through a
|
|
44
|
+
* `WifiNetworkSpecifier`: Android shows its dialog, the person picks the
|
|
45
|
+
* network, and the module keeps the app's traffic on it
|
|
46
|
+
* (`bindProcessToNetwork`), since a device's access point has no internet
|
|
47
|
+
* and Android would otherwise keep using mobile data. Without `joinOnce` it
|
|
48
|
+
* adds a `WifiNetworkSuggestion`, which the phone joins whenever it's in
|
|
49
|
+
* range, once the person allows the app's suggestions. Both need Android 10.
|
|
50
|
+
* - `leave` releases the specifier's network and removes the suggestion.
|
|
51
|
+
*
|
|
52
|
+
* The generator leaves this file and the lines in MainActivity that register
|
|
53
|
+
* it out of an app whose angular.json doesn't set `wifi`, and each part's
|
|
54
|
+
* lines (`// angular-lynx:wifi-read`, `// angular-lynx:wifi-join`) out of an
|
|
55
|
+
* app that doesn't turn it on, with its manifest permissions. A method taken
|
|
56
|
+
* out isn't on the module, so the runtime rejects it with `unavailable`.
|
|
57
|
+
*/
|
|
58
|
+
class WifiModule(context: Context, param: Any?) : LynxModule(context, param) {
|
|
59
|
+
private val appContext = context.applicationContext
|
|
60
|
+
|
|
61
|
+
// The module's state is the main thread's, where MainActivity's prompt
|
|
62
|
+
// and Android's network callbacks answer.
|
|
63
|
+
private val main = Handler(Looper.getMainLooper())
|
|
64
|
+
|
|
65
|
+
// angular-lynx:wifi-read
|
|
66
|
+
/**
|
|
67
|
+
* MainActivity's permission prompt. It's null for a module registered
|
|
68
|
+
* without it, as a project ejected before the prompt was lent to this
|
|
69
|
+
* module registers it: that app can't ask, so a read without the
|
|
70
|
+
* permission answers `denied`.
|
|
71
|
+
*/
|
|
72
|
+
private val permissions = param as? PermissionHost
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The reads waiting for the person to answer the location prompt. The
|
|
76
|
+
* first one opens it, and those that come while it's open wait for the
|
|
77
|
+
* same answer, since the activity shows one prompt at a time.
|
|
78
|
+
*/
|
|
79
|
+
private val waitingForLocation = mutableListOf<Callback>()
|
|
80
|
+
|
|
81
|
+
/** Set once Lynx lets the module go, after which it asks no more. */
|
|
82
|
+
private var destroyed = false
|
|
83
|
+
|
|
84
|
+
@LynxMethod
|
|
85
|
+
fun currentNetwork(callback: Callback) {
|
|
86
|
+
if (locationGranted()) {
|
|
87
|
+
read(callback)
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
main.post { askForLocation(callback) }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private fun locationGranted(): Boolean =
|
|
94
|
+
ContextCompat.checkSelfPermission(
|
|
95
|
+
appContext, Manifest.permission.ACCESS_FINE_LOCATION,
|
|
96
|
+
) == PackageManager.PERMISSION_GRANTED
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Asks for the person's location, then reads the network for [callback]
|
|
100
|
+
* if they gave it. Coarse location is asked for with fine, as Android 12
|
|
101
|
+
* and later require: the person then picks between precise and
|
|
102
|
+
* approximate, and only precise gives the network's name.
|
|
103
|
+
*/
|
|
104
|
+
private fun askForLocation(callback: Callback) {
|
|
105
|
+
if (destroyed) {
|
|
106
|
+
callback.invoke(error("failed", PAGE_CLOSED))
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
waitingForLocation += callback
|
|
110
|
+
if (waitingForLocation.size > 1) return
|
|
111
|
+
val host = permissions
|
|
112
|
+
val asked = try {
|
|
113
|
+
host?.requestPermissions(LOCATION_PERMISSIONS) { locationAnswered() } ?: false
|
|
114
|
+
} catch (_: IllegalStateException) {
|
|
115
|
+
// The activity's launcher throws once the activity is going.
|
|
116
|
+
false
|
|
117
|
+
}
|
|
118
|
+
if (asked) return
|
|
119
|
+
// Without a host the app can't ask, which is as good as refused;
|
|
120
|
+
// another module's prompt being open is only for now.
|
|
121
|
+
val answer = when {
|
|
122
|
+
host == null -> error("denied", NO_PROMPT)
|
|
123
|
+
else -> error("failed", PROMPT_OPEN)
|
|
124
|
+
}
|
|
125
|
+
answerWaiting { it.invoke(answer) }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The person answered the prompt: each waiting read goes on or fails. */
|
|
129
|
+
private fun locationAnswered() {
|
|
130
|
+
if (locationGranted()) {
|
|
131
|
+
answerWaiting(::read)
|
|
132
|
+
} else {
|
|
133
|
+
val answer = error("denied", REFUSED)
|
|
134
|
+
answerWaiting { it.invoke(answer) }
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private fun answerWaiting(answer: (Callback) -> Unit) {
|
|
139
|
+
val waiting = waitingForLocation.toList()
|
|
140
|
+
waitingForLocation.clear()
|
|
141
|
+
waiting.forEach(answer)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Reads the network, once the app has the location permission. */
|
|
145
|
+
private fun read(callback: Callback) {
|
|
146
|
+
val locations = appContext.getSystemService(LocationManager::class.java)
|
|
147
|
+
if (locations == null || !LocationManagerCompat.isLocationEnabled(locations)) {
|
|
148
|
+
callback.invoke(
|
|
149
|
+
error(
|
|
150
|
+
"denied",
|
|
151
|
+
"Location is off. Android gives the Wi-Fi network's name only while it's on.",
|
|
152
|
+
),
|
|
153
|
+
)
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
val wifi = appContext.getSystemService(WifiManager::class.java)
|
|
157
|
+
// Deprecated from Android 12 for NetworkCapabilities' transport
|
|
158
|
+
// info, which hides the name unless asked for through a network
|
|
159
|
+
// callback, and still answering for an app with the permission.
|
|
160
|
+
@Suppress("DEPRECATION")
|
|
161
|
+
val info = wifi?.connectionInfo
|
|
162
|
+
@Suppress("DEPRECATION")
|
|
163
|
+
val ssid = info?.ssid?.let(::unquoted)
|
|
164
|
+
// Off Wi-Fi, Android answers the placeholder, or nothing.
|
|
165
|
+
if (info == null || ssid.isNullOrEmpty() || ssid == UNKNOWN_SSID) {
|
|
166
|
+
callback.invoke(JavaOnlyMap().apply { putBoolean("none", true) })
|
|
167
|
+
return
|
|
168
|
+
}
|
|
169
|
+
callback.invoke(
|
|
170
|
+
JavaOnlyMap().apply {
|
|
171
|
+
putString("ssid", ssid)
|
|
172
|
+
@Suppress("DEPRECATION")
|
|
173
|
+
val bssid = info.bssid
|
|
174
|
+
// Android answers this placeholder when it hides the address.
|
|
175
|
+
if (bssid != null && bssid != HIDDEN_BSSID) putString("bssid", bssid)
|
|
176
|
+
},
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The SSID without the quotes Android puts round one it could read as
|
|
182
|
+
* UTF-8. One it couldn't comes as hex digits, without quotes.
|
|
183
|
+
*/
|
|
184
|
+
private fun unquoted(ssid: String): String =
|
|
185
|
+
if (ssid.length >= 2 && ssid.startsWith('"') && ssid.endsWith('"')) {
|
|
186
|
+
ssid.substring(1, ssid.length - 1)
|
|
187
|
+
} else {
|
|
188
|
+
ssid
|
|
189
|
+
}
|
|
190
|
+
// /angular-lynx:wifi-read
|
|
191
|
+
|
|
192
|
+
// angular-lynx:wifi-join
|
|
193
|
+
private val connectivity = appContext.getSystemService(ConnectivityManager::class.java)
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* A network `join` asked for with `joinOnce`: its callback keeps the
|
|
197
|
+
* network up until `leave` releases it.
|
|
198
|
+
*/
|
|
199
|
+
private inner class Request(private val ssid: String, private val done: Callback) :
|
|
200
|
+
ConnectivityManager.NetworkCallback() {
|
|
201
|
+
/** Whether `join` has called back, which it does once. */
|
|
202
|
+
private var answered = false
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* The network this request bound the process to, so releasing it
|
|
206
|
+
* unbinds only its own network, not one another request bound.
|
|
207
|
+
*/
|
|
208
|
+
private var bound: Network? = null
|
|
209
|
+
|
|
210
|
+
override fun onAvailable(network: Network) {
|
|
211
|
+
// Android otherwise keeps the app's traffic on the network with
|
|
212
|
+
// internet, and the device would be unreachable. It refuses when
|
|
213
|
+
// the network went before this ran: the app couldn't reach the
|
|
214
|
+
// device then, so the join fails rather than reporting a route it
|
|
215
|
+
// doesn't have.
|
|
216
|
+
if (connectivity?.bindProcessToNetwork(network) != true) {
|
|
217
|
+
if (requests[ssid] === this) requests.remove(ssid)
|
|
218
|
+
release("Android couldn't send the app's traffic over $ssid: the phone lost the network.")
|
|
219
|
+
return
|
|
220
|
+
}
|
|
221
|
+
bound = network
|
|
222
|
+
answer(JavaOnlyMap().apply { putBoolean("done", true) })
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
override fun onLost(network: Network) {
|
|
226
|
+
unbind(network)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Android calls it when the person closes its dialog, or when no such
|
|
230
|
+
// network is in range, and doesn't say which.
|
|
231
|
+
override fun onUnavailable() {
|
|
232
|
+
if (requests[ssid] === this) requests.remove(ssid)
|
|
233
|
+
answer(
|
|
234
|
+
error(
|
|
235
|
+
"notFound",
|
|
236
|
+
"The phone didn't join $ssid: it isn't in range, or the person closed Android's dialog.",
|
|
237
|
+
),
|
|
238
|
+
)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Stops asking for the network and gives it up. Android calls an
|
|
243
|
+
* unregistered callback no more, so a join still waiting for the
|
|
244
|
+
* person is answered here, or its promise would never settle.
|
|
245
|
+
*/
|
|
246
|
+
fun release(why: String) {
|
|
247
|
+
try {
|
|
248
|
+
connectivity?.unregisterNetworkCallback(this)
|
|
249
|
+
} catch (_: IllegalArgumentException) {
|
|
250
|
+
// Android already let it go.
|
|
251
|
+
}
|
|
252
|
+
bound?.let(::unbind)
|
|
253
|
+
answer(error("failed", why))
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
private fun unbind(network: Network) {
|
|
257
|
+
if (bound != network) return
|
|
258
|
+
bound = null
|
|
259
|
+
connectivity?.let {
|
|
260
|
+
if (it.boundNetworkForProcess == network) it.bindProcessToNetwork(null)
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
private fun answer(result: JavaOnlyMap) {
|
|
265
|
+
if (answered) return
|
|
266
|
+
answered = true
|
|
267
|
+
done.invoke(result)
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** The networks `join` asked for with `joinOnce`, by SSID. */
|
|
272
|
+
private val requests = mutableMapOf<String, Request>()
|
|
273
|
+
|
|
274
|
+
/** The suggestions `join` added, by SSID, for `leave` to remove. */
|
|
275
|
+
private val suggestions = mutableMapOf<String, WifiNetworkSuggestion>()
|
|
276
|
+
|
|
277
|
+
/** Joins [options]: `{ ssid, password?, joinOnce }`. */
|
|
278
|
+
@LynxMethod
|
|
279
|
+
fun join(options: ReadableMap, callback: Callback) {
|
|
280
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
|
281
|
+
callback.invoke(error("unavailable", "Joining a Wi-Fi network needs Android 10 or later."))
|
|
282
|
+
return
|
|
283
|
+
}
|
|
284
|
+
val ssid = options.getString("ssid")
|
|
285
|
+
if (ssid.isNullOrEmpty()) {
|
|
286
|
+
callback.invoke(error("failed", "The network needs its name."))
|
|
287
|
+
return
|
|
288
|
+
}
|
|
289
|
+
val password = if (options.hasKey("password")) options.getString("password") else null
|
|
290
|
+
val joinOnce = options.hasKey("joinOnce") && options.getBoolean("joinOnce")
|
|
291
|
+
// The module's state is the main thread's, as are Android's network
|
|
292
|
+
// callbacks (see requestNetwork's handler).
|
|
293
|
+
main.post {
|
|
294
|
+
try {
|
|
295
|
+
if (joinOnce) joinOnce(ssid, password, callback) else suggest(ssid, password, callback)
|
|
296
|
+
} catch (error: SecurityException) {
|
|
297
|
+
callback.invoke(error("failed", error.message ?: "Android refused the network."))
|
|
298
|
+
} catch (error: IllegalArgumentException) {
|
|
299
|
+
// The builders refuse a name or passphrase they can't take.
|
|
300
|
+
callback.invoke(error("failed", error.message ?: "Android refused the network's name or password."))
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** Leaves the network `join` joined as [ssid], however it joined. */
|
|
306
|
+
@LynxMethod
|
|
307
|
+
fun leave(ssid: String, callback: Callback) {
|
|
308
|
+
main.post {
|
|
309
|
+
requests.remove(ssid)?.release("The app left $ssid before the phone joined it.")
|
|
310
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
311
|
+
val added = suggestions.remove(ssid)
|
|
312
|
+
// An earlier run's suggestions are still the phone's, which
|
|
313
|
+
// Android 11 and later list.
|
|
314
|
+
val listed = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
315
|
+
appContext.getSystemService(android.net.wifi.WifiManager::class.java)
|
|
316
|
+
?.networkSuggestions.orEmpty().filter { it.ssid == ssid }
|
|
317
|
+
} else {
|
|
318
|
+
emptyList()
|
|
319
|
+
}
|
|
320
|
+
val remove = (listOfNotNull(added) + listed).distinct()
|
|
321
|
+
if (remove.isNotEmpty()) {
|
|
322
|
+
appContext.getSystemService(android.net.wifi.WifiManager::class.java)
|
|
323
|
+
?.removeNetworkSuggestions(remove)
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
callback.invoke(JavaOnlyMap().apply { putBoolean("done", true) })
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
private fun joinOnce(ssid: String, password: String?, callback: Callback) {
|
|
331
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || connectivity == null) {
|
|
332
|
+
callback.invoke(error("unavailable", "This phone can't join a Wi-Fi network for the app."))
|
|
333
|
+
return
|
|
334
|
+
}
|
|
335
|
+
// A second join for the same network replaces the first.
|
|
336
|
+
requests.remove(ssid)?.release("Another join for $ssid replaced this one.")
|
|
337
|
+
val specifier = WifiNetworkSpecifier.Builder().setSsid(ssid).apply {
|
|
338
|
+
if (password != null) setWpa2Passphrase(password)
|
|
339
|
+
}.build()
|
|
340
|
+
val request = NetworkRequest.Builder()
|
|
341
|
+
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
|
|
342
|
+
// A device's access point has no internet, which Android would
|
|
343
|
+
// otherwise require of a network it hands the app.
|
|
344
|
+
.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
|
345
|
+
.setNetworkSpecifier(specifier)
|
|
346
|
+
.build()
|
|
347
|
+
val networkCallback = Request(ssid, callback)
|
|
348
|
+
requests[ssid] = networkCallback
|
|
349
|
+
connectivity.requestNetwork(request, networkCallback, main)
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
private fun suggest(ssid: String, password: String?, callback: Callback) {
|
|
353
|
+
val wifi = appContext.getSystemService(android.net.wifi.WifiManager::class.java)
|
|
354
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || wifi == null) {
|
|
355
|
+
callback.invoke(error("unavailable", "This phone can't take the app's Wi-Fi networks."))
|
|
356
|
+
return
|
|
357
|
+
}
|
|
358
|
+
val suggestion = WifiNetworkSuggestion.Builder().setSsid(ssid).apply {
|
|
359
|
+
if (password != null) setWpa2Passphrase(password)
|
|
360
|
+
}.build()
|
|
361
|
+
// Android refuses a suggestion it already has, so one with a new
|
|
362
|
+
// password replaces the old.
|
|
363
|
+
suggestions.remove(ssid)?.let { wifi.removeNetworkSuggestions(listOf(it)) }
|
|
364
|
+
var status = wifi.addNetworkSuggestions(listOf(suggestion))
|
|
365
|
+
if (status == android.net.wifi.WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE) {
|
|
366
|
+
wifi.removeNetworkSuggestions(listOf(suggestion))
|
|
367
|
+
status = wifi.addNetworkSuggestions(listOf(suggestion))
|
|
368
|
+
}
|
|
369
|
+
when (status) {
|
|
370
|
+
android.net.wifi.WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS -> {
|
|
371
|
+
suggestions[ssid] = suggestion
|
|
372
|
+
callback.invoke(JavaOnlyMap().apply { putBoolean("done", true) })
|
|
373
|
+
}
|
|
374
|
+
// The person turned off the app's suggestions in Settings.
|
|
375
|
+
android.net.wifi.WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_APP_DISALLOWED ->
|
|
376
|
+
callback.invoke(error("canceled", "The person doesn't allow this app to suggest Wi-Fi networks."))
|
|
377
|
+
else -> callback.invoke(error("failed", "Android refused the network (status $status)."))
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
// /angular-lynx:wifi-join
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Lets go of what the module holds when Lynx lets it go, as a reload of
|
|
384
|
+
* the page does. A read waiting for the location prompt is answered,
|
|
385
|
+
* since this module won't hear the person's answer. The networks the
|
|
386
|
+
* app joined once are given up: the next module has none of them to
|
|
387
|
+
* release, so they'd stay up, and the process bound, until the app ends.
|
|
388
|
+
*/
|
|
389
|
+
override fun destroy() {
|
|
390
|
+
main.post {
|
|
391
|
+
// angular-lynx:wifi-read
|
|
392
|
+
destroyed = true
|
|
393
|
+
val answer = error("failed", PAGE_CLOSED)
|
|
394
|
+
answerWaiting { it.invoke(answer) }
|
|
395
|
+
// /angular-lynx:wifi-read
|
|
396
|
+
// angular-lynx:wifi-join
|
|
397
|
+
for (request in requests.values) request.release("The app was reloaded.")
|
|
398
|
+
requests.clear()
|
|
399
|
+
// /angular-lynx:wifi-join
|
|
400
|
+
}
|
|
401
|
+
super.destroy()
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
private fun error(code: String, message: String) = JavaOnlyMap().apply {
|
|
405
|
+
putString("error", code)
|
|
406
|
+
putString("message", message)
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
companion object {
|
|
410
|
+
const val NAME = "AngularLynxWifi"
|
|
411
|
+
// angular-lynx:wifi-read
|
|
412
|
+
/** What `WifiInfo.getSSID` answers when it hides the name. */
|
|
413
|
+
private const val UNKNOWN_SSID = "<unknown ssid>"
|
|
414
|
+
/** What `WifiInfo.getBSSID` answers when it hides the address. */
|
|
415
|
+
private const val HIDDEN_BSSID = "02:00:00:00:00:00"
|
|
416
|
+
private val LOCATION_PERMISSIONS = arrayOf(
|
|
417
|
+
Manifest.permission.ACCESS_FINE_LOCATION,
|
|
418
|
+
Manifest.permission.ACCESS_COARSE_LOCATION,
|
|
419
|
+
)
|
|
420
|
+
private const val REFUSED =
|
|
421
|
+
"The person didn't give the app their precise location, which Android needs to give the Wi-Fi network's name. Once they've refused it twice, Android stops asking, and only Settings can grant it."
|
|
422
|
+
private const val NO_PROMPT =
|
|
423
|
+
"ACCESS_FINE_LOCATION is not granted, and this app can't ask for it: its MainActivity doesn't lend the module its permission prompt. The person can grant it in Settings."
|
|
424
|
+
private const val PROMPT_OPEN =
|
|
425
|
+
"Another permission prompt is open. Ask again once the person has answered it."
|
|
426
|
+
private const val PAGE_CLOSED = "The page closed before the person answered the location prompt."
|
|
427
|
+
// /angular-lynx:wifi-read
|
|
428
|
+
}
|
|
429
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<!--
|
|
3
|
+
The reason a biometric prompt shows when the app gives none. The generator
|
|
4
|
+
writes angular.json's permissions.biometrics here, or deletes this file with
|
|
5
|
+
BiometricsModule.kt from an app without it.
|
|
6
|
+
-->
|
|
7
|
+
<resources>
|
|
8
|
+
<string name="angular_lynx_biometrics_reason">Confirm it\'s you</string>
|
|
9
|
+
</resources>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<!--
|
|
3
|
+
angular.json's shareTarget.mimeTypes, which ShareTargetModule checks each
|
|
4
|
+
shared file against. The generator writes them here, and leaves this file
|
|
5
|
+
out of an app without shareTarget, with the module.
|
|
6
|
+
-->
|
|
7
|
+
<resources>
|
|
8
|
+
<string-array name="angular_lynx_share_mime_types" translatable="false">
|
|
9
|
+
<item>text/plain</item>
|
|
10
|
+
</string-array>
|
|
11
|
+
</resources>
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
|
2
2
|
<!--
|
|
3
3
|
Auto Backup up to Android 11 (data_extraction_rules.xml is Android 12's).
|
|
4
|
-
Everything is backed up but LynxSecureStorage's values
|
|
5
|
-
that
|
|
6
|
-
read (SecureStorageModule.kt
|
|
4
|
+
Everything is backed up but LynxSecureStorage's values, those behind
|
|
5
|
+
biometrics too: the Keystore keys that encrypt them never leave the device,
|
|
6
|
+
so a restored copy couldn't be read (SecureStorageModule.kt and
|
|
7
|
+
BiometricsModule.kt).
|
|
7
8
|
-->
|
|
8
9
|
<full-backup-content>
|
|
9
10
|
<exclude domain="sharedpref" path="angular_lynx_secure_storage.xml" />
|
|
11
|
+
<exclude domain="sharedpref" path="angular_lynx_biometric_storage.xml" />
|
|
10
12
|
</full-backup-content>
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
|
2
2
|
<!--
|
|
3
3
|
Backup and device transfer from Android 12 (backup_rules.xml is for older
|
|
4
|
-
versions). Everything goes but LynxSecureStorage's values
|
|
5
|
-
that
|
|
6
|
-
read (SecureStorageModule.kt
|
|
4
|
+
versions). Everything goes but LynxSecureStorage's values, those behind
|
|
5
|
+
biometrics too: the Keystore keys that encrypt them never leave the device,
|
|
6
|
+
so a copy elsewhere couldn't be read (SecureStorageModule.kt and
|
|
7
|
+
BiometricsModule.kt).
|
|
7
8
|
-->
|
|
8
9
|
<data-extraction-rules>
|
|
9
10
|
<cloud-backup>
|
|
10
11
|
<exclude domain="sharedpref" path="angular_lynx_secure_storage.xml" />
|
|
12
|
+
<exclude domain="sharedpref" path="angular_lynx_biometric_storage.xml" />
|
|
11
13
|
</cloud-backup>
|
|
12
14
|
<device-transfer>
|
|
13
15
|
<exclude domain="sharedpref" path="angular_lynx_secure_storage.xml" />
|
|
16
|
+
<exclude domain="sharedpref" path="angular_lynx_biometric_storage.xml" />
|
|
14
17
|
</device-transfer>
|
|
15
18
|
</data-extraction-rules>
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
|
2
2
|
<!--
|
|
3
|
-
The
|
|
4
|
-
writes them there), and
|
|
3
|
+
The folders FileProvider shares from, and nothing else of the app's:
|
|
4
|
+
LynxShare's files (ShareModule.kt writes them there), and the folder the
|
|
5
|
+
camera app writes LynxImagePicker's photo to (ImagePickerModule.kt), which
|
|
6
|
+
only an app with angular.json's permissions.camera keeps.
|
|
5
7
|
-->
|
|
6
8
|
<paths>
|
|
7
9
|
<cache-path name="shared" path="angular-lynx-share/" />
|
|
10
|
+
<!-- angular-lynx:image-picker-camera -->
|
|
11
|
+
<cache-path name="camera" path="angular-lynx-camera/" />
|
|
12
|
+
<!-- /angular-lynx:image-picker-camera -->
|
|
8
13
|
</paths>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
distributionBase=GRADLE_USER_HOME
|
|
2
2
|
distributionPath=wrapper/dists
|
|
3
|
-
distributionSha256Sum=
|
|
4
|
-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.
|
|
3
|
+
distributionSha256Sum=4f2135b741f272acc88c168a52202a0a63fceee0cd61ee753da79694cd2b1e4b
|
|
4
|
+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.3-bin.zip
|
|
5
5
|
networkTimeout=10000
|
|
6
6
|
retries=0
|
|
7
7
|
retryBackOffMs=500
|