Commit c50da9c2 authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Unity][Android] Don't enable checkboxes if sync is disabled

This CL reimplements SyncAndServicesPreferences.updateDataTypeState to
unify configuration of checkboxes. It resolves the issue when all
checkboxes become enabled even though requirements for some data types
aren't met.

Bug: 889015
Change-Id: If9cffded02ce163edd33eaeeba73ddd244b9ce89
Reviewed-on: https://chromium-review.googlesource.com/c/1258007Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596234}
parent a8d2ee4d
...@@ -20,6 +20,7 @@ import android.preference.PreferenceGroup; ...@@ -20,6 +20,7 @@ import android.preference.PreferenceGroup;
import android.provider.Settings; import android.provider.Settings;
import android.support.annotation.IntDef; import android.support.annotation.IntDef;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.util.ArraySet;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
...@@ -690,45 +691,49 @@ public class SyncAndServicesPreferences extends PreferenceFragment ...@@ -690,45 +691,49 @@ public class SyncAndServicesPreferences extends PreferenceFragment
*/ */
private void updateDataTypeState() { private void updateDataTypeState() {
boolean syncEverything = UnifiedConsentServiceBridge.isUnifiedConsentGiven(); boolean syncEverything = UnifiedConsentServiceBridge.isUnifiedConsentGiven();
boolean passwordSyncConfigurable = mProfileSyncService.isEngineInitialized() if (syncEverything) {
&& mProfileSyncService.isCryptographerReady(); for (CheckBoxPreference pref : mSyncAllTypes) {
boolean hasCustomPassphrase = mProfileSyncService.isEngineInitialized() pref.setChecked(true);
&& mProfileSyncService.getPassphraseType() == PassphraseType.CUSTOM_PASSPHRASE; pref.setEnabled(false);
Set<Integer> syncTypes = mProfileSyncService.getPreferredDataTypes();
boolean syncAutofill = syncTypes.contains(ModelType.AUTOFILL);
boolean syncHistory = syncTypes.contains(ModelType.TYPED_URLS);
for (CheckBoxPreference pref : mSyncAllTypes) {
// Set the default state of each data type checkbox.
boolean canSyncType = true;
if (pref == mSyncPasswords) canSyncType = passwordSyncConfigurable;
if (pref == mSyncPaymentsIntegration) {
canSyncType = syncAutofill || syncEverything;
}
if (pref == mSyncActivityAndInteractions) {
canSyncType = syncHistory && !hasCustomPassphrase;
} }
return;
}
if (syncEverything) { Set<Integer> syncTypes =
pref.setChecked(canSyncType); mIsSyncEnabled ? mProfileSyncService.getPreferredDataTypes() : new ArraySet<>();
} mSyncAutofill.setChecked(syncTypes.contains(ModelType.AUTOFILL));
mSyncAutofill.setEnabled(true);
mSyncBookmarks.setChecked(syncTypes.contains(ModelType.BOOKMARKS));
mSyncBookmarks.setEnabled(true);
mSyncHistory.setChecked(syncTypes.contains(ModelType.TYPED_URLS));
mSyncHistory.setEnabled(true);
mSyncRecentTabs.setChecked(syncTypes.contains(ModelType.PROXY_TABS));
mSyncRecentTabs.setEnabled(true);
mSyncSettings.setChecked(syncTypes.contains(ModelType.PREFERENCES));
mSyncSettings.setEnabled(true);
// Payments integration requires AUTOFILL model type
boolean syncAutofill = syncTypes.contains(ModelType.AUTOFILL);
mSyncPaymentsIntegration.setChecked(
syncAutofill && PersonalDataManager.isPaymentsIntegrationEnabled());
mSyncPaymentsIntegration.setEnabled(syncAutofill);
pref.setEnabled(!syncEverything && canSyncType); boolean passwordsConfigurable = mProfileSyncService.isEngineInitialized()
} && mProfileSyncService.isCryptographerReady();
if (mIsSyncEnabled && !syncEverything) { mSyncPasswords.setChecked(passwordsConfigurable && syncTypes.contains(ModelType.PASSWORDS));
// If "Use sync and all services" is off, check/uncheck the individual checkboxes mSyncPasswords.setEnabled(passwordsConfigurable);
// to match the prefs.
mSyncAutofill.setChecked(syncAutofill); // USER_EVENTS sync type doesn't work with custom passphrase and needs history sync
mSyncBookmarks.setChecked(syncTypes.contains(ModelType.BOOKMARKS)); boolean userEventsConfigurable =
mSyncPaymentsIntegration.setChecked( !hasCustomPassphrase() && syncTypes.contains(ModelType.TYPED_URLS);
syncAutofill && PersonalDataManager.isPaymentsIntegrationEnabled()); mSyncActivityAndInteractions.setChecked(
mSyncHistory.setChecked(syncHistory); userEventsConfigurable && syncTypes.contains(ModelType.USER_EVENTS));
mSyncPasswords.setChecked( mSyncActivityAndInteractions.setEnabled(userEventsConfigurable);
passwordSyncConfigurable && syncTypes.contains(ModelType.PASSWORDS)); }
mSyncRecentTabs.setChecked(syncTypes.contains(ModelType.PROXY_TABS));
mSyncSettings.setChecked(syncTypes.contains(ModelType.PREFERENCES)); private boolean hasCustomPassphrase() {
mSyncActivityAndInteractions.setChecked(syncHistory && !hasCustomPassphrase return mProfileSyncService.isEngineInitialized()
&& syncTypes.contains(ModelType.USER_EVENTS)); && mProfileSyncService.getPassphraseType() == PassphraseType.CUSTOM_PASSPHRASE;
}
} }
private void updateSyncErrorCard() { private void updateSyncErrorCard() {
...@@ -866,9 +871,7 @@ public class SyncAndServicesPreferences extends PreferenceFragment ...@@ -866,9 +871,7 @@ public class SyncAndServicesPreferences extends PreferenceFragment
getPreferenceScreen().addPreference(mUseSyncAndAllServices); getPreferenceScreen().addPreference(mUseSyncAndAllServices);
mUseSyncAndAllServices.setChecked(useSyncAndAllServices); mUseSyncAndAllServices.setChecked(useSyncAndAllServices);
boolean hasCustomPassphrase = mProfileSyncService.isEngineInitialized() mUseSyncAndAllServices.setEnabled(!hasCustomPassphrase());
&& mProfileSyncService.getPassphraseType() == PassphraseType.CUSTOM_PASSPHRASE;
mUseSyncAndAllServices.setEnabled(!hasCustomPassphrase);
mSyncGroup.setEnabled(true); mSyncGroup.setEnabled(true);
mGoogleActivityControls.setOnPreferenceClickListener( mGoogleActivityControls.setOnPreferenceClickListener(
......
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