| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 | 178 |
| 179 /** | 179 /** |
| 180 * Initiate fetching the user accounts data (images and the full name). | 180 * Initiate fetching the user accounts data (images and the full name). |
| 181 * Fetched data will be sent to observers of ProfileDownloader. | 181 * Fetched data will be sent to observers of ProfileDownloader. |
| 182 * | 182 * |
| 183 * @param profile Profile to use. | 183 * @param profile Profile to use. |
| 184 */ | 184 */ |
| 185 private static void startFetchingAccountsInformation(Context context, Profil
e profile) { | 185 private static void startFetchingAccountsInformation(Context context, Profil
e profile) { |
| 186 Account[] accounts = AccountManagerHelper.get(context).getGoogleAccounts
(); | 186 Account[] accounts = AccountManagerHelper.get().getGoogleAccounts(); |
| 187 for (int i = 0; i < accounts.length; i++) { | 187 for (int i = 0; i < accounts.length; i++) { |
| 188 startFetchingAccountInformation(context, profile, accounts[i].name); | 188 startFetchingAccountInformation(context, profile, accounts[i].name); |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 | 191 |
| 192 public void update() { | 192 public void update() { |
| 193 final Context context = getActivity(); | 193 final Context context = getActivity(); |
| 194 if (context == null) return; | 194 if (context == null) return; |
| 195 | 195 |
| 196 if (getPreferenceScreen() != null) getPreferenceScreen().removeAll(); | 196 if (getPreferenceScreen() != null) getPreferenceScreen().removeAll(); |
| 197 | 197 |
| 198 ChromeSigninController signInController = ChromeSigninController.get(con
text); | 198 ChromeSigninController signInController = ChromeSigninController.get(); |
| 199 if (!signInController.isSignedIn()) { | 199 if (!signInController.isSignedIn()) { |
| 200 // The AccountManagementFragment can only be shown when the user is
signed in. If the | 200 // The AccountManagementFragment can only be shown when the user is
signed in. If the |
| 201 // user is signed out, exit the fragment. | 201 // user is signed out, exit the fragment. |
| 202 getActivity().finish(); | 202 getActivity().finish(); |
| 203 return; | 203 return; |
| 204 } | 204 } |
| 205 | 205 |
| 206 addPreferencesFromResource(R.xml.account_management_preferences); | 206 addPreferencesFromResource(R.xml.account_management_preferences); |
| 207 | 207 |
| 208 String signedInAccountName = | 208 String signedInAccountName = ChromeSigninController.get().getSignedInAcc
ountName(); |
| 209 ChromeSigninController.get(getActivity()).getSignedInAccountName
(); | |
| 210 String fullName = getCachedUserName(signedInAccountName); | 209 String fullName = getCachedUserName(signedInAccountName); |
| 211 if (TextUtils.isEmpty(fullName)) { | 210 if (TextUtils.isEmpty(fullName)) { |
| 212 fullName = ProfileDownloader.getCachedFullName(Profile.getLastUsedPr
ofile()); | 211 fullName = ProfileDownloader.getCachedFullName(Profile.getLastUsedPr
ofile()); |
| 213 } | 212 } |
| 214 if (TextUtils.isEmpty(fullName)) fullName = signedInAccountName; | 213 if (TextUtils.isEmpty(fullName)) fullName = signedInAccountName; |
| 215 | 214 |
| 216 getActivity().setTitle(fullName); | 215 getActivity().setTitle(fullName); |
| 217 | 216 |
| 218 configureSignOutSwitch(); | 217 configureSignOutSwitch(); |
| 219 configureAddAccountPreference(); | 218 configureAddAccountPreference(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 239 Preference signOutSwitch = findPreference(PREF_SIGN_OUT); | 238 Preference signOutSwitch = findPreference(PREF_SIGN_OUT); |
| 240 if (isChildAccount) { | 239 if (isChildAccount) { |
| 241 getPreferenceScreen().removePreference(signOutSwitch); | 240 getPreferenceScreen().removePreference(signOutSwitch); |
| 242 } else { | 241 } else { |
| 243 signOutSwitch.setEnabled(getSignOutAllowedPreferenceValue(getActivit
y())); | 242 signOutSwitch.setEnabled(getSignOutAllowedPreferenceValue(getActivit
y())); |
| 244 signOutSwitch.setOnPreferenceClickListener(new OnPreferenceClickList
ener() { | 243 signOutSwitch.setOnPreferenceClickListener(new OnPreferenceClickList
ener() { |
| 245 @Override | 244 @Override |
| 246 public boolean onPreferenceClick(Preference preference) { | 245 public boolean onPreferenceClick(Preference preference) { |
| 247 if (!isVisible() || !isResumed()) return false; | 246 if (!isVisible() || !isResumed()) return false; |
| 248 | 247 |
| 249 if (ChromeSigninController.get(getActivity()).isSignedIn() | 248 if (ChromeSigninController.get().isSignedIn() |
| 250 && getSignOutAllowedPreferenceValue(getActivity()))
{ | 249 && getSignOutAllowedPreferenceValue(getActivity()))
{ |
| 251 AccountManagementScreenHelper.logEvent( | 250 AccountManagementScreenHelper.logEvent( |
| 252 ProfileAccountManagementMetrics.TOGGLE_SIGNOUT, | 251 ProfileAccountManagementMetrics.TOGGLE_SIGNOUT, |
| 253 mGaiaServiceType); | 252 mGaiaServiceType); |
| 254 | 253 |
| 255 String managementDomain = | 254 String managementDomain = |
| 256 SigninManager.get(getActivity()).getManagementDo
main(); | 255 SigninManager.get(getActivity()).getManagementDo
main(); |
| 257 if (managementDomain != null) { | 256 if (managementDomain != null) { |
| 258 // Show the 'You are signing out of a managed accoun
t' dialog. | 257 // Show the 'You are signing out of a managed accoun
t' dialog. |
| 259 ConfirmManagedSyncDataDialog.showSignOutFromManagedA
ccountDialog( | 258 ConfirmManagedSyncDataDialog.showSignOutFromManagedA
ccountDialog( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 275 | 274 |
| 276 return false; | 275 return false; |
| 277 } | 276 } |
| 278 | 277 |
| 279 }); | 278 }); |
| 280 } | 279 } |
| 281 } | 280 } |
| 282 | 281 |
| 283 private void configureSyncSettings() { | 282 private void configureSyncSettings() { |
| 284 final Preferences preferences = (Preferences) getActivity(); | 283 final Preferences preferences = (Preferences) getActivity(); |
| 285 final Account account = ChromeSigninController.get(getActivity()).getSig
nedInUser(); | 284 final Account account = ChromeSigninController.get().getSignedInUser(); |
| 286 findPreference(PREF_SYNC_SETTINGS) | 285 findPreference(PREF_SYNC_SETTINGS) |
| 287 .setOnPreferenceClickListener(new OnPreferenceClickListener() { | 286 .setOnPreferenceClickListener(new OnPreferenceClickListener() { |
| 288 @Override | 287 @Override |
| 289 public boolean onPreferenceClick(Preference preference) { | 288 public boolean onPreferenceClick(Preference preference) { |
| 290 if (!isVisible() || !isResumed()) return false; | 289 if (!isVisible() || !isResumed()) return false; |
| 291 | 290 |
| 292 if (ProfileSyncService.get() == null) return true; | 291 if (ProfileSyncService.get() == null) return true; |
| 293 | 292 |
| 294 Bundle args = new Bundle(); | 293 Bundle args = new Bundle(); |
| 295 args.putString(SyncCustomizationFragment.ARGUMENT_ACCOUN
T, account.name); | 294 args.putString(SyncCustomizationFragment.ARGUMENT_ACCOUN
T, account.name); |
| 296 preferences.startFragment(SyncCustomizationFragment.clas
s.getName(), args); | 295 preferences.startFragment(SyncCustomizationFragment.clas
s.getName(), args); |
| 297 | 296 |
| 298 return true; | 297 return true; |
| 299 } | 298 } |
| 300 }); | 299 }); |
| 301 } | 300 } |
| 302 | 301 |
| 303 private void configureGoogleActivityControls() { | 302 private void configureGoogleActivityControls() { |
| 304 Preference pref = findPreference(PREF_GOOGLE_ACTIVITY_CONTROLS); | 303 Preference pref = findPreference(PREF_GOOGLE_ACTIVITY_CONTROLS); |
| 305 if (ChildAccountService.isChildAccount()) { | 304 if (ChildAccountService.isChildAccount()) { |
| 306 pref.setSummary(R.string.sign_in_google_activity_controls_message_ch
ild_account); | 305 pref.setSummary(R.string.sign_in_google_activity_controls_message_ch
ild_account); |
| 307 } | 306 } |
| 308 pref.setOnPreferenceClickListener(new OnPreferenceClickListener() { | 307 pref.setOnPreferenceClickListener(new OnPreferenceClickListener() { |
| 309 @Override | 308 @Override |
| 310 public boolean onPreferenceClick(Preference preference) { | 309 public boolean onPreferenceClick(Preference preference) { |
| 311 Activity activity = getActivity(); | 310 Activity activity = getActivity(); |
| 312 AppHooks.get().createGoogleActivityController().openWebAndAppAct
ivitySettings( | 311 AppHooks.get().createGoogleActivityController().openWebAndAppAct
ivitySettings( |
| 313 activity, ChromeSigninController.get(activity).getSigned
InAccountName()); | 312 activity, ChromeSigninController.get().getSignedInAccoun
tName()); |
| 314 RecordUserAction.record("Signin_AccountSettings_GoogleActivityCo
ntrolsClicked"); | 313 RecordUserAction.record("Signin_AccountSettings_GoogleActivityCo
ntrolsClicked"); |
| 315 return true; | 314 return true; |
| 316 } | 315 } |
| 317 }); | 316 }); |
| 318 } | 317 } |
| 319 | 318 |
| 320 private void configureAddAccountPreference() { | 319 private void configureAddAccountPreference() { |
| 321 ChromeBasePreference addAccount = (ChromeBasePreference) findPreference(
PREF_ADD_ACCOUNT); | 320 ChromeBasePreference addAccount = (ChromeBasePreference) findPreference(
PREF_ADD_ACCOUNT); |
| 322 | 321 |
| 323 if (ChildAccountService.isChildAccount()) { | 322 if (ChildAccountService.isChildAccount()) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 private void updateAccountsList() { | 408 private void updateAccountsList() { |
| 410 PreferenceScreen prefScreen = getPreferenceScreen(); | 409 PreferenceScreen prefScreen = getPreferenceScreen(); |
| 411 if (prefScreen == null) return; | 410 if (prefScreen == null) return; |
| 412 | 411 |
| 413 for (int i = 0; i < mAccountsListPreferences.size(); i++) { | 412 for (int i = 0; i < mAccountsListPreferences.size(); i++) { |
| 414 prefScreen.removePreference(mAccountsListPreferences.get(i)); | 413 prefScreen.removePreference(mAccountsListPreferences.get(i)); |
| 415 } | 414 } |
| 416 mAccountsListPreferences.clear(); | 415 mAccountsListPreferences.clear(); |
| 417 | 416 |
| 418 final Preferences activity = (Preferences) getActivity(); | 417 final Preferences activity = (Preferences) getActivity(); |
| 419 Account[] accounts = AccountManagerHelper.get(activity).getGoogleAccount
s(); | 418 Account[] accounts = AccountManagerHelper.get().getGoogleAccounts(); |
| 420 int nextPrefOrder = FIRST_ACCOUNT_PREF_ORDER; | 419 int nextPrefOrder = FIRST_ACCOUNT_PREF_ORDER; |
| 421 | 420 |
| 422 for (Account account : accounts) { | 421 for (Account account : accounts) { |
| 423 ChromeBasePreference pref = new ChromeBasePreference(activity); | 422 ChromeBasePreference pref = new ChromeBasePreference(activity); |
| 424 pref.setSelectable(false); | 423 pref.setSelectable(false); |
| 425 pref.setTitle(account.name); | 424 pref.setTitle(account.name); |
| 426 | 425 |
| 427 boolean isChildAccount = ChildAccountService.isChildAccount(); | 426 boolean isChildAccount = ChildAccountService.isChildAccount(); |
| 428 pref.setUseReducedPadding(isChildAccount); | 427 pref.setUseReducedPadding(isChildAccount); |
| 429 pref.setIcon(new BitmapDrawable(getResources(), | 428 pref.setIcon(new BitmapDrawable(getResources(), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 dialog.setMessage(getString(R.string.wiping_profile_data_message)); | 467 dialog.setMessage(getString(R.string.wiping_profile_data_message)); |
| 469 dialog.setIndeterminate(true); | 468 dialog.setIndeterminate(true); |
| 470 return dialog; | 469 return dialog; |
| 471 } | 470 } |
| 472 } | 471 } |
| 473 | 472 |
| 474 @Override | 473 @Override |
| 475 public void onSignOutClicked() { | 474 public void onSignOutClicked() { |
| 476 // In case the user reached this fragment without being signed in, we gu
ard the sign out so | 475 // In case the user reached this fragment without being signed in, we gu
ard the sign out so |
| 477 // we do not hit a native crash. | 476 // we do not hit a native crash. |
| 478 if (!ChromeSigninController.get(getActivity()).isSignedIn()) return; | 477 if (!ChromeSigninController.get().isSignedIn()) return; |
| 479 | 478 |
| 480 final Activity activity = getActivity(); | 479 final Activity activity = getActivity(); |
| 481 final DialogFragment clearDataProgressDialog = new ClearDataProgressDial
og(); | 480 final DialogFragment clearDataProgressDialog = new ClearDataProgressDial
og(); |
| 482 SigninManager.get(activity).signOut(null, new SigninManager.WipeDataHook
s() { | 481 SigninManager.get(activity).signOut(null, new SigninManager.WipeDataHook
s() { |
| 483 @Override | 482 @Override |
| 484 public void preWipeData() { | 483 public void preWipeData() { |
| 485 clearDataProgressDialog.show( | 484 clearDataProgressDialog.show( |
| 486 activity.getFragmentManager(), CLEAR_DATA_PROGRESS_DIALO
G_TAG); | 485 activity.getFragmentManager(), CLEAR_DATA_PROGRESS_DIALO
G_TAG); |
| 487 } | 486 } |
| 488 @Override | 487 @Override |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 update(); | 535 update(); |
| 537 } | 536 } |
| 538 | 537 |
| 539 @Override | 538 @Override |
| 540 public void onSignedOut() { | 539 public void onSignedOut() { |
| 541 update(); | 540 update(); |
| 542 } | 541 } |
| 543 | 542 |
| 544 /** | 543 /** |
| 545 * Open the account management UI. | 544 * Open the account management UI. |
| 546 * @param applicationContext An application context. | |
| 547 * @param profile A user profile. | |
| 548 * @param serviceType A signin::GAIAServiceType that triggered the dialog. | 545 * @param serviceType A signin::GAIAServiceType that triggered the dialog. |
| 549 */ | 546 */ |
| 550 public static void openAccountManagementScreen( | 547 public static void openAccountManagementScreen(int serviceType) { |
| 551 Context applicationContext, Profile profile, int serviceType) { | 548 Intent intent = PreferencesLauncher.createIntentForSettingsPage( |
| 552 Intent intent = PreferencesLauncher.createIntentForSettingsPage(applicat
ionContext, | 549 ContextUtils.getApplicationContext(), AccountManagementFragment.
class.getName()); |
| 553 AccountManagementFragment.class.getName()); | |
| 554 Bundle arguments = new Bundle(); | 550 Bundle arguments = new Bundle(); |
| 555 arguments.putInt(SHOW_GAIA_SERVICE_TYPE_EXTRA, serviceType); | 551 arguments.putInt(SHOW_GAIA_SERVICE_TYPE_EXTRA, serviceType); |
| 556 intent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, arguments); | 552 intent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, arguments); |
| 557 applicationContext.startActivity(intent); | 553 ContextUtils.getApplicationContext().startActivity(intent); |
| 558 } | 554 } |
| 559 | 555 |
| 560 /** | 556 /** |
| 561 * Converts a square user picture to a round user picture. | 557 * Converts a square user picture to a round user picture. |
| 562 * @param bitmap A bitmap to convert. | 558 * @param bitmap A bitmap to convert. |
| 563 * @return A rounded picture bitmap. | 559 * @return A rounded picture bitmap. |
| 564 */ | 560 */ |
| 565 public static Bitmap makeRoundUserPicture(Bitmap bitmap) { | 561 public static Bitmap makeRoundUserPicture(Bitmap bitmap) { |
| 566 if (bitmap == null) return null; | 562 if (bitmap == null) return null; |
| 567 | 563 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 context, profile, accountName, imageSidePixels, false); | 689 context, profile, accountName, imageSidePixels, false); |
| 694 } | 690 } |
| 695 | 691 |
| 696 /** | 692 /** |
| 697 * Prefetch the primary account image and name. | 693 * Prefetch the primary account image and name. |
| 698 * | 694 * |
| 699 * @param context A context to use. | 695 * @param context A context to use. |
| 700 * @param profile A profile to use. | 696 * @param profile A profile to use. |
| 701 */ | 697 */ |
| 702 public static void prefetchUserNamePicture(Context context, Profile profile)
{ | 698 public static void prefetchUserNamePicture(Context context, Profile profile)
{ |
| 703 final String accountName = ChromeSigninController.get(context).getSigned
InAccountName(); | 699 final String accountName = ChromeSigninController.get().getSignedInAccou
ntName(); |
| 704 if (TextUtils.isEmpty(accountName)) return; | 700 if (TextUtils.isEmpty(accountName)) return; |
| 705 if (sToNamePicture.get(accountName) != null) return; | 701 if (sToNamePicture.get(accountName) != null) return; |
| 706 | 702 |
| 707 ProfileDownloader.addObserver(new ProfileDownloader.Observer() { | 703 ProfileDownloader.addObserver(new ProfileDownloader.Observer() { |
| 708 @Override | 704 @Override |
| 709 public void onProfileDownloaded(String accountId, String fullName, S
tring givenName, | 705 public void onProfileDownloaded(String accountId, String fullName, S
tring givenName, |
| 710 Bitmap bitmap) { | 706 Bitmap bitmap) { |
| 711 if (TextUtils.equals(accountName, accountId)) { | 707 if (TextUtils.equals(accountName, accountId)) { |
| 712 updateUserNamePictureCache(accountId, fullName, bitmap); | 708 updateUserNamePictureCache(accountId, fullName, bitmap); |
| 713 ProfileDownloader.removeObserver(this); | 709 ProfileDownloader.removeObserver(this); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 732 * @param context A context | 728 * @param context A context |
| 733 * @param isAllowed True if the sign out is not disabled due to a child/EDU
account | 729 * @param isAllowed True if the sign out is not disabled due to a child/EDU
account |
| 734 */ | 730 */ |
| 735 public static void setSignOutAllowedPreferenceValue(Context context, boolean
isAllowed) { | 731 public static void setSignOutAllowedPreferenceValue(Context context, boolean
isAllowed) { |
| 736 ContextUtils.getAppSharedPreferences() | 732 ContextUtils.getAppSharedPreferences() |
| 737 .edit() | 733 .edit() |
| 738 .putBoolean(SIGN_OUT_ALLOWED, isAllowed) | 734 .putBoolean(SIGN_OUT_ALLOWED, isAllowed) |
| 739 .apply(); | 735 .apply(); |
| 740 } | 736 } |
| 741 } | 737 } |
| OLD | NEW |