aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java179
-rw-r--r--java/src/com/android/inputmethod/latin/settings/CorrectionSettingsFragment.java43
-rw-r--r--java/src/com/android/inputmethod/latin/settings/Settings.java1
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SettingsFragment.java14
4 files changed, 123 insertions, 114 deletions
diff --git a/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java
index a2ae0ef4e..cb2097826 100644
--- a/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java
@@ -42,6 +42,8 @@ import com.android.inputmethod.latin.accounts.LoginAccountUtils;
import com.android.inputmethod.latin.define.ProductionFlags;
import com.android.inputmethod.latin.utils.ManagedProfileUtils;
+import java.util.concurrent.atomic.AtomicBoolean;
+
import javax.annotation.Nullable;
/**
@@ -96,12 +98,26 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
*/
private Preference mAccountSwitcher;
+ /**
+ * Stores if we are currently detecting a managed profile.
+ */
+ private AtomicBoolean mManagedProfileBeingDetected = new AtomicBoolean(true);
+
+ /**
+ * Stores if we have successfully detected if the device has a managed profile.
+ */
+ private AtomicBoolean mHasManagedProfile = new AtomicBoolean(false);
@Override
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.prefs_screen_accounts);
+ mAccountSwitcher = findPreference(PREF_ACCCOUNT_SWITCHER);
+ mEnableSyncPreference = (TwoStatePreference) findPreference(PREF_ENABLE_SYNC_NOW);
+ mSyncNowPreference = findPreference(PREF_SYNC_NOW);
+ mClearSyncDataPreference = findPreference(PREF_CLEAR_SYNC_DATA);
+
if (ProductionFlags.IS_METRICS_LOGGING_SUPPORTED) {
final Preference enableMetricsLogging =
findPreference(Settings.PREF_ENABLE_METRICS_LOGGING);
@@ -118,8 +134,7 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
if (!ProductionFlags.ENABLE_USER_HISTORY_DICTIONARY_SYNC) {
removeSyncPreferences();
} else {
- // Temporarily disable the preferences till we can
- // check that we don't have a work profile.
+ // Disable by default till we are sure we can enable this.
disableSyncPreferences();
new ManagedProfileCheckerTask(this).execute();
}
@@ -129,7 +144,7 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
* Task to check work profile. If found, it removes the sync prefs. If not,
* it enables them.
*/
- private static class ManagedProfileCheckerTask extends AsyncTask<Void, Void, Void> {
+ private static class ManagedProfileCheckerTask extends AsyncTask<Void, Void, Boolean> {
private final AccountsSettingsFragment mFragment;
private ManagedProfileCheckerTask(final AccountsSettingsFragment fragment) {
@@ -137,56 +152,70 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
}
@Override
- protected Void doInBackground(Void... params) {
- if (ManagedProfileUtils.getInstance().hasWorkProfile(mFragment.getActivity())) {
- mFragment.removeSyncPreferences();
- } else {
- mFragment.refreshAccountAndDependentPreferences(
- mFragment.getSignedInAccountName());
- }
- return null;
+ protected void onPreExecute() {
+ mFragment.mManagedProfileBeingDetected.set(true);
+ }
+ @Override
+ protected Boolean doInBackground(Void... params) {
+ return ManagedProfileUtils.getInstance().hasWorkProfile(mFragment.getActivity());
+ }
+
+ @Override
+ protected void onPostExecute(final Boolean hasWorkProfile) {
+ mFragment.mHasManagedProfile.set(hasWorkProfile);
+ mFragment.mManagedProfileBeingDetected.set(false);
+ mFragment.refreshSyncSettingsUI();
}
}
- private void enableSyncPreferences() {
- mAccountSwitcher = findPreference(PREF_ACCCOUNT_SWITCHER);
- if (mAccountSwitcher == null) {
- // Preference has been removed because the device has a managed profile.
+ private void enableSyncPreferences(final String[] accountsForLogin,
+ final String currentAccountName) {
+ if (!ProductionFlags.ENABLE_USER_HISTORY_DICTIONARY_SYNC) {
return;
}
mAccountSwitcher.setEnabled(true);
- mEnableSyncPreference = (TwoStatePreference) findPreference(PREF_ENABLE_SYNC_NOW);
mEnableSyncPreference.setEnabled(true);
mEnableSyncPreference.setOnPreferenceClickListener(mEnableSyncClickListener);
- mSyncNowPreference = findPreference(PREF_SYNC_NOW);
mSyncNowPreference.setEnabled(true);
mSyncNowPreference.setOnPreferenceClickListener(mSyncNowListener);
- mClearSyncDataPreference = findPreference(PREF_CLEAR_SYNC_DATA);
- mSyncNowPreference.setEnabled(true);
+ mClearSyncDataPreference.setEnabled(true);
mClearSyncDataPreference.setOnPreferenceClickListener(mDeleteSyncDataListener);
+
+ if (currentAccountName != null) {
+ mAccountSwitcher.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(final Preference preference) {
+ if (accountsForLogin.length > 0) {
+ // TODO: Add addition of account.
+ createAccountPicker(accountsForLogin, getSignedInAccountName(),
+ new AccountChangedListener(null)).show();
+ }
+ return true;
+ }
+ });
+ }
}
+ /**
+ * Two reasons for disable - work profile or no accounts on device.
+ */
private void disableSyncPreferences() {
- mAccountSwitcher = findPreference(PREF_ACCCOUNT_SWITCHER);
- if (mAccountSwitcher == null) {
- // Preference has been removed because the device has a managed profile.
+ if (!ProductionFlags.ENABLE_USER_HISTORY_DICTIONARY_SYNC) {
return;
}
- mAccountSwitcher.setEnabled(false);
- mEnableSyncPreference = (TwoStatePreference) findPreference(PREF_ENABLE_SYNC_NOW);
+ mAccountSwitcher.setEnabled(false);
mEnableSyncPreference.setEnabled(false);
-
- mSyncNowPreference = findPreference(PREF_SYNC_NOW);
- mSyncNowPreference.setEnabled(false);
-
- mClearSyncDataPreference = findPreference(PREF_CLEAR_SYNC_DATA);
mSyncNowPreference.setEnabled(false);
+ mClearSyncDataPreference.setEnabled(false);
}
+ /**
+ * Called only when ProductionFlag is turned off.
+ */
private void removeSyncPreferences() {
removePreference(PREF_ACCCOUNT_SWITCHER);
removePreference(PREF_ENABLE_CLOUD_SYNC);
@@ -197,20 +226,20 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
@Override
public void onResume() {
super.onResume();
- refreshAccountAndDependentPreferences(getSignedInAccountName());
+ refreshSyncSettingsUI();
}
@Override
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
if (TextUtils.equals(key, PREF_ACCOUNT_NAME)) {
- refreshAccountAndDependentPreferences(prefs.getString(PREF_ACCOUNT_NAME, null));
+ refreshSyncSettingsUI();
} else if (TextUtils.equals(key, PREF_ENABLE_CLOUD_SYNC)) {
- final boolean syncEnabled = prefs.getBoolean(PREF_ENABLE_CLOUD_SYNC, false);
mEnableSyncPreference = (TwoStatePreference) findPreference(PREF_ENABLE_SYNC_NOW);
- if (syncEnabled) {
- mEnableSyncPreference.setSummary(R.string.cloud_sync_summary);
+ final boolean syncEnabled = prefs.getBoolean(PREF_ENABLE_CLOUD_SYNC, false);
+ if (isSyncEnabled()) {
+ mEnableSyncPreference.setSummary(getString(R.string.cloud_sync_summary));
} else {
- mEnableSyncPreference.setSummary(R.string.cloud_sync_summary_disabled);
+ mEnableSyncPreference.setSummary(getString(R.string.cloud_sync_summary_disabled));
}
AccountStateChangedListener.onSyncPreferenceChanged(getSignedInAccountName(),
syncEnabled);
@@ -218,47 +247,67 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
}
/**
- * Summarizes what account is being used and turns off dependent preferences if no account
- * is currently selected.
+ * Checks different states like whether account is present or managed profile is present
+ * and sets the sync settings accordingly.
*/
- private void refreshAccountAndDependentPreferences(@Nullable final String currentAccount) {
- // TODO(cvnguyen): Write tests.
- if (!ProductionFlags.ENABLE_ACCOUNT_SIGN_IN) {
+ private void refreshSyncSettingsUI() {
+ if (!ProductionFlags.ENABLE_USER_HISTORY_DICTIONARY_SYNC) {
return;
}
-
final String[] accountsForLogin =
LoginAccountUtils.getAccountsForLogin(getActivity());
+ final String currentAccount = getSignedInAccountName();
- if (accountsForLogin.length > 0) {
- enableSyncPreferences();
- if (mAccountSwitcher == null) {
- return;
- }
- mAccountSwitcher.setOnPreferenceClickListener(new OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(final Preference preference) {
- if (accountsForLogin.length > 0) {
- // TODO: Add addition of account.
- createAccountPicker(accountsForLogin, currentAccount,
- new AccountChangedListener(null)).show();
- }
- return true;
- }
- });
+ if (!mManagedProfileBeingDetected.get() &&
+ !mHasManagedProfile.get() && accountsForLogin.length > 0) {
+ // Sync can be used by user; enable all preferences.
+ enableSyncPreferences(accountsForLogin, currentAccount);
} else {
- mAccountSwitcher.setEnabled(false);
+ // Sync cannot be used by user; disable all preferences.
disableSyncPreferences();
- mEnableSyncPreference.setSummary(getString(R.string.add_account_to_enable_sync));
}
+ refreshSyncSettingsMessaging(mManagedProfileBeingDetected.get(),
+ mHasManagedProfile.get(), accountsForLogin.length > 0,
+ currentAccount);
+ }
- if (currentAccount == null) {
- // No account is currently selected; switch enable sync preference off.
- mAccountSwitcher.setSummary(getString(R.string.no_accounts_selected));
- mEnableSyncPreference.setChecked(false);
+ /**
+ * @param managedProfileBeingDetected whether we are in process of determining work profile.
+ * @param hasManagedProfile whether the device has work profile.
+ * @param hasAccountsForLogin whether the device has enough accounts for login.
+ * @param currentAccount the account currently selected in the application.
+ */
+ private void refreshSyncSettingsMessaging(boolean managedProfileBeingDetected,
+ boolean hasManagedProfile, boolean hasAccountsForLogin, String currentAccount) {
+ if (!ProductionFlags.ENABLE_USER_HISTORY_DICTIONARY_SYNC) {
+ return;
+ }
+
+ // If we are determining eligiblity, we show empty summaries.
+ // Once we have some deterministic result, we set summaries based on different results.
+ if (managedProfileBeingDetected) {
+ mEnableSyncPreference.setSummary("");
+ mAccountSwitcher.setSummary("");
+ } else if (hasManagedProfile) {
+ mEnableSyncPreference.setSummary(
+ getString(R.string.cloud_sync_summary_disabled_work_profile));
+ } else if (!hasAccountsForLogin) {
+ mEnableSyncPreference.setSummary(getString(R.string.add_account_to_enable_sync));
+ } else if (isSyncEnabled()) {
+ mEnableSyncPreference.setSummary(getString(R.string.cloud_sync_summary));
} else {
- // Set the currently selected account as the summary text.
- mAccountSwitcher.setSummary(getString(R.string.account_selected, currentAccount));
+ mEnableSyncPreference.setSummary(getString(R.string.cloud_sync_summary_disabled));
+ }
+
+ // Set some interdependent settings.
+ // No account automatically turns off sync.
+ if (!managedProfileBeingDetected && !hasManagedProfile) {
+ if (currentAccount != null) {
+ mAccountSwitcher.setSummary(getString(R.string.account_selected, currentAccount));
+ } else {
+ mEnableSyncPreference.setChecked(false);
+ mAccountSwitcher.setSummary(getString(R.string.no_accounts_selected));
+ }
}
}
diff --git a/java/src/com/android/inputmethod/latin/settings/CorrectionSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/CorrectionSettingsFragment.java
index 62834cd2a..aa73a9a83 100644
--- a/java/src/com/android/inputmethod/latin/settings/CorrectionSettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/CorrectionSettingsFragment.java
@@ -16,29 +16,20 @@
package com.android.inputmethod.latin.settings;
-import android.app.Activity;
import android.content.Context;
import android.content.Intent;
-import android.content.SharedPreferences;
import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
-import android.preference.TwoStatePreference;
import com.android.inputmethod.dictionarypack.DictionarySettingsActivity;
import com.android.inputmethod.latin.R;
-import com.android.inputmethod.latin.userdictionary.UserDictionaryList;
-import com.android.inputmethod.latin.userdictionary.UserDictionarySettings;
-
-import java.util.TreeSet;
/**
* "Text correction" settings sub screen.
*
* This settings sub screen handles the following text correction preferences.
- * - Personal dictionary
* - Add-on dictionaries
* - Block offensive words
* - Auto-correction
@@ -68,39 +59,5 @@ public final class CorrectionSettingsFragment extends SubScreenFragment {
if (0 >= number) {
removePreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY);
}
-
- final Preference editPersonalDictionary =
- findPreference(Settings.PREF_EDIT_PERSONAL_DICTIONARY);
- final Intent editPersonalDictionaryIntent = editPersonalDictionary.getIntent();
- final ResolveInfo ri = USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS ? null
- : pm.resolveActivity(
- editPersonalDictionaryIntent, PackageManager.MATCH_DEFAULT_ONLY);
- if (ri == null) {
- overwriteUserDictionaryPreference(editPersonalDictionary);
- }
- }
-
- private void overwriteUserDictionaryPreference(final Preference userDictionaryPreference) {
- final Activity activity = getActivity();
- final TreeSet<String> localeList = UserDictionaryList.getUserDictionaryLocalesSet(activity);
- if (null == localeList) {
- // The locale list is null if and only if the user dictionary service is
- // not present or disabled. In this case we need to remove the preference.
- getPreferenceScreen().removePreference(userDictionaryPreference);
- } else if (localeList.size() <= 1) {
- userDictionaryPreference.setFragment(UserDictionarySettings.class.getName());
- // If the size of localeList is 0, we don't set the locale parameter in the
- // extras. This will be interpreted by the UserDictionarySettings class as
- // meaning "the current locale".
- // Note that with the current code for UserDictionaryList#getUserDictionaryLocalesSet()
- // the locale list always has at least one element, since it always includes the current
- // locale explicitly. @see UserDictionaryList.getUserDictionaryLocalesSet().
- if (localeList.size() == 1) {
- final String locale = (String)localeList.toArray()[0];
- userDictionaryPreference.getExtras().putString("locale", locale);
- }
- } else {
- userDictionaryPreference.setFragment(UserDictionaryList.class.getName());
- }
}
}
diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java
index 715f7bb38..e9645eef1 100644
--- a/java/src/com/android/inputmethod/latin/settings/Settings.java
+++ b/java/src/com/android/inputmethod/latin/settings/Settings.java
@@ -55,7 +55,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
// PREF_VOICE_MODE_OBSOLETE is obsolete. Use PREF_VOICE_INPUT_KEY instead.
public static final String PREF_VOICE_MODE_OBSOLETE = "voice_mode";
public static final String PREF_VOICE_INPUT_KEY = "pref_voice_input_key";
- public static final String PREF_EDIT_PERSONAL_DICTIONARY = "edit_personal_dictionary";
public static final String PREF_CONFIGURE_DICTIONARIES_KEY = "configure_dictionaries_key";
// PREF_AUTO_CORRECTION_THRESHOLD_OBSOLETE is obsolete. Use PREF_AUTO_CORRECTION instead.
public static final String PREF_AUTO_CORRECTION_THRESHOLD_OBSOLETE =
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java
index f5455e3db..874f221c6 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java
@@ -18,6 +18,7 @@ package com.android.inputmethod.latin.settings;
import android.app.Activity;
import android.content.Intent;
+import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceScreen;
@@ -71,11 +72,7 @@ public final class SettingsFragment extends InputMethodSettingsFragment {
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
final Activity activity = getActivity();
- final int setupStatus = Secure.getInt(
- activity.getContentResolver(),
- "user_setup_complete",
- 0 /* default */);
- if (setupStatus == 0) {
+ if (!isUserSetupComplete(activity)) {
// If setup is not complete, it's not safe to launch Help or other activities
// because they might go to the Play Store. See b/19866981.
return true;
@@ -94,4 +91,11 @@ public final class SettingsFragment extends InputMethodSettingsFragment {
}
return super.onOptionsItemSelected(item);
}
+
+ private static boolean isUserSetupComplete(final Activity activity) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
+ return true;
+ }
+ return Secure.getInt(activity.getContentResolver(), "user_setup_complete", 0) != 0;
+ }
}