Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/signin/AccountManagementFragment.java

Issue 1660353002: Update account and sync management UX (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add TODO in comments for an additional task for the bug Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/signin/AccountManagementFragment.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountManagementFragment.java b/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountManagementFragment.java
index 998453bd1304a458ba387f0f8fb11433fbd3a8b6..ab8e0ffae30b8e9e2cd881c509dfcf1c15e718c6 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountManagementFragment.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountManagementFragment.java
@@ -22,12 +22,10 @@ import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
-import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.UserManager;
import android.preference.Preference;
-import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
@@ -37,22 +35,18 @@ import android.text.TextUtils;
import android.util.Pair;
import org.chromium.chrome.R;
-import org.chromium.chrome.browser.IntentHandler;
-import org.chromium.chrome.browser.UrlConstants;
import org.chromium.chrome.browser.childaccounts.ChildAccountService;
-import org.chromium.chrome.browser.document.ChromeLauncherActivity;
import org.chromium.chrome.browser.preferences.ChromeBasePreference;
-import org.chromium.chrome.browser.preferences.ChromeSwitchPreference;
import org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.preferences.Preferences;
import org.chromium.chrome.browser.preferences.PreferencesLauncher;
+import org.chromium.chrome.browser.preferences.SyncPreference;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.profiles.ProfileAccountManagementMetrics;
import org.chromium.chrome.browser.profiles.ProfileDownloader;
import org.chromium.chrome.browser.signin.SignOutDialogFragment.SignOutDialogListener;
import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver;
-import org.chromium.chrome.browser.sync.GoogleServiceAuthError;
import org.chromium.chrome.browser.sync.ProfileSyncService;
import org.chromium.chrome.browser.sync.ProfileSyncService.SyncStateChangedListener;
import org.chromium.chrome.browser.sync.ui.SyncCustomizationFragment;
@@ -75,7 +69,6 @@ import java.util.HashMap;
public class AccountManagementFragment extends PreferenceFragment
implements SignOutDialogListener, ProfileDownloader.Observer,
SyncStateChangedListener, SignInStateObserver {
-
public static final String SIGN_OUT_DIALOG_TAG = "sign_out_dialog_tag";
private static final String CLEAR_DATA_PROGRESS_DIALOG_TAG = "clear_data_progress";
@@ -85,13 +78,7 @@ public class AccountManagementFragment extends PreferenceFragment
* specify the correct GAIA service that has triggered the dialog.
* If the argument is not set, GAIA_SERVICE_TYPE_NONE is used as the origin of the dialog.
*/
- private static final String SHOW_GAIA_SERVICE_TYPE_EXTRA = "ShowGAIAServiceType";
-
- /**
- * The signin::GAIAServiceType value used in openAccountManagementScreen when the dialog
- * hasn't been triggered from the content area.
- */
- private static final int GAIA_SERVICE_TYPE_NONE = 0;
+ public static final String SHOW_GAIA_SERVICE_TYPE_EXTRA = "ShowGAIAServiceType";
/**
* Account name preferences will be ordered sequentially, starting with this "order" value.
@@ -113,27 +100,23 @@ public class AccountManagementFragment extends PreferenceFragment
private static String sChildAccountId = null;
private static Bitmap sCachedBadgedPicture = null;
- public static final String PREF_GO_INCOGNITO = "go_incognito";
-
- public static final String PREF_SIGN_OUT_SWITCH = "sign_out_switch";
- public static final String PREF_SIGN_IN_CHILD_MESSAGE = "sign_in_child_message";
+ public static final String PREF_SIGN_OUT = "sign_out";
public static final String PREF_ADD_ACCOUNT = "add_account";
- public static final String PREF_NOT_YOU = "not_you";
public static final String PREF_PARENTAL_SETTINGS = "parental_settings";
public static final String PREF_PARENT_ACCOUNTS = "parent_accounts";
public static final String PREF_CHILD_CONTENT = "child_content";
public static final String PREF_CHILD_SAFE_SITES = "child_safe_sites";
+ public static final String PREF_SYNC_SETTINGS = "sync_settings";
private int mGaiaServiceType;
private ArrayList<Preference> mAccountsListPreferences = new ArrayList<Preference>();
- private Preference mPrimaryAccountPreference;
@Override
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
- mGaiaServiceType = GAIA_SERVICE_TYPE_NONE;
+ mGaiaServiceType = AccountManagementScreenHelper.GAIA_SERVICE_TYPE_NONE;
if (getArguments() != null) {
mGaiaServiceType =
getArguments().getInt(SHOW_GAIA_SERVICE_TYPE_EXTRA, mGaiaServiceType);
@@ -173,6 +156,7 @@ public class AccountManagementFragment extends PreferenceFragment
/**
* Initiate fetching the user accounts data (images and the full name).
* Fetched data will be sent to observers of ProfileDownloader.
+ *
* @param profile Profile to use.
*/
private static void startFetchingAccountsInformation(Context context, Profile profile) {
@@ -209,9 +193,9 @@ public class AccountManagementFragment extends PreferenceFragment
getActivity().setTitle(fullName);
configureSignOutSwitch();
- configureAddAccountPreference(fullName);
- configureGoIncognitoPreferences(fullName);
+ configureAddAccountPreference();
configureChildAccountPreferences();
+ configureSyncSettings();
updateAccountsList();
}
@@ -228,21 +212,15 @@ public class AccountManagementFragment extends PreferenceFragment
private void configureSignOutSwitch() {
boolean isChildAccount = ChildAccountService.isChildAccount();
- ChromeSwitchPreference signOutSwitch =
- (ChromeSwitchPreference) findPreference(PREF_SIGN_OUT_SWITCH);
+ Preference signOutSwitch = findPreference(PREF_SIGN_OUT);
if (isChildAccount) {
getPreferenceScreen().removePreference(signOutSwitch);
} else {
- getPreferenceScreen().removePreference(findPreference(PREF_SIGN_IN_CHILD_MESSAGE));
- signOutSwitch.setChecked(true);
signOutSwitch.setEnabled(getSignOutAllowedPreferenceValue(getActivity()));
- signOutSwitch.setSummary(canAddAccounts() ? R.string.sign_in_accounts_message
- : R.string.sign_in_accounts_message_managed);
- signOutSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+ signOutSwitch.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
+ public boolean onPreferenceClick(Preference preference) {
if (!isVisible() || !isResumed()) return false;
- if ((boolean) newValue) return true;
if (ChromeSigninController.get(getActivity()).isSignedIn()
&& getSignOutAllowedPreferenceValue(getActivity())) {
@@ -251,28 +229,55 @@ public class AccountManagementFragment extends PreferenceFragment
mGaiaServiceType);
SignOutDialogFragment signOutFragment = new SignOutDialogFragment();
+ Bundle args = new Bundle();
+ args.putInt(SHOW_GAIA_SERVICE_TYPE_EXTRA, mGaiaServiceType);
+ signOutFragment.setArguments(args);
+
signOutFragment.setTargetFragment(AccountManagementFragment.this, 0);
signOutFragment.show(getFragmentManager(), SIGN_OUT_DIALOG_TAG);
+ return true;
}
- // Return false to prevent the switch from updating. The
- // AccountManagementFragment is hidden when the user signs out of Chrome, so the
- // switch never actually needs to be updated.
return false;
}
+
});
}
}
- private void configureAddAccountPreference(String fullName) {
+ private void configureSyncSettings() {
+ SyncPreference pref = (SyncPreference) findPreference(PREF_SYNC_SETTINGS);
+ final Preferences preferences = (Preferences) getActivity();
+ final Account account = ChromeSigninController.get(getActivity()).getSignedInUser();
+
+ pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ if (!isVisible() || !isResumed()) return false;
+
+ if (ProfileSyncService.get() == null) return true;
+
+ if (AndroidSyncSettings.isMasterSyncEnabled(preferences)) {
+ Bundle args = new Bundle();
+ args.putString(SyncCustomizationFragment.ARGUMENT_ACCOUNT, account.name);
+ preferences.startFragment(SyncCustomizationFragment.class.getName(), args);
+ } else {
+ openSyncSettingsPage(preferences);
+ }
+
+ return true;
+ }
+ });
+ }
+
+ private void configureAddAccountPreference() {
ChromeBasePreference addAccount = (ChromeBasePreference) findPreference(PREF_ADD_ACCOUNT);
if (ChildAccountService.isChildAccount()) {
getPreferenceScreen().removePreference(addAccount);
} else {
- String addAccountString = getResources().getString(
- R.string.account_management_add_account_title, fullName).toString();
- addAccount.setTitle(addAccountString);
+ addAccount.setTitle(getResources().getString(
+ R.string.account_management_add_account_title));
addAccount.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
@@ -286,7 +291,7 @@ public class AccountManagementFragment extends PreferenceFragment
getActivity(), AccountAdder.ADD_ACCOUNT_RESULT);
// Return to the last opened tab if triggered from the content area.
- if (mGaiaServiceType != GAIA_SERVICE_TYPE_NONE) {
+ if (mGaiaServiceType != AccountManagementScreenHelper.GAIA_SERVICE_TYPE_NONE) {
if (isAdded()) getActivity().finish();
}
@@ -302,59 +307,6 @@ public class AccountManagementFragment extends PreferenceFragment
}
}
- private void configureGoIncognitoPreferences(String fullName) {
- boolean isChildAccount = ChildAccountService.isChildAccount();
- Preference notYouPref = findPreference(PREF_NOT_YOU);
- ChromeBasePreference goIncognito = (ChromeBasePreference) findPreference(PREF_GO_INCOGNITO);
-
- if (isChildAccount) {
- getPreferenceScreen().removePreference(notYouPref);
- getPreferenceScreen().removePreference(goIncognito);
- } else {
- notYouPref.setTitle(
- getResources().getString(R.string.account_management_not_you_text, fullName));
- goIncognito.setOnPreferenceClickListener(new OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- if (!isVisible() || !isResumed()) return false;
- if (!PrefServiceBridge.getInstance().isIncognitoModeEnabled()) return false;
-
- AccountManagementScreenHelper.logEvent(
- ProfileAccountManagementMetrics.GO_INCOGNITO,
- mGaiaServiceType);
- openIncognitoTab(getActivity());
- if (isAdded()) getActivity().finish();
-
- return true;
- }
- });
- goIncognito.setManagedPreferenceDelegate(new ManagedPreferenceDelegate() {
- @Override
- public boolean isPreferenceControlledByPolicy(Preference preference) {
- // Incognito mode can be enabled by policy, but this has no visible impact on
- // the user. Thus, the managed icon is displayed only if incognito mode is
- // disabled.
- PrefServiceBridge prefs = PrefServiceBridge.getInstance();
- return prefs.isIncognitoModeManaged() && !prefs.isIncognitoModeEnabled();
- }
- });
- }
- }
-
- private static void openIncognitoTab(Activity activity) {
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(
- IntentHandler.GOOGLECHROME_NAVIGATE_PREFIX + UrlConstants.NTP_URL));
- intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
- intent.setPackage(activity.getApplicationContext().getPackageName());
- intent.setClassName(activity.getApplicationContext().getPackageName(),
- ChromeLauncherActivity.class.getName());
-
- intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
- | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK
- | Intent.FLAG_ACTIVITY_CLEAR_TOP);
- IntentHandler.startActivityForTrustedIntent(intent, activity);
- }
-
private void configureChildAccountPreferences() {
Preference parentAccounts = findPreference(PREF_PARENT_ACCOUNTS);
Preference childContent = findPreference(PREF_CHILD_CONTENT);
@@ -402,6 +354,15 @@ public class AccountManagementFragment extends PreferenceFragment
}
}
+ private void openSyncSettingsPage(Activity activity) {
+ // TODO(crbug/557784): This needs to actually take the user to a specific account settings
+ // page. There doesn't seem to be an obvious way to do that at the moment, but should update
+ // this when we figure that out.
+ Intent intent = new Intent(Settings.ACTION_SYNC_SETTINGS);
+ intent.putExtra(Settings.EXTRA_ACCOUNT_TYPES, new String[] {"com.google"});
+ activity.startActivity(intent);
+ }
+
private void updateAccountsList() {
PreferenceScreen prefScreen = getPreferenceScreen();
if (prefScreen == null) return;
@@ -410,65 +371,36 @@ public class AccountManagementFragment extends PreferenceFragment
prefScreen.removePreference(mAccountsListPreferences.get(i));
}
mAccountsListPreferences.clear();
- mPrimaryAccountPreference = null;
final Preferences activity = (Preferences) getActivity();
Account[] accounts = AccountManagerHelper.get(activity).getGoogleAccounts();
int nextPrefOrder = FIRST_ACCOUNT_PREF_ORDER;
- for (final Account account : accounts) {
+ for (Account account : accounts) {
ChromeBasePreference pref = new ChromeBasePreference(activity);
pref.setTitle(account.name);
- String signedInAccountName =
- ChromeSigninController.get(getActivity()).getSignedInAccountName();
- boolean isPrimaryAccount = TextUtils.equals(account.name, signedInAccountName);
boolean isChildAccount = ChildAccountService.isChildAccount();
- pref.setIcon(new BitmapDrawable(getResources(), isChildAccount
- ? getBadgedUserPicture(account.name) : getUserPicture(account.name)));
+ pref.setIcon(new BitmapDrawable(getResources(),
+ isChildAccount ? getBadgedUserPicture(account.name, getResources()) :
+ getUserPicture(account.name, getResources())));
- if (isPrimaryAccount) {
- mPrimaryAccountPreference = pref;
- pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- if (!isVisible() || !isResumed()) return false;
-
- AccountManagementScreenHelper.logEvent(
- ProfileAccountManagementMetrics.CLICK_PRIMARY_ACCOUNT,
- mGaiaServiceType);
-
- if (ProfileSyncService.get() == null) return true;
+ pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ if (!isVisible() || !isResumed()) return false;
- if (AndroidSyncSettings.isMasterSyncEnabled(activity)) {
- Bundle args = new Bundle();
- args.putString(
- SyncCustomizationFragment.ARGUMENT_ACCOUNT, account.name);
- activity.startFragment(SyncCustomizationFragment.class.getName(), args);
- } else {
- Intent intent = new Intent(Settings.ACTION_SYNC_SETTINGS);
- intent.putExtra("account_types", new String[]{"com.google"});
- activity.startActivity(intent);
- }
+ openSyncSettingsPage(activity);
+ return true;
+ }
- return true;
- }
- });
- }
+ });
pref.setOrder(nextPrefOrder++);
prefScreen.addPreference(pref);
mAccountsListPreferences.add(pref);
}
-
- updateSyncStatus();
- }
-
- private void updateSyncStatus() {
- if (mPrimaryAccountPreference != null) {
- mPrimaryAccountPreference.setSummary(getSyncStatusSummary(getActivity()));
- }
}
// ProfileDownloader.Observer implementation:
@@ -545,7 +477,10 @@ public class AccountManagementFragment extends PreferenceFragment
@Override
public void syncStateChanged() {
- updateSyncStatus();
+ SyncPreference pref = (SyncPreference) findPreference(PREF_SYNC_SETTINGS);
+ pref.updateSyncSummary();
+
+ // TODO(crbug/557784): Show notification for sync error
}
// SignInStateObserver implementation:
@@ -560,43 +495,6 @@ public class AccountManagementFragment extends PreferenceFragment
update();
}
- private static String getSyncStatusSummary(Activity activity) {
- if (!ChromeSigninController.get(activity).isSignedIn()) return "";
-
- ProfileSyncService profileSyncService = ProfileSyncService.get();
- Resources res = activity.getResources();
-
- if (ChildAccountService.isChildAccount()) {
- return res.getString(R.string.kids_account);
- }
-
- if (!AndroidSyncSettings.isMasterSyncEnabled(activity)) {
- return res.getString(R.string.sync_android_master_sync_disabled);
- }
-
- if (profileSyncService == null) {
- return res.getString(R.string.sync_is_disabled);
- }
-
- if (profileSyncService.getAuthError() != GoogleServiceAuthError.State.NONE) {
- return res.getString(profileSyncService.getAuthError().getMessage());
- }
-
- if (AndroidSyncSettings.isSyncEnabled(activity)) {
- if (!profileSyncService.isBackendInitialized()) {
- return res.getString(R.string.sync_setup_progress);
- }
-
- if (profileSyncService.isPassphraseRequiredForDecryption()) {
- return res.getString(R.string.sync_need_passphrase);
- }
- }
-
- return AndroidSyncSettings.isSyncEnabled(activity)
- ? res.getString(R.string.sync_is_enabled)
- : res.getString(R.string.sync_is_disabled);
- }
-
/**
* Open the account management UI.
* @param applicationContext An application context.
@@ -644,10 +542,9 @@ public class AccountManagementFragment extends PreferenceFragment
* @param badge A bitmap to overlay with.
* @return A bitmap with the badge overlaying the {@code userPicture}.
*/
- private Bitmap overlayChildBadgeOnUserPicture(Bitmap userPicture, Bitmap badge) {
- Resources resources = getResources();
- assert userPicture.getWidth()
- == resources.getDimensionPixelSize(R.dimen.user_picture_size);
+ private static Bitmap overlayChildBadgeOnUserPicture(
+ Bitmap userPicture, Bitmap badge, Resources resources) {
+ assert userPicture.getWidth() == resources.getDimensionPixelSize(R.dimen.user_picture_size);
int borderSize = resources.getDimensionPixelOffset(R.dimen.badge_border_size);
int badgeRadius = resources.getDimensionPixelOffset(R.dimen.badge_radius);
@@ -699,24 +596,28 @@ public class AccountManagementFragment extends PreferenceFragment
}
/**
+ * Gets the user picture for the account from the cache, or returns the default picture if
+ * unavailable.
+ *
* @param accountId A child account.
* @return A user picture with badge for a given child account.
*/
- private Bitmap getBadgedUserPicture(String accountId) {
+ public static Bitmap getBadgedUserPicture(String accountId, Resources res) {
if (sChildAccountId != null) {
assert TextUtils.equals(accountId, sChildAccountId);
return sCachedBadgedPicture;
}
sChildAccountId = accountId;
- Bitmap picture = getUserPicture(accountId);
- Bitmap badge = BitmapFactory.decodeResource(getResources(), R.drawable.ic_account_child);
- sCachedBadgedPicture = overlayChildBadgeOnUserPicture(picture, badge);
+ Bitmap picture = getUserPicture(accountId, res);
+ Bitmap badge = BitmapFactory.decodeResource(res, R.drawable.ic_account_child);
+ sCachedBadgedPicture = overlayChildBadgeOnUserPicture(picture, badge, res);
return sCachedBadgedPicture;
}
/**
- * Gets the user picture for the account from the cache,
- * or returns the default picture if unavailable.
+ * Gets the user picture for the account from the cache, or returns the default picture if
+ * unavailable.
+ *
* @param accountId An account.
* @param resources The collection containing the application resources.
* @return A user picture for a given account.
@@ -728,18 +629,9 @@ public class AccountManagementFragment extends PreferenceFragment
}
/**
- * Gets the user picture for the account from the cache,
- * or returns the default picture if unavailable.
- * @param accountId An account.
- * @return A user picture for a given account.
- */
- private Bitmap getUserPicture(String accountId) {
- return getUserPicture(accountId, getResources());
- }
-
- /**
- * Initiate fetching of an image and a picture of a given account.
- * Fetched data will be sent to observers of ProfileDownloader.
+ * Initiate fetching of an image and a picture of a given account. Fetched data will be sent to
+ * observers of ProfileDownloader.
+ *
* @param context A context.
* @param profile A profile.
* @param accountName An account name.
@@ -757,6 +649,7 @@ public class AccountManagementFragment extends PreferenceFragment
/**
* Prefetch the primary account image and name.
+ *
* @param context A context to use.
* @param profile A profile to use.
*/
@@ -789,6 +682,7 @@ public class AccountManagementFragment extends PreferenceFragment
/**
* Sets the sign out allowed preference value.
+ *
* @param context A context
* @param isAllowed True if the sign out is not disabled due to a child/EDU account
*/

Powered by Google App Engine
This is Rietveld 408576698