-
Notifications
You must be signed in to change notification settings - Fork 937
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
423 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...impl/src/main/java/com/duckduckgo/autofill/impl/reporting/AutofillBreakageReportSender.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright (c) 2024 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.duckduckgo.autofill.impl.reporting | ||
|
||
import android.net.Uri | ||
import androidx.core.net.toUri | ||
import com.duckduckgo.app.di.AppCoroutineScope | ||
import com.duckduckgo.app.statistics.pixels.Pixel | ||
import com.duckduckgo.appbuildconfig.api.AppBuildConfig | ||
import com.duckduckgo.autofill.api.PrivacyProtectionStatus | ||
import com.duckduckgo.autofill.api.PrivacyProtectionStatus.Disabled | ||
import com.duckduckgo.autofill.api.PrivacyProtectionStatus.Enabled | ||
import com.duckduckgo.autofill.api.PrivacyProtectionStatus.Unknown | ||
import com.duckduckgo.autofill.api.email.EmailManager | ||
import com.duckduckgo.autofill.impl.AutofillGlobalCapabilityChecker | ||
import com.duckduckgo.autofill.impl.pixel.AutofillPixelNames.AUTOFILL_SITE_BREAKAGE_REPORT | ||
import com.duckduckgo.autofill.impl.store.NeverSavedSiteRepository | ||
import com.duckduckgo.common.utils.DispatcherProvider | ||
import com.duckduckgo.di.scopes.AppScope | ||
import com.squareup.anvil.annotations.ContributesBinding | ||
import dagger.SingleInstanceIn | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
import timber.log.Timber | ||
|
||
interface AutofillBreakageReportSender { | ||
fun sendBreakageReport( | ||
url: String, | ||
privacyProtectionStatus: PrivacyProtectionStatus, | ||
) | ||
} | ||
|
||
@SingleInstanceIn(AppScope::class) | ||
@ContributesBinding(AppScope::class) | ||
class AutofillBreakageReportSenderImpl @Inject constructor( | ||
private val appBuildConfig: AppBuildConfig, | ||
private val autofillCapabilityChecker: AutofillGlobalCapabilityChecker, | ||
private val pixel: Pixel, | ||
private val dispatchers: DispatcherProvider, | ||
@AppCoroutineScope private val appCoroutineScope: CoroutineScope, | ||
private val emailManager: EmailManager, | ||
private val neverSavedSiteRepository: NeverSavedSiteRepository, | ||
) : AutofillBreakageReportSender { | ||
|
||
/** | ||
* website: the URL + path of the website with all query parameters removed (to identify the page with an issue e.g. checkout form vs login page) | ||
* language: the app’s language setting (e.g. `en`, `fr`) as autofill issues are frequently language specific | ||
* autofill_enabled: whether the user has the autofill feature enabled (true / false) | ||
* privacy_protection : whether privacy protection was enabled for the site (true / false) | ||
* email_protection: whether a user has enabled email protection (true / false) | ||
* never_prompt: whether a user has decided if they want to be prompted to save logins for this site (true / false) | ||
*/ | ||
|
||
override fun sendBreakageReport( | ||
url: String, | ||
privacyProtectionStatus: PrivacyProtectionStatus, | ||
) { | ||
appCoroutineScope.launch(dispatchers.io()) { | ||
val params = mapOf( | ||
"website" to formatUrl(url), | ||
"language" to formatLanguage(), | ||
"autofill_enabled" to formatAutofillEnabledStatus(), | ||
"privacy_protection" to formatPrivacyProtectionStatus(privacyProtectionStatus), | ||
"email_protection" to formatEmailProtectionStatus(), | ||
"never_prompt" to formatNeverProtectThisSiteStatus(url), | ||
) | ||
Timber.d("Sending autofill breakage report %s", params) | ||
|
||
pixel.fire(AUTOFILL_SITE_BREAKAGE_REPORT, parameters = params) | ||
} | ||
} | ||
|
||
private suspend fun formatNeverProtectThisSiteStatus(url: String): String { | ||
return neverSavedSiteRepository.isInNeverSaveList(url).toString() | ||
} | ||
|
||
private fun formatEmailProtectionStatus(): String { | ||
return emailManager.isSignedIn().toString() | ||
} | ||
|
||
private fun formatPrivacyProtectionStatus(privacyProtectionStatus: PrivacyProtectionStatus): String { | ||
return when (privacyProtectionStatus) { | ||
Enabled -> true.toString() | ||
Disabled -> false.toString() | ||
Unknown -> "unknown" | ||
} | ||
} | ||
|
||
private suspend fun formatAutofillEnabledStatus(): String { | ||
return autofillCapabilityChecker.isAutofillEnabledByUser().toString() | ||
} | ||
|
||
private fun formatUrl(url: String): String { | ||
val uri = url.toUri() | ||
return Uri.Builder() | ||
.scheme(uri.scheme) | ||
.authority(uri.authority) | ||
.path(uri.path) | ||
.fragment(uri.fragment) | ||
.build() | ||
.toString() | ||
} | ||
|
||
private fun formatLanguage(): String { | ||
return appBuildConfig.deviceLocale.language | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.