Model LAN invitation JNI calls and multicast lock failures
This commit is contained in:
1 parent
e32e4be28b
commit
0b8caaa810
3 files changed
+48
No files matched your search
@@ -5,6 +5,7 @@ import android.app.NotificationManager
|
||||
import android.os.PowerManager
|
||||
import android.os.Vibrator
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.wifi.WifiManager
|
||||
import android.hardware.SensorManager
|
||||
import android.telephony.SubscriptionManager
|
||||
import android.telephony.TelephonyManager
|
||||
@@ -16,6 +17,7 @@ class Context {
|
||||
companion object {
|
||||
const val AUDIO_SERVICE = "audio"; const val SENSOR_SERVICE = "sensor"; const val VIBRATOR_SERVICE = "vibrator"
|
||||
const val POWER_SERVICE = "power"
|
||||
const val WIFI_SERVICE = "wifi"
|
||||
}
|
||||
val packageName = "com.utun.chat"
|
||||
var cacheDir = File(System.getProperty("java.io.tmpdir"), "utun-router-host-cache")
|
||||
@@ -25,6 +27,8 @@ class Context {
|
||||
var notificationManager: NotificationManager? = NotificationManager()
|
||||
var permissionGranted = true
|
||||
var connectivityManager: ConnectivityManager? = ConnectivityManager()
|
||||
var wifiManager: WifiManager? = WifiManager()
|
||||
var failWifiService = false
|
||||
var sensorManager: SensorManager? = SensorManager()
|
||||
var subscriptionManager: SubscriptionManager? = SubscriptionManager()
|
||||
var telephonyManager: TelephonyManager? = TelephonyManager()
|
||||
@@ -35,6 +39,7 @@ class Context {
|
||||
SENSOR_SERVICE -> sensorManager
|
||||
VIBRATOR_SERVICE -> vibrator
|
||||
POWER_SERVICE -> powerManager
|
||||
WIFI_SERVICE -> { check(!failWifiService) { "Wi-Fi service unavailable" }; wifiManager }
|
||||
else -> error("Unknown service: $name")
|
||||
}
|
||||
fun <T> getSystemService(type: Class<T>): T? {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package android.net.wifi
|
||||
|
||||
/** Host-модель MulticastLock: отказы до/после побочного эффекта и проверка повторного использования владельца. */
|
||||
class WifiManager {
|
||||
var failures = emptySet<String>()
|
||||
val locks = mutableListOf<MulticastLock>()
|
||||
fun createMulticastLock(tag: String): MulticastLock {
|
||||
check("create" !in failures) { "multicast create unavailable" }
|
||||
return MulticastLock(tag, failures).also { locks.add(it) }
|
||||
}
|
||||
class MulticastLock(val tag: String, var failures: Set<String>) {
|
||||
var held = false
|
||||
var counted = true
|
||||
private set
|
||||
var acquisitions = 0
|
||||
var releases = 0
|
||||
val isHeld: Boolean get() { check("query" !in failures) { "multicast query unavailable" }; return held }
|
||||
fun setReferenceCounted(value: Boolean) {
|
||||
check("configure" !in failures) { "multicast configure unavailable" }
|
||||
counted = value
|
||||
}
|
||||
fun acquire() {
|
||||
acquisitions++
|
||||
check("acquire_before" !in failures) { "multicast acquire before effect" }
|
||||
held = true
|
||||
check("acquire_after" !in failures) { "multicast acquire after effect" }
|
||||
}
|
||||
fun release() {
|
||||
releases++
|
||||
check("release_before" !in failures) { "multicast release before effect" }
|
||||
held = false
|
||||
check("release_after" !in failures) { "multicast release after effect" }
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -34,6 +34,14 @@ object LogManager {
|
||||
|
||||
/** Только host-тест: считает уведомления standby, не загружает JNI и не запускает ядро. */
|
||||
object NativeLib {
|
||||
data class LocalInvite(val peer: Long, val request: Long, val link: String)
|
||||
val localInvites = mutableListOf<LocalInvite>()
|
||||
var sendLocal: (LocalInvite) -> Boolean = { true }
|
||||
fun sendLocalInvite(peer: Long, request: Long, link: String): Boolean {
|
||||
val call = LocalInvite(peer, request, link)
|
||||
localInvites.add(call)
|
||||
return sendLocal(call)
|
||||
}
|
||||
data class FileTransfer(val id: Long, val group: Long, val server: Long, val owner: Long,
|
||||
val remote: String, val local: String, val upload: Boolean, val version: ByteArray)
|
||||
var fileRequest: (Long, Long, ByteArray) -> Boolean = { _, _, _ -> true }
|
||||
|
||||
Reference in new issue
Block a user