Skip to content

Commit 95f3f52

Browse files
committed
Allow to connect to HTTP endpoints if not in the production environment.
1 parent 9f04169 commit 95f3f52

4 files changed

Lines changed: 20 additions & 1 deletion

File tree

android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<application
1919
android:allowBackup="true"
2020
android:dataExtractionRules="@xml/data_extraction_rules"
21+
android:networkSecurityConfig="@xml/network_security_config"
2122
android:fullBackupContent="@xml/backup_rules"
2223
android:icon="@mipmap/ic_launcher"
2324
android:label="@string/app_name"

android/app/src/main/java/com/httpsms/LoginActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class LoginActivity : AppCompatActivity() {
127127
return
128128
}
129129

130-
if (!URLUtil.isHttpsUrl(serverUrl.text.toString().trim())) {
130+
if (Settings.isProductionEnvironment(this) && !URLUtil.isHttpsUrl(serverUrl.text.toString().trim())) {
131131
Timber.e("url number [${serverUrl.text.toString()}] is not an https URL")
132132
resetView()
133133
serverUrlLayout.error = "Server URL [${serverUrl.text.toString()}] must be HTTPS"

android/app/src/main/java/com/httpsms/Settings.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ object Settings {
1515
private const val SETTINGS_FCM_TOKEN = "SETTINGS_FCM_TOKEN"
1616
private const val SETTINGS_FCM_TOKEN_UPDATE_TIMESTAMP = "SETTINGS_FCM_TOKEN_UPDATE_TIMESTAMP"
1717
private const val SETTINGS_HEARTBEAT_TIMESTAMP = "SETTINGS_HEARTBEAT_TIMESTAMP"
18+
private const val SETTINGS_PRODUCTION_ENV = "SETTINGS_PRODUCTION_ENV";
1819

1920
fun getOwner(context: Context): String? {
2021
Timber.d(Settings::getOwner.name)
@@ -82,6 +83,17 @@ object Settings {
8283
return activeStatus
8384
}
8485

86+
fun isProductionEnvironment(context: Context): Boolean {
87+
Timber.d(Settings::isProductionEnvironment.name)
88+
89+
val isProductionEnv = PreferenceManager
90+
.getDefaultSharedPreferences(context)
91+
.getBoolean(this.SETTINGS_PRODUCTION_ENV, true)
92+
93+
Timber.d("SETTINGS_PRODUCTION_ENV: [$isProductionEnv]")
94+
return isProductionEnv
95+
}
96+
8597
fun setActiveStatusAsync(context: Context, status: Boolean) {
8698
Timber.d(Settings::setActiveStatusAsync.name)
8799

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<network-security-config>
3+
<!--domain-config cleartextTrafficPermitted="true">
4+
<domain includeSubdomains="true">127.0.0.1</domain>
5+
</domain-config-->
6+
</network-security-config>

0 commit comments

Comments
 (0)