diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt index 3bb8b282..f2f9fa67 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt @@ -2,7 +2,6 @@ package be.mygod.vpnhotspot.manage import android.Manifest import android.annotation.TargetApi -import android.content.ClipData import android.content.Context import android.content.Intent import android.content.pm.PackageManager @@ -175,21 +174,6 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(), this.capability = capability data.notifyChange() } - @RequiresApi(30) - override fun onBlockedClientConnecting(client: Parcelable, blockedReason: Int) { - @Suppress("NAME_SHADOWING") - val client = WifiClient(client) - val macAddress = client.macAddress - var name = macAddress.toString() - if (BuildCompat.isAtLeastS()) client.apInstanceIdentifier?.let { name += "%$it" } - val reason = WifiApManager.clientBlockLookup(blockedReason, true) - Timber.i("$name blocked from connecting: $reason ($blockedReason)") - SmartSnackbar.make(parent.getString(R.string.tethering_manage_wifi_client_blocked, name, reason)).apply { - action(R.string.tethering_manage_wifi_copy_mac) { - app.clipboard.setPrimaryClip(ClipData.newPlainText(null, macAddress.toString())) - } - }.show() - } override val title get() = parent.getString(R.string.tethering_manage_wifi) override val tetherType get() = TetherType.WIFI diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/root/WifiApCommands.kt b/mobile/src/main/java/be/mygod/vpnhotspot/root/WifiApCommands.kt index bea331cd..e05e7f10 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/root/WifiApCommands.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/root/WifiApCommands.kt @@ -1,12 +1,18 @@ package be.mygod.vpnhotspot.root +import android.annotation.TargetApi +import android.content.ClipData import android.os.Parcelable import androidx.annotation.RequiresApi +import androidx.core.os.BuildCompat import be.mygod.librootkotlinx.ParcelableBoolean import be.mygod.librootkotlinx.RootCommand import be.mygod.librootkotlinx.RootCommandChannel +import be.mygod.vpnhotspot.App.Companion.app +import be.mygod.vpnhotspot.R import be.mygod.vpnhotspot.net.wifi.SoftApConfigurationCompat import be.mygod.vpnhotspot.net.wifi.WifiApManager +import be.mygod.vpnhotspot.net.wifi.WifiClient import be.mygod.vpnhotspot.widget.SmartSnackbar import kotlinx.coroutines.* import kotlinx.coroutines.channels.* @@ -119,6 +125,19 @@ object WifiApCommands { } is SoftApCallbackParcel.OnInfoChanged -> synchronized(callbacks) { lastCallback.info = parcel } is SoftApCallbackParcel.OnCapabilityChanged -> synchronized(callbacks) { lastCallback.capability = parcel } + is SoftApCallbackParcel.OnBlockedClientConnecting -> @TargetApi(30) { // passively consume events + val client = WifiClient(parcel.client) + val macAddress = client.macAddress + var name = macAddress.toString() + if (BuildCompat.isAtLeastS()) client.apInstanceIdentifier?.let { name += "%$it" } + val reason = WifiApManager.clientBlockLookup(parcel.blockedReason, true) + Timber.i("$name blocked from connecting: $reason (${parcel.blockedReason})") + SmartSnackbar.make(app.getString(R.string.tethering_manage_wifi_client_blocked, name, reason)).apply { + action(R.string.tethering_manage_wifi_copy_mac) { + app.clipboard.setPrimaryClip(ClipData.newPlainText(null, macAddress.toString())) + } + }.show() + } } for (callback in synchronized(callbacks) { callbacks.toList() }) parcel.dispatch(callback) }