Skip to content

Commit

Permalink
fix wrong rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
cmonfortep committed Feb 5, 2025
1 parent 02b2608 commit 3844218
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,8 @@

package com.duckduckgo.autofill.impl.ui.credential.management

import android.app.Activity
import android.app.assist.AssistStructure
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.service.autofill.Dataset
import android.view.WindowManager
import android.view.autofill.AutofillManager
import android.view.autofill.AutofillValue
import android.widget.RemoteViews
import androidx.annotation.DrawableRes
import androidx.core.content.IntentCompat
import androidx.core.view.isVisible
import androidx.fragment.app.commit
import androidx.fragment.app.commitNow
Expand All @@ -49,12 +39,6 @@ import com.duckduckgo.autofill.impl.deviceauth.DeviceAuthenticator
import com.duckduckgo.autofill.impl.deviceauth.DeviceAuthenticator.AuthResult.Error
import com.duckduckgo.autofill.impl.deviceauth.DeviceAuthenticator.AuthResult.Success
import com.duckduckgo.autofill.impl.deviceauth.DeviceAuthenticator.AuthResult.UserCancelled
import com.duckduckgo.autofill.impl.service.AutofillFieldType
import com.duckduckgo.autofill.impl.service.AutofillFieldType.UNKNOWN
import com.duckduckgo.autofill.impl.service.AutofillParser
import com.duckduckgo.autofill.impl.service.AutofillRootNode
import com.duckduckgo.autofill.impl.service.ParsedAutofillField
import com.duckduckgo.autofill.impl.ui.credential.management.AutofillSettingsViewModel.Command.AutofillLogin
import com.duckduckgo.autofill.impl.ui.credential.management.AutofillSettingsViewModel.Command.ExitCredentialMode
import com.duckduckgo.autofill.impl.ui.credential.management.AutofillSettingsViewModel.Command.ExitDisabledMode
import com.duckduckgo.autofill.impl.ui.credential.management.AutofillSettingsViewModel.Command.ExitListMode
Expand Down Expand Up @@ -114,20 +98,13 @@ class AutofillManagementActivity : DuckDuckGoActivity(), PasswordsScreenPromotio
@Inject
lateinit var settingsPageFeature: SettingsPageFeature

@Inject
lateinit var autofillParser: AutofillParser

private var assistStructure: AssistStructure? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

if (deviceAuthenticator.isAuthenticationRequiredForAutofill()) {
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
}

assistStructure = IntentCompat.getParcelableExtra(intent, AutofillManager.EXTRA_ASSIST_STRUCTURE, AssistStructure::class.java)

setContentView(binding.root)
setupToolbar(binding.toolbar)
observeViewModel()
Expand Down Expand Up @@ -232,7 +209,6 @@ class AutofillManagementActivity : DuckDuckGoActivity(), PasswordsScreenPromotio
is ExitLockedMode -> exitLockedMode()
is ExitDisabledMode -> exitDisabledMode()
is ExitListMode -> exitListMode()
is AutofillLogin -> autofillLogin(command)
else -> processed = false
}
if (processed) {
Expand All @@ -241,147 +217,6 @@ class AutofillManagementActivity : DuckDuckGoActivity(), PasswordsScreenPromotio
}
}

private fun autofillLogin(command: AutofillLogin) {
val structure = assistStructure ?: return
val parsedNodes = autofillParser.parseStructure(structure)
val detectedNode: Pair<AutofillRootNode, ParsedAutofillField>? = parsedNodes.firstNotNullOfOrNull { node ->
val focusedDetectedField = node.parsedAutofillFields
.firstOrNull { field ->
field.originalNode.isFocused && field.type != UNKNOWN
}
if (focusedDetectedField != null) {
return@firstNotNullOfOrNull Pair(node, focusedDetectedField)
}
val firstDetectedField = node.parsedAutofillFields.firstOrNull { field -> field.type != UNKNOWN }
if (firstDetectedField != null) {
return@firstNotNullOfOrNull Pair(node, firstDetectedField)
}
return@firstNotNullOfOrNull null
}

if (detectedNode == null) {
return
}

val fields = detectedNode.first.parsedAutofillFields.filter { it.type != UNKNOWN }

val dataset = buildDataset(fields, command)

val resultIntent = Intent().apply {
putExtra(AutofillManager.EXTRA_AUTHENTICATION_RESULT, dataset)
}
this.setResult(Activity.RESULT_OK, resultIntent)
this.finish()
}

private fun buildDataset(
fields: List<ParsedAutofillField>,
command: AutofillLogin,
): Dataset {
val datasetBuilder = Dataset.Builder()
fields.forEach { fieldsToAutofill ->
val suggestionTitle = "name ${fieldsToAutofill.autofillId}"
val suggestionSubtitle = "subtitle"
val icon = R.drawable.ic_autofill_color_24
// >= android 11
/*val isInlineSupported = if (inlinePresentationSpec != null ) {
UiVersions.getVersions(inlinePresentationSpec.style).contains(UiVersions.INLINE_UI_VERSION_1)
} else {
false
}
if (isInlineSupported) {
val slice = InlineSuggestionUi.newContentBuilder(
PendingIntent.getService(
this,
0,
Intent(),
PendingIntent.FLAG_ONE_SHOT or
PendingIntent.FLAG_UPDATE_CURRENT or
PendingIntent.FLAG_IMMUTABLE,
),
).setTitle(suggestionTitle)
.setSubtitle(suggestionSubtitle)
.setStartIcon(Icon.createWithResource(this, icon))
.build().slice
val inlinePresentation = InlinePresentation(slice, inlinePresentationSpec!!, false)
datasetBuilder.setInlinePresentation(inlinePresentation)
}*/

// Supported in all android apis
val remoteView = buildAutofillRemoteViews(
name = suggestionTitle,
subtitle = suggestionSubtitle,
iconRes = icon,
shouldTintIcon = false,
)
datasetBuilder.setValue(
fieldsToAutofill.autofillId,
if (fieldsToAutofill.type == AutofillFieldType.USERNAME) {
AutofillValue.forText(command.credentials.username)
} else {
AutofillValue.forText(command.credentials.password)
},
remoteView,
)

fieldsToAutofill.autofillId
}
return datasetBuilder.build()
}

private fun buildAutofillRemoteViews(
// autofillContentDescription: String?,
name: String,
subtitle: String,
@DrawableRes iconRes: Int,
shouldTintIcon: Boolean,
): RemoteViews =
RemoteViews(
packageName,
R.layout.autofill_remote_view,
).apply {
/*autofillContentDescription?.let {
setContentDescription(
R.id.container,
it,
)
}*/
setTextViewText(
R.id.title,
name,
)
setTextViewText(
R.id.subtitle,
subtitle,
)
setImageViewResource(
R.id.icon,
iconRes,
)
/*setInt(
R.id.container,
"setBackgroundColor",
Color.CYAN,
)*/
setInt(
R.id.title,
"setTextColor",
Color.BLACK,
)
setInt(
R.id.subtitle,
"setTextColor",
Color.BLACK,
)
if (shouldTintIcon) {
setInt(
R.id.icon,
"setColorFilter",
Color.BLACK,
)
}
}

private fun showCopiedToClipboardSnackbar(dataType: CopiedToClipboardDataType) {
val stringResourceId = when (dataType) {
is CopiedToClipboardDataType.Username -> R.string.autofillManagementUsernameCopied
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import com.duckduckgo.autofill.impl.reporting.AutofillBreakageReportSender
import com.duckduckgo.autofill.impl.reporting.AutofillSiteBreakageReportingDataStore
import com.duckduckgo.autofill.impl.store.InternalAutofillStore
import com.duckduckgo.autofill.impl.store.NeverSavedSiteRepository
import com.duckduckgo.autofill.impl.ui.credential.management.AutofillSettingsViewModel.Command.AutofillLogin
import com.duckduckgo.autofill.impl.ui.credential.management.AutofillSettingsViewModel.Command.ExitCredentialMode
import com.duckduckgo.autofill.impl.ui.credential.management.AutofillSettingsViewModel.Command.ExitDisabledMode
import com.duckduckgo.autofill.impl.ui.credential.management.AutofillSettingsViewModel.Command.ExitListMode
Expand Down Expand Up @@ -199,13 +198,12 @@ class AutofillSettingsViewModel @Inject constructor(
fun onViewCredentials(
credentials: LoginCredentials,
) {
addCommand(AutofillLogin(credentials))
/*_viewState.value = viewState.value.copy(
_viewState.value = viewState.value.copy(
credentialMode = Viewing(credentialsViewed = credentials, showLinkButton = credentials.shouldShowLinkButton()),
)
addCommand(ShowCredentialMode)

updateDuckAddressStatus(credentials.username)*/
updateDuckAddressStatus(credentials.username)
}

fun onCreateNewCredentials() {
Expand Down Expand Up @@ -865,7 +863,6 @@ class AutofillSettingsViewModel @Inject constructor(
class OfferUserUndoDeletion(val credentials: LoginCredentials?) : Command()
class OfferUserUndoMassDeletion(val credentials: List<LoginCredentials>) : Command()

class AutofillLogin(val credentials: LoginCredentials) : Command()
object ShowListMode : Command()
object ShowCredentialMode : Command()
object ShowDisabledMode : Command()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ class AutofillManagementListMode : DuckDuckGoFragment(R.layout.fragment_autofill

private fun getCurrentSiteUrl() = arguments?.getString(ARG_CURRENT_URL, null)
private fun getPrivacyProtectionEnabled() = arguments?.getBoolean(ARG_PRIVACY_PROTECTION_STATUS)
private fun isLaunchedFromAutofill() = arguments?.getBoolean(ARG_AUTOFILL_MODE_LAUNCH, false)
private fun getAutofillSettingsLaunchSource(): AutofillSettingsLaunchSource? =
arguments?.getSerializable(ARG_AUTOFILL_SETTINGS_LAUNCH_SOURCE) as AutofillSettingsLaunchSource?

Expand Down Expand Up @@ -655,7 +654,6 @@ class AutofillManagementListMode : DuckDuckGoFragment(R.layout.fragment_autofill
currentUrl: String? = null,
privacyProtectionEnabled: Boolean?,
source: AutofillSettingsLaunchSource? = null,
autofillMode: Boolean = true,
) =
AutofillManagementListMode().apply {
arguments = Bundle().apply {
Expand All @@ -668,15 +666,12 @@ class AutofillManagementListMode : DuckDuckGoFragment(R.layout.fragment_autofill
if (source != null) {
putSerializable(ARG_AUTOFILL_SETTINGS_LAUNCH_SOURCE, source)
}

putBoolean(ARG_AUTOFILL_MODE_LAUNCH, autofillMode)
}
}

private const val ARG_CURRENT_URL = "ARG_CURRENT_URL"
private const val ARG_PRIVACY_PROTECTION_STATUS = "ARG_PRIVACY_PROTECTION_STATUS"
private const val ARG_AUTOFILL_SETTINGS_LAUNCH_SOURCE = "ARG_AUTOFILL_SETTINGS_LAUNCH_SOURCE"
private const val ARG_AUTOFILL_MODE_LAUNCH = "ARG_AUTOFILL_MODE_LAUNCH"
private const val LEARN_MORE_LINK = "https://duckduckgo.com/duckduckgo-help-pages/sync-and-backup/password-manager-security/"
private const val IMPORT_FROM_GPM_DIALOG_TAG = "IMPORT_FROM_GPM_DIALOG_TAG"
}
Expand Down
Loading

0 comments on commit 3844218

Please sign in to comment.