Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not require screenlock on ChromeOS for passwords sync #27056

Merged
merged 3 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.chromium.chrome.browser.sync.settings;

import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
Expand All @@ -24,12 +25,11 @@
import org.chromium.components.browser_ui.settings.ChromeSwitchPreference;
import org.chromium.ui.widget.Toast;

import java.util.Optional;
import java.util.Timer;
import java.util.TimerTask;

/**
* See org.brave.bytecode.BraveManageSyncSettingsClassAdapter
*/
/** See org.brave.bytecode.BraveManageSyncSettingsClassAdapter */
public class BraveManageSyncSettings extends ManageSyncSettings {
private static final String TAG = "BMSS";

Expand All @@ -49,6 +49,11 @@ public class BraveManageSyncSettings extends ManageSyncSettings {
private static final String VERBOSE_SYNC_PASSWORDS_PREF_COMMAND_LINE_KEY =
"verbose_sync_passwords_pref";

// Android Runtime for Chrome
public static final String ARC_FEATURE = "org.chromium.arc";
AlexeyBarabash marked this conversation as resolved.
Show resolved Hide resolved
public static final String ARC_DEVICE_MANAGEMENT_FEATURE = "org.chromium.arc.device_management";
private static Optional<Boolean> sIsChromeOSForTesting = Optional.empty();

private void verboseIfEnabled(String message) {
if (!mVerboseSyncPasswordsPref) {
return;
Expand Down Expand Up @@ -105,8 +110,27 @@ public void onCreatePreferences(@Nullable Bundle savedInstanceState, String root
mPrefSyncPasswords = findPreference(PREF_SYNC_PASSWORDS);
assert mPrefSyncPasswords != null : "Something has changed in the upstream!";

overrideWithAuthConfirmationSyncPasswords();
overrideWithAuthConfirmationSyncEverything();
// We cannot require Android screenlock if browser runs at ChromeOS
// Google App Runtime emulator, because it is managed by ChromeOS and
// not by the Android subsystem
if (!isRunningOnChromeOS()) {
overrideWithAuthConfirmationSyncPasswords();
overrideWithAuthConfirmationSyncEverything();
}
}

@VisibleForTesting
public static void setIsRunningOnChromeOSForTesting(Boolean isRunningOnChromeOS) {
sIsChromeOSForTesting = Optional.of(isRunningOnChromeOS);
}

private static Boolean isRunningOnChromeOS() {
if (sIsChromeOSForTesting.isPresent()) {
return sIsChromeOSForTesting.get();
}
PackageManager pm = ContextUtils.getApplicationContext().getPackageManager();
return pm.hasSystemFeature(ARC_FEATURE)
|| pm.hasSystemFeature(ARC_DEVICE_MANAGEMENT_FEATURE);
}

private void showScreenLockToast() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* Copyright (c) 2024 The Brave Authors. All rights reserved.
* 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 https://mozilla.org/MPL/2.0/. */

package org.chromium.chrome.browser.sync;

import androidx.preference.Preference;
import androidx.test.filters.SmallTest;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DoNotBatch;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.Features.DisableFeatures;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.settings.SettingsActivity;
import org.chromium.chrome.browser.settings.SettingsActivityTestRule;
import org.chromium.chrome.browser.sync.settings.BraveManageSyncSettings;
import org.chromium.chrome.browser.sync.settings.ManageSyncSettings;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.components.browser_ui.settings.ChromeSwitchPreference;

/** Tests for BraveManageSyncSettings. */
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@DoNotBatch(reason = "TODO(crbug.com/40743432): SyncTestRule doesn't support batching.")
public class BraveManageSyncSettingsTest {
private SettingsActivity mSettingsActivity;

private final SettingsActivityTestRule<BraveManageSyncSettings> mSettingsActivityTestRule =
new SettingsActivityTestRule<>(BraveManageSyncSettings.class);

@Before
public void setUp() {}

@Test
@SmallTest
@Feature({"Sync"})
@DisableFeatures({ChromeFeatureList.REPLACE_SYNC_PROMOS_WITH_SIGN_IN_PROMOS})
public void syncEverythingOrPasswordsHandlerIsOriginalOnChromeOS() {
syncEverythingOrPasswordsOverridden(true, false);
}

@Test
@SmallTest
@Feature({"Sync"})
@DisableFeatures({ChromeFeatureList.REPLACE_SYNC_PROMOS_WITH_SIGN_IN_PROMOS})
public void syncEverythingOrPasswordsHandlerOverriddenOnNonChromeOS() {
syncEverythingOrPasswordsOverridden(false, true);
}

void syncEverythingOrPasswordsOverridden(
Boolean isChromeOS, Boolean handlerShouldBeOverridden) {
BraveManageSyncSettings.setIsRunningOnChromeOSForTesting(isChromeOS);
BraveManageSyncSettings fragment = startManageSyncPreferences();

ChromeSwitchPreference prefSyncPasswords =
fragment.findPreference(ManageSyncSettings.PREF_SYNC_PASSWORDS);
ChromeSwitchPreference syncEverything =
fragment.findPreference(ManageSyncSettings.PREF_SYNC_EVERYTHING);

Preference.OnPreferenceChangeListener origSyncPasswordsListner =
prefSyncPasswords.getOnPreferenceChangeListener();
Preference.OnPreferenceChangeListener origSyncEverythingListner =
syncEverything.getOnPreferenceChangeListener();

Assert.assertEquals(
handlerShouldBeOverridden,
origSyncPasswordsListner != (Preference.OnPreferenceChangeListener) fragment);
Assert.assertEquals(
handlerShouldBeOverridden,
origSyncEverythingListner != (Preference.OnPreferenceChangeListener) fragment);
}

private BraveManageSyncSettings startManageSyncPreferences() {
mSettingsActivity = mSettingsActivityTestRule.startSettingsActivity();
return mSettingsActivityTestRule.getFragment();
}
}
4 changes: 4 additions & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,7 @@ if (is_android) {
"//brave/android/javatests/org/chromium/chrome/browser/privacy/settings/BravePrivacySettingsTest.java",
"//brave/android/javatests/org/chromium/chrome/browser/safe_browsing/settings/BraveSafeBrowsingSettingsFragmentTest.java",
"//brave/android/javatests/org/chromium/chrome/browser/safety_check/BraveSafetyCheckSettingsFragmentTest.java",
"//brave/android/javatests/org/chromium/chrome/browser/sync/BraveManageSyncSettingsTest.java",
]

deps = [
Expand All @@ -1266,6 +1267,7 @@ if (is_android) {
"//chrome/browser/contextmenu:java",
"//chrome/browser/data_sharing:tab_group_ui_java",
"//chrome/browser/feed/android:java",
"//chrome/browser/flags:java",
"//chrome/browser/fullscreen/android:java",
"//chrome/browser/hub:java",
"//chrome/browser/password_manager/android:java",
Expand All @@ -1288,6 +1290,7 @@ if (is_android) {
"//chrome/browser/ui/android/toolbar:java",
"//chrome/browser/ui/messages/android:java",
"//chrome/browser/user_education:java",
"//chrome/test:test_support_java",
"//chrome/test/android:chrome_java_integration_test_support",
"//chrome/test/android:chrome_java_test_support_common",
"//components/browser_ui/bottomsheet/android:java",
Expand Down Expand Up @@ -1315,6 +1318,7 @@ if (is_android) {
"//components/sync/android:sync_java",
"//components/variations/android:variations_java",
"//content/public/android:content_full_java",
"//third_party/androidx:androidx_annotation_annotation_java",
"//third_party/androidx:androidx_appcompat_appcompat_java",
"//third_party/androidx:androidx_fragment_fragment_java",
"//third_party/androidx:androidx_preference_preference_java",
Expand Down
Loading