temporary fix
This commit is contained in:
@@ -2,6 +2,7 @@ package io.nekohasekai.sfa.vendor
|
|||||||
|
|
||||||
import io.nekohasekai.libbox.HTTPResponseWriteToProgressHandler
|
import io.nekohasekai.libbox.HTTPResponseWriteToProgressHandler
|
||||||
import io.nekohasekai.libbox.Libbox
|
import io.nekohasekai.libbox.Libbox
|
||||||
|
import io.nekohasekai.libbox.writeToWithProgress
|
||||||
import io.nekohasekai.sfa.Application
|
import io.nekohasekai.sfa.Application
|
||||||
import io.nekohasekai.sfa.update.UpdateState
|
import io.nekohasekai.sfa.update.UpdateState
|
||||||
import io.nekohasekai.sfa.utils.HTTPClient
|
import io.nekohasekai.sfa.utils.HTTPClient
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package io.nekohasekai.libbox
|
||||||
|
|
||||||
|
class FDroidMirror(
|
||||||
|
val url: String,
|
||||||
|
val name: String,
|
||||||
|
val country: String,
|
||||||
|
)
|
||||||
|
|
||||||
|
class FDroidMirrorIterator(
|
||||||
|
private val items: List<FDroidMirror>,
|
||||||
|
) {
|
||||||
|
private var index = 0
|
||||||
|
fun hasNext(): Boolean = index < items.size
|
||||||
|
fun next(): FDroidMirror = items[index++]
|
||||||
|
}
|
||||||
|
|
||||||
|
class FDroidMirrorPingResult(
|
||||||
|
val url: String,
|
||||||
|
val latencyMs: Int,
|
||||||
|
)
|
||||||
|
|
||||||
|
class FDroidUpdateResult(
|
||||||
|
val versionCode: Int,
|
||||||
|
val versionName: String,
|
||||||
|
val downloadURL: String,
|
||||||
|
val fileSize: Long,
|
||||||
|
)
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package io.nekohasekai.libbox
|
||||||
|
|
||||||
|
interface HTTPResponseWriteToProgressHandler {
|
||||||
|
fun update(progress: Long, total: Long)
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package io.nekohasekai.libbox
|
||||||
|
|
||||||
|
fun HTTPResponse.writeToWithProgress(path: String, handler: HTTPResponseWriteToProgressHandler) {
|
||||||
|
writeTo(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ConnectionOwner.setAndroidPackageNames(names: StringIterator) {
|
||||||
|
if (names.hasNext()) {
|
||||||
|
androidPackageName = names.next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ProcessInfo.packageNames(): StringIterator? {
|
||||||
|
val name = packageName ?: return null
|
||||||
|
if (name.isEmpty()) return null
|
||||||
|
return object : StringIterator {
|
||||||
|
private var consumed = false
|
||||||
|
override fun len(): Int = 1
|
||||||
|
override fun hasNext(): Boolean = !consumed
|
||||||
|
override fun next(): String { consumed = true; return name }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getFDroidMirrors(): FDroidMirrorIterator {
|
||||||
|
return FDroidMirrorIterator(emptyList())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun pingFDroidMirror(url: String): FDroidMirrorPingResult {
|
||||||
|
return FDroidMirrorPingResult(url, -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun checkFDroidUpdate(mirrorUrl: String, packageName: String, versionCode: Int, cachePath: String): FDroidUpdateResult? {
|
||||||
|
return null
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package io.nekohasekai.libbox
|
||||||
|
|
||||||
|
interface NeighborUpdateListener
|
||||||
@@ -16,6 +16,7 @@ import io.nekohasekai.libbox.PlatformInterface
|
|||||||
import io.nekohasekai.libbox.StringIterator
|
import io.nekohasekai.libbox.StringIterator
|
||||||
import io.nekohasekai.libbox.TunOptions
|
import io.nekohasekai.libbox.TunOptions
|
||||||
import io.nekohasekai.libbox.WIFIState
|
import io.nekohasekai.libbox.WIFIState
|
||||||
|
import io.nekohasekai.libbox.setAndroidPackageNames
|
||||||
import io.nekohasekai.sfa.Application
|
import io.nekohasekai.sfa.Application
|
||||||
import java.net.Inet6Address
|
import java.net.Inet6Address
|
||||||
import java.net.InetSocketAddress
|
import java.net.InetSocketAddress
|
||||||
|
|||||||
@@ -15,12 +15,10 @@ class ProxyService :
|
|||||||
override fun onBind(intent: Intent) = service.onBind()
|
override fun onBind(intent: Intent) = service.onBind()
|
||||||
|
|
||||||
override fun onDestroy() = service.onDestroy()
|
override fun onDestroy() = service.onDestroy()
|
||||||
override fun closeNeighborMonitor(listener: NeighborUpdateListener?) {
|
fun closeNeighborMonitor(listener: NeighborUpdateListener?) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun sendNotification(notification: Notification) = service.sendNotification(notification)
|
override fun sendNotification(notification: Notification) = service.sendNotification(notification)
|
||||||
override fun startNeighborMonitor(listener: NeighborUpdateListener?) {
|
fun startNeighborMonitor(listener: NeighborUpdateListener?) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class VPNService :
|
|||||||
protect(fd)
|
protect(fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun closeNeighborMonitor(listener: NeighborUpdateListener?) {
|
fun closeNeighborMonitor(listener: NeighborUpdateListener?) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var systemProxyAvailable = false
|
var systemProxyAvailable = false
|
||||||
@@ -186,6 +186,6 @@ class VPNService :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun sendNotification(notification: Notification) = service.sendNotification(notification)
|
override fun sendNotification(notification: Notification) = service.sendNotification(notification)
|
||||||
override fun startNeighborMonitor(listener: NeighborUpdateListener?) {
|
fun startNeighborMonitor(listener: NeighborUpdateListener?) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package io.nekohasekai.sfa.compose.model
|
package io.nekohasekai.sfa.compose.model
|
||||||
|
|
||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
|
import io.nekohasekai.libbox.packageNames
|
||||||
import io.nekohasekai.sfa.ktx.toList
|
import io.nekohasekai.sfa.ktx.toList
|
||||||
import io.nekohasekai.libbox.Connection as LibboxConnection
|
import io.nekohasekai.libbox.Connection as LibboxConnection
|
||||||
import io.nekohasekai.libbox.ProcessInfo as LibboxProcessInfo
|
import io.nekohasekai.libbox.ProcessInfo as LibboxProcessInfo
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ import androidx.lifecycle.Lifecycle
|
|||||||
import androidx.lifecycle.compose.LifecycleEventEffect
|
import androidx.lifecycle.compose.LifecycleEventEffect
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import io.nekohasekai.libbox.Libbox
|
import io.nekohasekai.libbox.Libbox
|
||||||
|
import io.nekohasekai.libbox.getFDroidMirrors
|
||||||
import io.nekohasekai.sfa.Application
|
import io.nekohasekai.sfa.Application
|
||||||
import io.nekohasekai.sfa.BuildConfig
|
import io.nekohasekai.sfa.BuildConfig
|
||||||
import io.nekohasekai.sfa.R
|
import io.nekohasekai.sfa.R
|
||||||
@@ -838,7 +839,7 @@ fun AppSettingsScreen(navController: NavController) {
|
|||||||
supportingContent = {
|
supportingContent = {
|
||||||
val mirrorUrl = Settings.fdroidMirrorUrl
|
val mirrorUrl = Settings.fdroidMirrorUrl
|
||||||
val mirrorName = remember(mirrorUrl) {
|
val mirrorName = remember(mirrorUrl) {
|
||||||
val iter = Libbox.getFDroidMirrors()
|
val iter = getFDroidMirrors()
|
||||||
var name: String? = null
|
var name: String? = null
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
val m = iter.next()
|
val m = iter.next()
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ import androidx.compose.ui.text.style.TextOverflow
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import io.nekohasekai.libbox.Libbox
|
import io.nekohasekai.libbox.Libbox
|
||||||
|
import io.nekohasekai.libbox.getFDroidMirrors
|
||||||
|
import io.nekohasekai.libbox.pingFDroidMirror
|
||||||
import io.nekohasekai.sfa.R
|
import io.nekohasekai.sfa.R
|
||||||
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
||||||
import io.nekohasekai.sfa.database.Settings
|
import io.nekohasekai.sfa.database.Settings
|
||||||
@@ -99,7 +101,7 @@ fun FDroidMirrorScreen(navController: NavController) {
|
|||||||
|
|
||||||
val builtinMirrors = remember {
|
val builtinMirrors = remember {
|
||||||
val mirrors = mutableListOf<MirrorEntry>()
|
val mirrors = mutableListOf<MirrorEntry>()
|
||||||
val iter = Libbox.getFDroidMirrors()
|
val iter = getFDroidMirrors()
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
val m = iter.next()
|
val m = iter.next()
|
||||||
mirrors.add(MirrorEntry(url = m.url, name = m.name, country = m.country))
|
mirrors.add(MirrorEntry(url = m.url, name = m.name, country = m.country))
|
||||||
@@ -132,7 +134,7 @@ fun FDroidMirrorScreen(navController: NavController) {
|
|||||||
scope.launch {
|
scope.launch {
|
||||||
allMirrors.map { mirror ->
|
allMirrors.map { mirror ->
|
||||||
async(Dispatchers.IO) {
|
async(Dispatchers.IO) {
|
||||||
val r = Libbox.pingFDroidMirror(mirror.url)
|
val r = pingFDroidMirror(mirror.url)
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
if (r.latencyMs < 0) {
|
if (r.latencyMs < 0) {
|
||||||
latencyErrors[r.url] = true
|
latencyErrors[r.url] = true
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package io.nekohasekai.sfa.update
|
package io.nekohasekai.sfa.update
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import io.nekohasekai.libbox.Libbox
|
import io.nekohasekai.libbox.checkFDroidUpdate as libboxCheckFDroidUpdate
|
||||||
import io.nekohasekai.sfa.database.Settings
|
import io.nekohasekai.sfa.database.Settings
|
||||||
|
|
||||||
fun checkFDroidUpdate(context: Context): UpdateInfo? {
|
fun checkFDroidUpdate(context: Context): UpdateInfo? {
|
||||||
@@ -9,7 +9,7 @@ fun checkFDroidUpdate(context: Context): UpdateInfo? {
|
|||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
val versionCode = context.packageManager.getPackageInfo(packageName, 0).versionCode
|
val versionCode = context.packageManager.getPackageInfo(packageName, 0).versionCode
|
||||||
val result = Libbox.checkFDroidUpdate(
|
val result = libboxCheckFDroidUpdate(
|
||||||
Settings.fdroidMirrorUrl,
|
Settings.fdroidMirrorUrl,
|
||||||
packageName,
|
packageName,
|
||||||
versionCode,
|
versionCode,
|
||||||
|
|||||||
Reference in New Issue
Block a user