mirror of
https://github.com/MatsuriDayo/NekoBoxForAndroid.git
synced 2025-12-19 22:50:05 +08:00
Fix bugs
This commit is contained in:
parent
022cd798a9
commit
3aa428b06f
@ -6,7 +6,6 @@ import io.nekohasekai.sagernet.aidl.TrafficData;
|
|||||||
oneway interface ISagerNetServiceCallback {
|
oneway interface ISagerNetServiceCallback {
|
||||||
void stateChanged(int state, String profileName, String msg);
|
void stateChanged(int state, String profileName, String msg);
|
||||||
void missingPlugin(String profileName, String pluginName);
|
void missingPlugin(String profileName, String pluginName);
|
||||||
void routeAlert(int type, String routeName);
|
|
||||||
void cbSpeedUpdate(in SpeedDisplayData stats);
|
void cbSpeedUpdate(in SpeedDisplayData stats);
|
||||||
void cbTrafficUpdate(in TrafficData stats);
|
void cbTrafficUpdate(in TrafficData stats);
|
||||||
void cbSelectorUpdate(long id);
|
void cbSelectorUpdate(long id);
|
||||||
|
|||||||
@ -345,12 +345,6 @@ class BaseService {
|
|||||||
startProcesses()
|
startProcesses()
|
||||||
data.changeState(State.Connected)
|
data.changeState(State.Connected)
|
||||||
|
|
||||||
for ((type, routeName) in proxy.config.alerts) {
|
|
||||||
data.binder.broadcast {
|
|
||||||
it.routeAlert(type, routeName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lateInit()
|
lateInit()
|
||||||
} catch (_: CancellationException) { // if the job was cancelled, it is canceller's responsibility to call stopRunner
|
} catch (_: CancellationException) { // if the job was cancelled, it is canceller's responsibility to call stopRunner
|
||||||
} catch (_: UnknownHostException) {
|
} catch (_: UnknownHostException) {
|
||||||
|
|||||||
@ -44,7 +44,6 @@ class SagerConnection(
|
|||||||
fun stateChanged(state: BaseService.State, profileName: String?, msg: String?)
|
fun stateChanged(state: BaseService.State, profileName: String?, msg: String?)
|
||||||
|
|
||||||
fun missingPlugin(profileName: String, pluginName: String) {}
|
fun missingPlugin(profileName: String, pluginName: String) {}
|
||||||
fun routeAlert(type: Int, routeName: String) {}
|
|
||||||
|
|
||||||
fun onServiceConnected(service: ISagerNetService)
|
fun onServiceConnected(service: ISagerNetService)
|
||||||
|
|
||||||
@ -98,13 +97,6 @@ class SagerConnection(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun routeAlert(type: Int, routeName: String) {
|
|
||||||
val callback = callback ?: return
|
|
||||||
runOnMainDispatcher {
|
|
||||||
callback.routeAlert(type, routeName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var binder: IBinder? = null
|
private var binder: IBinder? = null
|
||||||
|
|||||||
@ -54,7 +54,7 @@ data class RuleEntity(
|
|||||||
-1L -> app.getString(R.string.route_bypass)
|
-1L -> app.getString(R.string.route_bypass)
|
||||||
-2L -> app.getString(R.string.route_block)
|
-2L -> app.getString(R.string.route_block)
|
||||||
else -> ProfileManager.getProfile(outbound)?.displayName()
|
else -> ProfileManager.getProfile(outbound)?.displayName()
|
||||||
?: app.getString(R.string.route_proxy)
|
?: app.getString(R.string.error_title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
package io.nekohasekai.sagernet.fmt
|
package io.nekohasekai.sagernet.fmt
|
||||||
|
|
||||||
|
import android.widget.Toast
|
||||||
import io.nekohasekai.sagernet.IPv6Mode
|
import io.nekohasekai.sagernet.IPv6Mode
|
||||||
import io.nekohasekai.sagernet.Key
|
import io.nekohasekai.sagernet.Key
|
||||||
|
import io.nekohasekai.sagernet.R
|
||||||
|
import io.nekohasekai.sagernet.SagerNet
|
||||||
import io.nekohasekai.sagernet.bg.VpnService
|
import io.nekohasekai.sagernet.bg.VpnService
|
||||||
import io.nekohasekai.sagernet.database.DataStore
|
import io.nekohasekai.sagernet.database.DataStore
|
||||||
import io.nekohasekai.sagernet.database.ProxyEntity
|
import io.nekohasekai.sagernet.database.ProxyEntity
|
||||||
@ -59,7 +62,6 @@ class ConfigBuildResult(
|
|||||||
var mainEntId: Long,
|
var mainEntId: Long,
|
||||||
var trafficMap: Map<String, List<ProxyEntity>>,
|
var trafficMap: Map<String, List<ProxyEntity>>,
|
||||||
var profileTagMap: Map<Long, String>,
|
var profileTagMap: Map<Long, String>,
|
||||||
val alerts: List<Pair<Int, String>>,
|
|
||||||
val selectorGroupId: Long,
|
val selectorGroupId: Long,
|
||||||
) {
|
) {
|
||||||
data class IndexEntity(var chain: LinkedHashMap<Int, ProxyEntity>)
|
data class IndexEntity(var chain: LinkedHashMap<Int, ProxyEntity>)
|
||||||
@ -78,7 +80,6 @@ fun buildConfig(
|
|||||||
proxy.id, //
|
proxy.id, //
|
||||||
mapOf(TAG_PROXY to listOf(proxy)), //
|
mapOf(TAG_PROXY to listOf(proxy)), //
|
||||||
mapOf(proxy.id to TAG_PROXY), //
|
mapOf(proxy.id to TAG_PROXY), //
|
||||||
listOf(),
|
|
||||||
-1L
|
-1L
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -153,7 +154,6 @@ fun buildConfig(
|
|||||||
val externalIndexMap = ArrayList<IndexEntity>()
|
val externalIndexMap = ArrayList<IndexEntity>()
|
||||||
val requireTransproxy = if (forTest) false else DataStore.requireTransproxy
|
val requireTransproxy = if (forTest) false else DataStore.requireTransproxy
|
||||||
val ipv6Mode = if (forTest) IPv6Mode.ENABLE else DataStore.ipv6Mode
|
val ipv6Mode = if (forTest) IPv6Mode.ENABLE else DataStore.ipv6Mode
|
||||||
val alerts = mutableListOf<Pair<Int, String>>()
|
|
||||||
|
|
||||||
fun genDomainStrategy(noAsIs: Boolean): String {
|
fun genDomainStrategy(noAsIs: Boolean): String {
|
||||||
return when {
|
return when {
|
||||||
@ -524,7 +524,11 @@ fun buildConfig(
|
|||||||
}
|
}
|
||||||
val uidList = rule.packages.map {
|
val uidList = rule.packages.map {
|
||||||
if (!isVPN) {
|
if (!isVPN) {
|
||||||
alerts.add(0 to rule.displayName())
|
Toast.makeText(
|
||||||
|
SagerNet.application,
|
||||||
|
SagerNet.application.getString(R.string.route_need_vpn, rule.displayName()),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
}
|
}
|
||||||
PackageCache[it]?.takeIf { uid -> uid >= 1000 }
|
PackageCache[it]?.takeIf { uid -> uid >= 1000 }
|
||||||
}.toHashSet().filterNotNull()
|
}.toHashSet().filterNotNull()
|
||||||
@ -605,13 +609,20 @@ fun buildConfig(
|
|||||||
0L -> TAG_PROXY
|
0L -> TAG_PROXY
|
||||||
-1L -> TAG_BYPASS
|
-1L -> TAG_BYPASS
|
||||||
-2L -> TAG_BLOCK
|
-2L -> TAG_BLOCK
|
||||||
else -> if (outId == proxy.id) TAG_PROXY else tagMap[outId]
|
else -> if (outId == proxy.id) TAG_PROXY else tagMap[outId] ?: ""
|
||||||
?: throw Exception("invalid rule")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ruleObj.checkEmpty()) {
|
if (!ruleObj.checkEmpty()) {
|
||||||
route.rules.add(ruleObj)
|
if (ruleObj.outbound.isNullOrBlank()) {
|
||||||
|
Toast.makeText(
|
||||||
|
SagerNet.application,
|
||||||
|
"Warning: " + rule.displayName() + ": A non-existent outbound was specified.",
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
} else {
|
||||||
|
route.rules.add(ruleObj)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -780,7 +791,6 @@ fun buildConfig(
|
|||||||
proxy.id,
|
proxy.id,
|
||||||
trafficMap,
|
trafficMap,
|
||||||
tagMap,
|
tagMap,
|
||||||
alerts,
|
|
||||||
if (buildSelector) group!!.id else -1L
|
if (buildSelector) group!!.id else -1L
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -248,7 +248,12 @@ class GroupSettingsActivity(
|
|||||||
finish()
|
finish()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
entity.subscription?.subscriptionUserinfo = "";
|
val keepUserInfo = (entity.type == GroupType.SUBSCRIPTION &&
|
||||||
|
DataStore.groupType == GroupType.SUBSCRIPTION &&
|
||||||
|
entity.subscription?.link == DataStore.subscriptionLink)
|
||||||
|
if (!keepUserInfo) {
|
||||||
|
entity.subscription?.subscriptionUserinfo = "";
|
||||||
|
}
|
||||||
GroupManager.updateGroup(entity.apply { serialize() })
|
GroupManager.updateGroup(entity.apply { serialize() })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -363,18 +363,6 @@ class MainActivity : ThemedActivity(),
|
|||||||
changeState(state, msg, true)
|
changeState(state, msg, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun routeAlert(type: Int, routeName: String) {
|
|
||||||
when (type) {
|
|
||||||
0 -> {
|
|
||||||
// need vpn
|
|
||||||
|
|
||||||
Toast.makeText(
|
|
||||||
this, getString(R.string.route_need_vpn, routeName), Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val connection = SagerConnection(SagerConnection.CONNECTION_ID_MAIN_ACTIVITY_FOREGROUND, true)
|
val connection = SagerConnection(SagerConnection.CONNECTION_ID_MAIN_ACTIVITY_FOREGROUND, true)
|
||||||
override fun onServiceConnected(service: ISagerNetService) = changeState(
|
override fun onServiceConnected(service: ISagerNetService) = changeState(
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user