refactor: renomear package me.capcom.smsgateway → pt.whatsms.gateway
Build AAB — WhatSMS Gateway / build (push) Failing after 34s
Build AAB — WhatSMS Gateway / build (push) Failing after 34s
- namespace, applicationId, todos os ficheiros .kt/.xml/.gradle actualizados - directório me/capcom/smsgateway/ → pt/whatsms/gateway/ - zero referências a capcom no código fonte
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
package pt.whatsms.gateway.providers
|
||||
|
||||
interface IPProvider {
|
||||
suspend fun getIP(): String?
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package pt.whatsms.gateway.providers
|
||||
|
||||
import android.content.Context
|
||||
import android.net.wifi.WifiManager
|
||||
import java.net.Inet4Address
|
||||
import java.net.NetworkInterface
|
||||
|
||||
|
||||
class LocalIPProvider(private val context: Context): IPProvider {
|
||||
override suspend fun getIP(): String? {
|
||||
try {
|
||||
val wifiManager =
|
||||
context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
|
||||
|
||||
// If the device is in tethering mode, the following method may return null or a default IP
|
||||
wifiManager.connectionInfo?.let { connectionInfo ->
|
||||
val ipInt = connectionInfo.ipAddress
|
||||
if (ipInt != 0) {
|
||||
return (ipInt and 0xFF).toString() + "." +
|
||||
((ipInt shr 8) and 0xFF) + "." +
|
||||
((ipInt shr 16) and 0xFF) + "." +
|
||||
((ipInt shr 24) and 0xFF)
|
||||
}
|
||||
}
|
||||
|
||||
// If the above doesn't work, try to find the WiFi network interface directly
|
||||
val wifiInterface = NetworkInterface.getNetworkInterfaces().asSequence()
|
||||
.find { it.name.contains("wlan", ignoreCase = true) }
|
||||
|
||||
wifiInterface?.inetAddresses?.asSequence()
|
||||
?.find { !it.isLoopbackAddress && it is Inet4Address }
|
||||
?.let { inetAddress ->
|
||||
return inetAddress.hostAddress
|
||||
}
|
||||
|
||||
// Check any other network interface
|
||||
val interfaces = NetworkInterface.getNetworkInterfaces()
|
||||
while (interfaces.hasMoreElements()) {
|
||||
val intf = interfaces.nextElement()
|
||||
val addrs = intf.inetAddresses
|
||||
while (addrs.hasMoreElements()) {
|
||||
val addr = addrs.nextElement()
|
||||
if (!addr.isLoopbackAddress && addr is Inet4Address) {
|
||||
return addr.hostAddress
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package pt.whatsms.gateway.providers
|
||||
|
||||
import pt.whatsms.gateway.modules.gateway.GatewayService
|
||||
import org.koin.java.KoinJavaComponent.inject
|
||||
|
||||
class PublicIPProvider: IPProvider {
|
||||
private val gatewaySvc by inject<GatewayService>(GatewayService::class.java)
|
||||
|
||||
override suspend fun getIP(): String? {
|
||||
return try {
|
||||
gatewaySvc.getPublicIP()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user