Commit b4fc4420 authored by Tanmoy Mollik's avatar Tanmoy Mollik Committed by Commit Bot

[Android] Get rid of explicit register/unregister in SignInPreference

Replace register and unregister with onAttached and onDetached methods
in SignInPreference

Bug: 1127990
Change-Id: If4f385691b44ea2845428c9c76143d566c82cce5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2409964
Commit-Queue: Tanmoy Mollik <triploblastic@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822664}
parent a08cc488
......@@ -131,7 +131,6 @@ public class MainSettings extends PreferenceFragmentCompat
Profile.getLastUsedRegularProfile());
if (signinManager.isSigninSupported()) {
signinManager.addSignInStateObserver(this);
mSignInPreference.registerForUpdates();
}
ProfileSyncService syncService = ProfileSyncService.get();
if (syncService != null) {
......@@ -146,7 +145,6 @@ public class MainSettings extends PreferenceFragmentCompat
Profile.getLastUsedRegularProfile());
if (signinManager.isSigninSupported()) {
signinManager.removeSignInStateObserver(this);
mSignInPreference.unregisterForUpdates();
}
ProfileSyncService syncService = ProfileSyncService.get();
if (syncService != null) {
......@@ -409,14 +407,10 @@ public class MainSettings extends PreferenceFragmentCompat
// "You and Google" section header if the personalized sync promo is shown.
boolean isShowingPersonalizedPromo =
mSignInPreference.getState() == SignInPreference.State.PERSONALIZED_PROMO;
if (ChromeFeatureList.isEnabled(ChromeFeatureList.MOBILE_IDENTITY_CONSISTENCY)) {
findPreference(PREF_ACCOUNT_AND_GOOGLE_SERVICES_SECTION)
.setVisible(!isShowingPersonalizedPromo);
} else if (isShowingPersonalizedPromo) {
removePreferenceIfPresent(PREF_ACCOUNT_SECTION);
} else {
addPreferenceIfAbsent(PREF_ACCOUNT_SECTION);
}
String prefName = ChromeFeatureList.isEnabled(ChromeFeatureList.MOBILE_IDENTITY_CONSISTENCY)
? PREF_ACCOUNT_AND_GOOGLE_SERVICES_SECTION
: PREF_ACCOUNT_SECTION;
findPreference(prefName).setVisible(!isShowingPersonalizedPromo);
}
// TemplateUrlService.LoadListener implementation.
......
......@@ -94,10 +94,10 @@ public class SignInPreference
mState = State.SIGNED_IN;
}
/**
* Starts listening for updates to the sign-in and sync state.
*/
public void registerForUpdates() {
@Override
public void onAttached() {
super.onAttached();
mAccountManagerFacade.addObserver(this);
IdentityServicesProvider.get()
.getSigninManager(Profile.getLastUsedRegularProfile())
......@@ -114,11 +114,10 @@ public class SignInPreference
update();
}
/**
* Stops listening for updates to the sign-in and sync state. Every call to registerForUpdates()
* must be matched with a call to this method.
*/
public void unregisterForUpdates() {
@Override
public void onDetached() {
super.onDetached();
mAccountManagerFacade.removeObserver(this);
IdentityServicesProvider.get()
.getSigninManager(Profile.getLastUsedRegularProfile())
......
......@@ -337,7 +337,6 @@ public class SyncAndServicesSettings extends PreferenceFragmentCompat
public void onStart() {
super.onStart();
mProfileSyncService.addSyncStateChangedListener(this);
mSigninPreference.registerForUpdates();
if (!mIsFromSigninScreen
|| IdentityServicesProvider.get()
......@@ -363,7 +362,6 @@ public class SyncAndServicesSettings extends PreferenceFragmentCompat
public void onStop() {
super.onStop();
mSigninPreference.unregisterForUpdates();
mProfileSyncService.removeSyncStateChangedListener(this);
}
......
......@@ -220,8 +220,8 @@ public class MainSettingsFragmentTest {
// SignInPreference status check.
// As the user is not signed in, sign in promo will show, section header will be hidden.
Assert.assertNull("Account section header should be hidden.",
mMainSettings.findPreference(MainSettings.PREF_ACCOUNT_SECTION));
Assert.assertFalse("Account section header should be hidden.",
mMainSettings.findPreference(MainSettings.PREF_ACCOUNT_SECTION).isVisible());
// Assert for "Basics" section
assertSettingsExists(MainSettings.PREF_SEARCH_ENGINE, SearchEngineSettings.class);
......@@ -379,8 +379,8 @@ public class MainSettingsFragmentTest {
(SignInPreference) assertSettingsExists(MainSettings.PREF_SIGN_IN, null);
Assert.assertEquals("SignInPreference should be at the personalized promo state. ",
signInPreference.getState(), State.PERSONALIZED_PROMO);
Assert.assertNull("Account section header should be hidden when promo is shown.",
mMainSettings.findPreference(MainSettings.PREF_ACCOUNT_SECTION));
Assert.assertFalse("Account section header should be hidden when promo is shown.",
mMainSettings.findPreference(MainSettings.PREF_ACCOUNT_SECTION).isVisible());
// SignIn to see the changes
mSyncTestRule.setUpAccountAndEnableSyncForTesting();
......
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