Commit 75b8a52c authored by Ioana Pandele's avatar Ioana Pandele Committed by Commit Bot

[Android] Configure leak detection toggle

This CL makes sure that the toggle is disabled and displayed as off
when the feature cannot be used and replaces the old strings.

Bug:986322

Change-Id: Idccdfb16755095a46ff5e05db5e3d2daaa7e6285
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1787544
Commit-Queue: Ioana Pandele <ioanap@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693866}
parent 5ebe501b
......@@ -30,6 +30,7 @@ public final class PasswordUIView implements PasswordManagerHandler {
/**
* Constructor creates the native object as well. Callers should call destroy() after usage.
*
* @param PasswordListObserver The only observer.
*/
public PasswordUIView(PasswordListObserver observer) {
......@@ -95,12 +96,17 @@ public final class PasswordUIView implements PasswordManagerHandler {
/**
* Returns the URL for the website for managing one's passwords without the need to use Chrome
* with the user's profile signed in.
*
* @return The string with the URL.
*/
public static String getAccountDashboardURL() {
return nativeGetAccountDashboardURL();
}
public static boolean hasAccountForLeakCheckRequest() {
return nativeHasAccountForLeakCheckRequest();
}
/**
* Destroy the native object.
*/
......@@ -132,6 +138,8 @@ public final class PasswordUIView implements PasswordManagerHandler {
private static native String nativeGetAccountDashboardURL();
private static native boolean nativeHasAccountForLeakCheckRequest();
private native void nativeDestroy(long nativePasswordUIViewAndroid);
private native void nativeHandleSerializePasswords(long nativePasswordUIViewAndroid,
......
......@@ -34,7 +34,6 @@ import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.preferences.PreferencesLauncher;
import org.chromium.chrome.browser.preferences.SearchUtils;
import org.chromium.chrome.browser.preferences.TextMessagePreference;
import org.chromium.components.signin.ChromeSigninController;
import org.chromium.ui.text.SpanApplier;
import java.util.Locale;
......@@ -210,12 +209,7 @@ public class SavePasswordsPreferences
getPreferenceScreen().removeAll();
if (mSearchQuery == null) {
createSavePasswordsSwitch();
ChromeSigninController signInController = ChromeSigninController.get();
if (signInController != null && signInController.isSignedIn()) {
createAutoLeakDetectionSwitch();
}
createAutoLeakDetectionSwitch();
createAutoSignInCheckbox();
}
PasswordManagerHandlerProvider.getInstance()
......@@ -448,16 +442,32 @@ public class SavePasswordsPreferences
mAutoLeakDetectionSwitch.setKey(PREF_LEAK_DETECTION_SWITCH);
mAutoLeakDetectionSwitch.setTitle(R.string.passwords_leak_detection_switch_title);
mAutoLeakDetectionSwitch.setOrder(ORDER_AUTO_LEAK_DETECTION_SWITCH);
mAutoLeakDetectionSwitch.setSummary(R.string.passwords_leak_detection_switch_description);
mAutoLeakDetectionSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
PrefServiceBridge.getInstance().setPasswordLeakDetectionEnabled((boolean) newValue);
return true;
});
mAutoLeakDetectionSwitch.setManagedPreferenceDelegate(
preference -> PrefServiceBridge.getInstance().isPasswordLeakDetectionManaged());
getPreferenceScreen().addPreference(mAutoLeakDetectionSwitch);
mAutoLeakDetectionSwitch.setChecked(
PrefServiceBridge.getInstance().isPasswordLeakDetectionEnabled());
if (PasswordUIView.hasAccountForLeakCheckRequest()) {
mAutoLeakDetectionSwitch.setChecked(
PrefServiceBridge.getInstance().isPasswordLeakDetectionEnabled());
mAutoLeakDetectionSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
PrefServiceBridge.getInstance().setPasswordLeakDetectionEnabled((boolean) newValue);
return true;
});
mAutoLeakDetectionSwitch.setSummary(
R.string.passwords_leak_detection_switch_signed_in_description);
} else {
mAutoLeakDetectionSwitch.setChecked(false);
mAutoLeakDetectionSwitch.setEnabled(false);
mAutoLeakDetectionSwitch.setOnPreferenceClickListener(null);
if (PrefServiceBridge.getInstance().isPasswordLeakDetectionEnabled()) {
mAutoLeakDetectionSwitch.setSummary(
R.string.passwords_leak_detection_switch_signed_out_full_description);
} else {
mAutoLeakDetectionSwitch.setSummary(
R.string.passwords_leak_detection_switch_signed_out_partial_description);
}
}
}
private void displayManageAccountLink() {
......
......@@ -560,9 +560,15 @@ CHAR-LIMIT guidelines:
<message name="IDS_PASSWORDS_LEAK_DETECTION_SWITCH_TITLE" desc="Title for the switch toggling whether Chrome should check that entered credentials have been part of a leak.">
Check password safety
</message>
<message name="IDS_PASSWORDS_LEAK_DETECTION_SWITCH_DESCRIPTION" desc="Description for the switch toggling whether Chrome should check that entered credentials have been part of a leak.">
<message name="IDS_PASSWORDS_LEAK_DETECTION_SWITCH_SIGNED_IN_DESCRIPTION" desc="Description for the switch toggling whether Chrome should check that entered credentials have been part of a leak.">
Warns you if a password you use was part of a data breach
</message>
<message name="IDS_PASSWORDS_LEAK_DETECTION_SWITCH_SIGNED_OUT_FULL_DESCRIPTION" desc="Description for the switch toggling whether Chrome should check that entered credentials have been part of a leak. Displayed for users who are not signed in and syncing.">
Google can check if your passwords were part of a data breach. This will be turned on when you sign in with your Google Account and turn on sync.
</message>
<message name="IDS_PASSWORDS_LEAK_DETECTION_SWITCH_SIGNED_OUT_PARTIAL_DESCRIPTION" desc="Description for the switch toggling whether Chrome should check that entered credentials have been part of a leak. Displayed for users who are not signed in and syncing who have at some point in time disabled the feature manually">
Google can check if your passwords were part of a data breach
</message>
<message name="IDS_SECTION_SAVED_PASSWORDS_EXCEPTIONS" desc="Header for the list of websites for which user selected to never save passwords. [CHAR-LIMIT=32]">
Never saved
</message>
......
......@@ -576,71 +576,6 @@ public class SavePasswordsPreferencesTest {
});
}
@Test
@SmallTest
@Feature({"Preferences"})
@Features.EnableFeatures({SavePasswordsPreferences.PASSWORD_LEAK_DETECTION_FEATURE})
public void testLeakDetectionSwitchEnabled() throws Exception {
// The switch is only displayed for signed in users.
ChromeSigninController.get().setSignedInAccountName("Test Account");
TestThreadUtils.runOnUiThreadBlocking(
() -> { PrefServiceBridge.getInstance().setPasswordLeakDetectionEnabled(true); });
final Preferences preferences =
PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(),
SavePasswordsPreferences.class.getName());
SavePasswordsPreferences savedPasswordPrefs =
(SavePasswordsPreferences) preferences.getMainFragment();
ChromeSwitchPreference onOffSwitch =
(ChromeSwitchPreference) savedPasswordPrefs.findPreference(
SavePasswordsPreferences.PREF_LEAK_DETECTION_SWITCH);
Assert.assertTrue(onOffSwitch.isChecked());
TestThreadUtils.runOnUiThreadBlocking(() -> {
onOffSwitch.performClick();
Assert.assertFalse(PrefServiceBridge.getInstance().isPasswordLeakDetectionEnabled());
onOffSwitch.performClick();
Assert.assertTrue(PrefServiceBridge.getInstance().isPasswordLeakDetectionEnabled());
});
}
@Test
@SmallTest
@Feature({"Preferences"})
@Features.EnableFeatures({SavePasswordsPreferences.PASSWORD_LEAK_DETECTION_FEATURE})
public void testLeakDetectionSwitchDisabled() throws Exception {
// The switch is only displayed for signed in users.
ChromeSigninController.get().setSignedInAccountName("Test Account");
TestThreadUtils.runOnUiThreadBlocking(
() -> { PrefServiceBridge.getInstance().setPasswordLeakDetectionEnabled(false); });
final Preferences preferences =
PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(),
SavePasswordsPreferences.class.getName());
SavePasswordsPreferences savedPasswordPrefs =
(SavePasswordsPreferences) preferences.getMainFragment();
ChromeSwitchPreference onOffSwitch =
(ChromeSwitchPreference) savedPasswordPrefs.findPreference(
SavePasswordsPreferences.PREF_LEAK_DETECTION_SWITCH);
Assert.assertFalse(onOffSwitch.isChecked());
}
@Test
@SmallTest
@Feature({"Preferences"})
@Features.EnableFeatures({SavePasswordsPreferences.PASSWORD_LEAK_DETECTION_FEATURE})
public void testLeakDetectionNonSignedIn() throws Exception {
final Preferences preferences =
PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(),
SavePasswordsPreferences.class.getName());
SavePasswordsPreferences savedPasswordPrefs =
(SavePasswordsPreferences) preferences.getMainFragment();
// The switch shouldn't be displayed for non signed-in users.
Assert.assertNull(savedPasswordPrefs.findPreference(
SavePasswordsPreferences.PREF_LEAK_DETECTION_SWITCH));
}
/**
* Tests that the link pointing to managing passwords in the user's account is not displayed
* for non signed in users.
......
......@@ -27,9 +27,11 @@
#include "chrome/browser/android/password_editing_bridge.h"
#include "chrome/browser/password_manager/password_store_factory.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/grit/generated_resources.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/export/password_csv_writer.h"
#include "components/password_manager/core/browser/leak_detection/authenticated_leak_check.h"
#include "components/password_manager/core/browser/password_ui_utils.h"
#include "components/password_manager/core/browser/ui/credential_provider_interface.h"
#include "content/public/browser/browser_thread.h"
......@@ -219,6 +221,14 @@ ScopedJavaLocalRef<jstring> JNI_PasswordUIView_GetAccountDashboardURL(
env, l10n_util::GetStringUTF16(IDS_PASSWORDS_WEB_LINK));
}
jboolean JNI_PasswordUIView_HasAccountForLeakCheckRequest(JNIEnv* env) {
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(
ProfileManager::GetLastUsedProfile());
return password_manager::AuthenticatedLeakCheck::HasAccountForRequest(
identity_manager);
}
// static
static jlong JNI_PasswordUIView_Init(JNIEnv* env,
const JavaParamRef<jobject>& obj) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment