diff --git a/app/src/main/java/com/aws/amazonlocation/utils/Constants.kt b/app/src/main/java/com/aws/amazonlocation/utils/Constants.kt index 7415cdf1..c9c93f96 100644 --- a/app/src/main/java/com/aws/amazonlocation/utils/Constants.kt +++ b/app/src/main/java/com/aws/amazonlocation/utils/Constants.kt @@ -152,6 +152,7 @@ const val LAT_LNG_REG_EXP = "([+-]?\\d+\\.?\\d+)\\s*,\\s*([+-]?\\d+\\.?\\d+)" const val GEOFENCE_NAME_REG_EXP = "^[-._\\p{L}\\p{N}]+\$" const val userPoolIdPattern = "[\\w-]+_[0-9a-zA-Z]+" const val userPoolClientId = "[\\w+]+" +const val regionPattern = "^[a-zA-Z-]+-\\d+$" const val LOCATION_AWS_PREFIX = "location.aws.com.demo." const val LOCATION_MAPS_PREFIX = "maps." diff --git a/app/src/main/java/com/aws/amazonlocation/utils/GeneralUtils.kt b/app/src/main/java/com/aws/amazonlocation/utils/GeneralUtils.kt index 963b59f7..2315087c 100644 --- a/app/src/main/java/com/aws/amazonlocation/utils/GeneralUtils.kt +++ b/app/src/main/java/com/aws/amazonlocation/utils/GeneralUtils.kt @@ -566,16 +566,22 @@ fun Context.isInternetAvailable(): Boolean { } fun validateIdentityPoolId(mIdentityPoolId: String?, region: String?): Boolean { - val cognitoCredentialsProvider = CognitoCredentialsProvider( - mIdentityPoolId, - Regions.fromName(region) - ) + val pattern = Pattern.compile(regionPattern) + val matcher = region?.let { pattern.matcher(it) } + if (matcher?.matches() != true) return false try { + val cognitoCredentialsProvider = CognitoCredentialsProvider( + mIdentityPoolId, + Regions.fromName(region) + ) cognitoCredentialsProvider.refresh() } catch (exception: Exception) { if (exception is com.amazonaws.services.cognitoidentity.model.ResourceNotFoundException) { return false } + if (exception is IllegalArgumentException) { + return false + } } return true }