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; |
(...skipping 10 matching lines...) Expand all Loading... |
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.chrome.browser.util.IntentUtils; | 58 import org.chromium.chrome.browser.util.IntentUtils; |
58 import org.chromium.components.signin.AccountManagerHelper; | 59 import org.chromium.components.signin.AccountManagerHelper; |
59 import org.chromium.components.signin.ChromeSigninController; | 60 import org.chromium.components.signin.ChromeSigninController; |
60 | 61 |
61 import java.util.ArrayList; | |
62 import java.util.HashMap; | 62 import java.util.HashMap; |
63 | 63 |
64 /** | 64 /** |
65 * The settings screen with information and settings related to the user's accou
nts. | 65 * The settings screen with information and settings related to the user's accou
nts. |
66 * | 66 * |
67 * This shows which accounts the user is signed in with, allows the user to sign
out of Chrome, | 67 * This shows which accounts the user is signed in with, allows the user to sign
out of Chrome, |
68 * links to sync settings, has links to add accounts and go incognito, and shows
parental settings | 68 * links to sync settings, has links to add accounts and go incognito, and shows
parental settings |
69 * if a child account is in use. | 69 * if a child account is in use. |
70 * | 70 * |
71 * Note: This can be triggered from a web page, e.g. a GAIA sign-in page. | 71 * Note: This can be triggered from a web page, e.g. a GAIA sign-in page. |
72 */ | 72 */ |
73 public class AccountManagementFragment extends PreferenceFragment | 73 public class AccountManagementFragment extends PreferenceFragment |
74 implements SignOutDialogListener, ProfileDownloader.Observer, | 74 implements SignOutDialogListener, ProfileDownloader.Observer, |
75 SyncStateChangedListener, SignInStateObserver, | 75 SyncStateChangedListener, SignInStateObserver, |
76 ConfirmManagedSyncDataDialog.Listener { | 76 ConfirmManagedSyncDataDialog.Listener { |
77 private static final String TAG = "AcctManagementPref"; | 77 private static final String TAG = "AcctManagementPref"; |
78 | 78 |
79 public static final String SIGN_OUT_DIALOG_TAG = "sign_out_dialog_tag"; | 79 public static final String SIGN_OUT_DIALOG_TAG = "sign_out_dialog_tag"; |
80 private static final String CLEAR_DATA_PROGRESS_DIALOG_TAG = "clear_data_pro
gress"; | 80 private static final String CLEAR_DATA_PROGRESS_DIALOG_TAG = "clear_data_pro
gress"; |
81 | 81 |
82 /** | 82 /** |
83 * The key for an integer value in | 83 * The key for an integer value in |
84 * {@link Preferences#EXTRA_SHOW_FRAGMENT_ARGUMENTS} bundle to | 84 * {@link Preferences#EXTRA_SHOW_FRAGMENT_ARGUMENTS} bundle to |
85 * specify the correct GAIA service that has triggered the dialog. | 85 * specify the correct GAIA service that has triggered the dialog. |
86 * If the argument is not set, GAIA_SERVICE_TYPE_NONE is used as the origin
of the dialog. | 86 * If the argument is not set, GAIA_SERVICE_TYPE_NONE is used as the origin
of the dialog. |
87 */ | 87 */ |
88 public static final String SHOW_GAIA_SERVICE_TYPE_EXTRA = "ShowGAIAServiceTy
pe"; | 88 public static final String SHOW_GAIA_SERVICE_TYPE_EXTRA = "ShowGAIAServiceTy
pe"; |
89 | 89 |
90 /** | 90 /** |
91 * Account name preferences will be ordered sequentially, starting with this
"order" value. | |
92 * This ensures that the account name preferences appear in the correct loca
tion in the | |
93 * preference fragment. See account_management_preferences.xml for details. | |
94 */ | |
95 private static final int FIRST_ACCOUNT_PREF_ORDER = 100; | |
96 | |
97 /** | |
98 * SharedPreference name for the preference that disables signing out of Chr
ome. | 91 * SharedPreference name for the preference that disables signing out of Chr
ome. |
99 * Signing out is forever disabled once Chrome signs the user in automatical
ly | 92 * Signing out is forever disabled once Chrome signs the user in automatical
ly |
100 * if the device has a child account or if the device is an Android EDU devi
ce. | 93 * if the device has a child account or if the device is an Android EDU devi
ce. |
101 */ | 94 */ |
102 private static final String SIGN_OUT_ALLOWED = "auto_signed_in_school_accoun
t"; | 95 private static final String SIGN_OUT_ALLOWED = "auto_signed_in_school_accoun
t"; |
103 | 96 |
104 private static final HashMap<String, Pair<String, Bitmap>> sToNamePicture =
new HashMap<>(); | 97 private static final HashMap<String, Pair<String, Bitmap>> sToNamePicture =
new HashMap<>(); |
105 | 98 |
106 private static String sChildAccountId; | 99 private static String sChildAccountId; |
107 private static Bitmap sCachedBadgedPicture; | 100 private static Bitmap sCachedBadgedPicture; |
108 | 101 |
109 public static final String PREF_ADD_ACCOUNT = "add_account"; | 102 public static final String PREF_ACCOUNTS_CATEGORY = "accounts_category"; |
110 public static final String PREF_PARENTAL_SETTINGS = "parental_settings"; | 103 public static final String PREF_PARENTAL_SETTINGS = "parental_settings"; |
111 public static final String PREF_PARENT_ACCOUNTS = "parent_accounts"; | 104 public static final String PREF_PARENT_ACCOUNTS = "parent_accounts"; |
112 public static final String PREF_CHILD_CONTENT = "child_content"; | 105 public static final String PREF_CHILD_CONTENT = "child_content"; |
113 public static final String PREF_CHILD_CONTENT_DIVIDER = "child_content_divid
er"; | 106 public static final String PREF_CHILD_CONTENT_DIVIDER = "child_content_divid
er"; |
114 public static final String PREF_GOOGLE_ACTIVITY_CONTROLS = "google_activity_
controls"; | 107 public static final String PREF_GOOGLE_ACTIVITY_CONTROLS = "google_activity_
controls"; |
115 public static final String PREF_SYNC_SETTINGS = "sync_settings"; | 108 public static final String PREF_SYNC_SETTINGS = "sync_settings"; |
116 public static final String PREF_SIGN_OUT = "sign_out"; | 109 public static final String PREF_SIGN_OUT = "sign_out"; |
117 public static final String PREF_SIGN_OUT_DIVIDER = "sign_out_divider"; | 110 public static final String PREF_SIGN_OUT_DIVIDER = "sign_out_divider"; |
118 | 111 |
119 private static final String ACCOUNT_SETTINGS_ACTION = "android.settings.ACCO
UNT_SYNC_SETTINGS"; | 112 private static final String ACCOUNT_SETTINGS_ACTION = "android.settings.ACCO
UNT_SYNC_SETTINGS"; |
120 private static final String ACCOUNT_SETTINGS_ACCOUNT_KEY = "account"; | 113 private static final String ACCOUNT_SETTINGS_ACCOUNT_KEY = "account"; |
121 | 114 |
122 private int mGaiaServiceType; | 115 private int mGaiaServiceType; |
123 | 116 |
124 private ArrayList<Preference> mAccountsListPreferences = new ArrayList<>(); | |
125 | |
126 private Profile mProfile; | 117 private Profile mProfile; |
127 private String mSignedInAccountName; | 118 private String mSignedInAccountName; |
128 | 119 |
129 @Override | 120 @Override |
130 public void onCreate(Bundle savedState) { | 121 public void onCreate(Bundle savedState) { |
131 super.onCreate(savedState); | 122 super.onCreate(savedState); |
132 | 123 |
133 // Prevent sync from starting if it hasn't already to give the user a ch
ance to change | 124 // Prevent sync from starting if it hasn't already to give the user a ch
ance to change |
134 // their sync settings. | 125 // their sync settings. |
135 ProfileSyncService syncService = ProfileSyncService.get(); | 126 ProfileSyncService syncService = ProfileSyncService.get(); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 217 |
227 String fullName = getCachedUserName(mSignedInAccountName); | 218 String fullName = getCachedUserName(mSignedInAccountName); |
228 if (TextUtils.isEmpty(fullName)) { | 219 if (TextUtils.isEmpty(fullName)) { |
229 fullName = ProfileDownloader.getCachedFullName(mProfile); | 220 fullName = ProfileDownloader.getCachedFullName(mProfile); |
230 } | 221 } |
231 if (TextUtils.isEmpty(fullName)) fullName = mSignedInAccountName; | 222 if (TextUtils.isEmpty(fullName)) fullName = mSignedInAccountName; |
232 | 223 |
233 getActivity().setTitle(fullName); | 224 getActivity().setTitle(fullName); |
234 | 225 |
235 configureSignOutSwitch(); | 226 configureSignOutSwitch(); |
236 configureAddAccountPreference(); | |
237 configureChildAccountPreferences(); | 227 configureChildAccountPreferences(); |
238 configureSyncSettings(); | 228 configureSyncSettings(); |
239 configureGoogleActivityControls(); | 229 configureGoogleActivityControls(); |
240 | 230 |
241 updateAccountsList(); | 231 updateAccountsList(); |
242 } | 232 } |
243 | 233 |
244 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 234 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
245 private boolean canAddAccounts() { | 235 private boolean canAddAccounts() { |
246 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return true; | 236 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return true; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 public boolean onPreferenceClick(Preference preference) { | 314 public boolean onPreferenceClick(Preference preference) { |
325 Activity activity = getActivity(); | 315 Activity activity = getActivity(); |
326 AppHooks.get().createGoogleActivityController().openWebAndAppAct
ivitySettings( | 316 AppHooks.get().createGoogleActivityController().openWebAndAppAct
ivitySettings( |
327 activity, mSignedInAccountName); | 317 activity, mSignedInAccountName); |
328 RecordUserAction.record("Signin_AccountSettings_GoogleActivityCo
ntrolsClicked"); | 318 RecordUserAction.record("Signin_AccountSettings_GoogleActivityCo
ntrolsClicked"); |
329 return true; | 319 return true; |
330 } | 320 } |
331 }); | 321 }); |
332 } | 322 } |
333 | 323 |
334 private void configureAddAccountPreference() { | |
335 ChromeBasePreference addAccount = (ChromeBasePreference) findPreference(
PREF_ADD_ACCOUNT); | |
336 | |
337 if (mProfile.isChild()) { | |
338 getPreferenceScreen().removePreference(addAccount); | |
339 } else { | |
340 addAccount.setTitle(getResources().getString( | |
341 R.string.account_management_add_account_title)); | |
342 addAccount.setOnPreferenceClickListener(new OnPreferenceClickListene
r() { | |
343 @Override | |
344 public boolean onPreferenceClick(Preference preference) { | |
345 if (!isVisible() || !isResumed()) return false; | |
346 | |
347 AccountManagementScreenHelper.logEvent( | |
348 ProfileAccountManagementMetrics.ADD_ACCOUNT, | |
349 mGaiaServiceType); | |
350 | |
351 AccountAdder.getInstance().addAccount( | |
352 getActivity(), AccountAdder.ADD_ACCOUNT_RESULT); | |
353 | |
354 // Return to the last opened tab if triggered from the conte
nt area. | |
355 if (mGaiaServiceType != AccountManagementScreenHelper.GAIA_S
ERVICE_TYPE_NONE) { | |
356 if (isAdded()) getActivity().finish(); | |
357 } | |
358 | |
359 return true; | |
360 } | |
361 }); | |
362 addAccount.setManagedPreferenceDelegate(new ManagedPreferenceDelegat
e() { | |
363 @Override | |
364 public boolean isPreferenceControlledByPolicy(Preference prefere
nce) { | |
365 return !canAddAccounts(); | |
366 } | |
367 }); | |
368 } | |
369 } | |
370 | |
371 private void configureChildAccountPreferences() { | 324 private void configureChildAccountPreferences() { |
372 Preference parentAccounts = findPreference(PREF_PARENT_ACCOUNTS); | 325 Preference parentAccounts = findPreference(PREF_PARENT_ACCOUNTS); |
373 Preference childContent = findPreference(PREF_CHILD_CONTENT); | 326 Preference childContent = findPreference(PREF_CHILD_CONTENT); |
374 if (mProfile.isChild()) { | 327 if (mProfile.isChild()) { |
375 Resources res = getActivity().getResources(); | 328 Resources res = getActivity().getResources(); |
376 PrefServiceBridge prefService = PrefServiceBridge.getInstance(); | 329 PrefServiceBridge prefService = PrefServiceBridge.getInstance(); |
377 | 330 |
378 String firstParent = prefService.getSupervisedUserCustodianEmail(); | 331 String firstParent = prefService.getSupervisedUserCustodianEmail(); |
379 String secondParent = prefService.getSupervisedUserSecondCustodianEm
ail(); | 332 String secondParent = prefService.getSupervisedUserSecondCustodianEm
ail(); |
380 String parentText; | 333 String parentText; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 } else { | 366 } else { |
414 PreferenceScreen prefScreen = getPreferenceScreen(); | 367 PreferenceScreen prefScreen = getPreferenceScreen(); |
415 prefScreen.removePreference(findPreference(PREF_PARENTAL_SETTINGS)); | 368 prefScreen.removePreference(findPreference(PREF_PARENTAL_SETTINGS)); |
416 prefScreen.removePreference(parentAccounts); | 369 prefScreen.removePreference(parentAccounts); |
417 prefScreen.removePreference(childContent); | 370 prefScreen.removePreference(childContent); |
418 prefScreen.removePreference(findPreference(PREF_CHILD_CONTENT_DIVIDE
R)); | 371 prefScreen.removePreference(findPreference(PREF_CHILD_CONTENT_DIVIDE
R)); |
419 } | 372 } |
420 } | 373 } |
421 | 374 |
422 private void updateAccountsList() { | 375 private void updateAccountsList() { |
423 PreferenceScreen prefScreen = getPreferenceScreen(); | 376 PreferenceCategory accountsCategory = |
424 if (prefScreen == null) return; | 377 (PreferenceCategory) findPreference(PREF_ACCOUNTS_CATEGORY); |
| 378 if (accountsCategory == null) return; |
425 | 379 |
426 for (int i = 0; i < mAccountsListPreferences.size(); i++) { | 380 accountsCategory.removeAll(); |
427 prefScreen.removePreference(mAccountsListPreferences.get(i)); | |
428 } | |
429 mAccountsListPreferences.clear(); | |
430 | 381 |
| 382 boolean isChildAccount = mProfile.isChild(); |
431 Account[] accounts = AccountManagerHelper.get().getGoogleAccounts(); | 383 Account[] accounts = AccountManagerHelper.get().getGoogleAccounts(); |
432 int nextPrefOrder = FIRST_ACCOUNT_PREF_ORDER; | |
433 | |
434 for (final Account account : accounts) { | 384 for (final Account account : accounts) { |
435 ChromeBasePreference pref = new ChromeBasePreference(getActivity()); | 385 ChromeBasePreference pref = new ChromeBasePreference(getActivity()); |
436 pref.setTitle(account.name); | 386 pref.setTitle(account.name); |
437 | 387 |
438 boolean isChildAccount = mProfile.isChild(); | |
439 pref.setUseReducedPadding(isChildAccount); | 388 pref.setUseReducedPadding(isChildAccount); |
440 pref.setIcon(new BitmapDrawable(getResources(), | 389 pref.setIcon(new BitmapDrawable(getResources(), |
441 isChildAccount ? getBadgedUserPicture(account.name, getResou
rces()) : | 390 isChildAccount ? getBadgedUserPicture(account.name, getResou
rces()) : |
442 getUserPicture(account.name, getResources()))); | 391 getUserPicture(account.name, getResources()))); |
443 | 392 |
444 pref.setOnPreferenceClickListener(new OnPreferenceClickListener() { | 393 pref.setOnPreferenceClickListener(new OnPreferenceClickListener() { |
445 @Override | 394 @Override |
446 public boolean onPreferenceClick(Preference preference) { | 395 public boolean onPreferenceClick(Preference preference) { |
447 Intent intent = new Intent(ACCOUNT_SETTINGS_ACTION); | 396 Intent intent = new Intent(ACCOUNT_SETTINGS_ACTION); |
448 intent.putExtra(ACCOUNT_SETTINGS_ACCOUNT_KEY, account); | 397 intent.putExtra(ACCOUNT_SETTINGS_ACCOUNT_KEY, account); |
449 return IntentUtils.safeStartActivity(getActivity(), intent); | 398 return IntentUtils.safeStartActivity(getActivity(), intent); |
450 } | 399 } |
451 }); | 400 }); |
452 | 401 |
453 pref.setOrder(nextPrefOrder++); | 402 accountsCategory.addPreference(pref); |
454 prefScreen.addPreference(pref); | |
455 mAccountsListPreferences.add(pref); | |
456 } | 403 } |
| 404 |
| 405 if (!isChildAccount) { |
| 406 accountsCategory.addPreference(createAddAccountPreference()); |
| 407 } |
| 408 } |
| 409 |
| 410 private ChromeBasePreference createAddAccountPreference() { |
| 411 ChromeBasePreference addAccountPreference = new ChromeBasePreference(get
Activity()); |
| 412 addAccountPreference.setIcon(R.drawable.add_circle_blue); |
| 413 addAccountPreference.setTitle(R.string.account_management_add_account_ti
tle); |
| 414 addAccountPreference.setOnPreferenceClickListener(new OnPreferenceClickL
istener() { |
| 415 @Override |
| 416 public boolean onPreferenceClick(Preference preference) { |
| 417 if (!isVisible() || !isResumed()) return false; |
| 418 |
| 419 AccountManagementScreenHelper.logEvent( |
| 420 ProfileAccountManagementMetrics.ADD_ACCOUNT, mGaiaServic
eType); |
| 421 |
| 422 AccountAdder.getInstance().addAccount( |
| 423 getActivity(), AccountAdder.ADD_ACCOUNT_RESULT); |
| 424 |
| 425 // Return to the last opened tab if triggered from the content a
rea. |
| 426 if (mGaiaServiceType != AccountManagementScreenHelper.GAIA_SERVI
CE_TYPE_NONE) { |
| 427 if (isAdded()) getActivity().finish(); |
| 428 } |
| 429 |
| 430 return true; |
| 431 } |
| 432 }); |
| 433 addAccountPreference.setManagedPreferenceDelegate(new ManagedPreferenceD
elegate() { |
| 434 @Override |
| 435 public boolean isPreferenceControlledByPolicy(Preference preference)
{ |
| 436 return !canAddAccounts(); |
| 437 } |
| 438 }); |
| 439 return addAccountPreference; |
457 } | 440 } |
458 | 441 |
459 // ProfileDownloader.Observer implementation: | 442 // ProfileDownloader.Observer implementation: |
460 | 443 |
461 @Override | 444 @Override |
462 public void onProfileDownloaded(String accountId, String fullName, String gi
venName, | 445 public void onProfileDownloaded(String accountId, String fullName, String gi
venName, |
463 Bitmap bitmap) { | 446 Bitmap bitmap) { |
464 updateUserNamePictureCache(accountId, fullName, bitmap); | 447 updateUserNamePictureCache(accountId, fullName, bitmap); |
465 updateAccountsList(); | 448 updateAccountsList(); |
466 } | 449 } |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 * | 705 * |
723 * @param isAllowed True if the sign out is not disabled due to a child/EDU
account | 706 * @param isAllowed True if the sign out is not disabled due to a child/EDU
account |
724 */ | 707 */ |
725 public static void setSignOutAllowedPreferenceValue(boolean isAllowed) { | 708 public static void setSignOutAllowedPreferenceValue(boolean isAllowed) { |
726 ContextUtils.getAppSharedPreferences() | 709 ContextUtils.getAppSharedPreferences() |
727 .edit() | 710 .edit() |
728 .putBoolean(SIGN_OUT_ALLOWED, isAllowed) | 711 .putBoolean(SIGN_OUT_ALLOWED, isAllowed) |
729 .apply(); | 712 .apply(); |
730 } | 713 } |
731 } | 714 } |
OLD | NEW |