unregisterTetheringEventCallback onTetherableInterfaceRegexpsChanged

This commit is contained in:
Mygod
2020-06-02 16:54:18 -04:00
parent d64c04a9e1
commit 2a0f899547

View File

@@ -7,6 +7,7 @@ import androidx.core.os.BuildCompat
import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.R import be.mygod.vpnhotspot.R
import be.mygod.vpnhotspot.util.Event0 import be.mygod.vpnhotspot.util.Event0
import timber.log.Timber
import java.util.regex.Pattern import java.util.regex.Pattern
enum class TetherType(@DrawableRes val icon: Int) { enum class TetherType(@DrawableRes val icon: Int) {
@@ -47,6 +48,7 @@ enum class TetherType(@DrawableRes val icon: Int) {
@RequiresApi(30) @RequiresApi(30)
private fun updateRegexs() { private fun updateRegexs() {
requiresUpdate = false requiresUpdate = false
TetheringManager.registerTetheringEventCallback(null, this)
val tethering = "com.android.networkstack.tethering" to app.packageManager.getResourcesForApplication( val tethering = "com.android.networkstack.tethering" to app.packageManager.getResourcesForApplication(
TetheringManager.resolvedService.serviceInfo.applicationInfo) TetheringManager.resolvedService.serviceInfo.applicationInfo)
usbRegexs = tethering.getRegexs("config_tether_usb_regexs") usbRegexs = tethering.getRegexs("config_tether_usb_regexs")
@@ -58,6 +60,8 @@ enum class TetherType(@DrawableRes val icon: Int) {
@RequiresApi(30) @RequiresApi(30)
override fun onTetherableInterfaceRegexpsChanged() { override fun onTetherableInterfaceRegexpsChanged() {
Timber.i("onTetherableInterfaceRegexpsChanged")
TetheringManager.unregisterTetheringEventCallback(this)
requiresUpdate = true requiresUpdate = true
listener() listener()
} }
@@ -67,10 +71,7 @@ enum class TetherType(@DrawableRes val icon: Int) {
*/ */
init { init {
val system = "android" to Resources.getSystem() val system = "android" to Resources.getSystem()
if (BuildCompat.isAtLeastR()) { if (BuildCompat.isAtLeastR()) requiresUpdate = true else {
requiresUpdate = true
TetheringManager.registerTetheringEventCallback(null, this)
} else {
usbRegexs = system.getRegexs("config_tether_usb_regexs") usbRegexs = system.getRegexs("config_tether_usb_regexs")
wifiRegexs = system.getRegexs("config_tether_wifi_regexs") wifiRegexs = system.getRegexs("config_tether_wifi_regexs")
bluetoothRegexs = system.getRegexs("config_tether_bluetooth_regexs") bluetoothRegexs = system.getRegexs("config_tether_bluetooth_regexs")