Commit 07bbbb57 authored by Tanmoy Mollik's avatar Tanmoy Mollik Committed by Commit Bot

[Android] Don't show sign out dialog in GoogleServicesSettings

If the user has only signed in without giving sync consent then toggling
"Allow Chrome sign in" off should not show the sign out dialog. Instead
it will sign the user out directly without deleting data saved on device

Bug: 1136075
Change-Id: I7d8a75a9c2474759f67fbb0018fa68ad3fa16163
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2460729Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Commit-Queue: Tanmoy Mollik <triploblastic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816969}
parent cd1569d0
...@@ -40,6 +40,8 @@ import org.chromium.components.browser_ui.settings.SettingsUtils; ...@@ -40,6 +40,8 @@ import org.chromium.components.browser_ui.settings.SettingsUtils;
import org.chromium.components.prefs.PrefService; import org.chromium.components.prefs.PrefService;
import org.chromium.components.signin.GAIAServiceType; import org.chromium.components.signin.GAIAServiceType;
import org.chromium.components.signin.identitymanager.ConsentLevel; import org.chromium.components.signin.identitymanager.ConsentLevel;
import org.chromium.components.signin.identitymanager.IdentityManager;
import org.chromium.components.signin.metrics.SignoutReason;
import org.chromium.components.user_prefs.UserPrefs; import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.content_public.browser.UiThreadTaskTraits; import org.chromium.content_public.browser.UiThreadTaskTraits;
...@@ -196,23 +198,34 @@ public class GoogleServicesSettings ...@@ -196,23 +198,34 @@ public class GoogleServicesSettings
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey(); String key = preference.getKey();
if (PREF_ALLOW_SIGNIN.equals(key)) { if (PREF_ALLOW_SIGNIN.equals(key)) {
IdentityManager identityManager = IdentityServicesProvider.get().getIdentityManager(
Profile.getLastUsedRegularProfile());
boolean shouldSignUserOut = boolean shouldSignUserOut =
IdentityServicesProvider.get() identityManager.getPrimaryAccountInfo(ConsentLevel.NOT_REQUIRED) != null
.getIdentityManager(Profile.getLastUsedRegularProfile())
.getPrimaryAccountInfo(ConsentLevel.NOT_REQUIRED)
!= null
&& !((boolean) newValue); && !((boolean) newValue);
if (shouldSignUserOut) { if (!shouldSignUserOut) {
SignOutDialogFragment signOutFragment =
SignOutDialogFragment.create(GAIAServiceType.GAIA_SERVICE_TYPE_NONE);
signOutFragment.setTargetFragment(this, 0);
signOutFragment.show(getFragmentManager(), SIGN_OUT_DIALOG_TAG);
// Don't change the preference state yet, it will be updated by onSignOutClicked if
// the user actually confirms the sign-out.
return false;
} else {
mPrefService.setBoolean(Pref.SIGNIN_ALLOWED, (boolean) newValue); mPrefService.setBoolean(Pref.SIGNIN_ALLOWED, (boolean) newValue);
return true;
} }
boolean shouldShowSignOutDialog =
identityManager.getPrimaryAccountInfo(ConsentLevel.SYNC) != null;
if (!shouldShowSignOutDialog) {
// Don't show signout dialog if there's no sync consent, as it never wipes the data.
IdentityServicesProvider.get()
.getSigninManager(Profile.getLastUsedRegularProfile())
.signOut(SignoutReason.USER_CLICKED_SIGNOUT_SETTINGS, null, false);
mPrefService.setBoolean(Pref.SIGNIN_ALLOWED, false);
return true;
}
SignOutDialogFragment signOutFragment =
SignOutDialogFragment.create(GAIAServiceType.GAIA_SERVICE_TYPE_NONE);
signOutFragment.setTargetFragment(this, 0);
signOutFragment.show(getFragmentManager(), SIGN_OUT_DIALOG_TAG);
// Don't change the preference state yet, it will be updated by onSignOutClicked
// if the user actually confirms the sign-out.
return false;
} else if (PREF_SEARCH_SUGGESTIONS.equals(key)) { } else if (PREF_SEARCH_SUGGESTIONS.equals(key)) {
mPrefService.setBoolean(Pref.SEARCH_SUGGEST_ENABLED, (boolean) newValue); mPrefService.setBoolean(Pref.SEARCH_SUGGEST_ENABLED, (boolean) newValue);
} else if (PREF_SAFE_BROWSING.equals(key)) { } else if (PREF_SAFE_BROWSING.equals(key)) {
...@@ -365,8 +378,7 @@ public class GoogleServicesSettings ...@@ -365,8 +378,7 @@ public class GoogleServicesSettings
final DialogFragment clearDataProgressDialog = new ClearDataProgressDialog(); final DialogFragment clearDataProgressDialog = new ClearDataProgressDialog();
IdentityServicesProvider.get() IdentityServicesProvider.get()
.getSigninManager(Profile.getLastUsedRegularProfile()) .getSigninManager(Profile.getLastUsedRegularProfile())
.signOut(org.chromium.components.signin.metrics.SignoutReason .signOut(SignoutReason.USER_CLICKED_SIGNOUT_SETTINGS,
.USER_CLICKED_SIGNOUT_SETTINGS,
new SigninManager.SignOutCallback() { new SigninManager.SignOutCallback() {
@Override @Override
public void preWipeData() { public void preWipeData() {
......
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