Fix deprecations

This commit is contained in:
Mygod
2020-08-18 05:02:09 +08:00
parent 8a1df227c1
commit 35055bc074
10 changed files with 33 additions and 34 deletions

View File

@@ -81,7 +81,7 @@ object AppProcess {
val script = StringBuilder() val script = StringBuilder()
val (baseDir, relocated) = if (Build.VERSION.SDK_INT < 29) "/dev" to "/dev/app_process_$token" else { val (baseDir, relocated) = if (Build.VERSION.SDK_INT < 29) "/dev" to "/dev/app_process_$token" else {
val apexPath = "/apex/$token" val apexPath = "/apex/$token"
script.appendln("[ -d $apexPath ] || " + script.appendLine("[ -d $apexPath ] || " +
"mkdir $apexPath && " + "mkdir $apexPath && " +
// we need to mount a new tmpfs to override noexec flag // we need to mount a new tmpfs to override noexec flag
"mount -t tmpfs -o size=1M tmpfs $apexPath || exit 1") "mount -t tmpfs -o size=1M tmpfs $apexPath || exit 1")
@@ -95,13 +95,13 @@ object AppProcess {
Logger.me.w("Failed to locate system section", e) Logger.me.w("Failed to locate system section", e)
"system" "system"
} }
script.appendln("[ -f $ldConfig ] || " + script.appendLine("[ -f $ldConfig ] || " +
"mkdir -p $apexPath/etc && " + "mkdir -p $apexPath/etc && " +
"echo dir.$section = $apexPath >$ldConfig && " + "echo dir.$section = $apexPath >$ldConfig && " +
"cat $masterLdConfig >>$ldConfig || exit 1") "cat $masterLdConfig >>$ldConfig || exit 1")
"$apexPath/bin" to "$apexPath/bin/app_process" "$apexPath/bin" to "$apexPath/bin/app_process"
} }
script.appendln("[ -f $relocated ] || " + script.appendLine("[ -f $relocated ] || " +
"mkdir -p $baseDir && " + "mkdir -p $baseDir && " +
"cp $myExe $relocated && " + "cp $myExe $relocated && " +
"chmod 700 $relocated || exit 1") "chmod 700 $relocated || exit 1")

View File

@@ -152,7 +152,7 @@ class RootServer {
UUID.randomUUID().toString().also { persistence.writeText(it) } UUID.randomUUID().toString().also { persistence.writeText(it) }
} }
val (script, relocated) = AppProcess.relocateScript(uuid) val (script, relocated) = AppProcess.relocateScript(uuid)
script.appendln(AppProcess.launchString(context.packageCodePath, RootServer::class.java.name, relocated, script.appendLine(AppProcess.launchString(context.packageCodePath, RootServer::class.java.name, relocated,
niceName) + " $token2") niceName) + " $token2")
writer.writeBytes(script.toString()) writer.writeBytes(script.toString())
writer.flush() writer.flush()
@@ -409,7 +409,7 @@ class RootServer {
Os.dup2(FileDescriptor.err, OsConstants.STDOUT_FILENO) Os.dup2(FileDescriptor.err, OsConstants.STDOUT_FILENO)
System.setOut(System.err) System.setOut(System.err)
val writer = writer() val writer = writer()
writer.appendln(args[0]) // echo ready signal writer.appendLine(args[0]) // echo ready signal
writer.flush() writer.flush()
}) })
// thread safety: usage of input should be in main thread // thread safety: usage of input should be in main thread

View File

@@ -6,7 +6,6 @@ import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.observe
import be.mygod.vpnhotspot.client.ClientViewModel import be.mygod.vpnhotspot.client.ClientViewModel
import be.mygod.vpnhotspot.client.ClientsFragment import be.mygod.vpnhotspot.client.ClientsFragment
import be.mygod.vpnhotspot.databinding.ActivityMainBinding import be.mygod.vpnhotspot.databinding.ActivityMainBinding

View File

@@ -143,7 +143,7 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
// WifiP2pServiceImpl only removes self address // WifiP2pServiceImpl only removes self address
Build.VERSION.SDK_INT >= 29 && address == MacAddressCompat.ANY_ADDRESS || address == ownerAddress Build.VERSION.SDK_INT >= 29 && address == MacAddressCompat.ANY_ADDRESS || address == ownerAddress
} }
val main = ownedGroups.minBy { it.networkId } val main = ownedGroups.minByOrNull { it.networkId }
// do not replace current group if it's better // do not replace current group if it's better
if (binder.group?.passphrase == null) binder.group = main if (binder.group?.passphrase == null) binder.group = main
return if (main != null) ownedGroups.filter { it.networkId != main.networkId } else emptyList() return if (main != null) ownedGroups.filter { it.networkId != main.networkId } else emptyList()

View File

@@ -52,10 +52,10 @@ open class Client(val mac: MacAddressCompat, val iface: String) {
val titleSelectable = record.map { it.nickname.isEmpty() } val titleSelectable = record.map { it.nickname.isEmpty() }
val description = record.map { record -> val description = record.map { record ->
SpannableStringBuilder().apply { SpannableStringBuilder().apply {
if (record.nickname.isNotEmpty()) appendln(macIface) if (record.nickname.isNotEmpty()) appendLine(macIface)
ip.entries.forEach { (ip, state) -> ip.entries.forEach { (ip, state) ->
append(makeIpSpan(ip)) append(makeIpSpan(ip))
appendln(app.getText(when (state) { appendLine(app.getText(when (state) {
IpNeighbour.State.INCOMPLETE -> R.string.connected_state_incomplete IpNeighbour.State.INCOMPLETE -> R.string.connected_state_incomplete
IpNeighbour.State.VALID -> R.string.connected_state_valid IpNeighbour.State.VALID -> R.string.connected_state_valid
IpNeighbour.State.FAILED -> R.string.connected_state_failed IpNeighbour.State.FAILED -> R.string.connected_state_failed

View File

@@ -20,7 +20,6 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.lifecycle.findViewTreeLifecycleOwner import androidx.lifecycle.findViewTreeLifecycleOwner
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.observe
import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.ListAdapter

View File

@@ -52,24 +52,24 @@ class Routing(private val caller: Any, private val downstream: String) : IpNeigh
const val IP6TABLES = "ip6tables -w" const val IP6TABLES = "ip6tables -w"
fun appendCleanCommands(commands: BufferedWriter) { fun appendCleanCommands(commands: BufferedWriter) {
commands.appendln("$IPTABLES -t nat -F PREROUTING") commands.appendLine("$IPTABLES -t nat -F PREROUTING")
commands.appendln("while $IPTABLES -D FORWARD -j vpnhotspot_fwd; do done") commands.appendLine("while $IPTABLES -D FORWARD -j vpnhotspot_fwd; do done")
commands.appendln("$IPTABLES -F vpnhotspot_fwd") commands.appendLine("$IPTABLES -F vpnhotspot_fwd")
commands.appendln("$IPTABLES -X vpnhotspot_fwd") commands.appendLine("$IPTABLES -X vpnhotspot_fwd")
commands.appendln("$IPTABLES -F vpnhotspot_acl") commands.appendLine("$IPTABLES -F vpnhotspot_acl")
commands.appendln("$IPTABLES -X vpnhotspot_acl") commands.appendLine("$IPTABLES -X vpnhotspot_acl")
commands.appendln("while $IPTABLES -t nat -D POSTROUTING -j vpnhotspot_masquerade; do done") commands.appendLine("while $IPTABLES -t nat -D POSTROUTING -j vpnhotspot_masquerade; do done")
commands.appendln("$IPTABLES -t nat -F vpnhotspot_masquerade") commands.appendLine("$IPTABLES -t nat -F vpnhotspot_masquerade")
commands.appendln("$IPTABLES -t nat -X vpnhotspot_masquerade") commands.appendLine("$IPTABLES -t nat -X vpnhotspot_masquerade")
commands.appendln("while $IP6TABLES -D INPUT -j vpnhotspot_filter; do done") commands.appendLine("while $IP6TABLES -D INPUT -j vpnhotspot_filter; do done")
commands.appendln("while $IP6TABLES -D FORWARD -j vpnhotspot_filter; do done") commands.appendLine("while $IP6TABLES -D FORWARD -j vpnhotspot_filter; do done")
commands.appendln("while $IP6TABLES -D OUTPUT -j vpnhotspot_filter; do done") commands.appendLine("while $IP6TABLES -D OUTPUT -j vpnhotspot_filter; do done")
commands.appendln("$IP6TABLES -F vpnhotspot_filter") commands.appendLine("$IP6TABLES -F vpnhotspot_filter")
commands.appendln("$IP6TABLES -X vpnhotspot_filter") commands.appendLine("$IP6TABLES -X vpnhotspot_filter")
commands.appendln("while $IP rule del priority $RULE_PRIORITY_DNS; do done") commands.appendLine("while $IP rule del priority $RULE_PRIORITY_DNS; do done")
commands.appendln("while $IP rule del priority $RULE_PRIORITY_UPSTREAM; do done") commands.appendLine("while $IP rule del priority $RULE_PRIORITY_UPSTREAM; do done")
commands.appendln("while $IP rule del priority $RULE_PRIORITY_UPSTREAM_FALLBACK; do done") commands.appendLine("while $IP rule del priority $RULE_PRIORITY_UPSTREAM_FALLBACK; do done")
commands.appendln("while $IP rule del priority $RULE_PRIORITY_UPSTREAM_DISABLE_SYSTEM; do done") commands.appendLine("while $IP rule del priority $RULE_PRIORITY_UPSTREAM_DISABLE_SYSTEM; do done")
} }
suspend fun clean() { suspend fun clean() {

View File

@@ -219,7 +219,8 @@ data class SoftApConfigurationCompat(
SoftApConfiguration.SECURITY_TYPE_WPA2_PSK SoftApConfiguration.SECURITY_TYPE_WPA2_PSK
} }
android.net.wifi.WifiConfiguration.KeyMgmt.SAE -> SoftApConfiguration.SECURITY_TYPE_WPA3_SAE android.net.wifi.WifiConfiguration.KeyMgmt.SAE -> SoftApConfiguration.SECURITY_TYPE_WPA3_SAE
else -> android.net.wifi.WifiConfiguration.KeyMgmt.strings.getOrElse(selected) { "?" }.let { else -> android.net.wifi.WifiConfiguration.KeyMgmt.strings
.getOrElse<String>(selected) { "?" }.let {
throw IllegalArgumentException("Unrecognized key management $it ($selected)") throw IllegalArgumentException("Unrecognized key management $it ($selected)")
} }
} }

View File

@@ -36,12 +36,12 @@ data class Dump(val path: String, val cacheDir: File = app.deviceStorage.codeCac
process.outputStream.bufferedWriter().use { commands -> process.outputStream.bufferedWriter().use { commands ->
// https://android.googlesource.com/platform/external/iptables/+/android-7.0.0_r1/iptables/Android.mk#34 // https://android.googlesource.com/platform/external/iptables/+/android-7.0.0_r1/iptables/Android.mk#34
val iptablesSave = if (Build.VERSION.SDK_INT < 24) File(cacheDir, "iptables-save").absolutePath.also { val iptablesSave = if (Build.VERSION.SDK_INT < 24) File(cacheDir, "iptables-save").absolutePath.also {
commands.appendln("ln -sf /system/bin/iptables $it") commands.appendLine("ln -sf /system/bin/iptables $it")
} else "iptables-save" } else "iptables-save"
val ip6tablesSave = if (Build.VERSION.SDK_INT < 24) File(cacheDir, "ip6tables-save").absolutePath.also { val ip6tablesSave = if (Build.VERSION.SDK_INT < 24) File(cacheDir, "ip6tables-save").absolutePath.also {
commands.appendln("ln -sf /system/bin/ip6tables $it") commands.appendLine("ln -sf /system/bin/ip6tables $it")
} else "ip6tables-save" } else "ip6tables-save"
commands.appendln(""" commands.appendLine("""
|echo dumpsys ${Context.WIFI_P2P_SERVICE} |echo dumpsys ${Context.WIFI_P2P_SERVICE}
|dumpsys ${Context.WIFI_P2P_SERVICE} |dumpsys ${Context.WIFI_P2P_SERVICE}
|echo |echo

View File

@@ -92,11 +92,11 @@ fun makeMacSpan(mac: String) = if (app.hasTouch) SpannableString(mac).apply {
fun NetworkInterface.formatAddresses(macOnly: Boolean = false) = SpannableStringBuilder().apply { fun NetworkInterface.formatAddresses(macOnly: Boolean = false) = SpannableStringBuilder().apply {
try { try {
hardwareAddress?.let { appendln(makeMacSpan(MacAddressCompat.bytesToString(it))) } hardwareAddress?.let { appendLine(makeMacSpan(MacAddressCompat.bytesToString(it))) }
} catch (_: SocketException) { } } catch (_: SocketException) { }
if (!macOnly) for (address in interfaceAddresses) { if (!macOnly) for (address in interfaceAddresses) {
append(makeIpSpan(address.address)) append(makeIpSpan(address.address))
appendln("/${address.networkPrefixLength}") appendLine("/${address.networkPrefixLength}")
} }
}.trimEnd() }.trimEnd()