This commit is contained in:
parent
fd16bea84f
commit
fd99d655a0
4 changed files with 47 additions and 8 deletions
|
|
@ -9,11 +9,11 @@ android {
|
|||
|
||||
defaultConfig {
|
||||
applicationId "com.ldc.kiosk"
|
||||
minSdkVersion 21
|
||||
minSdkVersion 24
|
||||
targetSdkVersion 30
|
||||
versionCode 14
|
||||
//versionName "1.9.2"
|
||||
versionName "0.0.1"
|
||||
versionName "0.0.3"
|
||||
|
||||
javaCompileOptions {
|
||||
annotationProcessorOptions {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@
|
|||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
android:theme="@style/AppTheme"
|
||||
android:networkSecurityConfig="@xml/network_security_config">
|
||||
<activity
|
||||
android:name=".ui.ldc.KioskActivity"
|
||||
android:exported="true">
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ import java.io.BufferedReader
|
|||
import java.io.IOException
|
||||
import java.io.Reader
|
||||
import kotlin.collections.ArrayList
|
||||
import java.util.regex.Matcher
|
||||
import java.util.regex.Pattern
|
||||
|
||||
class KioskActivity : AppCompatActivity(), LifecycleObserver {
|
||||
|
||||
|
|
@ -137,14 +139,14 @@ class KioskActivity : AppCompatActivity(), LifecycleObserver {
|
|||
for (csvRecord: CSVRecord in parser) {
|
||||
val identifier = csvRecord.get(0);
|
||||
// Si le premier caractère est un dieze la ligne est commentée donc on passe
|
||||
if (identifier[0] == '#') {
|
||||
if (identifier[0] == '#' || identifier.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
val ip = csvRecord.get(3);
|
||||
val port = csvRecord.get(4);
|
||||
// On test si l´Identifiant TID correspond à celle du Device
|
||||
if (identifier.length == 11 && identifier.equals(getIdentifier())) {
|
||||
if (ip!!.isEmpty()) {
|
||||
val ip = csvRecord.get(3);
|
||||
val port = csvRecord.get(4);
|
||||
if (ip!!.isEmpty() || !isValidIpAddress(ip)) {
|
||||
runOnUiThread(Runnable {
|
||||
Toast.makeText(
|
||||
context,
|
||||
|
|
@ -155,7 +157,7 @@ class KioskActivity : AppCompatActivity(), LifecycleObserver {
|
|||
manageButtons("enable")
|
||||
return
|
||||
}
|
||||
if (port!!.isEmpty()) {
|
||||
if (port!!.isEmpty() || !isValidPort(port)) {
|
||||
runOnUiThread(Runnable {
|
||||
Toast.makeText(
|
||||
context,
|
||||
|
|
@ -391,4 +393,34 @@ class KioskActivity : AppCompatActivity(), LifecycleObserver {
|
|||
return networkInfo.isConnected
|
||||
}
|
||||
}
|
||||
|
||||
private fun isValidIpAddress(str: String): Boolean {
|
||||
if (str.isEmpty())
|
||||
{
|
||||
return false
|
||||
}
|
||||
// Regex for IPV4 and IPV6
|
||||
val regex: String =
|
||||
"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\.(?!\$)|\$)){4}$"
|
||||
val p: Pattern = Pattern.compile(regex)
|
||||
val m: Matcher = p.matcher(str)
|
||||
return m.matches()
|
||||
}
|
||||
|
||||
private fun isValidPort(str: String): Boolean {
|
||||
if (str.isEmpty())
|
||||
{
|
||||
return false
|
||||
}
|
||||
try {
|
||||
str.toInt();
|
||||
} catch (e: NumberFormatException) {
|
||||
return false
|
||||
}
|
||||
val regex: String =
|
||||
"^((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([0-5]{0,5})|([0-9]{1,4}))\$"
|
||||
val p: Pattern = Pattern.compile(regex)
|
||||
val m: Matcher = p.matcher(str)
|
||||
return m.matches()
|
||||
}
|
||||
}
|
||||
6
app/src/main/res/xml/network_security_config.xml
Normal file
6
app/src/main/res/xml/network_security_config.xml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<network-security-config>
|
||||
<domain-config cleartextTrafficPermitted="true">
|
||||
<domain includeSubdomains="true">localtid</domain>
|
||||
</domain-config>
|
||||
</network-security-config>
|
||||
Loading…
Add table
Reference in a new issue