Support showing repeater frequency in Android Q
This commit is contained in:
@@ -21,6 +21,7 @@ import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper.netId
|
||||
import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper.requestPersistentGroupInfo
|
||||
import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper.setWifiP2pChannels
|
||||
import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper.startWps
|
||||
import be.mygod.vpnhotspot.net.wifi.configuration.channelToFrequency
|
||||
import be.mygod.vpnhotspot.util.*
|
||||
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
||||
import timber.log.Timber
|
||||
@@ -279,8 +280,9 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere
|
||||
} else p2pManager.createGroup(channel, WifiP2pConfig.Builder().apply {
|
||||
setNetworkName(PLACEHOLDER_NETWORK_NAME)
|
||||
setPassphrase(passphrase)
|
||||
val frequency = operatingChannel
|
||||
if (frequency == 0) setGroupOperatingBand(operatingBand) else setGroupOperatingFrequency(frequency)
|
||||
val channel = operatingChannel
|
||||
if (channel == 0) setGroupOperatingBand(operatingBand)
|
||||
else setGroupOperatingFrequency(channelToFrequency(channel))
|
||||
}.build().run {
|
||||
useParcel { p ->
|
||||
p.writeParcelable(this, 0)
|
||||
|
||||
@@ -55,6 +55,12 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
||||
else -> false
|
||||
}
|
||||
|
||||
val title: CharSequence @Bindable get() {
|
||||
if (BuildCompat.isAtLeastQ()) binder?.group?.frequency?.let {
|
||||
return parent.getString(R.string.repeater_channel, it, frequencyToChannel(it))
|
||||
}
|
||||
return parent.getString(R.string.title_repeater)
|
||||
}
|
||||
val addresses: CharSequence @Bindable get() {
|
||||
return try {
|
||||
NetworkInterface.getByName(p2pInterface ?: return "")?.formatAddresses() ?: ""
|
||||
@@ -70,6 +76,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
||||
}
|
||||
fun onGroupChanged(group: WifiP2pGroup? = null) {
|
||||
p2pInterface = group?.`interface`
|
||||
if (BuildCompat.isAtLeastQ()) notifyPropertyChanged(BR.title)
|
||||
notifyPropertyChanged(BR.addresses)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.core.os.BuildCompat
|
||||
import androidx.core.view.isGone
|
||||
import be.mygod.vpnhotspot.AlertDialogFragment
|
||||
import be.mygod.vpnhotspot.App.Companion.app
|
||||
@@ -112,7 +113,13 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
|
||||
if (!arg.readOnly) dialogView.password.addTextChangedListener(this@WifiApDialogFragment)
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
bandOptions = mutableListOf<BandOption>().apply {
|
||||
if (arg.p2pMode) add(BandOption.BandAny) else {
|
||||
if (arg.p2pMode) {
|
||||
add(BandOption.BandAny)
|
||||
if (BuildCompat.isAtLeastQ()) {
|
||||
add(BandOption.Band2GHz)
|
||||
add(BandOption.Band5GHz)
|
||||
}
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT >= 28) add(BandOption.BandAny)
|
||||
add(BandOption.Band2GHz)
|
||||
add(BandOption.Band5GHz)
|
||||
|
||||
@@ -64,6 +64,11 @@ fun channelToFrequency(channel: Int) = when (channel) {
|
||||
in 15..165 -> 5000 + 5 * channel
|
||||
else -> throw IllegalArgumentException("Invalid channel $channel")
|
||||
}
|
||||
fun frequencyToChannel(frequency: Int) = when (frequency % 5) {
|
||||
2 -> ((frequency - 2407) / 5).also { check(it in 1..14) { "Invalid 2.4 GHz frequency $frequency" } }
|
||||
0 -> ((frequency - 5000) / 5).also { check(it in 15..165) { "Invalid 5 GHz frequency $frequency" } }
|
||||
else -> throw IllegalArgumentException("Invalid frequency $frequency")
|
||||
}
|
||||
|
||||
val WifiConfiguration.apKeyManagement get() = allowedKeyManagement.nextSetBit(0).also { selected ->
|
||||
check(selected >= 0) { "No key management selected" }
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/title_repeater"
|
||||
android:text="@{data.title}"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"/>
|
||||
|
||||
<be.mygod.vpnhotspot.widget.AutoCollapseTextView
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<string name="title_clients">已连设备</string>
|
||||
<string name="title_settings">设置选项</string>
|
||||
|
||||
<string name="repeater_channel">无线中继 (%1$d MHz, 频道 %2$d)</string>
|
||||
<string name="repeater_wps">WPS(不安全)</string>
|
||||
<string name="repeater_wps_dialog_title">输入 PIN</string>
|
||||
<string name="repeater_wps_dialog_pbc">一键加密</string>
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
<string name="title_clients">Clients</string>
|
||||
<string name="title_settings">Settings</string>
|
||||
|
||||
<string name="repeater_channel">Repeater (%1$d MHz, channel %2$d)</string>
|
||||
<string name="repeater_wps">WPS (insecure)</string>
|
||||
<string name="repeater_wps_dialog_title">Enter PIN</string>
|
||||
<string name="repeater_wps_dialog_pbc">Push Button</string>
|
||||
|
||||
Reference in New Issue
Block a user