Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/SyncPreference.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/SyncPreference.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/SyncPreference.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c85bd86028571f2213e7638fe5f215667cc99137 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/SyncPreference.java |
| @@ -0,0 +1,75 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
|
newt (away)
2016/02/12 22:03:50
where is this class used?
May
2016/02/16 17:32:07
in account_management_preferences.xml
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +package org.chromium.chrome.browser.preferences; |
| + |
| +import android.accounts.Account; |
| +import android.content.Context; |
| +import android.content.res.Resources; |
| +import android.preference.Preference; |
| +import android.util.AttributeSet; |
| + |
| +import org.chromium.chrome.R; |
| +import org.chromium.chrome.browser.childaccounts.ChildAccountService; |
| +import org.chromium.chrome.browser.sync.GoogleServiceAuthError; |
| +import org.chromium.chrome.browser.sync.ProfileSyncService; |
| +import org.chromium.sync.AndroidSyncSettings; |
| +import org.chromium.sync.signin.ChromeSigninController; |
| + |
| +/** |
| + * A custom preference that displays information about the currently synced account. |
|
newt (away)
2016/02/12 22:03:50
"displays the current sync account and status (ena
|
| + */ |
| +public class SyncPreference extends Preference { |
| + public SyncPreference(Context context, AttributeSet attrs) { |
| + super(context, attrs); |
| + setShouldDisableView(false); |
|
newt (away)
2016/02/12 22:03:50
why?
May
2016/02/16 17:32:07
This shouldn't be there. Removed.
|
| + updateSyncSummary(); |
| + } |
| + |
| + public void updateSyncSummary() { |
|
newt (away)
2016/02/12 22:03:50
javadoc for all public methods
May
2016/02/16 17:32:07
Done.
|
| + setSummary(getSyncStatusSummary(getContext())); |
| + } |
| + |
| + private static String getSyncStatusSummary(Context context) { |
| + if (!ChromeSigninController.get(context).isSignedIn()) return ""; |
| + |
| + ProfileSyncService profileSyncService = ProfileSyncService.get(); |
| + Resources res = context.getResources(); |
| + |
| + if (ChildAccountService.isChildAccount()) { |
| + return res.getString(R.string.kids_account); |
| + } |
| + |
| + if (!AndroidSyncSettings.isMasterSyncEnabled(context)) { |
| + 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(context)) { |
| + if (!profileSyncService.isBackendInitialized()) { |
| + return res.getString(R.string.sync_setup_progress); |
| + } |
| + |
| + if (profileSyncService.isPassphraseRequiredForDecryption()) { |
| + return res.getString(R.string.sync_need_passphrase); |
| + } |
| + } |
| + |
| + boolean syncEnabled = AndroidSyncSettings.isSyncEnabled(context); |
| + |
| + if (syncEnabled) { |
| + Account account = ChromeSigninController.get(context).getSignedInUser(); |
|
newt (away)
2016/02/12 22:03:50
Could this ever be null? It shouldn't be (since Ch
May
2016/02/16 17:32:07
Technically it can be (as in, there's a path to re
newt (away)
2016/02/16 23:05:01
Sounds good. Thanks for checking.
|
| + return String.format( |
| + context.getString(R.string.account_management_sync_summary), account.name); |
| + } else { |
| + return context.getString(R.string.sync_is_disabled); |
| + } |
| + } |
| +} |