From 6a7a16a0c789f06055b22af7229b19177776e853 Mon Sep 17 00:00:00 2001 From: Mygod Date: Fri, 1 Feb 2019 16:46:00 +0800 Subject: [PATCH] Move away KEY_OPERATING_CHANNEL --- mobile/src/main/java/be/mygod/vpnhotspot/App.kt | 6 ------ .../main/java/be/mygod/vpnhotspot/RepeaterService.kt | 11 +++++++++-- .../be/mygod/vpnhotspot/manage/RepeaterManager.kt | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/App.kt b/mobile/src/main/java/be/mygod/vpnhotspot/App.kt index 183e4fbe..75de33ce 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/App.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/App.kt @@ -23,8 +23,6 @@ import java.util.* class App : Application() { companion object { - const val KEY_OPERATING_CHANNEL = "service.repeater.oc" - @SuppressLint("StaticFieldLeak") lateinit var app: App } @@ -80,10 +78,6 @@ class App : Application() { .build() } - val operatingChannel: Int get() { - val result = pref.getString(KEY_OPERATING_CHANNEL, null)?.toIntOrNull() ?: 0 - return if (result in 1..165) result else 0 - } val masquerade get() = pref.getBoolean("service.masquerade", true) val dhcpWorkaround get() = pref.getBoolean("service.dhcpWorkaround", false) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt index 39e3857e..abaa1638 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt @@ -36,6 +36,8 @@ import java.lang.reflect.InvocationTargetException class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPreferences.OnSharedPreferenceChangeListener { companion object { private const val TAG = "RepeaterService" + const val KEY_OPERATING_CHANNEL = "service.repeater.oc" + /** * This is only a "ServiceConnection" to system service and its impact on system is minimal. */ @@ -49,6 +51,11 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere } val supported get() = p2pManager != null var persistentSupported = false + + val operatingChannel: Int get() { + val result = app.pref.getString(KEY_OPERATING_CHANNEL, null)?.toIntOrNull() ?: 0 + return if (result in 1..165) result else 0 + } } enum class Status { @@ -156,7 +163,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere override fun onBind(intent: Intent) = binder - private fun setOperatingChannel(oc: Int = app.operatingChannel) = try { + private fun setOperatingChannel(oc: Int = operatingChannel) = try { val channel = channel if (channel == null) SmartSnackbar.make(R.string.repeater_failure_disconnected).show() // we don't care about listening channel @@ -186,7 +193,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere } override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { - if (key == App.KEY_OPERATING_CHANNEL) setOperatingChannel() + if (key == KEY_OPERATING_CHANNEL) setOperatingChannel() } private fun onPersistentGroupsChanged() { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt index 6aea6f3e..64fc39cb 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt @@ -61,10 +61,10 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic } var oc: CharSequence @Bindable get() { - val oc = app.operatingChannel + val oc = RepeaterService.operatingChannel return if (oc in 1..165) oc.toString() else "" } - set(value) = app.pref.edit().putString(App.KEY_OPERATING_CHANNEL, value.toString()).apply() + set(value) = app.pref.edit().putString(RepeaterService.KEY_OPERATING_CHANNEL, value.toString()).apply() fun onStatusChanged() { notifyPropertyChanged(BR.switchEnabled)