Commit 584b97c8 authored by Ioana Pandele's avatar Ioana Pandele Committed by Commit Bot

[Android] Add switch for leak detection in settings

This CL adds a switch in Settings > Passwords through which users can
disable the password breach checks. This switch is disabled if the
pref is managed.

Bug:986322

Change-Id: If402241c4def52a437250740f2d42045b16c4141
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1746251Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Commit-Queue: Ioana Pandele <ioanap@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689548}
parent c5fec8c6
......@@ -257,6 +257,10 @@ public class PrefServiceBridge {
return nativeGetPasswordManagerAutoSigninEnabled();
}
public boolean isPasswordLeakDetectionEnabled() {
return nativeGetPasswordLeakDetectionEnabled();
}
/**
* @return Whether password storage is configured by policy
*/
......@@ -268,6 +272,13 @@ public class PrefServiceBridge {
return nativeGetPasswordManagerAutoSigninManaged();
}
/**
* @return Whether leak detection is enabled/disabled by policy
*/
public boolean isPasswordLeakDetectionManaged() {
return nativeGetPasswordLeakDetectionManaged();
}
/**
* @return Whether vibration is enabled for notifications.
*/
......@@ -632,6 +643,10 @@ public class PrefServiceBridge {
nativeSetPasswordManagerAutoSigninEnabled(enabled);
}
public void setPasswordLeakDetectionEnabled(boolean enabled) {
nativeSetPasswordLeakDetectionEnabled(enabled);
}
public void setNotificationsVibrateEnabled(boolean enabled) {
nativeSetNotificationsVibrateEnabled(enabled);
}
......@@ -1082,8 +1097,10 @@ public class PrefServiceBridge {
private native boolean nativeGetBlockThirdPartyCookiesManaged();
private native boolean nativeGetRememberPasswordsEnabled();
private native boolean nativeGetPasswordManagerAutoSigninEnabled();
private native boolean nativeGetPasswordLeakDetectionEnabled();
private native boolean nativeGetRememberPasswordsManaged();
private native boolean nativeGetPasswordManagerAutoSigninManaged();
private native boolean nativeGetPasswordLeakDetectionManaged();
private native boolean nativeGetAllowLocationUserModifiable();
private native boolean nativeGetLocationAllowedByPolicy();
private native boolean nativeGetAllowLocationManagedByCustodian();
......@@ -1129,6 +1146,7 @@ public class PrefServiceBridge {
private native void nativeSetDoNotTrackEnabled(boolean enabled);
private native void nativeSetRememberPasswordsEnabled(boolean allow);
private native void nativeSetPasswordManagerAutoSigninEnabled(boolean enabled);
private native void nativeSetPasswordLeakDetectionEnabled(boolean enabled);
private native boolean nativeGetAllowLocationEnabled();
private native boolean nativeGetNotificationsEnabled();
private native boolean nativeGetNotificationsVibrateEnabled();
......
......@@ -26,6 +26,7 @@ import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.StrictModeContext;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference;
import org.chromium.chrome.browser.preferences.ChromeBasePreference;
import org.chromium.chrome.browser.preferences.ChromeSwitchPreference;
......@@ -44,6 +45,8 @@ import java.util.Locale;
public class SavePasswordsPreferences
extends PreferenceFragmentCompat implements PasswordManagerHandler.PasswordListObserver,
Preference.OnPreferenceClickListener {
public static final String PASSWORD_LEAK_DETECTION_FEATURE = "PasswordLeakDetection";
// Keys for name/password dictionaries.
public static final String PASSWORD_LIST_URL = "url";
public static final String PASSWORD_LIST_NAME = "name";
......@@ -57,6 +60,7 @@ public class SavePasswordsPreferences
public static final String PREF_SAVE_PASSWORDS_SWITCH = "save_passwords_switch";
public static final String PREF_AUTOSIGNIN_SWITCH = "autosignin_switch";
public static final String PREF_LEAK_DETECTION_SWITCH = "leak_detection_switch";
public static final String PREF_KEY_MANAGE_ACCOUNT_LINK = "manage_account_link";
// A PasswordEntryViewer receives a boolean value with this key. If set true, the the entry was
......@@ -69,10 +73,11 @@ public class SavePasswordsPreferences
private static final int ORDER_SWITCH = 0;
private static final int ORDER_AUTO_SIGNIN_CHECKBOX = 1;
private static final int ORDER_MANAGE_ACCOUNT_LINK = 2;
private static final int ORDER_SAVED_PASSWORDS = 3;
private static final int ORDER_EXCEPTIONS = 4;
private static final int ORDER_SAVED_PASSWORDS_NO_TEXT = 5;
private static final int ORDER_AUTO_LEAK_DETECTION_SWITCH = 2;
private static final int ORDER_MANAGE_ACCOUNT_LINK = 3;
private static final int ORDER_SAVED_PASSWORDS = 4;
private static final int ORDER_EXCEPTIONS = 5;
private static final int ORDER_SAVED_PASSWORDS_NO_TEXT = 6;
private boolean mNoPasswords;
private boolean mNoPasswordExceptions;
......@@ -84,6 +89,7 @@ public class SavePasswordsPreferences
private Preference mLinkPref;
private ChromeSwitchPreference mSavePasswordsSwitch;
private ChromeBaseCheckBoxPreference mAutoSignInSwitch;
private ChromeSwitchPreference mAutoLeakDetectionSwitch;
private TextMessagePreference mEmptyView;
private boolean mSearchRecorded;
private Menu mMenu;
......@@ -201,8 +207,11 @@ public class SavePasswordsPreferences
mNoPasswords = false;
mNoPasswordExceptions = false;
getPreferenceScreen().removeAll();
createSavePasswordsSwitch();
createAutoSignInCheckbox();
if (mSearchQuery == null) {
createSavePasswordsSwitch();
createAutoSignInCheckbox();
createAutoLeakDetectionSwitch();
}
PasswordManagerHandlerProvider.getInstance()
.getPasswordManagerHandler()
.updatePasswordLists();
......@@ -384,9 +393,6 @@ public class SavePasswordsPreferences
}
private void createSavePasswordsSwitch() {
if (mSearchQuery != null) {
return; // Don't create this option when the preferences are filtered for passwords.
}
mSavePasswordsSwitch = new ChromeSwitchPreference(getStyledContext(), null);
mSavePasswordsSwitch.setKey(PREF_SAVE_PASSWORDS_SWITCH);
mSavePasswordsSwitch.setTitle(R.string.prefs_saved_passwords);
......@@ -413,9 +419,6 @@ public class SavePasswordsPreferences
}
private void createAutoSignInCheckbox() {
if (mSearchQuery != null) {
return; // Don't create this option when the preferences are filtered for passwords.
}
mAutoSignInSwitch = new ChromeBaseCheckBoxPreference(getStyledContext(), null);
mAutoSignInSwitch.setKey(PREF_AUTOSIGNIN_SWITCH);
mAutoSignInSwitch.setTitle(R.string.passwords_auto_signin_title);
......@@ -432,6 +435,25 @@ public class SavePasswordsPreferences
PrefServiceBridge.getInstance().isPasswordManagerAutoSigninEnabled());
}
private void createAutoLeakDetectionSwitch() {
if (!ChromeFeatureList.isEnabled(PASSWORD_LEAK_DETECTION_FEATURE)) return;
mAutoLeakDetectionSwitch = new ChromeSwitchPreference(getStyledContext(), null);
mAutoLeakDetectionSwitch.setKey(PREF_LEAK_DETECTION_SWITCH);
// TODO(crbug.com/986317): Add description and update title.
mAutoLeakDetectionSwitch.setTitle(R.string.passwords_leak_detection_switch_title);
mAutoLeakDetectionSwitch.setOrder(ORDER_AUTO_LEAK_DETECTION_SWITCH);
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());
}
private void displayManageAccountLink() {
if (!PreferencesLauncher.isSyncingPasswordsWithoutCustomPassphrase()) {
return;
......
......@@ -551,6 +551,9 @@ CHAR-LIMIT guidelines:
<message name="IDS_PASSWORDS_AUTO_SIGNIN_DESCRIPTION" desc="Text under 'Auto sign-in' checkbox">
Automatically sign in to websites using stored credentials. When the feature is off, you’ll be asked for verification every time before signing in to a website.
</message>
<message name="IDS_PASSWORDS_LEAK_DETECTION_SWITCH_TITLE" desc="Title for the switch togglingwhether Chrome should check that entered credentials have been part of a leak.">
Check password safety
</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>
......
......@@ -530,6 +530,50 @@ public class SavePasswordsPreferencesTest {
});
}
@Test
@SmallTest
@Feature({"Preferences"})
@Features.EnableFeatures({SavePasswordsPreferences.PASSWORD_LEAK_DETECTION_FEATURE})
public void testLeakDetectionSwitchEnabled() throws Exception {
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 {
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());
}
/**
* Tests that the link pointing to managing passwords in the user's account is not displayed
* for non signed in users.
......
......@@ -212,6 +212,7 @@ const base::Feature* kFeaturesExposedToJava[] = {
&omnibox::kOmniboxSearchEngineLogo,
&password_manager::features::kGooglePasswordManager,
&password_manager::features::kPasswordEditingAndroid,
&password_manager::features::kLeakDetection,
&safe_browsing::kCaptureSafetyNetId,
&signin::kMiceFeature,
&switches::kSyncManualStartAndroid,
......
......@@ -334,6 +334,13 @@ static jboolean JNI_PrefServiceBridge_GetPasswordManagerAutoSigninEnabled(
password_manager::prefs::kCredentialsEnableAutosignin);
}
static jboolean JNI_PrefServiceBridge_GetPasswordLeakDetectionEnabled(
JNIEnv* env,
const JavaParamRef<jobject>& obj) {
return GetPrefService()->GetBoolean(
password_manager::prefs::kPasswordLeakDetectionEnabled);
}
static jboolean JNI_PrefServiceBridge_GetRememberPasswordsManaged(
JNIEnv* env,
const JavaParamRef<jobject>& obj) {
......@@ -348,6 +355,13 @@ static jboolean JNI_PrefServiceBridge_GetPasswordManagerAutoSigninManaged(
password_manager::prefs::kCredentialsEnableAutosignin);
}
static jboolean JNI_PrefServiceBridge_GetPasswordLeakDetectionManaged(
JNIEnv* env,
const JavaParamRef<jobject>& obj) {
return GetPrefService()->IsManagedPreference(
password_manager::prefs::kPasswordLeakDetectionEnabled);
}
static jboolean JNI_PrefServiceBridge_GetDoNotTrackEnabled(
JNIEnv* env,
const JavaParamRef<jobject>& obj) {
......@@ -787,6 +801,14 @@ static void JNI_PrefServiceBridge_SetPasswordManagerAutoSigninEnabled(
password_manager::prefs::kCredentialsEnableAutosignin, enabled);
}
static void JNI_PrefServiceBridge_SetPasswordLeakDetectionEnabled(
JNIEnv* env,
const JavaParamRef<jobject>& obj,
jboolean enabled) {
GetPrefService()->SetBoolean(
password_manager::prefs::kPasswordLeakDetectionEnabled, enabled);
}
static void JNI_PrefServiceBridge_SetAllowLocationEnabled(
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