-
-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Disable editing repeater credentials on Android 5"
This reverts commit df304fe. 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.
- Loading branch information
Showing
3 changed files
with
87 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package be.mygod.vpnhotspot.net.wifi | ||
|
||
import android.content.Context | ||
import android.content.DialogInterface | ||
import android.net.wifi.WifiConfiguration | ||
import android.net.wifi.WifiConfiguration.AuthAlgorithm | ||
import android.os.Bundle | ||
import com.google.android.material.textfield.TextInputLayout | ||
import androidx.appcompat.app.AlertDialog | ||
import android.text.Editable | ||
import android.text.TextWatcher | ||
import android.view.View | ||
import android.widget.EditText | ||
import android.widget.TextView | ||
import be.mygod.vpnhotspot.R | ||
import java.nio.charset.Charset | ||
|
||
/** | ||
* https://android.googlesource.com/platform/packages/apps/Settings/+/39b4674/src/com/android/settings/wifi/WifiApDialog.java | ||
*/ | ||
class WifiP2pDialog(mContext: Context, private val mListener: DialogInterface.OnClickListener, | ||
private val mWifiConfig: WifiConfiguration?) : AlertDialog(mContext), TextWatcher { | ||
companion object { | ||
private const val BUTTON_SUBMIT = DialogInterface.BUTTON_POSITIVE | ||
} | ||
|
||
private lateinit var mView: View | ||
private lateinit var mSsid: TextView | ||
private lateinit var mPassword: EditText | ||
val config: WifiConfiguration? | ||
get() { | ||
val config = WifiConfiguration() | ||
config.SSID = mSsid.text.toString() | ||
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN) | ||
if (mPassword.length() != 0) { | ||
val password = mPassword.text.toString() | ||
config.preSharedKey = password | ||
} | ||
return config | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
mView = layoutInflater.inflate(R.layout.dialog_wifi_ap, null) | ||
setView(mView) | ||
val context = context | ||
setTitle(R.string.repeater_configure) | ||
mSsid = mView.findViewById(R.id.ssid) | ||
mPassword = mView.findViewById(R.id.password) | ||
setButton(BUTTON_SUBMIT, context.getString(R.string.wifi_save), mListener) | ||
setButton(DialogInterface.BUTTON_NEGATIVE, | ||
context.getString(R.string.wifi_cancel), mListener) | ||
setButton(DialogInterface.BUTTON_NEUTRAL, context.getString(R.string.repeater_reset_credentials), mListener) | ||
if (mWifiConfig != null) { | ||
mSsid.text = mWifiConfig.SSID | ||
mPassword.setText(mWifiConfig.preSharedKey) | ||
} | ||
mSsid.addTextChangedListener(this) | ||
mPassword.addTextChangedListener(this) | ||
super.onCreate(savedInstanceState) | ||
validate() | ||
} | ||
|
||
private fun validate() { | ||
val mSsidString = mSsid.text.toString() | ||
val ssidValid = mSsid.length() != 0 && Charset.forName("UTF-8").encode(mSsidString).limit() <= 32 | ||
val passwordValid = mPassword.length() >= 8 | ||
mView.findViewById<TextInputLayout>(R.id.password_wrapper).error = | ||
if (passwordValid) null else context.getString(R.string.credentials_password_too_short) | ||
getButton(BUTTON_SUBMIT).isEnabled = ssidValid && passwordValid | ||
} | ||
|
||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { } | ||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { } | ||
override fun afterTextChanged(editable: Editable) { | ||
validate() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters