From 2b2639e288e6b34e4e8c047d7f362b150a767ffb Mon Sep 17 00:00:00 2001 From: Mygod Date: Sat, 21 Apr 2018 23:49:10 -0700 Subject: [PATCH] Refine code style --- .../java/be/mygod/vpnhotspot/RepeaterService.kt | 2 +- .../java/be/mygod/vpnhotspot/TetheringFragment.kt | 13 ++++++------- .../main/java/be/mygod/vpnhotspot/net/VpnMonitor.kt | 1 - .../net/wifi/P2pSupplicantConfiguration.kt | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt index 82299f73..d83b1080 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt @@ -85,7 +85,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, VpnMonitor.Ca else -> Log.w(TAG, "Unexpected groups: $it") } }) - } catch (e: Exception) { + } catch (e: ReflectiveOperationException) { e.printStackTrace() Toast.makeText(this@RepeaterService, e.message, Toast.LENGTH_LONG).show() } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/TetheringFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/TetheringFragment.kt index 794b9813..63f03073 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/TetheringFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/TetheringFragment.kt @@ -179,13 +179,12 @@ class TetheringFragment : Fragment(), ServiceConnection { /** * Based on: https://android.googlesource.com/platform/packages/apps/Settings/+/78d5efd/src/com/android/settings/TetherSettings.java */ - fun isStarted(type: TetherType, enabledTypes: Set = this.enabledTypes): Boolean { - return if (type == TetherType.BLUETOOTH) { - val pan = pan - BluetoothAdapter.getDefaultAdapter()?.state == BluetoothAdapter.STATE_ON && pan != null && - isTetheringOn.invoke(pan) as Boolean - } else enabledTypes.contains(type) - } + fun isStarted(type: TetherType, enabledTypes: Set = this.enabledTypes) = + if (type == TetherType.BLUETOOTH) { + val pan = pan + BluetoothAdapter.getDefaultAdapter()?.state == BluetoothAdapter.STATE_ON && pan != null && + isTetheringOn.invoke(pan) as Boolean + } else enabledTypes.contains(type) } class TetheredInterface(val name: String, lookup: Map) : Comparable { val addresses = lookup[name]?.formatAddresses() ?: "" diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/VpnMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/VpnMonitor.kt index 6f492d5c..f482cac3 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/VpnMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/VpnMonitor.kt @@ -1,6 +1,5 @@ package be.mygod.vpnhotspot.net -import android.content.Context import android.net.ConnectivityManager import android.net.Network import android.net.NetworkCapabilities diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt index 48c8a619..a748cd22 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt @@ -22,7 +22,7 @@ class P2pSupplicantConfiguration { fun readPsk(): String? { return try { pskParser.findAll(content ?: return null).single().groupValues[1] - } catch (e: Exception) { + } catch (e: RuntimeException) { Log.w(TAG, content) e.printStackTrace() Toast.makeText(app, e.message, Toast.LENGTH_LONG).show()