Fix crashes on stupid devices

This commit is contained in:
Mygod
2018-06-13 15:51:10 +08:00
parent 202c4f87a8
commit 09690f19c8
5 changed files with 28 additions and 7 deletions

View File

@@ -122,6 +122,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere
WifiP2pManager.P2P_UNSUPPORTED -> getString(R.string.repeater_failure_reason_p2p_unsupported)
WifiP2pManager.BUSY -> getString(R.string.repeater_failure_reason_busy)
WifiP2pManager.NO_SERVICE_REQUESTS -> getString(R.string.repeater_failure_reason_no_service_requests)
WifiP2pManagerHelper.UNSUPPORTED -> getString(R.string.repeater_failure_reason_unsupported_operation)
else -> getString(R.string.failure_reason_unknown, reason)
})
Crashlytics.logException(Failure(result))

View File

@@ -98,7 +98,7 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
true
}
findPreference("misc.source").setOnPreferenceClickListener {
customTabsIntent.launchUrl(activity, Uri.parse("https://github.com/Mygod/VPNHotspot"))
customTabsIntent.launchUrl(requireActivity(), Uri.parse("https://github.com/Mygod/VPNHotspot"))
true
}
}

View File

@@ -12,6 +12,7 @@ import java.util.regex.Pattern
object WifiP2pManagerHelper {
private const val TAG = "WifiP2pManagerHelper"
const val UNSUPPORTED = -2
/**
* Matches the output of dumpsys wifip2p. This part is available since Android 4.2.
@@ -36,8 +37,14 @@ object WifiP2pManagerHelper {
Int::class.java, Int::class.java, WifiP2pManager.ActionListener::class.java)
}
fun WifiP2pManager.setWifiP2pChannels(c: WifiP2pManager.Channel, lc: Int, oc: Int,
listener: WifiP2pManager.ActionListener) {
setWifiP2pChannels.invoke(this, c, lc, oc, listener)
listener: WifiP2pManager.ActionListener) {
try {
setWifiP2pChannels.invoke(this, c, lc, oc, listener)
} catch (e: NoSuchMethodException) {
e.printStackTrace()
Crashlytics.logException(e)
listener.onFailure(UNSUPPORTED)
}
}
/**
@@ -49,9 +56,14 @@ object WifiP2pManagerHelper {
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) {
startWps.invoke(this, c, wps, listener)
fun WifiP2pManager.startWps(c: WifiP2pManager.Channel, wps: WpsInfo, listener: WifiP2pManager.ActionListener) {
try {
startWps.invoke(this, c, wps, listener)
} catch (e: NoSuchMethodException) {
e.printStackTrace()
Crashlytics.logException(e)
listener.onFailure(UNSUPPORTED)
}
}
/**
@@ -65,7 +77,13 @@ object WifiP2pManagerHelper {
}
fun WifiP2pManager.deletePersistentGroup(c: WifiP2pManager.Channel, netId: Int,
listener: WifiP2pManager.ActionListener) {
deletePersistentGroup.invoke(this, c, netId, listener)
try {
deletePersistentGroup.invoke(this, c, netId, listener)
} catch (e: NoSuchMethodException) {
e.printStackTrace()
Crashlytics.logException(e)
listener.onFailure(UNSUPPORTED)
}
}
private val interfacePersistentGroupInfoListener by lazy @SuppressLint("PrivateApi") {

View File

@@ -27,6 +27,7 @@
<string name="repeater_failure_reason_p2p_unsupported">设备不支持 Wi\u2011Fi 直连</string>
<string name="repeater_failure_reason_busy">系统忙</string>
<string name="repeater_failure_reason_no_service_requests">未添加服务请求</string>
<string name="repeater_failure_reason_unsupported_operation">不支持此操作</string>
<string name="tethering_temp_hotspot">临时 WLAN 热点</string>
<string name="tethering_temp_hotspot_location">使用临时热点需要打开位置服务。</string>

View File

@@ -38,6 +38,7 @@
<string name="repeater_failure_reason_p2p_unsupported">Wi\u2011Fi direct unsupported</string>
<string name="repeater_failure_reason_busy">framework is busy</string>
<string name="repeater_failure_reason_no_service_requests">no service requests added</string>
<string name="repeater_failure_reason_unsupported_operation">unsupported operation</string>
<string name="tethering_temp_hotspot">Temporary Wi\u2011Fi hotspot</string>
<string name="tethering_temp_hotspot_location">Temporary hotspot requires location to be turned on.</string>