Skip to content

Commit 175ab64

Browse files
committed
Merge branch 'hotfix/5.10.5'
2 parents adcef6c + a96df1e commit 175ab64

File tree

8 files changed

+93
-28
lines changed

8 files changed

+93
-28
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ apply plugin: 'kotlin-kapt'
66
apply from: '../versioning.gradle'
77

88
ext {
9-
VERSION_NAME = "5.10.4"
9+
VERSION_NAME = "5.10.5"
1010
USE_ORCHESTRATOR = project.hasProperty('orchestrator') ? project.property('orchestrator') : false
1111
}
1212

app/src/androidTest/java/com/duckduckgo/app/di/StubStatisticsModule.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.duckduckgo.app.statistics.api.StatisticsUpdater
2121
import com.duckduckgo.app.statistics.pixels.Pixel
2222
import dagger.Module
2323
import dagger.Provides
24+
import io.reactivex.Completable
2425
import retrofit2.Retrofit
2526

2627
@Module
@@ -44,8 +45,14 @@ class StubStatisticsModule {
4445
@Provides
4546
fun stubPixel(): Pixel {
4647
return object : Pixel {
48+
4749
override fun fire(pixel: Pixel.PixelName, parameters: Map<String, String?>) {
4850
}
51+
52+
override fun fireCompletable(pixel: Pixel.PixelName, parameters: Map<String, String?>): Completable {
53+
return Completable.fromAction {}
54+
}
55+
4956
}
5057
}
5158
}

app/src/main/java/com/duckduckgo/app/browser/BrowserWebViewClient.kt

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import com.duckduckgo.app.httpsupgrade.HttpsUpgrader
3232
import com.duckduckgo.app.statistics.pixels.Pixel
3333
import com.duckduckgo.app.statistics.pixels.Pixel.PixelName.HTTPS_UPGRADE_SITE_ERROR
3434
import com.duckduckgo.app.statistics.pixels.Pixel.PixelParameter
35+
import com.duckduckgo.app.statistics.store.StatisticsDataStore
3536
import timber.log.Timber
3637
import javax.inject.Inject
3738
import kotlin.concurrent.thread
@@ -42,6 +43,7 @@ class BrowserWebViewClient @Inject constructor(
4243
private val specialUrlDetector: SpecialUrlDetector,
4344
private val webViewRequestInterceptor: WebViewRequestInterceptor,
4445
private val httpsUpgrader: HttpsUpgrader,
46+
private val statisticsDataStore: StatisticsDataStore,
4547
private val pixel: Pixel
4648
) : WebViewClient() {
4749

@@ -105,6 +107,11 @@ class BrowserWebViewClient @Inject constructor(
105107
currentUrl = url
106108
webViewClientListener?.loadingStarted()
107109
webViewClientListener?.urlChanged(url)
110+
111+
val uri = if (url != null) Uri.parse(url) else null
112+
if (uri != null) {
113+
reportHttpsIfInUpgradeList(uri)
114+
}
108115
}
109116

110117
override fun onPageFinished(webView: WebView, url: String?) {
@@ -125,7 +132,7 @@ class BrowserWebViewClient @Inject constructor(
125132
override fun onReceivedError(view: WebView, errorCode: Int, description: String, failingUrl: String) {
126133
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
127134
val url = failingUrl.toUri()
128-
reportHttpsErrorIfInUpgradeList(url, statusCode = null, error = "WEB_RESOURCE_ERROR_$errorCode")
135+
reportHttpsErrorIfInUpgradeList(url, error = "WEB_RESOURCE_ERROR_$errorCode")
129136
}
130137
super.onReceivedError(view, errorCode, description, failingUrl)
131138
}
@@ -134,43 +141,46 @@ class BrowserWebViewClient @Inject constructor(
134141
@TargetApi(Build.VERSION_CODES.M)
135142
override fun onReceivedError(view: WebView, request: WebResourceRequest, error: WebResourceError) {
136143
if (request.isForMainFrame) {
137-
reportHttpsErrorIfInUpgradeList(request.url, statusCode = null, error = "WEB_RESOURCE_ERROR_${error.errorCode}")
144+
reportHttpsErrorIfInUpgradeList(request.url, error = "WEB_RESOURCE_ERROR_${error.errorCode}")
138145
}
139146
super.onReceivedError(view, request, error)
140147
}
141148

142-
@UiThread
143-
override fun onReceivedHttpError(view: WebView, request: WebResourceRequest, errorResponse: WebResourceResponse) {
144-
if (request.isForMainFrame) {
145-
reportHttpsErrorIfInUpgradeList(request.url, errorResponse.statusCode, error = null)
146-
}
147-
super.onReceivedHttpError(view, request, errorResponse)
148-
}
149-
150149
@UiThread
151150
override fun onReceivedSslError(view: WebView, handler: SslErrorHandler, error: SslError) {
152151
val uri = error.url.toUri()
153-
reportHttpsErrorIfInUpgradeList(uri, null, "SSL_ERROR_${error.primaryError}")
152+
val isMainFrameRequest = currentUrl == uri.toString()
153+
if (isMainFrameRequest) {
154+
reportHttpsErrorIfInUpgradeList(uri, "SSL_ERROR_${error.primaryError}")
155+
}
154156
super.onReceivedSslError(view, handler, error)
155157
}
156158

157159
@AnyThread
158-
private fun reportHttpsErrorIfInUpgradeList(url: Uri, statusCode: Int?, error: String?) {
159-
160+
private fun reportHttpsErrorIfInUpgradeList(url: Uri, error: String?) {
160161
if (!url.isHttps) return
162+
thread {
163+
if (httpsUpgrader.isInUpgradeList(url)) {
164+
reportHttpsUpgradeSiteError(url, error)
165+
statisticsDataStore.httpsUpgradesFailures += 1
166+
}
167+
}
168+
}
161169

170+
@AnyThread
171+
private fun reportHttpsIfInUpgradeList(url: Uri) {
172+
if (!url.isHttps) return
162173
thread {
163174
if (httpsUpgrader.isInUpgradeList(url)) {
164-
reportHttpsUpgradeSiteError(url, statusCode, error)
175+
statisticsDataStore.httpsUpgradesTotal += 1
165176
}
166177
}
167178
}
168179

169-
private fun reportHttpsUpgradeSiteError(url: Uri, statusCode: Int?, error: String?) {
180+
private fun reportHttpsUpgradeSiteError(url: Uri, error: String?) {
170181
val params = mapOf(
171182
PixelParameter.URL to url.simpleUrl,
172-
PixelParameter.ERROR_CODE to error,
173-
PixelParameter.STATUS_CODE to statusCode.toString()
183+
PixelParameter.ERROR_CODE to error
174184
)
175185
pixel.fire(HTTPS_UPGRADE_SITE_ERROR, params)
176186
}

app/src/main/java/com/duckduckgo/app/httpsupgrade/api/HttpsUpgradeDataDownloader.kt

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ import com.duckduckgo.app.httpsupgrade.db.HttpsBloomFilterSpecDao
2424
import com.duckduckgo.app.httpsupgrade.db.HttpsWhitelistDao
2525
import com.duckduckgo.app.httpsupgrade.model.HttpsBloomFilterSpec
2626
import com.duckduckgo.app.httpsupgrade.model.HttpsBloomFilterSpec.Companion.HTTPS_BINARY_FILE
27+
import com.duckduckgo.app.statistics.pixels.Pixel
28+
import com.duckduckgo.app.statistics.pixels.Pixel.PixelParameter.FAILURE_COUNT
29+
import com.duckduckgo.app.statistics.pixels.Pixel.PixelParameter.TOTAL_COUNT
30+
import com.duckduckgo.app.statistics.store.StatisticsDataStore
2731
import io.reactivex.Completable
28-
import io.reactivex.Completable.fromAction
32+
import io.reactivex.Completable.*
2933
import timber.log.Timber
3034
import java.io.IOException
3135
import javax.inject.Inject
@@ -36,7 +40,9 @@ class HttpsUpgradeDataDownloader @Inject constructor(
3640
private val httpsBloomSpecDao: HttpsBloomFilterSpecDao,
3741
private val whitelistDao: HttpsWhitelistDao,
3842
private val binaryDataStore: BinaryDataStore,
39-
private val appDatabase: AppDatabase
43+
private val appDatabase: AppDatabase,
44+
private val statisticsDataStore: StatisticsDataStore,
45+
private val pixel: Pixel
4046
) {
4147

4248
fun download(): Completable {
@@ -107,4 +113,23 @@ class HttpsUpgradeDataDownloader @Inject constructor(
107113

108114
}
109115

116+
fun reportUpgradeStatistics(): Completable {
117+
return defer {
118+
119+
if (statisticsDataStore.httpsUpgradesTotal == 0) {
120+
return@defer complete()
121+
}
122+
val params = mapOf(
123+
TOTAL_COUNT to statisticsDataStore.httpsUpgradesTotal.toString(),
124+
FAILURE_COUNT to statisticsDataStore.httpsUpgradesFailures.toString()
125+
)
126+
127+
pixel.fireCompletable(Pixel.PixelName.HTTPS_UPGRADE_SITE_SUMMARY, params).andThen {
128+
Timber.v("Sent https statistics")
129+
statisticsDataStore.httpsUpgradesTotal = 0
130+
statisticsDataStore.httpsUpgradesFailures = 0
131+
}
132+
}
133+
}
134+
110135
}

app/src/main/java/com/duckduckgo/app/job/AppConfigurationDownloader.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class AppConfigurationDownloader(
4343
val disconnectDownload = trackerDataDownloader.downloadList(DISCONNECT)
4444
val surrogatesDownload = resourceSurrogateDownloader.downloadList()
4545
val httpsUpgradeDownload = httpsUpgradeDataDownloader.download()
46+
val httpStatisticsReport = httpsUpgradeDataDownloader.reportUpgradeStatistics()
4647

4748
return Completable.mergeDelayError(
4849
listOf(
@@ -51,12 +52,15 @@ class AppConfigurationDownloader(
5152
trackersWhitelist,
5253
disconnectDownload,
5354
surrogatesDownload,
54-
httpsUpgradeDownload
55+
httpsUpgradeDownload,
56+
httpStatisticsReport
5557
)
5658
).doOnComplete {
5759
Timber.i("Download task completed successfully")
5860
val appConfiguration = AppConfigurationEntity(appConfigurationDownloaded = true)
5961
appDatabase.appConfigurationDao().configurationDownloadSuccessful(appConfiguration)
6062
}
6163
}
64+
65+
6266
}

app/src/main/java/com/duckduckgo/app/statistics/pixels/Pixel.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.duckduckgo.app.global.device.DeviceInfo
2020
import com.duckduckgo.app.statistics.VariantManager
2121
import com.duckduckgo.app.statistics.api.PixelService
2222
import com.duckduckgo.app.statistics.store.StatisticsDataStore
23+
import io.reactivex.Completable
2324
import io.reactivex.schedulers.Schedulers
2425
import timber.log.Timber
2526
import javax.inject.Inject
@@ -48,17 +49,21 @@ interface Pixel {
4849
LONG_PRESS_NEW_BACKGROUND_TAB("mlp_b"),
4950
LONG_PRESS_SHARE("mlp_s"),
5051

51-
HTTPS_UPGRADE_SITE_ERROR("ehd")
52+
HTTPS_UPGRADE_SITE_ERROR("ehd"),
53+
HTTPS_UPGRADE_SITE_SUMMARY("ehs")
5254
}
5355

5456
object PixelParameter {
5557
const val URL = "url"
56-
const val STATUS_CODE = "status_code"
5758
const val ERROR_CODE = "error_code"
59+
const val TOTAL_COUNT = "total"
60+
const val FAILURE_COUNT = "failures"
5861
}
5962

6063
fun fire(pixel: PixelName, parameters: Map<String, String?> = emptyMap())
6164

65+
fun fireCompletable(pixel: Pixel.PixelName, parameters: Map<String, String?>): Completable
66+
6267
}
6368

6469
class ApiBasedPixel @Inject constructor(
@@ -69,10 +74,7 @@ class ApiBasedPixel @Inject constructor(
6974
) : Pixel {
7075

7176
override fun fire(pixel: Pixel.PixelName, parameters: Map<String, String?>) {
72-
73-
val atb = statisticsDataStore.atb?.formatWithVariant(variantManager.getVariant()) ?: ""
74-
75-
api.fire(pixel.pixelName, deviceInfo.formFactor().description, atb, parameters)
77+
fireCompletable(pixel, parameters)
7678
.subscribeOn(Schedulers.io())
7779
.subscribe({
7880
Timber.v("Pixel sent: ${pixel.pixelName}")
@@ -81,4 +83,9 @@ class ApiBasedPixel @Inject constructor(
8183
})
8284
}
8385

86+
override fun fireCompletable(pixel: Pixel.PixelName, parameters: Map<String, String?>): Completable {
87+
val atb = statisticsDataStore.atb?.formatWithVariant(variantManager.getVariant()) ?: ""
88+
return api.fire(pixel.pixelName, deviceInfo.formFactor().description, atb, parameters)
89+
}
90+
8491
}

app/src/main/java/com/duckduckgo/app/statistics/store/StatisticsDataStore.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ interface StatisticsDataStore {
2323
val hasInstallationStatistics: Boolean
2424

2525
var atb: Atb?
26-
2726
var retentionAtb: String?
2827
var variant: String?
2928

29+
var httpsUpgradesTotal: Int
30+
var httpsUpgradesFailures: Int
31+
3032
fun saveAtb(atb: Atb)
3133
fun clearAtb()
3234
}

app/src/main/java/com/duckduckgo/app/statistics/store/StatisticsSharedPreferences.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ class StatisticsSharedPreferences @Inject constructor(private val context: Conte
4343
get() = preferences.getString(KEY_RETENTION_ATB, null)
4444
set(value) = preferences.edit { putString(KEY_RETENTION_ATB, value) }
4545

46+
override var httpsUpgradesTotal: Int
47+
get() = preferences.getInt(KEY_HTTPS_UPGRADES_TOTAL, 0)
48+
set(value) = preferences.edit { putInt(KEY_HTTPS_UPGRADES_TOTAL, value) }
49+
50+
override var httpsUpgradesFailures: Int
51+
get() = preferences.getInt(KEY_HTTPS_UPGRADES_FAILURES, 0)
52+
set(value) = preferences.edit { putInt(KEY_HTTPS_UPGRADES_FAILURES, value) }
53+
4654
override fun saveAtb(atb: Atb) {
4755
preferences.edit {
4856
putString(KEY_ATB, atb.version)
@@ -65,5 +73,7 @@ class StatisticsSharedPreferences @Inject constructor(private val context: Conte
6573
private const val KEY_ATB = "com.duckduckgo.app.statistics.atb"
6674
private const val KEY_RETENTION_ATB = "com.duckduckgo.app.statistics.retentionatb"
6775
private const val KEY_VARIANT = "com.duckduckgo.app.statistics.variant"
76+
private const val KEY_HTTPS_UPGRADES_TOTAL = "com.duckduckgo.app.statistics.httpsupgradestotal"
77+
private const val KEY_HTTPS_UPGRADES_FAILURES = "com.duckduckgo.app.statistics.httpsupgradesfailures"
6878
}
6979
}

0 commit comments

Comments
 (0)