Support setting Wi-Fi operating channel

This commit is contained in:
Mygod
2018-04-21 14:49:38 -07:00
parent 7f81b3ae33
commit 97e0a6386f
6 changed files with 69 additions and 10 deletions

View File

@@ -15,6 +15,7 @@ import android.widget.Toast
class App : Application() {
companion object {
const val ACTION_CLEAN_ROUTINGS = "be.mygod.vpnhotspot.CLEAN_ROUTINGS"
const val KEY_OPERATING_CHANNEL = "service.repeater.oc"
private const val KEY_DNS = "service.dns"
@SuppressLint("StaticFieldLeak")
@@ -29,6 +30,7 @@ class App : Application() {
deviceContext.moveSharedPreferencesFrom(this, PreferenceManager.getDefaultSharedPreferencesName(this))
} else deviceContext = this
// workaround for support lib PreferenceDataStore bug
operatingChannel = operatingChannel
dns = dns
ServiceNotification.updateNotificationChannels()
}
@@ -43,6 +45,12 @@ class App : Application() {
val pref: SharedPreferences by lazy { PreferenceManager.getDefaultSharedPreferences(deviceContext) }
val connectivity by lazy { getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager }
var operatingChannel: Int
get() {
val result = pref.getString(KEY_OPERATING_CHANNEL, null)?.toIntOrNull() ?: 0
return if (result in 0..165) result else 0
}
set(value) = pref.edit().putString(KEY_OPERATING_CHANNEL, value.toString()).apply()
var dns: String
get() = pref.getString(KEY_DNS, "8.8.8.8")
set(value) = pref.edit().putString(KEY_DNS, value).apply()