For #24235 - Remove MasterPasswordTipProvider

upstream-sync
Gabriel Luong 2 years ago committed by mergify[bot]
parent 788b83bfaa
commit 0448530440

@ -1,252 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.components.tips.providers
import android.annotation.SuppressLint
import android.content.Context
import android.text.Editable
import android.text.TextWatcher
import android.view.LayoutInflater
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.view.isVisible
import com.google.android.material.button.MaterialButton
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import mozilla.components.concept.storage.Login
import mozilla.components.service.sync.logins.InvalidRecordException
import mozilla.components.service.sync.logins.LoginsStorageException
import mozilla.components.support.migration.FennecLoginsMPImporter
import mozilla.components.support.migration.FennecProfile
import org.mozilla.fenix.R
import org.mozilla.fenix.components.tips.Tip
import org.mozilla.fenix.components.tips.TipProvider
import org.mozilla.fenix.components.tips.TipType
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
/**
* Tip explaining to master password users how to migrate their logins.
*/
class MasterPasswordTipProvider(
private val context: Context,
private val navigateToLogins: () -> Unit,
private val dismissTip: (Tip) -> Unit
) : TipProvider {
private val fennecLoginsMPImporter: FennecLoginsMPImporter? by lazy {
FennecProfile.findDefault(
context,
context.components.analytics.crashReporter
)?.let {
FennecLoginsMPImporter(
it
)
}
}
override val tip: Tip? by lazy { masterPasswordMigrationTip() }
override val shouldDisplay: Boolean by lazy {
context.settings().shouldDisplayMasterPasswordMigrationTip &&
fennecLoginsMPImporter?.hasMasterPassword() == true
}
private fun masterPasswordMigrationTip(): Tip =
Tip(
type = TipType.Button(
text = context.getString(R.string.mp_homescreen_button),
action = ::showMasterPasswordMigration
),
identifier = context.getString(R.string.pref_key_master_password_tip),
title = context.getString(R.string.mp_homescreen_tip_title),
description = context.getString(R.string.mp_homescreen_tip_message),
learnMoreURL = null,
titleDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_login)
)
@SuppressLint("InflateParams")
private fun showMasterPasswordMigration() {
val dialogView = LayoutInflater.from(context).inflate(R.layout.mp_migration_dialog, null)
val dialogBuilder = AlertDialog.Builder(context).apply {
setTitle(context.getString(R.string.mp_dialog_title_recovery_transfer_saved_logins))
setMessage(context.getString(R.string.mp_dialog_message_recovery_transfer_saved_logins))
setView(dialogView)
create()
}
val dialog = dialogBuilder.show()
val passwordErrorText = context.getString(R.string.mp_dialog_error_transfer_saved_logins)
val migrationContinueButton =
dialogView.findViewById<MaterialButton>(R.id.migration_continue).apply {
alpha = HALF_OPACITY
isEnabled = false
}
val passwordView = dialogView.findViewById<TextInputEditText>(R.id.password_field)
val passwordLayout =
dialogView.findViewById<TextInputLayout>(R.id.password_text_input_layout)
passwordView.addTextChangedListener(
object : TextWatcher {
var isValid = false
override fun afterTextChanged(p: Editable?) {
when {
p.toString().isEmpty() -> {
isValid = false
passwordLayout.error = passwordErrorText
}
else -> {
val possiblePassword = passwordView.text.toString()
isValid =
fennecLoginsMPImporter?.checkPassword(possiblePassword) == true
passwordLayout.error = if (isValid) null else passwordErrorText
}
}
migrationContinueButton.alpha = if (isValid) 1F else HALF_OPACITY
migrationContinueButton.isEnabled = isValid
}
override fun beforeTextChanged(
p: CharSequence?,
start: Int,
count: Int,
after: Int
) {
// NOOP
}
override fun onTextChanged(p: CharSequence?, start: Int, before: Int, count: Int) {
// NOOP
}
})
migrationContinueButton.apply {
setOnClickListener {
// Step 1: Verify the password again before trying to use it
val possiblePassword = passwordView.text.toString()
val isValid = fennecLoginsMPImporter?.checkPassword(possiblePassword) == true
// Step 2: With valid MP, get logins and complete the migration
if (isValid) {
val logins = fennecLoginsMPImporter?.getLoginRecords(
possiblePassword,
context.components.analytics.crashReporter
)
if (logins.isNullOrEmpty()) {
showFailureDialog()
dialog.dismiss()
} else {
saveLogins(logins, dialog)
}
} else {
passwordView.error =
context?.getString(R.string.mp_dialog_error_transfer_saved_logins)
}
}
}
dialogView.findViewById<MaterialButton>(R.id.migration_cancel).apply {
setOnClickListener {
dialog.dismiss()
}
}
}
@SuppressLint("InflateParams")
private fun showFailureDialog() {
val dialogView =
LayoutInflater.from(context).inflate(R.layout.mp_migration_done_dialog, null)
val dialogBuilder = AlertDialog.Builder(context).apply {
setTitle(context.getString(R.string.mp_dialog_title_transfer_failure))
setMessage(context.getString(R.string.mp_dialog_message_transfer_failure))
setView(dialogView)
create()
}
val dialog = dialogBuilder.show()
dialogView.findViewById<MaterialButton>(R.id.positive_button).apply {
text = context.getString(R.string.mp_dialog_close_transfer)
setOnClickListener {
dismissMPTip()
dialog.dismiss()
}
}
dialogView.findViewById<MaterialButton>(R.id.negative_button).apply {
isVisible = false
}
}
private fun saveLogins(logins: List<Login>, dialog: AlertDialog) {
CoroutineScope(IO).launch {
try {
context.components.core.passwordsStorage.importLoginsAsync(logins)
} catch (e: InvalidRecordException) {
// This record was invalid and we couldn't save this login
context.components.analytics.crashReporter.submitCaughtException(e)
} catch (e: LoginsStorageException) {
// Some other error occurred
context.components.analytics.crashReporter.submitCaughtException(e)
}
withContext(Dispatchers.Main) {
// Step 3: Dismiss this dialog and show the success dialog
showSuccessDialog()
dialog.dismiss()
}
}
}
private fun dismissMPTip() {
tip?.let {
context.components.settings.preferences
.edit()
.putBoolean(it.identifier, false)
.apply()
dismissTip(it)
}
}
@SuppressLint("InflateParams")
private fun showSuccessDialog() {
dismissMPTip()
val dialogView =
LayoutInflater.from(context).inflate(R.layout.mp_migration_done_dialog, null)
val dialogBuilder = AlertDialog.Builder(context).apply {
setTitle(context.getString(R.string.mp_dialog_title_transfer_success))
setMessage(context.getString(R.string.mp_dialog_message_transfer_success))
setView(dialogView)
create()
}
val dialog = dialogBuilder.show()
dialogView.findViewById<MaterialButton>(R.id.positive_button).apply {
setOnClickListener {
navigateToLogins()
dialog.dismiss()
}
}
dialogView.findViewById<MaterialButton>(R.id.negative_button).apply {
setOnClickListener {
dialog.dismiss()
}
}
}
companion object {
private const val HALF_OPACITY = .5F
}
}

@ -90,8 +90,6 @@ import org.mozilla.fenix.components.TabCollectionStorage
import org.mozilla.fenix.components.accounts.AccountState
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.tips.FenixTipManager
import org.mozilla.fenix.components.tips.Tip
import org.mozilla.fenix.components.tips.providers.MasterPasswordTipProvider
import org.mozilla.fenix.components.toolbar.FenixTabCounterMenu
import org.mozilla.fenix.components.toolbar.ToolbarPosition
import org.mozilla.fenix.databinding.FragmentHomeBinding
@ -248,13 +246,7 @@ class HomeFragment : Fragment() {
topSites = getTopSites(components),
tip = components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
FenixTipManager(
listOf(
MasterPasswordTipProvider(
requireContext(),
::navToSavedLogins,
::dismissTip
)
)
listOf()
).getTip()
},
recentBookmarks = emptyList(),
@ -424,10 +416,6 @@ class HomeFragment : Fragment() {
displayWallpaperIfEnabled()
}
private fun dismissTip(tip: Tip) {
sessionControlInteractor.onCloseTip(tip)
}
/**
* Returns a [TopSitesConfig] which specifies how many top sites to display and whether or
* not frequently visited sites should be displayed.
@ -710,13 +698,7 @@ class HomeFragment : Fragment() {
topSites = getTopSites(components),
tip = components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
FenixTipManager(
listOf(
MasterPasswordTipProvider(
requireContext(),
::navToSavedLogins,
::dismissTip
)
)
listOf()
).getTip()
},
showCollectionPlaceholder = components.settings.showCollectionsPlaceholderOnHome,
@ -790,12 +772,6 @@ class HomeFragment : Fragment() {
}
}
private fun navToSavedLogins() {
findNavController().navigate(
HomeFragmentDirections.actionGlobalSavedLoginsAuthFragment()
)
}
private fun dispatchModeChanges(mode: Mode) {
if (mode != Mode.fromBrowsingMode(browsingModeManager.mode)) {
homeFragmentStore.dispatch(HomeFragmentAction.ModeChange(mode))

@ -204,11 +204,6 @@ class Settings(private val appContext: Context) : PreferencesHolder {
default = false
)
var shouldDisplayMasterPasswordMigrationTip by booleanPreference(
appContext.getString(R.string.pref_key_master_password_tip),
true
)
var shouldReturnToBrowser by booleanPreference(
appContext.getString(R.string.pref_key_return_to_browser),
false

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M21.25 11h-9.351A5.01 5.01 0 0 0 7 7c-2.757 0-5 2.243-5 5s2.243 5 5 5c2.586 0 4.694-1.98 4.949-4.5H18.5v2.75a0.75 0.75 0 0 0 1.5 0V12.5h1.25a0.75 0.75 0 0 0 0-1.5zM7 15.5c-1.93 0-3.5-1.57-3.5-3.5S5.07 8.5 7 8.5s3.5 1.57 3.5 3.5-1.57 3.5-3.5 3.5z"
android:fillColor="?attr/textPrimary" />
</vector>

@ -1,71 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<mozilla.components.feature.prompts.widget.LoginPanelTextInputLayout
android:id="@+id/password_text_input_layout"
style="@style/MozTextInputLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingStart="24dp"
android:paddingEnd="24dp"
app:errorEnabled="true"
app:errorIconDrawable="@null"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:passwordToggleDrawable="@drawable/mozac_ic_password_reveal_two_state"
app:passwordToggleEnabled="true"
app:passwordToggleTint="?attr/textPrimary">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/password_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/mozac_feature_prompt_password_hint"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:singleLine="true"
android:textColor="?attr/textPrimary"
android:textSize="16sp" />
</mozilla.components.feature.prompts.widget.LoginPanelTextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/migration_continue"
style="@style/PositiveButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="24dp"
android:text="@string/mp_dialog_positive_transfer_saved_logins"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/password_text_input_layout" />
<com.google.android.material.button.MaterialButton
android:id="@+id/migration_cancel"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:letterSpacing="0"
android:padding="10dp"
android:text="@string/mp_dialog_negative_transfer_saved_logins"
android:textAllCaps="false"
android:textColor="?attr/textPrimary"
android:textStyle="bold"
app:fontFamily="@font/metropolis_semibold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/migration_continue" />
<View
android:layout_width="match_parent"
android:layout_height="24dp"
app:layout_constraintTop_toBottomOf="@id/migration_cancel" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -1,42 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.button.MaterialButton
android:id="@+id/positive_button"
style="@style/PositiveButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:text="@string/mp_dialog_positive_transfer_success"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton
android:id="@+id/negative_button"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:letterSpacing="0"
android:padding="10dp"
android:text="@string/mp_dialog_close_transfer"
android:textAllCaps="false"
android:textColor="?attr/textPrimary"
android:textStyle="bold"
app:fontFamily="@font/metropolis_semibold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/positive_button" />
<View
android:layout_width="match_parent"
android:layout_height="24dp"
app:layout_constraintTop_toBottomOf="@id/negative_button" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -226,8 +226,6 @@
<!-- A value of `true` means the jump back in onboarding popup has not been shown yet -->
<string name="pref_key_should_show_jump_back_in_tabs_popup" translatable="false">pref_key_should_show_jump_back_in_tabs_popup</string>
<string name="pref_key_master_password_tip" translatable="false">pref_key_master_password_tip</string>
<string name="pref_key_debug_settings" translatable="false">pref_key_debug_settings</string>
<string name="pref_key_open_tabs_count" translatable="false">pref_key_open_tabs_count</string>

@ -55,22 +55,6 @@
<!-- Name of the application for about page -->
<string name="daylight_app_name" translatable="false">Firefox Daylight</string>
<!-- MP Migration -->
<string name="mp_homescreen_tip_title">Looking for your logins?</string>
<string name="mp_homescreen_tip_message">If you had a master password before Firefox updated, youll need to enter it to transfer your saved logins.</string>
<string name="mp_homescreen_button">Enter master password</string>
<string name="mp_dialog_title_recovery_transfer_saved_logins">Transfer saved logins</string>
<string name="mp_dialog_message_recovery_transfer_saved_logins">Enter your previous master password.</string>
<string name="mp_dialog_positive_transfer_saved_logins">Continue and transfer</string>
<string name="mp_dialog_negative_transfer_saved_logins">Cancel</string>
<string name="mp_dialog_error_transfer_saved_logins">Invalid password</string>
<string name="mp_dialog_title_transfer_success">Transfer successful</string>
<string name="mp_dialog_message_transfer_success">Your saved logins have been transferred to Firefox.</string>
<string name="mp_dialog_positive_transfer_success">View saved logins</string>
<string name="mp_dialog_close_transfer">Close</string>
<string name="mp_dialog_title_transfer_failure">Transfer failed</string>
<string name="mp_dialog_message_transfer_failure">An unknown error occurred and logins could not be transferred.</string>
<!-- Secret debug info strings -->
<string name="debug_info_region_home" translatable="false">Home region</string>
<string name="debug_info_region_current" translatable="false">Current region</string>

Loading…
Cancel
Save