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();
boolean hasCustomPassphrase = mProfileSyncService.isEngineInitialized()
&& mProfileSyncService.getPassphraseType() == PassphraseType.CUSTOM_PASSPHRASE;
Set<Integer> syncTypes = mProfileSyncService.getPreferredDataTypes();
boolean syncAutofill = syncTypes.contains(ModelType.AUTOFILL);
boolean syncHistory = syncTypes.contains(ModelType.TYPED_URLS);
for (CheckBoxPreference pref : mSyncAllTypes) { for (CheckBoxPreference pref : mSyncAllTypes) {
// Set the default state of each data type checkbox. pref.setChecked(true);
boolean canSyncType = true; pref.setEnabled(false);
if (pref == mSyncPasswords) canSyncType = passwordSyncConfigurable;
if (pref == mSyncPaymentsIntegration) {
canSyncType = syncAutofill || syncEverything;
}
if (pref == mSyncActivityAndInteractions) {
canSyncType = syncHistory && !hasCustomPassphrase;
} }
return;
if (syncEverything) {
pref.setChecked(canSyncType);
} }
pref.setEnabled(!syncEverything && canSyncType); Set<Integer> syncTypes =
} mIsSyncEnabled ? mProfileSyncService.getPreferredDataTypes() : new ArraySet<>();
if (mIsSyncEnabled && !syncEverything) { mSyncAutofill.setChecked(syncTypes.contains(ModelType.AUTOFILL));
// If "Use sync and all services" is off, check/uncheck the individual checkboxes mSyncAutofill.setEnabled(true);
// to match the prefs.
mSyncAutofill.setChecked(syncAutofill);
mSyncBookmarks.setChecked(syncTypes.contains(ModelType.BOOKMARKS)); mSyncBookmarks.setChecked(syncTypes.contains(ModelType.BOOKMARKS));
mSyncPaymentsIntegration.setChecked( mSyncBookmarks.setEnabled(true);
syncAutofill && PersonalDataManager.isPaymentsIntegrationEnabled()); mSyncHistory.setChecked(syncTypes.contains(ModelType.TYPED_URLS));
mSyncHistory.setChecked(syncHistory); mSyncHistory.setEnabled(true);
mSyncPasswords.setChecked(
passwordSyncConfigurable && syncTypes.contains(ModelType.PASSWORDS));
mSyncRecentTabs.setChecked(syncTypes.contains(ModelType.PROXY_TABS)); mSyncRecentTabs.setChecked(syncTypes.contains(ModelType.PROXY_TABS));
mSyncRecentTabs.setEnabled(true);
mSyncSettings.setChecked(syncTypes.contains(ModelType.PREFERENCES)); mSyncSettings.setChecked(syncTypes.contains(ModelType.PREFERENCES));
mSyncActivityAndInteractions.setChecked(syncHistory && !hasCustomPassphrase mSyncSettings.setEnabled(true);
&& syncTypes.contains(ModelType.USER_EVENTS));
// Payments integration requires AUTOFILL model type
boolean syncAutofill = syncTypes.contains(ModelType.AUTOFILL);
mSyncPaymentsIntegration.setChecked(
syncAutofill && PersonalDataManager.isPaymentsIntegrationEnabled());
mSyncPaymentsIntegration.setEnabled(syncAutofill);
boolean passwordsConfigurable = mProfileSyncService.isEngineInitialized()
&& mProfileSyncService.isCryptographerReady();
mSyncPasswords.setChecked(passwordsConfigurable && syncTypes.contains(ModelType.PASSWORDS));
mSyncPasswords.setEnabled(passwordsConfigurable);
// USER_EVENTS sync type doesn't work with custom passphrase and needs history sync
boolean userEventsConfigurable =
!hasCustomPassphrase() && syncTypes.contains(ModelType.TYPED_URLS);
mSyncActivityAndInteractions.setChecked(
userEventsConfigurable && syncTypes.contains(ModelType.USER_EVENTS));
mSyncActivityAndInteractions.setEnabled(userEventsConfigurable);
} }
private boolean hasCustomPassphrase() {
return mProfileSyncService.isEngineInitialized()
&& 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