Allow user to turn off safe mode on Android 10 (Mar 2020 or newer)
Fixes #153. Basically, this "forward"-ports a workaround for Android 9- thanks to Jimmy Chen. As a consequence, #31 might reoccur if you turn off safe mode.
This commit is contained in:
@@ -11,7 +11,6 @@ import java.lang.reflect.Proxy
|
||||
|
||||
object WifiP2pManagerHelper {
|
||||
const val UNSUPPORTED = -2
|
||||
@Deprecated("No longer used since API 29")
|
||||
const val WIFI_P2P_PERSISTENT_GROUPS_CHANGED_ACTION = "android.net.wifi.p2p.PERSISTENT_GROUPS_CHANGED"
|
||||
|
||||
/**
|
||||
@@ -24,7 +23,6 @@ object WifiP2pManagerHelper {
|
||||
WifiP2pManager::class.java.getDeclaredMethod("setWifiP2pChannels", WifiP2pManager.Channel::class.java,
|
||||
Int::class.java, Int::class.java, WifiP2pManager.ActionListener::class.java)
|
||||
}
|
||||
@Deprecated("No longer used since API 29")
|
||||
fun WifiP2pManager.setWifiP2pChannels(c: WifiP2pManager.Channel, lc: Int, oc: Int,
|
||||
listener: WifiP2pManager.ActionListener) {
|
||||
try {
|
||||
@@ -63,7 +61,6 @@ object WifiP2pManagerHelper {
|
||||
WifiP2pManager::class.java.getDeclaredMethod("deletePersistentGroup",
|
||||
WifiP2pManager.Channel::class.java, Int::class.java, WifiP2pManager.ActionListener::class.java)
|
||||
}
|
||||
@Deprecated("No longer used since API 29")
|
||||
fun WifiP2pManager.deletePersistentGroup(c: WifiP2pManager.Channel, netId: Int,
|
||||
listener: WifiP2pManager.ActionListener) {
|
||||
try {
|
||||
@@ -90,7 +87,6 @@ object WifiP2pManagerHelper {
|
||||
* @param c is the channel created at {@link #initialize}
|
||||
* @param listener for callback when persistent group info list is available. Can be null.
|
||||
*/
|
||||
@Deprecated("No longer used since API 29")
|
||||
fun WifiP2pManager.requestPersistentGroupInfo(c: WifiP2pManager.Channel,
|
||||
listener: (Collection<WifiP2pGroup>) -> Unit) {
|
||||
val proxy = Proxy.newProxyInstance(interfacePersistentGroupInfoListener.classLoader,
|
||||
@@ -115,6 +111,5 @@ object WifiP2pManagerHelper {
|
||||
private val getNetworkId by lazy @SuppressLint("DiscouragedPrivateApi") {
|
||||
WifiP2pGroup::class.java.getDeclaredMethod("getNetworkId")
|
||||
}
|
||||
@Deprecated("No longer used since API 29")
|
||||
val WifiP2pGroup.netId get() = getNetworkId.invoke(this) as Int
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import java.io.File
|
||||
* https://android.googlesource.com/platform/external/wpa_supplicant_8/+/d2986c2/wpa_supplicant/config.c#488
|
||||
* https://android.googlesource.com/platform/external/wpa_supplicant_8/+/6fa46df/wpa_supplicant/config_file.c#182
|
||||
*/
|
||||
@Deprecated("No longer used since API 29")
|
||||
class P2pSupplicantConfiguration(private val group: WifiP2pGroup, ownerAddress: String?) {
|
||||
companion object {
|
||||
private const val TAG = "P2pSupplicantConfiguration"
|
||||
@@ -29,7 +28,7 @@ class P2pSupplicantConfiguration(private val group: WifiP2pGroup, ownerAddress:
|
||||
var pskLine: Int? = null
|
||||
var psk: String? = null
|
||||
var groupOwner = false
|
||||
var bssidMatches = false
|
||||
var bssid: String? = null
|
||||
|
||||
override fun toString() = joinToString("\n")
|
||||
}
|
||||
@@ -53,9 +52,9 @@ class P2pSupplicantConfiguration(private val group: WifiP2pGroup, ownerAddress:
|
||||
RootSession.checkOutput(command, shell, false, false)
|
||||
val parser = Parser(shell.out)
|
||||
try {
|
||||
val bssids = listOfNotNull(group.owner.deviceAddress, ownerAddress)
|
||||
val bssids = listOfNotNull(group.owner.deviceAddress, ownerAddress, RepeaterService.lastMac)
|
||||
.distinct()
|
||||
.filter { it != "00:00:00:00:00:00" }
|
||||
.filter { it != "00:00:00:00:00:00" && it != "02:00:00:00:00:00" }
|
||||
while (parser.next()) {
|
||||
if (parser.trimmed.startsWith("network={")) {
|
||||
val block = NetworkBlock()
|
||||
@@ -73,21 +72,20 @@ class P2pSupplicantConfiguration(private val group: WifiP2pGroup, ownerAddress:
|
||||
block.psk = match.groupValues[5].apply { check(length in 8..63) }
|
||||
}
|
||||
block.pskLine = block.size
|
||||
} else if (bssids.any { matchedBssid.equals(it, true) }) block.bssidMatches = true
|
||||
} else if (bssids.any { matchedBssid.equals(it, true) }) block.bssid = matchedBssid
|
||||
}
|
||||
}
|
||||
block.add(parser.line)
|
||||
}
|
||||
block.add(parser.line)
|
||||
result.add(block)
|
||||
if (block.bssidMatches && block.groupOwner && target == null) { // keep first only
|
||||
if (block.bssid != null && block.groupOwner && target == null) { // keep first only
|
||||
check(block.ssidLine != null && block.pskLine != null)
|
||||
target = block
|
||||
}
|
||||
} else result.add(parser.line)
|
||||
}
|
||||
if (target == null && !RepeaterService.persistentSupported) {
|
||||
val bssid = bssids.single()
|
||||
result.add("")
|
||||
result.add(NetworkBlock().apply {
|
||||
// generate a basic network block, it is likely that vendor is going to add more stuff here
|
||||
|
||||
@@ -28,7 +28,6 @@ import be.mygod.vpnhotspot.util.toByteArray
|
||||
import be.mygod.vpnhotspot.util.toParcelable
|
||||
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
import java.nio.charset.Charset
|
||||
|
||||
/**
|
||||
* Based on: https://android.googlesource.com/platform/packages/apps/Settings/+/39b4674/src/com/android/settings/wifi/WifiApDialog.java
|
||||
@@ -117,7 +116,7 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
|
||||
bandOptions = mutableListOf<BandOption>().apply {
|
||||
if (arg.p2pMode) {
|
||||
add(BandOption.BandAny)
|
||||
if (Build.VERSION.SDK_INT >= 29) {
|
||||
if (RepeaterService.safeMode) {
|
||||
add(BandOption.Band2GHz)
|
||||
add(BandOption.Band5GHz)
|
||||
}
|
||||
@@ -160,8 +159,10 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
|
||||
*/
|
||||
private fun validate() {
|
||||
if (!started) return
|
||||
val ssidValid = dialogView.ssid.length() != 0 &&
|
||||
Charset.forName("UTF-8").encode(dialogView.ssid.text.toString()).limit() <= 32
|
||||
val ssidLength = dialogView.ssid.text.toString().toByteArray().size
|
||||
dialogView.ssidWrapper.error = if (RepeaterService.safeModeConfigurable && ssidLength < 9) {
|
||||
requireContext().getString(R.string.settings_service_repeater_safe_mode_warning)
|
||||
} else null
|
||||
val passwordValid = when (selectedSecurity) {
|
||||
WifiConfiguration.KeyMgmt.WPA_PSK, WPA2_PSK -> dialogView.password.length() >= 8
|
||||
else -> true // do not try to validate
|
||||
@@ -169,7 +170,8 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
|
||||
dialogView.passwordWrapper.error = if (passwordValid) null else {
|
||||
requireContext().getString(R.string.credentials_password_too_short)
|
||||
}
|
||||
(dialog as? AlertDialog)?.getButton(DialogInterface.BUTTON_POSITIVE)?.isEnabled = ssidValid && passwordValid
|
||||
(dialog as? AlertDialog)?.getButton(DialogInterface.BUTTON_POSITIVE)?.isEnabled =
|
||||
ssidLength in 1..32 && passwordValid
|
||||
}
|
||||
|
||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { }
|
||||
|
||||
Reference in New Issue
Block a user