Skip to content

Commit 570d7dc

Browse files
committed
Fix cleartext request on pre 5.0 devices
1 parent 91c859b commit 570d7dc

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

xkcd/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ android {
8787
testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project-test.pro'
8888
applicationIdSuffix ".debug"
8989
multiDexEnabled false
90+
ext.enableCrashlytics = false
9091
}
9192

9293
release {

xkcd/src/debug/AndroidManifest.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="xyz.jienan.xkcd">
4+
5+
<application>
6+
7+
<meta-data
8+
android:name="firebase_crashlytics_collection_enabled"
9+
android:value="false" />
10+
11+
</application>
12+
13+
</manifest>

xkcd/src/main/java/xyz/jienan/xkcd/XkcdApplication.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class XkcdApplication : Application() {
6363

6464
private fun updateLocale() {
6565
XkcdModel.localizedUrl = resources.getString(R.string.api_xkcd_localization)
66-
Crashlytics.setString("locale", Locale.getDefault().toString())
66+
if (!BuildConfig.DEBUG) {
67+
Crashlytics.setString("locale", Locale.getDefault().toString())
68+
}
6769
}
6870
}

xkcd/src/main/java/xyz/jienan/xkcd/base/network/NetworkService.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ object NetworkService {
131131

132132
client.sslSocketFactory(TLSSocketFactory(), trustManager)
133133

134-
val spec = ConnectionSpec.Builder(ConnectionSpec.COMPATIBLE_TLS)
134+
val tlsSpec = ConnectionSpec.Builder(ConnectionSpec.COMPATIBLE_TLS)
135135
.tlsVersions(TlsVersion.TLS_1_2, TlsVersion.TLS_1_1, TlsVersion.TLS_1_0)
136136
.cipherSuites(
137137
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
@@ -146,7 +146,13 @@ object NetworkService {
146146
CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA)
147147
.build()
148148

149-
client.connectionSpecs(listOf(spec))
149+
val specs = if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {
150+
listOf(tlsSpec, ConnectionSpec.CLEARTEXT)
151+
} else {
152+
listOf(tlsSpec)
153+
}
154+
155+
client.connectionSpecs(specs)
150156
} catch (exc: Exception) {
151157
Timber.e(exc, "Error while setting TLS")
152158
}

0 commit comments

Comments
 (0)