OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.signin; | 5 package org.chromium.chrome.browser.signin; |
6 | 6 |
7 import android.accounts.Account; | 7 import android.accounts.Account; |
8 import android.annotation.TargetApi; | 8 import android.annotation.TargetApi; |
9 import android.app.Activity; | 9 import android.app.Activity; |
10 import android.app.Dialog; | 10 import android.app.Dialog; |
(...skipping 10 matching lines...) Expand all Loading... | |
21 import android.graphics.PorterDuff; | 21 import android.graphics.PorterDuff; |
22 import android.graphics.PorterDuffXfermode; | 22 import android.graphics.PorterDuffXfermode; |
23 import android.graphics.Rect; | 23 import android.graphics.Rect; |
24 import android.graphics.drawable.BitmapDrawable; | 24 import android.graphics.drawable.BitmapDrawable; |
25 import android.graphics.drawable.Drawable; | 25 import android.graphics.drawable.Drawable; |
26 import android.os.Build; | 26 import android.os.Build; |
27 import android.os.Bundle; | 27 import android.os.Bundle; |
28 import android.os.UserManager; | 28 import android.os.UserManager; |
29 import android.preference.Preference; | 29 import android.preference.Preference; |
30 import android.preference.Preference.OnPreferenceClickListener; | 30 import android.preference.Preference.OnPreferenceClickListener; |
31 import android.preference.PreferenceCategory; | |
31 import android.preference.PreferenceFragment; | 32 import android.preference.PreferenceFragment; |
32 import android.preference.PreferenceScreen; | 33 import android.preference.PreferenceScreen; |
33 import android.support.annotation.Nullable; | 34 import android.support.annotation.Nullable; |
34 import android.text.TextUtils; | 35 import android.text.TextUtils; |
35 import android.util.Pair; | 36 import android.util.Pair; |
36 import android.widget.ListView; | 37 import android.widget.ListView; |
37 | 38 |
38 import org.chromium.base.ApiCompatibilityUtils; | 39 import org.chromium.base.ApiCompatibilityUtils; |
39 import org.chromium.base.ContextUtils; | 40 import org.chromium.base.ContextUtils; |
40 import org.chromium.base.metrics.RecordUserAction; | 41 import org.chromium.base.metrics.RecordUserAction; |
41 import org.chromium.chrome.R; | 42 import org.chromium.chrome.R; |
42 import org.chromium.chrome.browser.AppHooks; | 43 import org.chromium.chrome.browser.AppHooks; |
43 import org.chromium.chrome.browser.preferences.ChromeBasePreference; | 44 import org.chromium.chrome.browser.preferences.ChromeBasePreference; |
44 import org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate; | 45 import org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate; |
45 import org.chromium.chrome.browser.preferences.PrefServiceBridge; | 46 import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
46 import org.chromium.chrome.browser.preferences.Preferences; | 47 import org.chromium.chrome.browser.preferences.Preferences; |
47 import org.chromium.chrome.browser.preferences.PreferencesLauncher; | 48 import org.chromium.chrome.browser.preferences.PreferencesLauncher; |
48 import org.chromium.chrome.browser.preferences.SyncPreference; | 49 import org.chromium.chrome.browser.preferences.SyncPreference; |
49 import org.chromium.chrome.browser.profiles.Profile; | 50 import org.chromium.chrome.browser.profiles.Profile; |
50 import org.chromium.chrome.browser.profiles.ProfileAccountManagementMetrics; | 51 import org.chromium.chrome.browser.profiles.ProfileAccountManagementMetrics; |
51 import org.chromium.chrome.browser.profiles.ProfileDownloader; | 52 import org.chromium.chrome.browser.profiles.ProfileDownloader; |
52 import org.chromium.chrome.browser.signin.SignOutDialogFragment.SignOutDialogLis tener; | 53 import org.chromium.chrome.browser.signin.SignOutDialogFragment.SignOutDialogLis tener; |
53 import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver; | 54 import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver; |
54 import org.chromium.chrome.browser.sync.ProfileSyncService; | 55 import org.chromium.chrome.browser.sync.ProfileSyncService; |
55 import org.chromium.chrome.browser.sync.ProfileSyncService.SyncStateChangedListe ner; | 56 import org.chromium.chrome.browser.sync.ProfileSyncService.SyncStateChangedListe ner; |
56 import org.chromium.chrome.browser.sync.ui.SyncCustomizationFragment; | 57 import org.chromium.chrome.browser.sync.ui.SyncCustomizationFragment; |
57 import org.chromium.components.signin.AccountManagerHelper; | 58 import org.chromium.components.signin.AccountManagerHelper; |
58 import org.chromium.components.signin.ChromeSigninController; | 59 import org.chromium.components.signin.ChromeSigninController; |
59 | 60 |
60 import java.util.ArrayList; | |
61 import java.util.HashMap; | 61 import java.util.HashMap; |
62 | 62 |
63 /** | 63 /** |
64 * The settings screen with information and settings related to the user's accou nts. | 64 * The settings screen with information and settings related to the user's accou nts. |
65 * | 65 * |
66 * This shows which accounts the user is signed in with, allows the user to sign out of Chrome, | 66 * This shows which accounts the user is signed in with, allows the user to sign out of Chrome, |
67 * links to sync settings, has links to add accounts and go incognito, and shows parental settings | 67 * links to sync settings, has links to add accounts and go incognito, and shows parental settings |
68 * if a child account is in use. | 68 * if a child account is in use. |
69 * | 69 * |
70 * Note: This can be triggered from a web page, e.g. a GAIA sign-in page. | 70 * Note: This can be triggered from a web page, e.g. a GAIA sign-in page. |
71 */ | 71 */ |
72 public class AccountManagementFragment extends PreferenceFragment | 72 public class AccountManagementFragment extends PreferenceFragment |
73 implements SignOutDialogListener, ProfileDownloader.Observer, | 73 implements SignOutDialogListener, ProfileDownloader.Observer, |
74 SyncStateChangedListener, SignInStateObserver, | 74 SyncStateChangedListener, SignInStateObserver, |
75 ConfirmManagedSyncDataDialog.Listener { | 75 ConfirmManagedSyncDataDialog.Listener { |
76 private static final String TAG = "AcctManagementPref"; | 76 private static final String TAG = "AcctManagementPref"; |
77 | 77 |
78 public static final String SIGN_OUT_DIALOG_TAG = "sign_out_dialog_tag"; | 78 public static final String SIGN_OUT_DIALOG_TAG = "sign_out_dialog_tag"; |
79 private static final String CLEAR_DATA_PROGRESS_DIALOG_TAG = "clear_data_pro gress"; | 79 private static final String CLEAR_DATA_PROGRESS_DIALOG_TAG = "clear_data_pro gress"; |
80 | 80 |
81 /** | 81 /** |
82 * The key for an integer value in | 82 * The key for an integer value in |
83 * {@link Preferences#EXTRA_SHOW_FRAGMENT_ARGUMENTS} bundle to | 83 * {@link Preferences#EXTRA_SHOW_FRAGMENT_ARGUMENTS} bundle to |
84 * specify the correct GAIA service that has triggered the dialog. | 84 * specify the correct GAIA service that has triggered the dialog. |
85 * If the argument is not set, GAIA_SERVICE_TYPE_NONE is used as the origin of the dialog. | 85 * If the argument is not set, GAIA_SERVICE_TYPE_NONE is used as the origin of the dialog. |
86 */ | 86 */ |
87 public static final String SHOW_GAIA_SERVICE_TYPE_EXTRA = "ShowGAIAServiceTy pe"; | 87 public static final String SHOW_GAIA_SERVICE_TYPE_EXTRA = "ShowGAIAServiceTy pe"; |
88 | 88 |
89 /** | 89 /** |
90 * Account name preferences will be ordered sequentially, starting with this "order" value. | |
91 * This ensures that the account name preferences appear in the correct loca tion in the | |
92 * preference fragment. See account_management_preferences.xml for details. | |
93 */ | |
94 private static final int FIRST_ACCOUNT_PREF_ORDER = 100; | |
95 | |
96 /** | |
97 * SharedPreference name for the preference that disables signing out of Chr ome. | 90 * SharedPreference name for the preference that disables signing out of Chr ome. |
98 * Signing out is forever disabled once Chrome signs the user in automatical ly | 91 * Signing out is forever disabled once Chrome signs the user in automatical ly |
99 * if the device has a child account or if the device is an Android EDU devi ce. | 92 * if the device has a child account or if the device is an Android EDU devi ce. |
100 */ | 93 */ |
101 private static final String SIGN_OUT_ALLOWED = "auto_signed_in_school_accoun t"; | 94 private static final String SIGN_OUT_ALLOWED = "auto_signed_in_school_accoun t"; |
102 | 95 |
103 private static final HashMap<String, Pair<String, Bitmap>> sToNamePicture = new HashMap<>(); | 96 private static final HashMap<String, Pair<String, Bitmap>> sToNamePicture = new HashMap<>(); |
104 | 97 |
105 private static String sChildAccountId; | 98 private static String sChildAccountId; |
106 private static Bitmap sCachedBadgedPicture; | 99 private static Bitmap sCachedBadgedPicture; |
107 | 100 |
108 public static final String PREF_ADD_ACCOUNT = "add_account"; | 101 public static final String PREF_ACCOUNTS_CATEGORY = "accounts_category"; |
109 public static final String PREF_PARENTAL_SETTINGS = "parental_settings"; | 102 public static final String PREF_PARENTAL_SETTINGS = "parental_settings"; |
110 public static final String PREF_PARENT_ACCOUNTS = "parent_accounts"; | 103 public static final String PREF_PARENT_ACCOUNTS = "parent_accounts"; |
111 public static final String PREF_CHILD_CONTENT = "child_content"; | 104 public static final String PREF_CHILD_CONTENT = "child_content"; |
112 public static final String PREF_CHILD_CONTENT_DIVIDER = "child_content_divid er"; | 105 public static final String PREF_CHILD_CONTENT_DIVIDER = "child_content_divid er"; |
113 public static final String PREF_GOOGLE_ACTIVITY_CONTROLS = "google_activity_ controls"; | 106 public static final String PREF_GOOGLE_ACTIVITY_CONTROLS = "google_activity_ controls"; |
114 public static final String PREF_SYNC_SETTINGS = "sync_settings"; | 107 public static final String PREF_SYNC_SETTINGS = "sync_settings"; |
115 public static final String PREF_SIGN_OUT = "sign_out"; | 108 public static final String PREF_SIGN_OUT = "sign_out"; |
116 public static final String PREF_SIGN_OUT_DIVIDER = "sign_out_divider"; | 109 public static final String PREF_SIGN_OUT_DIVIDER = "sign_out_divider"; |
117 | 110 |
118 private int mGaiaServiceType; | 111 private int mGaiaServiceType; |
119 | 112 |
120 private ArrayList<Preference> mAccountsListPreferences = new ArrayList<>(); | |
121 | |
122 private Profile mProfile; | 113 private Profile mProfile; |
123 private String mSignedInAccountName; | 114 private String mSignedInAccountName; |
124 | 115 |
125 @Override | 116 @Override |
126 public void onCreate(Bundle savedState) { | 117 public void onCreate(Bundle savedState) { |
127 super.onCreate(savedState); | 118 super.onCreate(savedState); |
128 | 119 |
129 // Prevent sync from starting if it hasn't already to give the user a ch ance to change | 120 // Prevent sync from starting if it hasn't already to give the user a ch ance to change |
130 // their sync settings. | 121 // their sync settings. |
131 ProfileSyncService syncService = ProfileSyncService.get(); | 122 ProfileSyncService syncService = ProfileSyncService.get(); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 | 213 |
223 String fullName = getCachedUserName(mSignedInAccountName); | 214 String fullName = getCachedUserName(mSignedInAccountName); |
224 if (TextUtils.isEmpty(fullName)) { | 215 if (TextUtils.isEmpty(fullName)) { |
225 fullName = ProfileDownloader.getCachedFullName(mProfile); | 216 fullName = ProfileDownloader.getCachedFullName(mProfile); |
226 } | 217 } |
227 if (TextUtils.isEmpty(fullName)) fullName = mSignedInAccountName; | 218 if (TextUtils.isEmpty(fullName)) fullName = mSignedInAccountName; |
228 | 219 |
229 getActivity().setTitle(fullName); | 220 getActivity().setTitle(fullName); |
230 | 221 |
231 configureSignOutSwitch(); | 222 configureSignOutSwitch(); |
232 configureAddAccountPreference(); | |
233 configureChildAccountPreferences(); | 223 configureChildAccountPreferences(); |
234 configureSyncSettings(); | 224 configureSyncSettings(); |
235 configureGoogleActivityControls(); | 225 configureGoogleActivityControls(); |
236 | 226 |
237 updateAccountsList(); | 227 updateAccountsList(); |
238 } | 228 } |
239 | 229 |
240 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 230 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
241 private boolean canAddAccounts() { | 231 private boolean canAddAccounts() { |
242 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return true; | 232 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return true; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 public boolean onPreferenceClick(Preference preference) { | 310 public boolean onPreferenceClick(Preference preference) { |
321 Activity activity = getActivity(); | 311 Activity activity = getActivity(); |
322 AppHooks.get().createGoogleActivityController().openWebAndAppAct ivitySettings( | 312 AppHooks.get().createGoogleActivityController().openWebAndAppAct ivitySettings( |
323 activity, mSignedInAccountName); | 313 activity, mSignedInAccountName); |
324 RecordUserAction.record("Signin_AccountSettings_GoogleActivityCo ntrolsClicked"); | 314 RecordUserAction.record("Signin_AccountSettings_GoogleActivityCo ntrolsClicked"); |
325 return true; | 315 return true; |
326 } | 316 } |
327 }); | 317 }); |
328 } | 318 } |
329 | 319 |
330 private void configureAddAccountPreference() { | |
331 ChromeBasePreference addAccount = (ChromeBasePreference) findPreference( PREF_ADD_ACCOUNT); | |
332 | |
333 if (mProfile.isChild()) { | |
334 getPreferenceScreen().removePreference(addAccount); | |
335 } else { | |
336 addAccount.setTitle(getResources().getString( | |
337 R.string.account_management_add_account_title)); | |
338 addAccount.setOnPreferenceClickListener(new OnPreferenceClickListene r() { | |
339 @Override | |
340 public boolean onPreferenceClick(Preference preference) { | |
341 if (!isVisible() || !isResumed()) return false; | |
342 | |
343 AccountManagementScreenHelper.logEvent( | |
344 ProfileAccountManagementMetrics.ADD_ACCOUNT, | |
345 mGaiaServiceType); | |
346 | |
347 AccountAdder.getInstance().addAccount( | |
348 getActivity(), AccountAdder.ADD_ACCOUNT_RESULT); | |
349 | |
350 // Return to the last opened tab if triggered from the conte nt area. | |
351 if (mGaiaServiceType != AccountManagementScreenHelper.GAIA_S ERVICE_TYPE_NONE) { | |
352 if (isAdded()) getActivity().finish(); | |
353 } | |
354 | |
355 return true; | |
356 } | |
357 }); | |
358 addAccount.setManagedPreferenceDelegate(new ManagedPreferenceDelegat e() { | |
359 @Override | |
360 public boolean isPreferenceControlledByPolicy(Preference prefere nce) { | |
361 return !canAddAccounts(); | |
362 } | |
363 }); | |
364 } | |
365 } | |
366 | |
367 private void configureChildAccountPreferences() { | 320 private void configureChildAccountPreferences() { |
368 Preference parentAccounts = findPreference(PREF_PARENT_ACCOUNTS); | 321 Preference parentAccounts = findPreference(PREF_PARENT_ACCOUNTS); |
369 Preference childContent = findPreference(PREF_CHILD_CONTENT); | 322 Preference childContent = findPreference(PREF_CHILD_CONTENT); |
370 if (mProfile.isChild()) { | 323 if (mProfile.isChild()) { |
371 Resources res = getActivity().getResources(); | 324 Resources res = getActivity().getResources(); |
372 PrefServiceBridge prefService = PrefServiceBridge.getInstance(); | 325 PrefServiceBridge prefService = PrefServiceBridge.getInstance(); |
373 | 326 |
374 String firstParent = prefService.getSupervisedUserCustodianEmail(); | 327 String firstParent = prefService.getSupervisedUserCustodianEmail(); |
375 String secondParent = prefService.getSupervisedUserSecondCustodianEm ail(); | 328 String secondParent = prefService.getSupervisedUserSecondCustodianEm ail(); |
376 String parentText; | 329 String parentText; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
409 } else { | 362 } else { |
410 PreferenceScreen prefScreen = getPreferenceScreen(); | 363 PreferenceScreen prefScreen = getPreferenceScreen(); |
411 prefScreen.removePreference(findPreference(PREF_PARENTAL_SETTINGS)); | 364 prefScreen.removePreference(findPreference(PREF_PARENTAL_SETTINGS)); |
412 prefScreen.removePreference(parentAccounts); | 365 prefScreen.removePreference(parentAccounts); |
413 prefScreen.removePreference(childContent); | 366 prefScreen.removePreference(childContent); |
414 prefScreen.removePreference(findPreference(PREF_CHILD_CONTENT_DIVIDE R)); | 367 prefScreen.removePreference(findPreference(PREF_CHILD_CONTENT_DIVIDE R)); |
415 } | 368 } |
416 } | 369 } |
417 | 370 |
418 private void updateAccountsList() { | 371 private void updateAccountsList() { |
419 PreferenceScreen prefScreen = getPreferenceScreen(); | 372 PreferenceCategory accountsCategory = |
420 if (prefScreen == null) return; | 373 (PreferenceCategory) findPreference(PREF_ACCOUNTS_CATEGORY); |
374 if (accountsCategory == null) return; | |
421 | 375 |
422 for (int i = 0; i < mAccountsListPreferences.size(); i++) { | 376 accountsCategory.removeAll(); |
423 prefScreen.removePreference(mAccountsListPreferences.get(i)); | |
424 } | |
425 mAccountsListPreferences.clear(); | |
426 | 377 |
427 final Preferences activity = (Preferences) getActivity(); | 378 boolean isChildAccount = mProfile.isChild(); |
428 Account[] accounts = AccountManagerHelper.get().getGoogleAccounts(); | 379 Account[] accounts = AccountManagerHelper.get().getGoogleAccounts(); |
429 int nextPrefOrder = FIRST_ACCOUNT_PREF_ORDER; | |
430 | |
431 for (Account account : accounts) { | 380 for (Account account : accounts) { |
432 ChromeBasePreference pref = new ChromeBasePreference(activity); | 381 ChromeBasePreference pref = new ChromeBasePreference(getActivity()); |
433 pref.setSelectable(false); | 382 pref.setSelectable(false); |
434 pref.setTitle(account.name); | 383 pref.setTitle(account.name); |
435 | 384 |
436 boolean isChildAccount = mProfile.isChild(); | |
437 pref.setUseReducedPadding(isChildAccount); | 385 pref.setUseReducedPadding(isChildAccount); |
438 pref.setIcon(new BitmapDrawable(getResources(), | 386 pref.setIcon(new BitmapDrawable(getResources(), |
439 isChildAccount ? getBadgedUserPicture(account.name, getResou rces()) : | 387 isChildAccount ? getBadgedUserPicture(account.name, getResou rces()) : |
440 getUserPicture(account.name, getResources()))); | 388 getUserPicture(account.name, getResources()))); |
441 | 389 |
442 pref.setOrder(nextPrefOrder++); | 390 accountsCategory.addPreference(pref); |
443 prefScreen.addPreference(pref); | |
444 mAccountsListPreferences.add(pref); | |
445 } | 391 } |
392 | |
393 if (isChildAccount) { | |
David Trainor- moved to gerrit
2017/05/31 15:57:14
Should this be !isChildAccount? I'm assuming we w
bsazonov
2017/05/31 16:06:42
Oops! Sorry for that.
Thanks a lot for catching th
| |
394 accountsCategory.addPreference(createAddAccountPreference()); | |
395 } | |
396 } | |
397 | |
398 private ChromeBasePreference createAddAccountPreference() { | |
399 ChromeBasePreference addAccountPreference = new ChromeBasePreference(get Activity()); | |
400 addAccountPreference.setIcon(R.drawable.add_circle_blue); | |
401 addAccountPreference.setTitle(R.string.account_management_add_account_ti tle); | |
402 addAccountPreference.setOnPreferenceClickListener(new OnPreferenceClickL istener() { | |
403 @Override | |
404 public boolean onPreferenceClick(Preference preference) { | |
405 if (!isVisible() || !isResumed()) return false; | |
406 | |
407 AccountManagementScreenHelper.logEvent( | |
408 ProfileAccountManagementMetrics.ADD_ACCOUNT, mGaiaServic eType); | |
409 | |
410 AccountAdder.getInstance().addAccount( | |
411 getActivity(), AccountAdder.ADD_ACCOUNT_RESULT); | |
412 | |
413 // Return to the last opened tab if triggered from the content a rea. | |
414 if (mGaiaServiceType != AccountManagementScreenHelper.GAIA_SERVI CE_TYPE_NONE) { | |
415 if (isAdded()) getActivity().finish(); | |
416 } | |
417 | |
418 return true; | |
419 } | |
420 }); | |
421 addAccountPreference.setManagedPreferenceDelegate(new ManagedPreferenceD elegate() { | |
422 @Override | |
423 public boolean isPreferenceControlledByPolicy(Preference preference) { | |
424 return !canAddAccounts(); | |
425 } | |
426 }); | |
427 return addAccountPreference; | |
446 } | 428 } |
447 | 429 |
448 // ProfileDownloader.Observer implementation: | 430 // ProfileDownloader.Observer implementation: |
449 | 431 |
450 @Override | 432 @Override |
451 public void onProfileDownloaded(String accountId, String fullName, String gi venName, | 433 public void onProfileDownloaded(String accountId, String fullName, String gi venName, |
452 Bitmap bitmap) { | 434 Bitmap bitmap) { |
453 updateUserNamePictureCache(accountId, fullName, bitmap); | 435 updateUserNamePictureCache(accountId, fullName, bitmap); |
454 updateAccountsList(); | 436 updateAccountsList(); |
455 } | 437 } |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
711 * | 693 * |
712 * @param isAllowed True if the sign out is not disabled due to a child/EDU account | 694 * @param isAllowed True if the sign out is not disabled due to a child/EDU account |
713 */ | 695 */ |
714 public static void setSignOutAllowedPreferenceValue(boolean isAllowed) { | 696 public static void setSignOutAllowedPreferenceValue(boolean isAllowed) { |
715 ContextUtils.getAppSharedPreferences() | 697 ContextUtils.getAppSharedPreferences() |
716 .edit() | 698 .edit() |
717 .putBoolean(SIGN_OUT_ALLOWED, isAllowed) | 699 .putBoolean(SIGN_OUT_ALLOWED, isAllowed) |
718 .apply(); | 700 .apply(); |
719 } | 701 } |
720 } | 702 } |
OLD | NEW |