-
Notifications
You must be signed in to change notification settings - Fork 950
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support showing autofill surveys based on remote config (#4981)
Task/Issue URL: https://app.asana.com/0/488551667048375/1207935899042228/f ### Description Adds support for consuming autofill surveys from remote config, and converts the autofill survey UI to make use of the new `PasswordsScreenPromotionPlugin` framework. ### Steps to test this PR **Test nothing has broken when no surveys available** - [x] Fresh install, visit `Passwords` screen - [x] Verify there is no survey showing. - [x] Verify there is no sync promo showing. - [x] Add a password (manually or through autofill), then return visit `Passwords` screen again; verify sync promo shows **Test survey shows when it is available** - [x] Apply patch to fake a remote config survey being available (see patch below) - [x] Launch the app and visit `Passwords` screen; verify the survey shows - [x] Verify `m_autofill_management_screen_visit_survey_available` pixel shows in logs **Test dismissing the survey** - [x] Dismiss the survey prompt; verify it goes away - [x] Verify you see the sync promo (if you still have >= 1 saved passwords) **Test taking the survey** - [x] Either do a fresh install, or use `Settings` -> `Autofill Dev Settings` -> `Previously Seen Surveys` to reset state - [x] Visit `Passwords` screen, and tap `Take Survey` button - [x] Verify it loads in a tab and the survey is shown (don't worry about the survey contents itself; still being refined) - [x] Return to the `Passwords` screen; verify the survey prompt does **not** show ### UI changes  ### Patch for testing Right now, there is no survey active in remote config, so you can use this patch to see a survey. ``` Index: privacy-config/privacy-config-api/src/main/java/com/duckduckgo/privacy/config/api/PrivacyFeatureName.kt IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/privacy-config/privacy-config-api/src/main/java/com/duckduckgo/privacy/config/api/PrivacyFeatureName.kt b/privacy-config/privacy-config-api/src/main/java/com/duckduckgo/privacy/config/api/PrivacyFeatureName.kt --- a/privacy-config/privacy-config-api/src/main/java/com/duckduckgo/privacy/config/api/PrivacyFeatureName.kt (revision Staged) +++ b/privacy-config/privacy-config-api/src/main/java/com/duckduckgo/privacy/config/api/PrivacyFeatureName.kt (date 1725364069768) @@ -27,4 +27,5 @@ TrackingParametersFeatureName("trackingParameters"), } -const val PRIVACY_REMOTE_CONFIG_URL = "https://staticcdn.duckduckgo.com/trackerblocking/config/v4/android-config.json" +// const val PRIVACY_REMOTE_CONFIG_URL = "https://staticcdn.duckduckgo.com/trackerblocking/config/v4/android-config.json" +const val PRIVACY_REMOTE_CONFIG_URL = "https://jsonblob.com/api/1280153728681107456" ```
- Loading branch information
Showing
24 changed files
with
558 additions
and
221 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
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
67 changes: 67 additions & 0 deletions
67
...ava/com/duckduckgo/autofill/impl/ui/credential/management/survey/AutofillSurveyFeature.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,67 @@ | ||
/* | ||
* 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.ui.credential.management.survey | ||
|
||
import com.duckduckgo.anvil.annotations.ContributesRemoteFeature | ||
import com.duckduckgo.app.di.AppCoroutineScope | ||
import com.duckduckgo.autofill.impl.reporting.remoteconfig.AutofillSiteBreakageReportingRemoteSettingsPersister | ||
import com.duckduckgo.common.utils.DispatcherProvider | ||
import com.duckduckgo.di.scopes.AppScope | ||
import com.duckduckgo.feature.toggles.api.FeatureSettings | ||
import com.duckduckgo.feature.toggles.api.RemoteFeatureStoreNamed | ||
import com.duckduckgo.feature.toggles.api.Toggle | ||
import com.duckduckgo.feature.toggles.api.Toggle.InternalAlwaysEnabled | ||
import com.squareup.anvil.annotations.ContributesBinding | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
|
||
@ContributesRemoteFeature( | ||
scope = AppScope::class, | ||
boundType = AutofillSurveysFeature::class, | ||
featureName = "autofillSurveys", | ||
settingsStore = AutofillSiteBreakageReportingRemoteSettingsPersister::class, | ||
) | ||
/** | ||
* This is the class that represents the feature flag for showing autofill user-surveys. | ||
*/ | ||
interface AutofillSurveysFeature { | ||
/** | ||
* @return `true` when the remote config has the global "autofillSurveys" feature flag enabled | ||
* | ||
* If the remote feature is not present defaults to `false` | ||
*/ | ||
|
||
@InternalAlwaysEnabled | ||
@Toggle.DefaultValue(false) | ||
fun self(): Toggle | ||
} | ||
|
||
@ContributesBinding(AppScope::class) | ||
@RemoteFeatureStoreNamed(AutofillSurveysFeature::class) | ||
class AutofillSurveyFeatureSettingsStore @Inject constructor( | ||
private val autofillSurveyStore: AutofillSurveyStore, | ||
@AppCoroutineScope private val appCoroutineScope: CoroutineScope, | ||
private val dispatchers: DispatcherProvider, | ||
) : FeatureSettings.Store { | ||
|
||
override fun store(jsonString: String) { | ||
appCoroutineScope.launch(dispatchers.io()) { | ||
autofillSurveyStore.updateAvailableSurveys(jsonString) | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
.../com/duckduckgo/autofill/impl/ui/credential/management/survey/AutofillSurveyJsonParser.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,62 @@ | ||
/* | ||
* 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.ui.credential.management.survey | ||
|
||
import com.duckduckgo.di.scopes.AppScope | ||
import com.squareup.anvil.annotations.ContributesBinding | ||
import com.squareup.moshi.JsonAdapter | ||
import com.squareup.moshi.Moshi | ||
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory | ||
import javax.inject.Inject | ||
|
||
interface AutofillSurveyJsonParser { | ||
suspend fun parseJson(json: String?): List<SurveyDetails> | ||
} | ||
|
||
@ContributesBinding(AppScope::class) | ||
class AutofillSurveyJsonParserImpl @Inject constructor() : AutofillSurveyJsonParser { | ||
|
||
private val jsonAdapter by lazy { buildJsonAdapter() } | ||
|
||
private fun buildJsonAdapter(): JsonAdapter<AutofillSettingsJson> { | ||
val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build() | ||
return moshi.adapter(AutofillSettingsJson::class.java) | ||
} | ||
|
||
override suspend fun parseJson(json: String?): List<SurveyDetails> { | ||
if (json == null) return emptyList() | ||
|
||
return kotlin.runCatching { | ||
val surveyDetailsJson = jsonAdapter.fromJson(json) | ||
return surveyDetailsJson?.surveys?.asSurveyDetails() ?: emptyList() | ||
}.getOrDefault(emptyList()) | ||
} | ||
|
||
private fun List<SurveyDetailsJson>?.asSurveyDetails(): List<SurveyDetails> { | ||
if (this == null) return emptyList() | ||
return this.map { SurveyDetails(id = it.id, url = it.url) } | ||
} | ||
|
||
data class AutofillSettingsJson( | ||
val surveys: List<SurveyDetailsJson>, | ||
) | ||
|
||
data class SurveyDetailsJson( | ||
val id: String, | ||
val url: String, | ||
) | ||
} |
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.