Revert "Disable editing repeater credentials on Android 5"
This reverts commit df304fe674.
This kind of addresses #31. Apparently we can't predict which wpa_supplicant is bundled into the system by inspecting Android version, especially now that it is put into /vendor/bin/hw (see also Project Treble: https://source.android.com/devices/architecture/vndk/).
It might be cool if someone makes a Magisk module that replaces wpa_supplicant to the latest version.
This commit is contained in:
@@ -1,15 +1,16 @@
|
|||||||
package be.mygod.vpnhotspot.net.wifi
|
package be.mygod.vpnhotspot.net.wifi
|
||||||
|
|
||||||
import android.net.wifi.WifiConfiguration
|
import android.net.wifi.WifiConfiguration
|
||||||
|
import android.os.Build
|
||||||
import android.os.Parcel
|
import android.os.Parcel
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.annotation.RequiresApi
|
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import be.mygod.vpnhotspot.util.loggerSu
|
import be.mygod.vpnhotspot.util.loggerSu
|
||||||
import be.mygod.vpnhotspot.util.noisySu
|
import be.mygod.vpnhotspot.util.noisySu
|
||||||
import com.crashlytics.android.Crashlytics
|
import com.crashlytics.android.Crashlytics
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
class P2pSupplicantConfiguration(private val initContent: String? = null) : Parcelable {
|
class P2pSupplicantConfiguration(private val initContent: String? = null) : Parcelable {
|
||||||
companion object CREATOR : Parcelable.Creator<P2pSupplicantConfiguration> {
|
companion object CREATOR : Parcelable.Creator<P2pSupplicantConfiguration> {
|
||||||
@@ -29,6 +30,7 @@ class P2pSupplicantConfiguration(private val initContent: String? = null) : Parc
|
|||||||
*/
|
*/
|
||||||
private val pskParser = "^[\\r\\t ]*psk=(ext:|\"(.*)\"|\"(.*)|[0-9a-fA-F]{64}\$)".toRegex(RegexOption.MULTILINE)
|
private val pskParser = "^[\\r\\t ]*psk=(ext:|\"(.*)\"|\"(.*)|[0-9a-fA-F]{64}\$)".toRegex(RegexOption.MULTILINE)
|
||||||
}
|
}
|
||||||
|
private class InvalidConfigurationError : IOException()
|
||||||
|
|
||||||
override fun writeToParcel(out: Parcel, flags: Int) {
|
override fun writeToParcel(out: Parcel, flags: Int) {
|
||||||
out.writeString(if (contentDelegate.isInitialized()) content else null)
|
out.writeString(if (contentDelegate.isInitialized()) content else null)
|
||||||
@@ -58,8 +60,6 @@ class P2pSupplicantConfiguration(private val initContent: String? = null) : Parc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pkill not available on Lollipop. Source: https://android.googlesource.com/platform/system/core/+/master/shell_and_utilities/README.md
|
|
||||||
@RequiresApi(23)
|
|
||||||
fun update(config: WifiConfiguration): Boolean? {
|
fun update(config: WifiConfiguration): Boolean? {
|
||||||
val content = content ?: return null
|
val content = content ?: return null
|
||||||
val tempFile = File.createTempFile("vpnhotspot-", ".conf", app.cacheDir)
|
val tempFile = File.createTempFile("vpnhotspot-", ".conf", app.cacheDir)
|
||||||
@@ -82,9 +82,13 @@ class P2pSupplicantConfiguration(private val initContent: String? = null) : Parc
|
|||||||
}
|
}
|
||||||
if (ssidFound != 1 || pskFound != 1) {
|
if (ssidFound != 1 || pskFound != 1) {
|
||||||
Crashlytics.log(Log.WARN, TAG, "Invalid conf ($ssidFound, $pskFound): $content")
|
Crashlytics.log(Log.WARN, TAG, "Invalid conf ($ssidFound, $pskFound): $content")
|
||||||
|
Crashlytics.logException(InvalidConfigurationError())
|
||||||
}
|
}
|
||||||
if (ssidFound == 0 || pskFound == 0) return false
|
if (ssidFound == 0 || pskFound == 0) return false
|
||||||
return noisySu("cat ${tempFile.absolutePath} > /data/misc/wifi/p2p_supplicant.conf", "pkill wpa_supplicant")
|
// pkill not available on Lollipop. Source: https://android.googlesource.com/platform/system/core/+/master/shell_and_utilities/README.md
|
||||||
|
return noisySu("cat ${tempFile.absolutePath} > /data/misc/wifi/p2p_supplicant.conf",
|
||||||
|
if (Build.VERSION.SDK_INT >= 23) "pkill wpa_supplicant"
|
||||||
|
else "set `ps | grep wpa_supplicant`; kill \$2")
|
||||||
} finally {
|
} finally {
|
||||||
if (!tempFile.delete()) tempFile.deleteOnExit()
|
if (!tempFile.delete()) tempFile.deleteOnExit()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
package be.mygod.vpnhotspot.net.wifi
|
package be.mygod.vpnhotspot.net.wifi
|
||||||
|
|
||||||
import android.annotation.TargetApi
|
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
import android.net.wifi.WifiConfiguration
|
import android.net.wifi.WifiConfiguration
|
||||||
import android.net.wifi.WifiConfiguration.AuthAlgorithm
|
import android.net.wifi.WifiConfiguration.AuthAlgorithm
|
||||||
import android.os.Build
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.Editable
|
import android.text.Editable
|
||||||
import android.text.TextWatcher
|
import android.text.TextWatcher
|
||||||
@@ -53,12 +51,7 @@ class WifiP2pDialogFragment : DialogFragment(), TextWatcher, DialogInterface.OnC
|
|||||||
setTitle(R.string.repeater_configure)
|
setTitle(R.string.repeater_configure)
|
||||||
mSsid = mView.findViewById(R.id.ssid)
|
mSsid = mView.findViewById(R.id.ssid)
|
||||||
mPassword = mView.findViewById(R.id.password)
|
mPassword = mView.findViewById(R.id.password)
|
||||||
// Note: Reading persistent group information in p2p_supplicant.conf wasn't available until this commit:
|
|
||||||
// https://android.googlesource.com/platform/external/wpa_supplicant_8/+/216983bceec7c450951e2fbcd076b5c75d432e57%5E%21/
|
|
||||||
// which isn't merged until Android 6.0.
|
|
||||||
if (Build.VERSION.SDK_INT >= 23) {
|
|
||||||
setPositiveButton(context.getString(R.string.wifi_save), this@WifiP2pDialogFragment)
|
setPositiveButton(context.getString(R.string.wifi_save), this@WifiP2pDialogFragment)
|
||||||
}
|
|
||||||
setNegativeButton(context.getString(R.string.wifi_cancel), this@WifiP2pDialogFragment)
|
setNegativeButton(context.getString(R.string.wifi_cancel), this@WifiP2pDialogFragment)
|
||||||
setNeutralButton(context.getString(R.string.repeater_reset_credentials), this@WifiP2pDialogFragment)
|
setNeutralButton(context.getString(R.string.repeater_reset_credentials), this@WifiP2pDialogFragment)
|
||||||
val arguments = arguments!!
|
val arguments = arguments!!
|
||||||
@@ -92,7 +85,7 @@ class WifiP2pDialogFragment : DialogFragment(), TextWatcher, DialogInterface.OnC
|
|||||||
|
|
||||||
override fun onClick(dialog: DialogInterface?, which: Int) {
|
override fun onClick(dialog: DialogInterface?, which: Int) {
|
||||||
when (which) {
|
when (which) {
|
||||||
DialogInterface.BUTTON_POSITIVE -> @TargetApi(23) when (configurer.update(config!!)) {
|
DialogInterface.BUTTON_POSITIVE -> when (configurer.update(config!!)) {
|
||||||
true -> {
|
true -> {
|
||||||
app.handler.postDelayed((targetFragment as TetheringFragment).adapter.repeaterManager
|
app.handler.postDelayed((targetFragment as TetheringFragment).adapter.repeaterManager
|
||||||
.binder!!::requestGroupUpdate, 1000)
|
.binder!!::requestGroupUpdate, 1000)
|
||||||
|
|||||||
Reference in New Issue
Block a user