-
Notifications
You must be signed in to change notification settings - Fork 942
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add feature flag for importing passwords via Google Password Manager
- Loading branch information
Showing
3 changed files
with
174 additions
and
0 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
85 changes: 85 additions & 0 deletions
85
...kduckgo/autofill/impl/importing/gpm/feature/AutofillImportPasswordFeatureSettingsStore.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,85 @@ | ||
/* | ||
* 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.importing.gpm.feature | ||
|
||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.core.stringPreferencesKey | ||
import com.duckduckgo.autofill.impl.di.AutofillModule.AutofillImportPasswordsFeatureDataStore | ||
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.flow.firstOrNull | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.withContext | ||
|
||
interface AutofillImportPasswordsFeatureStore { | ||
suspend fun updateAutofillImportPasswordsSettings(json: String) | ||
suspend fun getAutofillImportPasswordsSettings(): String | ||
} | ||
|
||
@ContributesBinding(AppScope::class, boundType = AutofillImportPasswordsFeatureStore::class) | ||
@SingleInstanceIn(AppScope::class) | ||
class AutofillImportPasswordsFeatureStoreImpl @Inject constructor( | ||
private val dispatchers: DispatcherProvider, | ||
@AutofillImportPasswordsFeatureDataStore private val dataStore: DataStore<Preferences>, | ||
) : AutofillImportPasswordsFeatureStore { | ||
|
||
override suspend fun updateAutofillImportPasswordsSettings(json: String) { | ||
withContext(dispatchers.io()) { | ||
dataStore.edit { | ||
it[settingsKey] = json | ||
} | ||
} | ||
} | ||
override suspend fun getAutofillImportPasswordsSettings(): String { | ||
return withContext(dispatchers.io()) { | ||
dataStore.data.map { | ||
it[settingsKey] ?: DEFAULT_SETTINGS | ||
}.firstOrNull() ?: DEFAULT_SETTINGS | ||
} | ||
} | ||
|
||
companion object { | ||
val settingsKey = stringPreferencesKey("settings") | ||
// private const val DEFAULT_SETTINGS = "{}" | ||
|
||
// this is temporary until the remote config is finalized and live. Then can revert this to the commented out line above. | ||
private const val DEFAULT_SETTINGS = """ | ||
{ | ||
"settingsButton": { | ||
"shouldAutotap": false, | ||
"selectors": ["a[href*='options']"], | ||
"labelTexts": ['Password options'] | ||
}, | ||
"exportButton": { | ||
"shouldAutotap": false, | ||
"selectors": ["c-wiz[data-node-index*='2;0'][data-p*='options']", "c-wiz[data-p*='options'][jsdata='deferred-i4']"], | ||
"labelTexts": ['Export'] | ||
}, | ||
"signInButton": { | ||
"shouldAutotap": false, | ||
"selectors": ['a[href*="ServiceLogin"]:not([target="_top"])', 'a[aria-label="Sign in"]:not([target="_top"])'], | ||
"labelTexts": ['Sign in'] | ||
} | ||
} | ||
""" | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...java/com/duckduckgo/autofill/impl/importing/gpm/feature/AutofillImportPasswordsFeature.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,70 @@ | ||
/* | ||
* 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.importing.gpm.feature | ||
|
||
import com.duckduckgo.anvil.annotations.ContributesRemoteFeature | ||
import com.duckduckgo.app.di.AppCoroutineScope | ||
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 = AutofillImportPasswordsFeature::class, | ||
featureName = "autofillImportPasswords", | ||
settingsStore = SettingsStore::class, | ||
) | ||
/** | ||
* This is the class that represents the feature flag for allowing users to import passwords. | ||
*/ | ||
interface AutofillImportPasswordsFeature { | ||
/** | ||
* @return `true` when the remote config has the global "autofillImportPasswords" feature flag enabled | ||
* | ||
* If the remote feature is not present defaults to `false` | ||
*/ | ||
|
||
@InternalAlwaysEnabled | ||
@Toggle.DefaultValue(false) | ||
fun self(): Toggle | ||
|
||
@InternalAlwaysEnabled | ||
@Toggle.DefaultValue(false) | ||
fun canImportFromGooglePasswordManager(): Toggle | ||
} | ||
|
||
@ContributesBinding(AppScope::class) | ||
@RemoteFeatureStoreNamed(AutofillImportPasswordsFeature::class) | ||
class SettingsStore @Inject constructor( | ||
@AppCoroutineScope private val appCoroutineScope: CoroutineScope, | ||
private val dispatchers: DispatcherProvider, | ||
private val store: AutofillImportPasswordsFeatureStore, | ||
) : FeatureSettings.Store { | ||
|
||
override fun store(jsonString: String) { | ||
appCoroutineScope.launch(dispatchers.io()) { | ||
store.updateAutofillImportPasswordsSettings(jsonString) | ||
} | ||
} | ||
} |