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;
import android.provider.Settings;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
import android.support.v4.util.ArraySet;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
......@@ -690,45 +691,49 @@ public class SyncAndServicesPreferences extends PreferenceFragment
*/
private void updateDataTypeState() {
boolean syncEverything = UnifiedConsentServiceBridge.isUnifiedConsentGiven();
boolean passwordSyncConfigurable = mProfileSyncService.isEngineInitialized()
&& 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);
if (syncEverything) {
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;
pref.setChecked(true);
pref.setEnabled(false);
}
if (syncEverything) {
pref.setChecked(canSyncType);
return;
}
pref.setEnabled(!syncEverything && canSyncType);
}
if (mIsSyncEnabled && !syncEverything) {
// If "Use sync and all services" is off, check/uncheck the individual checkboxes
// to match the prefs.
mSyncAutofill.setChecked(syncAutofill);
Set<Integer> syncTypes =
mIsSyncEnabled ? mProfileSyncService.getPreferredDataTypes() : new ArraySet<>();
mSyncAutofill.setChecked(syncTypes.contains(ModelType.AUTOFILL));
mSyncAutofill.setEnabled(true);
mSyncBookmarks.setChecked(syncTypes.contains(ModelType.BOOKMARKS));
mSyncPaymentsIntegration.setChecked(
syncAutofill && PersonalDataManager.isPaymentsIntegrationEnabled());
mSyncHistory.setChecked(syncHistory);
mSyncPasswords.setChecked(
passwordSyncConfigurable && syncTypes.contains(ModelType.PASSWORDS));
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));
mSyncActivityAndInteractions.setChecked(syncHistory && !hasCustomPassphrase
&& syncTypes.contains(ModelType.USER_EVENTS));
mSyncSettings.setEnabled(true);
// 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() {
......@@ -866,9 +871,7 @@ public class SyncAndServicesPreferences extends PreferenceFragment
getPreferenceScreen().addPreference(mUseSyncAndAllServices);
mUseSyncAndAllServices.setChecked(useSyncAndAllServices);
boolean hasCustomPassphrase = mProfileSyncService.isEngineInitialized()
&& mProfileSyncService.getPassphraseType() == PassphraseType.CUSTOM_PASSPHRASE;
mUseSyncAndAllServices.setEnabled(!hasCustomPassphrase);
mUseSyncAndAllServices.setEnabled(!hasCustomPassphrase());
mSyncGroup.setEnabled(true);
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