This commit is contained in:
arm64v8a 2023-06-29 21:24:30 +09:00
parent 022cd798a9
commit 3aa428b06f
7 changed files with 25 additions and 37 deletions

View File

@ -6,7 +6,6 @@ import io.nekohasekai.sagernet.aidl.TrafficData;
oneway interface ISagerNetServiceCallback {
void stateChanged(int state, String profileName, String msg);
void missingPlugin(String profileName, String pluginName);
void routeAlert(int type, String routeName);
void cbSpeedUpdate(in SpeedDisplayData stats);
void cbTrafficUpdate(in TrafficData stats);
void cbSelectorUpdate(long id);

View File

@ -345,12 +345,6 @@ class BaseService {
startProcesses()
data.changeState(State.Connected)
for ((type, routeName) in proxy.config.alerts) {
data.binder.broadcast {
it.routeAlert(type, routeName)
}
}
lateInit()
} catch (_: CancellationException) { // if the job was cancelled, it is canceller's responsibility to call stopRunner
} catch (_: UnknownHostException) {

View File

@ -44,7 +44,6 @@ class SagerConnection(
fun stateChanged(state: BaseService.State, profileName: String?, msg: String?)
fun missingPlugin(profileName: String, pluginName: String) {}
fun routeAlert(type: Int, routeName: String) {}
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

View File

@ -54,7 +54,7 @@ data class RuleEntity(
-1L -> app.getString(R.string.route_bypass)
-2L -> app.getString(R.string.route_block)
else -> ProfileManager.getProfile(outbound)?.displayName()
?: app.getString(R.string.route_proxy)
?: app.getString(R.string.error_title)
}
}

View File

@ -1,7 +1,10 @@
package io.nekohasekai.sagernet.fmt
import android.widget.Toast
import io.nekohasekai.sagernet.IPv6Mode
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.database.DataStore
import io.nekohasekai.sagernet.database.ProxyEntity
@ -59,7 +62,6 @@ class ConfigBuildResult(
var mainEntId: Long,
var trafficMap: Map<String, List<ProxyEntity>>,
var profileTagMap: Map<Long, String>,
val alerts: List<Pair<Int, String>>,
val selectorGroupId: Long,
) {
data class IndexEntity(var chain: LinkedHashMap<Int, ProxyEntity>)
@ -78,7 +80,6 @@ fun buildConfig(
proxy.id, //
mapOf(TAG_PROXY to listOf(proxy)), //
mapOf(proxy.id to TAG_PROXY), //
listOf(),
-1L
)
}
@ -153,7 +154,6 @@ fun buildConfig(
val externalIndexMap = ArrayList<IndexEntity>()
val requireTransproxy = if (forTest) false else DataStore.requireTransproxy
val ipv6Mode = if (forTest) IPv6Mode.ENABLE else DataStore.ipv6Mode
val alerts = mutableListOf<Pair<Int, String>>()
fun genDomainStrategy(noAsIs: Boolean): String {
return when {
@ -524,7 +524,11 @@ fun buildConfig(
}
val uidList = rule.packages.map {
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 }
}.toHashSet().filterNotNull()
@ -605,15 +609,22 @@ fun buildConfig(
0L -> TAG_PROXY
-1L -> TAG_BYPASS
-2L -> TAG_BLOCK
else -> if (outId == proxy.id) TAG_PROXY else tagMap[outId]
?: throw Exception("invalid rule")
else -> if (outId == proxy.id) TAG_PROXY else tagMap[outId] ?: ""
}
}
if (!ruleObj.checkEmpty()) {
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)
}
}
}
for (freedom in arrayOf(TAG_DIRECT, TAG_BYPASS)) outbounds.add(Outbound().apply {
tag = freedom
@ -780,7 +791,6 @@ fun buildConfig(
proxy.id,
trafficMap,
tagMap,
alerts,
if (buildSelector) group!!.id else -1L
)
}

View File

@ -248,7 +248,12 @@ class GroupSettingsActivity(
finish()
return
}
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() })
}

View File

@ -363,18 +363,6 @@ class MainActivity : ThemedActivity(),
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)
override fun onServiceConnected(service: ISagerNetService) = changeState(
try {