From 95306377b492d3dc1cc69f2054542862d4e74814 Mon Sep 17 00:00:00 2001 From: Mygod Date: Fri, 10 May 2019 15:34:25 +0800 Subject: [PATCH] Hide WPS if unsupported --- .../vpnhotspot/net/wifi/WifiP2pManagerHelper.kt | 15 ++++++++------- mobile/src/main/res/layout/listitem_repeater.xml | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pManagerHelper.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pManagerHelper.kt index 794ec602..22197122 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pManagerHelper.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pManagerHelper.kt @@ -39,18 +39,19 @@ object WifiP2pManagerHelper { * * Source: https://android.googlesource.com/platform/frameworks/base/+/android-4.3_r0.9/wifi/java/android/net/wifi/p2p/WifiP2pManager.java#958 */ - private val startWps by lazy { - WifiP2pManager::class.java.getDeclaredMethod("startWps", - WifiP2pManager.Channel::class.java, WpsInfo::class.java, WifiP2pManager.ActionListener::class.java) - } - fun WifiP2pManager.startWps(c: WifiP2pManager.Channel, wps: WpsInfo, listener: WifiP2pManager.ActionListener) { + @JvmStatic + val startWps by lazy { try { - startWps.invoke(this, c, wps, listener) + WifiP2pManager::class.java.getDeclaredMethod("startWps", + WifiP2pManager.Channel::class.java, WpsInfo::class.java, WifiP2pManager.ActionListener::class.java) } catch (e: NoSuchMethodException) { DebugHelper.logEvent("NoSuchMethod_startWps") - listener.onFailure(UNSUPPORTED) + null } } + fun WifiP2pManager.startWps(c: WifiP2pManager.Channel, wps: WpsInfo, listener: WifiP2pManager.ActionListener) { + startWps!!.invoke(this, c, wps, listener) + } /** * Available since Android 4.2. diff --git a/mobile/src/main/res/layout/listitem_repeater.xml b/mobile/src/main/res/layout/listitem_repeater.xml index d8723abb..4c075827 100644 --- a/mobile/src/main/res/layout/listitem_repeater.xml +++ b/mobile/src/main/res/layout/listitem_repeater.xml @@ -3,6 +3,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> + @@ -73,7 +74,7 @@ android:background="?android:attr/selectableItemBackground" android:padding="16dp" android:onClick="@{_ -> data.wps()}" - android:visibility="@{data.serviceStarted}"> + android:visibility="@{data.serviceStarted && WifiP2pManagerHelper.startWps != null}">