Commit fa281606 authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Signin][Android] Change getGoogleAccounts() return type to List

This CL changes AccountManagerFacade.getGoogleAccounts() return type
from Account[] to List<Account>. This is done to ensure immutability of
this list and for consistency with getGoogleAccountNames().

Bug: None
Change-Id: If703947028dd4ed0c9fdaf18856d97d6b6a52aa5
Reviewed-on: https://chromium-review.googlesource.com/c/1338088
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610026}
parent 4aa17434
...@@ -17,6 +17,7 @@ import org.chromium.base.annotations.CalledByNative; ...@@ -17,6 +17,7 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.components.signin.AccountManagerFacade; import org.chromium.components.signin.AccountManagerFacade;
import java.io.File; import java.io.File;
import java.util.List;
/** /**
* Helper for issuing intents to the android framework. * Helper for issuing intents to the android framework.
...@@ -40,10 +41,10 @@ public abstract class IntentHelper { ...@@ -40,10 +41,10 @@ public abstract class IntentHelper {
static void sendEmail( static void sendEmail(
String email, String subject, String body, String chooserTitle, String fileToAttach) { String email, String subject, String body, String chooserTitle, String fileToAttach) {
if (TextUtils.isEmpty(email)) { if (TextUtils.isEmpty(email)) {
Account[] accounts = AccountManagerFacade.get().tryGetGoogleAccounts(); List<Account> accounts = AccountManagerFacade.get().tryGetGoogleAccounts();
if (accounts != null && accounts.length == 1 if (accounts != null && accounts.size() == 1
&& Patterns.EMAIL_ADDRESS.matcher(accounts[0].name).matches()) { && Patterns.EMAIL_ADDRESS.matcher(accounts.get(0).name).matches()) {
email = accounts[0].name; email = accounts.get(0).name;
} }
} }
......
...@@ -376,9 +376,9 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat ...@@ -376,9 +376,9 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat
/** Choose an account to authenticate as for making RPCs to the backend. */ /** Choose an account to authenticate as for making RPCs to the backend. */
private void chooseAccountAsync(Bundle extras) { private void chooseAccountAsync(Bundle extras) {
AccountManagerFacade.get().tryGetGoogleAccounts(accounts -> { AccountManagerFacade.get().tryGetGoogleAccounts(accounts -> {
if (accounts.length == 1) { if (accounts.size() == 1) {
// If there's only one account, there aren't any doubts. // If there's only one account, there aren't any doubts.
onAccountChosen(accounts[0]); onAccountChosen(accounts.get(0));
return; return;
} }
Account signedIn = Account signedIn =
...@@ -414,8 +414,9 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat ...@@ -414,8 +414,9 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat
} }
} }
private static Account findAccountByName(Account[] accounts, String name) { private static Account findAccountByName(List<Account> accounts, String name) {
for (Account account : accounts) { for (int i = 0; i < accounts.size(); i++) {
Account account = accounts.get(i);
if (account.name.equals(name)) { if (account.name.equals(name)) {
return account; return account;
} }
......
...@@ -41,11 +41,11 @@ public class ChildAccountService { ...@@ -41,11 +41,11 @@ public class ChildAccountService {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
final AccountManagerFacade accountManager = AccountManagerFacade.get(); final AccountManagerFacade accountManager = AccountManagerFacade.get();
accountManager.tryGetGoogleAccounts(accounts -> { accountManager.tryGetGoogleAccounts(accounts -> {
if (accounts.length != 1) { if (accounts.size() != 1) {
// Child accounts can't share a device. // Child accounts can't share a device.
callback.onResult(ChildAccountStatus.NOT_CHILD); callback.onResult(ChildAccountStatus.NOT_CHILD);
} else { } else {
accountManager.checkChildAccountStatus(accounts[0], callback); accountManager.checkChildAccountStatus(accounts.get(0), callback);
} }
}); });
} }
......
...@@ -60,7 +60,7 @@ public abstract class FirstRunFlowSequencer { ...@@ -60,7 +60,7 @@ public abstract class FirstRunFlowSequencer {
// The following are initialized via initializeSharedState(). // The following are initialized via initializeSharedState().
private boolean mIsAndroidEduDevice; private boolean mIsAndroidEduDevice;
private @ChildAccountStatus.Status int mChildAccountStatus; private @ChildAccountStatus.Status int mChildAccountStatus;
private Account[] mGoogleAccounts; private List<Account> mGoogleAccounts;
private boolean mForceEduSignIn; private boolean mForceEduSignIn;
/** /**
...@@ -113,7 +113,7 @@ public abstract class FirstRunFlowSequencer { ...@@ -113,7 +113,7 @@ public abstract class FirstRunFlowSequencer {
} }
@VisibleForTesting @VisibleForTesting
protected Account[] getGoogleAccounts() { protected List<Account> getGoogleAccounts() {
return AccountManagerFacade.get().tryGetGoogleAccounts(); return AccountManagerFacade.get().tryGetGoogleAccounts();
} }
...@@ -163,7 +163,7 @@ public abstract class FirstRunFlowSequencer { ...@@ -163,7 +163,7 @@ public abstract class FirstRunFlowSequencer {
mGoogleAccounts = getGoogleAccounts(); mGoogleAccounts = getGoogleAccounts();
// EDU devices should always have exactly 1 google account, which will be automatically // EDU devices should always have exactly 1 google account, which will be automatically
// signed-in. All FRE screens are skipped in this case. // signed-in. All FRE screens are skipped in this case.
mForceEduSignIn = mIsAndroidEduDevice && mGoogleAccounts.length == 1 && !isSignedIn(); mForceEduSignIn = mIsAndroidEduDevice && mGoogleAccounts.size() == 1 && !isSignedIn();
} }
void processFreEnvironmentPreNative() { void processFreEnvironmentPreNative() {
...@@ -195,7 +195,7 @@ public abstract class FirstRunFlowSequencer { ...@@ -195,7 +195,7 @@ public abstract class FirstRunFlowSequencer {
/** /**
* Called onNativeInitialized() a given flow as completed. * Called onNativeInitialized() a given flow as completed.
* @param data Resulting FRE properties bundle. * @param freProperties Resulting FRE properties bundle.
*/ */
public void onNativeInitialized(Bundle freProperties) { public void onNativeInitialized(Bundle freProperties) {
// We show the sign-in page if sync is allowed, and not signed in, and this is not // We show the sign-in page if sync is allowed, and not signed in, and this is not
...@@ -203,13 +203,13 @@ public abstract class FirstRunFlowSequencer { ...@@ -203,13 +203,13 @@ public abstract class FirstRunFlowSequencer {
// - no "skip the first use hints" is set, or // - no "skip the first use hints" is set, or
// - "skip the first use hints" is set, but there is at least one account. // - "skip the first use hints" is set, but there is at least one account.
boolean offerSignInOk = isSyncAllowed() && !isSignedIn() && !mForceEduSignIn boolean offerSignInOk = isSyncAllowed() && !isSignedIn() && !mForceEduSignIn
&& (!shouldSkipFirstUseHints() || mGoogleAccounts.length > 0); && (!shouldSkipFirstUseHints() || !mGoogleAccounts.isEmpty());
freProperties.putBoolean(FirstRunActivity.SHOW_SIGNIN_PAGE, offerSignInOk); freProperties.putBoolean(FirstRunActivity.SHOW_SIGNIN_PAGE, offerSignInOk);
if (mForceEduSignIn || ChildAccountStatus.isChild(mChildAccountStatus)) { if (mForceEduSignIn || ChildAccountStatus.isChild(mChildAccountStatus)) {
// If the device is an Android EDU device or has a child account, there should be // If the device is an Android EDU device or has a child account, there should be
// exactly account on the device. Force sign-in in to that account. // exactly account on the device. Force sign-in in to that account.
freProperties.putString( freProperties.putString(
AccountFirstRunFragment.FORCE_SIGNIN_ACCOUNT_TO, mGoogleAccounts[0].name); AccountFirstRunFragment.FORCE_SIGNIN_ACCOUNT_TO, mGoogleAccounts.get(0).name);
} }
freProperties.putBoolean( freProperties.putBoolean(
......
...@@ -4,10 +4,8 @@ ...@@ -4,10 +4,8 @@
package org.chromium.chrome.browser.firstrun; package org.chromium.chrome.browser.firstrun;
import android.accounts.Account;
import android.content.Context; import android.content.Context;
import org.chromium.base.Callback;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils; import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
...@@ -77,29 +75,26 @@ public final class ForcedSigninProcessor { ...@@ -77,29 +75,26 @@ public final class ForcedSigninProcessor {
Log.d(TAG, "Sign in disallowed"); Log.d(TAG, "Sign in disallowed");
return; return;
} }
AccountManagerFacade.get().tryGetGoogleAccounts(new Callback<Account[]>() { AccountManagerFacade.get().tryGetGoogleAccounts(accounts -> {
@Override if (accounts.size() != 1) {
public void onResult(Account[] accounts) { Log.d(TAG, "Incorrect number of accounts (%d)", accounts.size());
if (accounts.length != 1) { return;
Log.d(TAG, "Incorrect number of accounts (%d)", accounts.length); }
return; signinManager.signIn(accounts.get(0), null, new SigninManager.SignInCallback() {
} @Override
signinManager.signIn(accounts[0], null, new SigninManager.SignInCallback() { public void onSignInComplete() {
@Override if (onComplete != null) {
public void onSignInComplete() { onComplete.run();
if (onComplete != null) {
onComplete.run();
}
} }
}
@Override @Override
public void onSignInAborted() { public void onSignInAborted() {
if (onComplete != null) { if (onComplete != null) {
onComplete.run(); onComplete.run();
}
} }
}); }
} });
}); });
} }
......
...@@ -201,7 +201,7 @@ public abstract class RequestGenerator { ...@@ -201,7 +201,7 @@ public abstract class RequestGenerator {
() -> ProcessInitializationHandler.getInstance().initializePreNative()); () -> ProcessInitializationHandler.getInstance().initializePreNative());
int numAccounts = 0; int numAccounts = 0;
try { try {
numAccounts = AccountManagerFacade.get().getGoogleAccounts().length; numAccounts = AccountManagerFacade.get().getGoogleAccounts().size();
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Can't get number of accounts.", e); Log.e(TAG, "Can't get number of accounts.", e);
} }
......
...@@ -15,6 +15,8 @@ import org.chromium.components.signin.AccountManagerFacade; ...@@ -15,6 +15,8 @@ import org.chromium.components.signin.AccountManagerFacade;
import org.chromium.components.signin.ChromeSigninController; import org.chromium.components.signin.ChromeSigninController;
import org.chromium.components.sync.AndroidSyncSettings; import org.chromium.components.sync.AndroidSyncSettings;
import java.util.List;
/** /**
* A preference that displays the account currently being synced and allows the user to choose a new * A preference that displays the account currently being synced and allows the user to choose a new
* account to use for syncing. The values used are the account names. * account to use for syncing. The values used are the account names.
...@@ -47,15 +49,15 @@ public class SyncedAccountPreference extends ListPreference { ...@@ -47,15 +49,15 @@ public class SyncedAccountPreference extends ListPreference {
// signed in account // signed in account
} }
Account[] accounts = AccountManagerFacade.get().tryGetGoogleAccounts(); List<Account> accounts = AccountManagerFacade.get().tryGetGoogleAccounts();
String[] accountNames = new String[accounts.length]; String[] accountNames = new String[accounts.size()];
String[] accountValues = new String[accounts.length]; String[] accountValues = new String[accounts.size()];
String signedInAccountName = ChromeSigninController.get().getSignedInAccountName(); String signedInAccountName = ChromeSigninController.get().getSignedInAccountName();
String signedInSettingsKey = ""; String signedInSettingsKey = "";
for (int i = 0; i < accounts.length; ++i) { for (int i = 0; i < accounts.size(); ++i) {
Account account = accounts[i]; Account account = accounts.get(i);
accountNames[i] = account.name; accountNames[i] = account.name;
accountValues[i] = account.name; accountValues[i] = account.name;
boolean isPrimaryAccount = TextUtils.equals(account.name, signedInAccountName); boolean isPrimaryAccount = TextUtils.equals(account.name, signedInAccountName);
......
...@@ -49,6 +49,8 @@ import org.chromium.chrome.browser.sync.ui.SyncCustomizationFragment; ...@@ -49,6 +49,8 @@ import org.chromium.chrome.browser.sync.ui.SyncCustomizationFragment;
import org.chromium.components.signin.AccountManagerFacade; import org.chromium.components.signin.AccountManagerFacade;
import org.chromium.components.signin.ChromeSigninController; import org.chromium.components.signin.ChromeSigninController;
import java.util.List;
/** /**
* The settings screen with information and settings related to the user's accounts. * The settings screen with information and settings related to the user's accounts.
* *
...@@ -358,8 +360,9 @@ public class AccountManagementFragment extends PreferenceFragment ...@@ -358,8 +360,9 @@ public class AccountManagementFragment extends PreferenceFragment
accountsCategory.removeAll(); accountsCategory.removeAll();
Account[] accounts = AccountManagerFacade.get().tryGetGoogleAccounts(); List<Account> accounts = AccountManagerFacade.get().tryGetGoogleAccounts();
for (final Account account : accounts) { for (int i = 0; i < accounts.size(); i++) {
Account account = accounts.get(i);
Preference pref = new Preference(getActivity()); Preference pref = new Preference(getActivity());
pref.setLayoutResource(R.layout.account_management_account_row); pref.setLayoutResource(R.layout.account_management_account_row);
pref.setTitle(account.name); pref.setTitle(account.name);
......
...@@ -136,10 +136,11 @@ public class AccountTrackerService { ...@@ -136,10 +136,11 @@ public class AccountTrackerService {
@Override @Override
public String[][] doInBackground() { public String[][] doInBackground() {
Log.d(TAG, "Getting id/email mapping"); Log.d(TAG, "Getting id/email mapping");
String[][] accountIdNameMap = new String[2][accounts.length]; String[][] accountIdNameMap = new String[2][accounts.size()];
for (int i = 0; i < accounts.length; ++i) { for (int i = 0; i < accounts.size(); ++i) {
accountIdNameMap[0][i] = accountIdProvider.getAccountId(accounts[i].name); accountIdNameMap[0][i] =
accountIdNameMap[1][i] = accounts[i].name; accountIdProvider.getAccountId(accounts.get(i).name);
accountIdNameMap[1][i] = accounts.get(i).name;
} }
return accountIdNameMap; return accountIdNameMap;
} }
...@@ -222,9 +223,9 @@ public class AccountTrackerService { ...@@ -222,9 +223,9 @@ public class AccountTrackerService {
return; return;
} }
String[] accountNames = new String[accounts.length]; String[] accountNames = new String[accounts.size()];
for (int i = 0; i < accounts.length; ++i) { for (int i = 0; i < accounts.size(); ++i) {
accountNames[i] = accounts[i].name; accountNames[i] = accounts.get(i).name;
} }
if (nativeAreAccountsSeeded(accountNames)) { if (nativeAreAccountsSeeded(accountNames)) {
mSystemAccountsSeedingStatus = SystemAccountsSeedingStatus.SEEDING_DONE; mSystemAccountsSeedingStatus = SystemAccountsSeedingStatus.SEEDING_DONE;
......
...@@ -233,8 +233,9 @@ public class SigninHelper { ...@@ -233,8 +233,9 @@ public class SigninHelper {
} }
private static boolean accountExists(Account account) { private static boolean accountExists(Account account) {
Account[] accounts = AccountManagerFacade.get().tryGetGoogleAccounts(); List<Account> accounts = AccountManagerFacade.get().tryGetGoogleAccounts();
for (Account a : accounts) { for (int i = 0; i < accounts.size(); i++) {
Account a = accounts.get(i);
if (a.equals(account)) { if (a.equals(account)) {
return true; return true;
} }
......
...@@ -21,6 +21,7 @@ import org.chromium.components.signin.ChromeSigninController; ...@@ -21,6 +21,7 @@ import org.chromium.components.signin.ChromeSigninController;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import java.util.Set; import java.util.Set;
/** /**
...@@ -119,9 +120,9 @@ public class SigninPromoUtil { ...@@ -119,9 +120,9 @@ public class SigninPromoUtil {
ProfileDataCache profileDataCache, PersonalizedSigninPromoView view, ProfileDataCache profileDataCache, PersonalizedSigninPromoView view,
SigninPromoController.OnDismissListener listener) { SigninPromoController.OnDismissListener listener) {
DisplayableProfileData profileData = null; DisplayableProfileData profileData = null;
Account[] accounts = AccountManagerFacade.get().tryGetGoogleAccounts(); List<Account> accounts = AccountManagerFacade.get().tryGetGoogleAccounts();
if (accounts.length > 0) { if (accounts.size() > 0) {
String defaultAccountName = accounts[0].name; String defaultAccountName = accounts.get(0).name;
profileDataCache.update(Collections.singletonList(defaultAccountName)); profileDataCache.update(Collections.singletonList(defaultAccountName));
profileData = profileDataCache.getProfileDataOrDefault(defaultAccountName); profileData = profileDataCache.getProfileDataOrDefault(defaultAccountName);
} }
......
...@@ -57,6 +57,7 @@ import org.chromium.components.sync.StopSource; ...@@ -57,6 +57,7 @@ import org.chromium.components.sync.StopSource;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
/** /**
...@@ -302,8 +303,8 @@ public class SyncCustomizationFragment extends PreferenceFragment ...@@ -302,8 +303,8 @@ public class SyncCustomizationFragment extends PreferenceFragment
// We remove the the SyncedAccountPreference if there's only 1 account on the device, so // We remove the the SyncedAccountPreference if there's only 1 account on the device, so
// it's possible for accountList to be null // it's possible for accountList to be null
if (accountList != null) { if (accountList != null) {
Account[] accounts = AccountManagerFacade.get().tryGetGoogleAccounts(); List<Account> accounts = AccountManagerFacade.get().tryGetGoogleAccounts();
if (accounts.length <= 1) { if (accounts.size() <= 1) {
getPreferenceScreen().removePreference(accountList); getPreferenceScreen().removePreference(accountList);
} else { } else {
accountList.setEnabled(mSyncSwitchPreference.isChecked()); accountList.setEnabled(mSyncSwitchPreference.isChecked());
......
...@@ -26,6 +26,9 @@ import org.chromium.base.test.BaseRobolectricTestRunner; ...@@ -26,6 +26,9 @@ import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.components.signin.ChildAccountStatus; import org.chromium.components.signin.ChildAccountStatus;
import java.util.Collections;
import java.util.List;
/** /**
* Tests FirstRunFlowSequencer which contains the core logic of what should be shown during the * Tests FirstRunFlowSequencer which contains the core logic of what should be shown during the
* first run. * first run.
...@@ -49,7 +52,7 @@ public class FirstRunFlowSequencerTest { ...@@ -49,7 +52,7 @@ public class FirstRunFlowSequencerTest {
public boolean isFirstRunFlowComplete; public boolean isFirstRunFlowComplete;
public boolean isSignedIn; public boolean isSignedIn;
public boolean isSyncAllowed; public boolean isSyncAllowed;
public Account[] googleAccounts; public List<Account> googleAccounts;
public boolean hasAnyUserSeenToS; public boolean hasAnyUserSeenToS;
public boolean shouldSkipFirstUseHints; public boolean shouldSkipFirstUseHints;
public boolean isFirstRunEulaAccepted; public boolean isFirstRunEulaAccepted;
...@@ -83,7 +86,7 @@ public class FirstRunFlowSequencerTest { ...@@ -83,7 +86,7 @@ public class FirstRunFlowSequencerTest {
} }
@Override @Override
public Account[] getGoogleAccounts() { public List<Account> getGoogleAccounts() {
return googleAccounts; return googleAccounts;
} }
...@@ -140,12 +143,11 @@ public class FirstRunFlowSequencerTest { ...@@ -140,12 +143,11 @@ public class FirstRunFlowSequencerTest {
@Test @Test
@Feature({"FirstRun"}) @Feature({"FirstRun"})
public void testFirstRunComplete() { public void testFirstRunComplete() {
Account[] accounts = new Account[1];
accounts[0] = new Account(DEFAULT_ACCOUNT, GOOGLE_ACCOUNT_TYPE);
mSequencer.isFirstRunFlowComplete = true; mSequencer.isFirstRunFlowComplete = true;
mSequencer.isSignedIn = false; mSequencer.isSignedIn = false;
mSequencer.isSyncAllowed = true; mSequencer.isSyncAllowed = true;
mSequencer.googleAccounts = accounts; mSequencer.googleAccounts =
Collections.singletonList(new Account(DEFAULT_ACCOUNT, GOOGLE_ACCOUNT_TYPE));
mSequencer.hasAnyUserSeenToS = true; mSequencer.hasAnyUserSeenToS = true;
mSequencer.shouldSkipFirstUseHints = false; mSequencer.shouldSkipFirstUseHints = false;
mSequencer.isFirstRunEulaAccepted = true; mSequencer.isFirstRunEulaAccepted = true;
...@@ -164,7 +166,7 @@ public class FirstRunFlowSequencerTest { ...@@ -164,7 +166,7 @@ public class FirstRunFlowSequencerTest {
mSequencer.isFirstRunFlowComplete = false; mSequencer.isFirstRunFlowComplete = false;
mSequencer.isSignedIn = false; mSequencer.isSignedIn = false;
mSequencer.isSyncAllowed = true; mSequencer.isSyncAllowed = true;
mSequencer.googleAccounts = new Account[0]; mSequencer.googleAccounts = Collections.emptyList();
mSequencer.hasAnyUserSeenToS = false; mSequencer.hasAnyUserSeenToS = false;
mSequencer.shouldSkipFirstUseHints = false; mSequencer.shouldSkipFirstUseHints = false;
mSequencer.shouldShowDataReductionPage = false; mSequencer.shouldShowDataReductionPage = false;
...@@ -189,12 +191,11 @@ public class FirstRunFlowSequencerTest { ...@@ -189,12 +191,11 @@ public class FirstRunFlowSequencerTest {
@Test @Test
@Feature({"FirstRun"}) @Feature({"FirstRun"})
public void testStandardFlowOneChildAccount() { public void testStandardFlowOneChildAccount() {
Account[] accounts = new Account[1];
accounts[0] = new Account(DEFAULT_ACCOUNT, GOOGLE_ACCOUNT_TYPE);
mSequencer.isFirstRunFlowComplete = false; mSequencer.isFirstRunFlowComplete = false;
mSequencer.isSignedIn = false; mSequencer.isSignedIn = false;
mSequencer.isSyncAllowed = true; mSequencer.isSyncAllowed = true;
mSequencer.googleAccounts = accounts; mSequencer.googleAccounts =
Collections.singletonList(new Account(DEFAULT_ACCOUNT, GOOGLE_ACCOUNT_TYPE));
mSequencer.hasAnyUserSeenToS = false; mSequencer.hasAnyUserSeenToS = false;
mSequencer.shouldSkipFirstUseHints = false; mSequencer.shouldSkipFirstUseHints = false;
mSequencer.shouldShowDataReductionPage = false; mSequencer.shouldShowDataReductionPage = false;
...@@ -224,7 +225,7 @@ public class FirstRunFlowSequencerTest { ...@@ -224,7 +225,7 @@ public class FirstRunFlowSequencerTest {
mSequencer.isFirstRunFlowComplete = false; mSequencer.isFirstRunFlowComplete = false;
mSequencer.isSignedIn = false; mSequencer.isSignedIn = false;
mSequencer.isSyncAllowed = true; mSequencer.isSyncAllowed = true;
mSequencer.googleAccounts = new Account[0]; mSequencer.googleAccounts = Collections.emptyList();
mSequencer.hasAnyUserSeenToS = false; mSequencer.hasAnyUserSeenToS = false;
mSequencer.shouldSkipFirstUseHints = false; mSequencer.shouldSkipFirstUseHints = false;
mSequencer.shouldShowDataReductionPage = true; mSequencer.shouldShowDataReductionPage = true;
...@@ -253,7 +254,7 @@ public class FirstRunFlowSequencerTest { ...@@ -253,7 +254,7 @@ public class FirstRunFlowSequencerTest {
mSequencer.isFirstRunFlowComplete = false; mSequencer.isFirstRunFlowComplete = false;
mSequencer.isSignedIn = false; mSequencer.isSignedIn = false;
mSequencer.isSyncAllowed = true; mSequencer.isSyncAllowed = true;
mSequencer.googleAccounts = new Account[0]; mSequencer.googleAccounts = Collections.emptyList();
mSequencer.hasAnyUserSeenToS = false; mSequencer.hasAnyUserSeenToS = false;
mSequencer.shouldSkipFirstUseHints = false; mSequencer.shouldSkipFirstUseHints = false;
mSequencer.shouldShowDataReductionPage = true; mSequencer.shouldShowDataReductionPage = true;
......
...@@ -33,6 +33,8 @@ import org.chromium.components.signin.util.PatternMatcher; ...@@ -33,6 +33,8 @@ import org.chromium.components.signin.util.PatternMatcher;
import org.chromium.net.NetworkChangeNotifier; import org.chromium.net.NetworkChangeNotifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
...@@ -83,9 +85,9 @@ public class AccountManagerFacade { ...@@ -83,9 +85,9 @@ public class AccountManagerFacade {
// These two variables should be accessed from either UI thread or during initialization phase. // These two variables should be accessed from either UI thread or during initialization phase.
private PatternMatcher[] mAccountRestrictionPatterns; private PatternMatcher[] mAccountRestrictionPatterns;
private AccountManagerResult<Account[]> mAllAccounts; private AccountManagerResult<List<Account>> mAllAccounts;
private final AtomicReference<AccountManagerResult<Account[]>> mFilteredAccounts = private final AtomicReference<AccountManagerResult<List<Account>>> mFilteredAccounts =
new AtomicReference<>(); new AtomicReference<>();
private final CountDownLatch mPopulateAccountCacheLatch = new CountDownLatch(1); private final CountDownLatch mPopulateAccountCacheLatch = new CountDownLatch(1);
private final CachedMetrics.TimesHistogramSample mPopulateAccountCacheWaitingTimeHistogram = private final CachedMetrics.TimesHistogramSample mPopulateAccountCacheWaitingTimeHistogram =
...@@ -270,7 +272,9 @@ public class AccountManagerFacade { ...@@ -270,7 +272,9 @@ public class AccountManagerFacade {
@AnyThread @AnyThread
public List<String> tryGetGoogleAccountNames() { public List<String> tryGetGoogleAccountNames() {
List<String> accountNames = new ArrayList<>(); List<String> accountNames = new ArrayList<>();
for (Account account : tryGetGoogleAccounts()) { List<Account> tryGetGoogleAccounts = tryGetGoogleAccounts();
for (int i = 0; i < tryGetGoogleAccounts.size(); i++) {
Account account = tryGetGoogleAccounts.get(i);
accountNames.add(account.name); accountNames.add(account.name);
} }
return accountNames; return accountNames;
...@@ -291,10 +295,10 @@ public class AccountManagerFacade { ...@@ -291,10 +295,10 @@ public class AccountManagerFacade {
public void getGoogleAccountNames( public void getGoogleAccountNames(
final Callback<AccountManagerResult<List<String>>> callback) { final Callback<AccountManagerResult<List<String>>> callback) {
runAfterCacheIsPopulated(() -> { runAfterCacheIsPopulated(() -> {
final AccountManagerResult<Account[]> accounts = mFilteredAccounts.get(); final AccountManagerResult<List<Account>> accounts = mFilteredAccounts.get();
final AccountManagerResult<List<String>> result; final AccountManagerResult<List<String>> result;
if (accounts.hasValue()) { if (accounts.hasValue()) {
List<String> accountNames = new ArrayList<>(accounts.getValue().length); List<String> accountNames = new ArrayList<>(accounts.getValue().size());
for (Account account : accounts.getValue()) { for (Account account : accounts.getValue()) {
accountNames.add(account.name); accountNames.add(account.name);
} }
...@@ -313,8 +317,8 @@ public class AccountManagerFacade { ...@@ -313,8 +317,8 @@ public class AccountManagerFacade {
* Chrome lacks necessary permissions, etc. * Chrome lacks necessary permissions, etc.
*/ */
@AnyThread @AnyThread
public Account[] getGoogleAccounts() throws AccountManagerDelegateException { public List<Account> getGoogleAccounts() throws AccountManagerDelegateException {
AccountManagerResult<Account[]> maybeAccounts = mFilteredAccounts.get(); AccountManagerResult<List<Account>> maybeAccounts = mFilteredAccounts.get();
if (maybeAccounts == null) { if (maybeAccounts == null) {
try { try {
// First call to update hasn't finished executing yet, should wait for it // First call to update hasn't finished executing yet, should wait for it
...@@ -336,7 +340,7 @@ public class AccountManagerFacade { ...@@ -336,7 +340,7 @@ public class AccountManagerFacade {
* Asynchronous version of {@link #getGoogleAccounts()}. * Asynchronous version of {@link #getGoogleAccounts()}.
*/ */
@MainThread @MainThread
public void getGoogleAccounts(final Callback<AccountManagerResult<Account[]>> callback) { public void getGoogleAccounts(Callback<AccountManagerResult<List<Account>>> callback) {
runAfterCacheIsPopulated(() -> callback.onResult(mFilteredAccounts.get())); runAfterCacheIsPopulated(() -> callback.onResult(mFilteredAccounts.get()));
} }
...@@ -345,11 +349,11 @@ public class AccountManagerFacade { ...@@ -345,11 +349,11 @@ public class AccountManagerFacade {
* Returns an empty array if an error occurs while getting account list. * Returns an empty array if an error occurs while getting account list.
*/ */
@AnyThread @AnyThread
public Account[] tryGetGoogleAccounts() { public List<Account> tryGetGoogleAccounts() {
try { try {
return getGoogleAccounts(); return getGoogleAccounts();
} catch (AccountManagerDelegateException e) { } catch (AccountManagerDelegateException e) {
return new Account[0]; return Collections.emptyList();
} }
} }
...@@ -357,7 +361,7 @@ public class AccountManagerFacade { ...@@ -357,7 +361,7 @@ public class AccountManagerFacade {
* Asynchronous version of {@link #tryGetGoogleAccounts()}. * Asynchronous version of {@link #tryGetGoogleAccounts()}.
*/ */
@MainThread @MainThread
public void tryGetGoogleAccounts(final Callback<Account[]> callback) { public void tryGetGoogleAccounts(final Callback<List<Account>> callback) {
runAfterCacheIsPopulated(() -> callback.onResult(tryGetGoogleAccounts())); runAfterCacheIsPopulated(() -> callback.onResult(tryGetGoogleAccounts()));
} }
...@@ -367,7 +371,7 @@ public class AccountManagerFacade { ...@@ -367,7 +371,7 @@ public class AccountManagerFacade {
*/ */
@AnyThread @AnyThread
public boolean hasGoogleAccounts() { public boolean hasGoogleAccounts() {
return tryGetGoogleAccounts().length > 0; return !tryGetGoogleAccounts().isEmpty();
} }
/** /**
...@@ -398,7 +402,7 @@ public class AccountManagerFacade { ...@@ -398,7 +402,7 @@ public class AccountManagerFacade {
@AnyThread @AnyThread
public Account getAccountFromName(String accountName) { public Account getAccountFromName(String accountName) {
String canonicalName = canonicalizeName(accountName); String canonicalName = canonicalizeName(accountName);
Account[] accounts = tryGetGoogleAccounts(); List<Account> accounts = tryGetGoogleAccounts();
for (Account account : accounts) { for (Account account : accounts) {
if (canonicalizeName(account.name).equals(canonicalName)) { if (canonicalizeName(account.name).equals(canonicalName)) {
return account; return account;
...@@ -615,15 +619,16 @@ public class AccountManagerFacade { ...@@ -615,15 +619,16 @@ public class AccountManagerFacade {
ContextUtils.getApplicationContext().registerReceiver(receiver, filter); ContextUtils.getApplicationContext().registerReceiver(receiver, filter);
} }
private AccountManagerResult<Account[]> getAllAccounts() { private AccountManagerResult<List<Account>> getAllAccounts() {
try { try {
return new AccountManagerResult<>(mDelegate.getAccountsSync()); List<Account> accounts = Arrays.asList(mDelegate.getAccountsSync());
return new AccountManagerResult<>(Collections.unmodifiableList(accounts));
} catch (AccountManagerDelegateException ex) { } catch (AccountManagerDelegateException ex) {
return new AccountManagerResult<>(ex); return new AccountManagerResult<>(ex);
} }
} }
private AccountManagerResult<Account[]> getFilteredAccounts() { private AccountManagerResult<List<Account>> getFilteredAccounts() {
if (mAllAccounts.hasException() || mAccountRestrictionPatterns == null) return mAllAccounts; if (mAllAccounts.hasException() || mAccountRestrictionPatterns == null) return mAllAccounts;
ArrayList<Account> filteredAccounts = new ArrayList<>(); ArrayList<Account> filteredAccounts = new ArrayList<>();
for (Account account : mAllAccounts.getValue()) { for (Account account : mAllAccounts.getValue()) {
...@@ -634,7 +639,7 @@ public class AccountManagerFacade { ...@@ -634,7 +639,7 @@ public class AccountManagerFacade {
} }
} }
} }
return new AccountManagerResult<>(filteredAccounts.toArray(new Account[0])); return new AccountManagerResult<>(Collections.unmodifiableList(filteredAccounts));
} }
private static PatternMatcher[] getAccountRestrictionPatterns() { private static PatternMatcher[] getAccountRestrictionPatterns() {
...@@ -673,7 +678,7 @@ public class AccountManagerFacade { ...@@ -673,7 +678,7 @@ public class AccountManagerFacade {
fireOnAccountsChangedNotification(); fireOnAccountsChangedNotification();
} }
private void setAllAccounts(AccountManagerResult<Account[]> allAccounts) { private void setAllAccounts(AccountManagerResult<List<Account>> allAccounts) {
mAllAccounts = allAccounts; mAllAccounts = allAccounts;
mFilteredAccounts.set(getFilteredAccounts()); mFilteredAccounts.set(getFilteredAccounts());
fireOnAccountsChangedNotification(); fireOnAccountsChangedNotification();
...@@ -741,19 +746,19 @@ public class AccountManagerFacade { ...@@ -741,19 +746,19 @@ public class AccountManagerFacade {
} }
} }
private class UpdateAccountsTask extends AsyncTask<AccountManagerResult<Account[]>> { private class UpdateAccountsTask extends AsyncTask<AccountManagerResult<List<Account>>> {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
++mUpdateTasksCounter; ++mUpdateTasksCounter;
} }
@Override @Override
protected AccountManagerResult<Account[]> doInBackground() { protected AccountManagerResult<List<Account>> doInBackground() {
return getAllAccounts(); return getAllAccounts();
} }
@Override @Override
protected void onPostExecute(AccountManagerResult<Account[]> allAccounts) { protected void onPostExecute(AccountManagerResult<List<Account>> allAccounts) {
setAllAccounts(allAccounts); setAllAccounts(allAccounts);
decrementUpdateCounter(); decrementUpdateCounter();
} }
......
...@@ -14,6 +14,8 @@ import android.os.UserManager; ...@@ -14,6 +14,8 @@ import android.os.UserManager;
import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest;
import android.support.test.rule.UiThreadTestRule; import android.support.test.rule.UiThreadTestRule;
import com.google.common.collect.ImmutableList;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
...@@ -22,7 +24,6 @@ import org.junit.runner.RunWith; ...@@ -22,7 +24,6 @@ import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import org.chromium.base.Callback;
import org.chromium.base.task.test.CustomShadowAsyncTask; import org.chromium.base.task.test.CustomShadowAsyncTask;
import org.chromium.base.test.BaseRobolectricTestRunner; import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.components.signin.AccountManagerDelegateException; import org.chromium.components.signin.AccountManagerDelegateException;
...@@ -130,20 +131,20 @@ public class AccountManagerFacadeRobolectricTest { ...@@ -130,20 +131,20 @@ public class AccountManagerFacadeRobolectricTest {
@Test @Test
@SmallTest @SmallTest
public void testGetAccounts() throws AccountManagerDelegateException { public void testGetAccounts() throws AccountManagerDelegateException {
Assert.assertArrayEquals(new Account[] {}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(), mFacade.getGoogleAccounts());
Account account = addTestAccount("test@gmail.com"); Account account = addTestAccount("test@gmail.com");
Assert.assertArrayEquals(new Account[] {account}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(account), mFacade.getGoogleAccounts());
Account account2 = addTestAccount("test2@gmail.com"); Account account2 = addTestAccount("test2@gmail.com");
Assert.assertArrayEquals(new Account[] {account, account2}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(account, account2), mFacade.getGoogleAccounts());
Account account3 = addTestAccount("test3@gmail.com"); Account account3 = addTestAccount("test3@gmail.com");
Assert.assertArrayEquals( Assert.assertEquals(
new Account[] {account, account2, account3}, mFacade.getGoogleAccounts()); ImmutableList.of(account, account2, account3), mFacade.getGoogleAccounts());
removeTestAccount(account2); removeTestAccount(account2);
Assert.assertArrayEquals(new Account[] {account, account3}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(account, account3), mFacade.getGoogleAccounts());
} }
@Test @Test
...@@ -151,19 +152,19 @@ public class AccountManagerFacadeRobolectricTest { ...@@ -151,19 +152,19 @@ public class AccountManagerFacadeRobolectricTest {
public void testGetAccountsWithAccountPattern() throws AccountManagerDelegateException { public void testGetAccountsWithAccountPattern() throws AccountManagerDelegateException {
setAccountRestrictionPatterns("*@example.com"); setAccountRestrictionPatterns("*@example.com");
Account account = addTestAccount("test@example.com"); Account account = addTestAccount("test@example.com");
Assert.assertArrayEquals(new Account[] {account}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(account), mFacade.getGoogleAccounts());
addTestAccount("test@gmail.com"); // Doesn't match the pattern. addTestAccount("test@gmail.com"); // Doesn't match the pattern.
Assert.assertArrayEquals(new Account[] {account}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(account), mFacade.getGoogleAccounts());
Account account2 = addTestAccount("test2@example.com"); Account account2 = addTestAccount("test2@example.com");
Assert.assertArrayEquals(new Account[] {account, account2}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(account, account2), mFacade.getGoogleAccounts());
addTestAccount("test2@gmail.com"); // Doesn't match the pattern. addTestAccount("test2@gmail.com"); // Doesn't match the pattern.
Assert.assertArrayEquals(new Account[] {account, account2}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(account, account2), mFacade.getGoogleAccounts());
removeTestAccount(account); removeTestAccount(account);
Assert.assertArrayEquals(new Account[] {account2}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(account2), mFacade.getGoogleAccounts());
} }
@Test @Test
...@@ -172,44 +173,44 @@ public class AccountManagerFacadeRobolectricTest { ...@@ -172,44 +173,44 @@ public class AccountManagerFacadeRobolectricTest {
setAccountRestrictionPatterns("test1@example.com", "test2@gmail.com"); setAccountRestrictionPatterns("test1@example.com", "test2@gmail.com");
addTestAccount("test@gmail.com"); // Doesn't match the pattern. addTestAccount("test@gmail.com"); // Doesn't match the pattern.
addTestAccount("test@example.com"); // Doesn't match the pattern. addTestAccount("test@example.com"); // Doesn't match the pattern.
Assert.assertArrayEquals(new Account[] {}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(), mFacade.getGoogleAccounts());
Account account = addTestAccount("test1@example.com"); Account account = addTestAccount("test1@example.com");
Assert.assertArrayEquals(new Account[] {account}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(account), mFacade.getGoogleAccounts());
addTestAccount("test2@example.com"); // Doesn't match the pattern. addTestAccount("test2@example.com"); // Doesn't match the pattern.
Assert.assertArrayEquals(new Account[] {account}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(account), mFacade.getGoogleAccounts());
Account account2 = addTestAccount("test2@gmail.com"); Account account2 = addTestAccount("test2@gmail.com");
Assert.assertArrayEquals(new Account[] {account, account2}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(account, account2), mFacade.getGoogleAccounts());
} }
@Test @Test
@SmallTest @SmallTest
public void testGetAccountsWithAccountPatternsChange() throws AccountManagerDelegateException { public void testGetAccountsWithAccountPatternsChange() throws AccountManagerDelegateException {
Assert.assertArrayEquals(new Account[] {}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(), mFacade.getGoogleAccounts());
Account account = addTestAccount("test@gmail.com"); Account account = addTestAccount("test@gmail.com");
Assert.assertArrayEquals(new Account[] {account}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(account), mFacade.getGoogleAccounts());
Account account2 = addTestAccount("test2@example.com"); Account account2 = addTestAccount("test2@example.com");
Assert.assertArrayEquals(new Account[] {account, account2}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(account, account2), mFacade.getGoogleAccounts());
Account account3 = addTestAccount("test3@gmail.com"); Account account3 = addTestAccount("test3@gmail.com");
Assert.assertArrayEquals( Assert.assertEquals(
new Account[] {account, account2, account3}, mFacade.getGoogleAccounts()); ImmutableList.of(account, account2, account3), mFacade.getGoogleAccounts());
setAccountRestrictionPatterns("test@gmail.com"); setAccountRestrictionPatterns("test@gmail.com");
Assert.assertArrayEquals(new Account[] {account}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(account), mFacade.getGoogleAccounts());
setAccountRestrictionPatterns("*@example.com", "test3@gmail.com"); setAccountRestrictionPatterns("*@example.com", "test3@gmail.com");
Assert.assertArrayEquals(new Account[] {account2, account3}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(account2, account3), mFacade.getGoogleAccounts());
removeTestAccount(account3); removeTestAccount(account3);
Assert.assertArrayEquals(new Account[] {account2}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(account2), mFacade.getGoogleAccounts());
clearAccountRestrictionPatterns(); clearAccountRestrictionPatterns();
Assert.assertArrayEquals(new Account[] {account, account2}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(account, account2), mFacade.getGoogleAccounts());
} }
@Test @Test
...@@ -217,7 +218,7 @@ public class AccountManagerFacadeRobolectricTest { ...@@ -217,7 +218,7 @@ public class AccountManagerFacadeRobolectricTest {
public void testGetAccountsMultipleMatchingPatterns() throws AccountManagerDelegateException { public void testGetAccountsMultipleMatchingPatterns() throws AccountManagerDelegateException {
setAccountRestrictionPatterns("*@gmail.com", "test@gmail.com"); setAccountRestrictionPatterns("*@gmail.com", "test@gmail.com");
Account account = addTestAccount("test@gmail.com"); // Matches both patterns Account account = addTestAccount("test@gmail.com"); // Matches both patterns
Assert.assertArrayEquals(new Account[] {account}, mFacade.getGoogleAccounts()); Assert.assertEquals(ImmutableList.of(account), mFacade.getGoogleAccounts());
} }
@Test @Test
...@@ -256,12 +257,9 @@ public class AccountManagerFacadeRobolectricTest { ...@@ -256,12 +257,9 @@ public class AccountManagerFacadeRobolectricTest {
private void assertChildAccountStatus( private void assertChildAccountStatus(
Account account, @ChildAccountStatus.Status Integer status) { Account account, @ChildAccountStatus.Status Integer status) {
final AtomicInteger callCount = new AtomicInteger(); final AtomicInteger callCount = new AtomicInteger();
AccountManagerFacade.get().checkChildAccountStatus(account, new Callback<Integer>() { AccountManagerFacade.get().checkChildAccountStatus(account, result -> {
@Override callCount.incrementAndGet();
public void onResult(@ChildAccountStatus.Status Integer result) { Assert.assertEquals(result, status);
callCount.incrementAndGet();
Assert.assertEquals(result, status);
}
}); });
Assert.assertEquals(1, callCount.get()); Assert.assertEquals(1, callCount.get());
} }
......
...@@ -14,6 +14,7 @@ import android.os.StrictMode; ...@@ -14,6 +14,7 @@ import android.os.StrictMode;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.ObserverList; import org.chromium.base.ObserverList;
import org.chromium.base.StrictModeContext;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.components.signin.AccountManagerFacade; import org.chromium.components.signin.AccountManagerFacade;
...@@ -242,41 +243,36 @@ public class AndroidSyncSettings { ...@@ -242,41 +243,36 @@ public class AndroidSyncSettings {
mIsSyncable = shouldBeSyncable; mIsSyncable = shouldBeSyncable;
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); try (StrictModeContext ignored = StrictModeContext.allowDiskWrites()) {
// Make account syncable if there is one. // Make account syncable if there is one.
if (shouldBeSyncable) { if (shouldBeSyncable) {
mSyncContentResolverDelegate.setIsSyncable(mAccount, mContractAuthority, 1); mSyncContentResolverDelegate.setIsSyncable(mAccount, mContractAuthority, 1);
// This reduces unnecessary resource usage. See http://crbug.com/480688 for details. // This reduces unnecessary resource usage. See http://crbug.com/480688 for details.
mSyncContentResolverDelegate.removePeriodicSync( mSyncContentResolverDelegate.removePeriodicSync(
mAccount, mContractAuthority, Bundle.EMPTY); mAccount, mContractAuthority, Bundle.EMPTY);
}
} }
StrictMode.setThreadPolicy(oldPolicy);
// Disable the syncability of Chrome for all other accounts. // Disable the syncability of Chrome for all other accounts.
ThreadUtils.postOnUiThread(new Runnable() { ThreadUtils.postOnUiThread(() -> {
@Override AccountManagerFacade.get().tryGetGoogleAccounts(accounts -> {
public void run() { synchronized (mLock) {
AccountManagerFacade.get().tryGetGoogleAccounts(new Callback<Account[]>() { try (StrictModeContext ignored = StrictModeContext.allowDiskWrites()) {
@Override for (int i = 0; i < accounts.size(); i++) {
public void onResult(Account[] accounts) { Account account = accounts.get(i);
synchronized (mLock) { if (!account.equals(mAccount)
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); && mSyncContentResolverDelegate.getIsSyncable(
for (Account account : accounts) { account, mContractAuthority)
if (!account.equals(mAccount) > 0) {
&& mSyncContentResolverDelegate.getIsSyncable( mSyncContentResolverDelegate.setIsSyncable(
account, mContractAuthority) account, mContractAuthority, 0);
> 0) {
mSyncContentResolverDelegate.setIsSyncable(
account, mContractAuthority, 0);
}
} }
StrictMode.setThreadPolicy(oldPolicy);
} }
if (callback != null) callback.onResult(true);
} }
}); }
}
if (callback != null) callback.onResult(true);
});
}); });
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment