Loading java-overridable/src/com/android/inputmethod/latin/accounts/LoginAccountUtils.java +6 −7 Original line number Diff line number Diff line Loading @@ -16,16 +16,20 @@ package com.android.inputmethod.latin.accounts; import android.accounts.Account; import android.content.Context; import javax.annotation.Nonnull; import javax.annotation.Nullable; /** * Utility class for retrieving accounts that may be used for login. */ public class LoginAccountUtils { /** * This defines the type of account this class deals with. * This account type is used when listing the accounts available on the device for login. */ public static final String ACCOUNT_TYPE = ""; private LoginAccountUtils() { // This utility class is not publicly instantiable. } Loading @@ -39,9 +43,4 @@ public class LoginAccountUtils { public static String[] getAccountsForLogin(final Context context) { return new String[0]; } @Nullable public static Account getCurrentAccount(final Context context) { return null; } } java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java +16 −10 Original line number Diff line number Diff line Loading @@ -101,7 +101,7 @@ public final class AccountsSettingsFragment extends SubScreenFragment { @Override public void onResume() { super.onResume(); refreshAccountAndDependentPreferences(getCurrentlySelectedAccount()); refreshAccountAndDependentPreferences(getSignedInAccountName()); } @Override Loading @@ -111,7 +111,7 @@ public final class AccountsSettingsFragment extends SubScreenFragment { prefs.getString(PREF_ACCOUNT_NAME, null)); } else if (TextUtils.equals(key, PREF_ENABLE_CLOUD_SYNC)) { final boolean syncEnabled = prefs.getBoolean(PREF_ENABLE_CLOUD_SYNC, false); updateSyncPolicy(syncEnabled, LoginAccountUtils.getCurrentAccount(getActivity())); updateSyncPolicy(syncEnabled, getSignedInAccountName()); } } Loading Loading @@ -182,16 +182,22 @@ public final class AccountsSettingsFragment extends SubScreenFragment { * set or unset the syncable property of the sync authority. * If the account is null, this method is a no-op currently, but we may want * to perform some cleanup in the future. * * @param enabled indicates whether the sync preference is enabled or not. * @param accountToUse indicaes the account to be used for sync, or null if the user * is not logged in. */ @UsedForTesting void updateSyncPolicy(boolean enabled, Account accountToUse) { void updateSyncPolicy(boolean enabled, @Nullable String accountToUse) { if (!ProductionFlags.ENABLE_PERSONAL_DICTIONARY_SYNC) { return; } if (accountToUse != null) { final int syncable = enabled ? 1 : 0; ContentResolver.setIsSyncable(accountToUse, AUTHORITY, syncable); ContentResolver.setIsSyncable( new Account(accountToUse, LoginAccountUtils.ACCOUNT_TYPE), AUTHORITY, syncable); // TODO: Also add a periodic sync here. // See ContentResolver.addPeriodicSync } else { Loading @@ -202,11 +208,11 @@ public final class AccountsSettingsFragment extends SubScreenFragment { } @Nullable private String getCurrentlySelectedAccount() { String getSignedInAccountName() { return getSharedPreferences().getString(LocalSettingsConstants.PREF_ACCOUNT_NAME, null); } private boolean isSyncEnabled() { boolean isSyncEnabled() { return getSharedPreferences().getBoolean(PREF_ENABLE_CLOUD_SYNC, false); } Loading Loading @@ -266,12 +272,11 @@ public final class AccountsSettingsFragment extends SubScreenFragment { // Attempt starting sync for the new account if sync was // previously enabled. // If not, stop it. updateSyncPolicy(isSyncEnabled(), LoginAccountUtils.getCurrentAccount(getActivity())); updateSyncPolicy(isSyncEnabled(), getSignedInAccountName()); break; case DialogInterface.BUTTON_NEUTRAL: // Signed out // Stop sync for the account that's being signed out of. updateSyncPolicy(false, LoginAccountUtils.getCurrentAccount(getActivity())); updateSyncPolicy(false, getSignedInAccountName()); getSharedPreferences() .edit() .remove(PREF_ACCOUNT_NAME) Loading @@ -288,7 +293,8 @@ public final class AccountsSettingsFragment extends SubScreenFragment { @Override public boolean onPreferenceClick(final Preference preference) { ContentResolver.requestSync( LoginAccountUtils.getCurrentAccount(getActivity()), AUTHORITY, Bundle.EMPTY); new Account(getSignedInAccountName(), LoginAccountUtils.ACCOUNT_TYPE), AUTHORITY, Bundle.EMPTY); return true; } } Loading tests/src/com/android/inputmethod/latin/settings/AccountsSettingsFragmentTests.java +8 −5 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.test.suitebuilder.annotation.MediumTest; import android.view.View; import android.widget.ListView; import com.android.inputmethod.latin.accounts.LoginAccountUtils; import com.android.inputmethod.latin.define.ProductionFlags; import java.util.concurrent.CountDownLatch; Loading @@ -38,7 +39,9 @@ public class AccountsSettingsFragmentTests extends ActivityInstrumentationTestCase2<TestFragmentActivity> { private static final String FRAG_NAME = AccountsSettingsFragment.class.getName(); private static final long TEST_TIMEOUT_MILLIS = 5000; private static final Account TEST_ACCOUNT = new Account("account-for-test", "account-type"); private static final String TEST_ACCOUNT_NAME = "AccountsSettingsFragmentTests"; private static final Account TEST_ACCOUNT = new Account(TEST_ACCOUNT_NAME, LoginAccountUtils.ACCOUNT_TYPE); private AlertDialog mDialog; Loading Loading @@ -154,7 +157,7 @@ public class AccountsSettingsFragmentTests final AccountsSettingsFragment fragment = (AccountsSettingsFragment) getActivity().mFragment; fragment.updateSyncPolicy(true, TEST_ACCOUNT); fragment.updateSyncPolicy(true, TEST_ACCOUNT_NAME); // Should be syncable now. assertEquals(1, ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY)); Loading @@ -170,7 +173,7 @@ public class AccountsSettingsFragmentTests final AccountsSettingsFragment fragment = (AccountsSettingsFragment) getActivity().mFragment; fragment.updateSyncPolicy(false, TEST_ACCOUNT); fragment.updateSyncPolicy(false, TEST_ACCOUNT_NAME); // Should not be syncable now. assertEquals(0, ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY)); Loading @@ -186,12 +189,12 @@ public class AccountsSettingsFragmentTests final AccountsSettingsFragment fragment = (AccountsSettingsFragment) getActivity().mFragment; fragment.updateSyncPolicy(true, TEST_ACCOUNT); fragment.updateSyncPolicy(true, TEST_ACCOUNT_NAME); // Should be syncable now. assertEquals(1, ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY)); fragment.updateSyncPolicy(false, TEST_ACCOUNT); fragment.updateSyncPolicy(false, TEST_ACCOUNT_NAME); // Should not be syncable now. assertEquals(0, ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY)); Loading Loading
java-overridable/src/com/android/inputmethod/latin/accounts/LoginAccountUtils.java +6 −7 Original line number Diff line number Diff line Loading @@ -16,16 +16,20 @@ package com.android.inputmethod.latin.accounts; import android.accounts.Account; import android.content.Context; import javax.annotation.Nonnull; import javax.annotation.Nullable; /** * Utility class for retrieving accounts that may be used for login. */ public class LoginAccountUtils { /** * This defines the type of account this class deals with. * This account type is used when listing the accounts available on the device for login. */ public static final String ACCOUNT_TYPE = ""; private LoginAccountUtils() { // This utility class is not publicly instantiable. } Loading @@ -39,9 +43,4 @@ public class LoginAccountUtils { public static String[] getAccountsForLogin(final Context context) { return new String[0]; } @Nullable public static Account getCurrentAccount(final Context context) { return null; } }
java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java +16 −10 Original line number Diff line number Diff line Loading @@ -101,7 +101,7 @@ public final class AccountsSettingsFragment extends SubScreenFragment { @Override public void onResume() { super.onResume(); refreshAccountAndDependentPreferences(getCurrentlySelectedAccount()); refreshAccountAndDependentPreferences(getSignedInAccountName()); } @Override Loading @@ -111,7 +111,7 @@ public final class AccountsSettingsFragment extends SubScreenFragment { prefs.getString(PREF_ACCOUNT_NAME, null)); } else if (TextUtils.equals(key, PREF_ENABLE_CLOUD_SYNC)) { final boolean syncEnabled = prefs.getBoolean(PREF_ENABLE_CLOUD_SYNC, false); updateSyncPolicy(syncEnabled, LoginAccountUtils.getCurrentAccount(getActivity())); updateSyncPolicy(syncEnabled, getSignedInAccountName()); } } Loading Loading @@ -182,16 +182,22 @@ public final class AccountsSettingsFragment extends SubScreenFragment { * set or unset the syncable property of the sync authority. * If the account is null, this method is a no-op currently, but we may want * to perform some cleanup in the future. * * @param enabled indicates whether the sync preference is enabled or not. * @param accountToUse indicaes the account to be used for sync, or null if the user * is not logged in. */ @UsedForTesting void updateSyncPolicy(boolean enabled, Account accountToUse) { void updateSyncPolicy(boolean enabled, @Nullable String accountToUse) { if (!ProductionFlags.ENABLE_PERSONAL_DICTIONARY_SYNC) { return; } if (accountToUse != null) { final int syncable = enabled ? 1 : 0; ContentResolver.setIsSyncable(accountToUse, AUTHORITY, syncable); ContentResolver.setIsSyncable( new Account(accountToUse, LoginAccountUtils.ACCOUNT_TYPE), AUTHORITY, syncable); // TODO: Also add a periodic sync here. // See ContentResolver.addPeriodicSync } else { Loading @@ -202,11 +208,11 @@ public final class AccountsSettingsFragment extends SubScreenFragment { } @Nullable private String getCurrentlySelectedAccount() { String getSignedInAccountName() { return getSharedPreferences().getString(LocalSettingsConstants.PREF_ACCOUNT_NAME, null); } private boolean isSyncEnabled() { boolean isSyncEnabled() { return getSharedPreferences().getBoolean(PREF_ENABLE_CLOUD_SYNC, false); } Loading Loading @@ -266,12 +272,11 @@ public final class AccountsSettingsFragment extends SubScreenFragment { // Attempt starting sync for the new account if sync was // previously enabled. // If not, stop it. updateSyncPolicy(isSyncEnabled(), LoginAccountUtils.getCurrentAccount(getActivity())); updateSyncPolicy(isSyncEnabled(), getSignedInAccountName()); break; case DialogInterface.BUTTON_NEUTRAL: // Signed out // Stop sync for the account that's being signed out of. updateSyncPolicy(false, LoginAccountUtils.getCurrentAccount(getActivity())); updateSyncPolicy(false, getSignedInAccountName()); getSharedPreferences() .edit() .remove(PREF_ACCOUNT_NAME) Loading @@ -288,7 +293,8 @@ public final class AccountsSettingsFragment extends SubScreenFragment { @Override public boolean onPreferenceClick(final Preference preference) { ContentResolver.requestSync( LoginAccountUtils.getCurrentAccount(getActivity()), AUTHORITY, Bundle.EMPTY); new Account(getSignedInAccountName(), LoginAccountUtils.ACCOUNT_TYPE), AUTHORITY, Bundle.EMPTY); return true; } } Loading
tests/src/com/android/inputmethod/latin/settings/AccountsSettingsFragmentTests.java +8 −5 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.test.suitebuilder.annotation.MediumTest; import android.view.View; import android.widget.ListView; import com.android.inputmethod.latin.accounts.LoginAccountUtils; import com.android.inputmethod.latin.define.ProductionFlags; import java.util.concurrent.CountDownLatch; Loading @@ -38,7 +39,9 @@ public class AccountsSettingsFragmentTests extends ActivityInstrumentationTestCase2<TestFragmentActivity> { private static final String FRAG_NAME = AccountsSettingsFragment.class.getName(); private static final long TEST_TIMEOUT_MILLIS = 5000; private static final Account TEST_ACCOUNT = new Account("account-for-test", "account-type"); private static final String TEST_ACCOUNT_NAME = "AccountsSettingsFragmentTests"; private static final Account TEST_ACCOUNT = new Account(TEST_ACCOUNT_NAME, LoginAccountUtils.ACCOUNT_TYPE); private AlertDialog mDialog; Loading Loading @@ -154,7 +157,7 @@ public class AccountsSettingsFragmentTests final AccountsSettingsFragment fragment = (AccountsSettingsFragment) getActivity().mFragment; fragment.updateSyncPolicy(true, TEST_ACCOUNT); fragment.updateSyncPolicy(true, TEST_ACCOUNT_NAME); // Should be syncable now. assertEquals(1, ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY)); Loading @@ -170,7 +173,7 @@ public class AccountsSettingsFragmentTests final AccountsSettingsFragment fragment = (AccountsSettingsFragment) getActivity().mFragment; fragment.updateSyncPolicy(false, TEST_ACCOUNT); fragment.updateSyncPolicy(false, TEST_ACCOUNT_NAME); // Should not be syncable now. assertEquals(0, ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY)); Loading @@ -186,12 +189,12 @@ public class AccountsSettingsFragmentTests final AccountsSettingsFragment fragment = (AccountsSettingsFragment) getActivity().mFragment; fragment.updateSyncPolicy(true, TEST_ACCOUNT); fragment.updateSyncPolicy(true, TEST_ACCOUNT_NAME); // Should be syncable now. assertEquals(1, ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY)); fragment.updateSyncPolicy(false, TEST_ACCOUNT); fragment.updateSyncPolicy(false, TEST_ACCOUNT_NAME); // Should not be syncable now. assertEquals(0, ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY)); Loading