Hide WPS if unsupported

This commit is contained in:
Mygod
2019-05-10 15:34:25 +08:00
parent 1d6d3b7dcc
commit 95306377b4
2 changed files with 10 additions and 8 deletions

View File

@@ -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.

View File

@@ -3,6 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data>
<import type="be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper"/>
<variable
name="data"
type="be.mygod.vpnhotspot.manage.RepeaterManager.Data"/>
@@ -73,7 +74,7 @@
android:background="?android:attr/selectableItemBackground"
android:padding="16dp"
android:onClick="@{_ -> data.wps()}"
android:visibility="@{data.serviceStarted}">
android:visibility="@{data.serviceStarted &amp;&amp; WifiP2pManagerHelper.startWps != null}">
<Space
android:layout_width="40dp"