diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/App.kt b/mobile/src/main/java/be/mygod/vpnhotspot/App.kt index ba743039..0e0eaa55 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/App.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/App.kt @@ -7,13 +7,13 @@ import android.content.res.Configuration import android.net.ConnectivityManager import android.net.wifi.WifiManager import android.os.Build -import android.preference.PreferenceManager import androidx.browser.customtabs.CustomTabsIntent import androidx.core.content.ContextCompat import androidx.core.content.getSystemService import androidx.core.provider.FontRequest import androidx.emoji.text.EmojiCompat import androidx.emoji.text.FontRequestEmojiCompatConfig +import androidx.preference.PreferenceManager import be.mygod.vpnhotspot.net.DhcpWorkaround import be.mygod.vpnhotspot.room.AppDatabase import be.mygod.vpnhotspot.util.DeviceStorageApp @@ -32,7 +32,8 @@ class App : Application() { app = this if (Build.VERSION.SDK_INT >= 24) { deviceStorage = DeviceStorageApp(this) - deviceStorage.moveSharedPreferencesFrom(this, PreferenceManager.getDefaultSharedPreferencesName(this)) + // alternative to PreferenceManager.getDefaultSharedPreferencesName(this) + deviceStorage.moveSharedPreferencesFrom(this, PreferenceManager(this).sharedPreferencesName) deviceStorage.moveDatabaseFrom(this, AppDatabase.DB_NAME) } else deviceStorage = this DebugHelper.init() @@ -51,7 +52,7 @@ class App : Application() { if (DhcpWorkaround.shouldEnable) DhcpWorkaround.enable(true) } - override fun onConfigurationChanged(newConfig: Configuration?) { + override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) ServiceNotification.updateNotificationChannels() } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt index 69fb257d..9d614aa6 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt @@ -120,9 +120,9 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere if (intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, 0) == WifiP2pManager.WIFI_P2P_STATE_DISABLED) clean() // ignore P2P enabled WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION -> onP2pConnectionChanged( - intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_INFO), + intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_INFO)!!, intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO), - intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_GROUP)) + intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_GROUP)!!) } } private val deviceListener = broadcastReceiver { _, intent -> diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt index 79af6088..33bbffcc 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt @@ -90,7 +90,7 @@ class TetheringService : IpNeighbourMonitoringService() { if (start()) check(downstreams.put(iface, this) == null) else destroy() } } - intent.getStringExtra(EXTRA_ADD_INTERFACE_MONITOR)?.let { iface -> + intent.getStringExtra(EXTRA_ADD_INTERFACE_MONITOR)?.also { iface -> val downstream = downstreams[iface] if (downstream == null) Downstream(this, iface, true).apply { start() @@ -98,7 +98,7 @@ class TetheringService : IpNeighbourMonitoringService() { downstreams[iface] = this } else downstream.monitor = true } - downstreams.remove(intent.getStringExtra(EXTRA_REMOVE_INTERFACE))?.destroy() + intent.getStringExtra(EXTRA_REMOVE_INTERFACE)?.also { downstreams.remove(it)?.destroy() } updateNotification() // call this first just in case we are shutting down immediately onDownstreamsChangedLocked() } else if (downstreams.isEmpty()) stopSelf(startId) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/client/MacLookup.kt b/mobile/src/main/java/be/mygod/vpnhotspot/client/MacLookup.kt index 5f7ed771..4a89e2b0 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/client/MacLookup.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/client/MacLookup.kt @@ -47,7 +47,7 @@ object MacLookup { try { val response = conn.inputStream.bufferedReader().readText() val obj = JSONObject(response).getJSONObject("result") - obj.optString("error", null)?.also { throw UnexpectedError(mac, it) } + obj.opt("error")?.also { throw UnexpectedError(mac, it.toString()) } val company = obj.getString("company") val match = extractCountry(mac, response, obj) val result = if (match != null) { @@ -71,7 +71,7 @@ object MacLookup { } private fun extractCountry(mac: Long, response: String, obj: JSONObject): MatchResult? { - obj.optString("country")?.let { countryCodeRegex.matchEntire(it) }?.also { return it } + countryCodeRegex.matchEntire(obj.optString("country"))?.also { return it } val address = obj.optString("address") if (address.isNullOrBlank()) return null countryCodeRegex.find(address)?.also { return it } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApManager.kt index 653d3f78..c4fbd5ec 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApManager.kt @@ -25,11 +25,13 @@ object WifiApManager { private fun WifiManager.setWifiApEnabled(wifiConfig: WifiConfiguration?, enabled: Boolean) = setWifiApEnabled.invoke(this, wifiConfig, enabled) as Boolean + @Suppress("DEPRECATION") @Deprecated("Not usable since API 26, malfunctioning on API 25") fun start(wifiConfig: WifiConfiguration? = null) { app.wifi.isWifiEnabled = false app.wifi.setWifiApEnabled(wifiConfig, true) } + @Suppress("DEPRECATION") @Deprecated("Not usable since API 26") fun stop() { app.wifi.setWifiApEnabled(null, false) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/util/SpanFormatter.kt b/mobile/src/main/java/be/mygod/vpnhotspot/util/SpanFormatter.kt index 8ed8a93a..e9fa604f 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/util/SpanFormatter.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/util/SpanFormatter.kt @@ -57,7 +57,7 @@ object SpanFormatter { i = m.start() val exprEnd = m.end() - val argTerm = m.group(1) + val argTerm = m.group(1)!! val modTerm = m.group(2) val typeTerm = m.group(3)