aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorJatin Matani <jatinm@google.com>2015-03-02 20:21:28 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-03-02 20:21:29 +0000
commit55d9651929729548c16270de0a83e3a01c7f2a9b (patch)
treedee7399833920479fc25d7556f8539bd468d0e62 /java
parent8b2908066dc5259870fbf210e0af7eeb01d2b1ef (diff)
parent854edce6ddd7ed2d64406b66f746480741d61b15 (diff)
downloadlatinime-55d9651929729548c16270de0a83e3a01c7f2a9b.tar.gz
latinime-55d9651929729548c16270de0a83e3a01c7f2a9b.tar.xz
latinime-55d9651929729548c16270de0a83e3a01c7f2a9b.zip
Merge "Turn off cloud sync if we have managed profiles"
Diffstat (limited to 'java')
-rw-r--r--java/res/xml/prefs_screen_accounts.xml7
-rw-r--r--java/res/xml/prefs_screen_advanced.xml6
-rw-r--r--java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java115
-rw-r--r--java/src/com/android/inputmethod/latin/settings/AdvancedSettingsFragment.java16
-rw-r--r--java/src/com/android/inputmethod/latin/utils/ManagedProfileUtils.java68
5 files changed, 159 insertions, 53 deletions
diff --git a/java/res/xml/prefs_screen_accounts.xml b/java/res/xml/prefs_screen_accounts.xml
index e4baf7984..f2ade91e1 100644
--- a/java/res/xml/prefs_screen_accounts.xml
+++ b/java/res/xml/prefs_screen_accounts.xml
@@ -48,4 +48,11 @@
android:title="@string/clear_sync_data_title"
android:summary="@string/clear_sync_data_summary"
android:dependency="pref_enable_cloud_sync" />
+
+ <!-- Title will be set programmatically to embed application name -->
+ <CheckBoxPreference
+ android:key="pref_enable_metrics_logging"
+ android:summary="@string/enable_metrics_logging_summary"
+ android:defaultValue="true"
+ android:persistent="true" />
</PreferenceScreen>
diff --git a/java/res/xml/prefs_screen_advanced.xml b/java/res/xml/prefs_screen_advanced.xml
index 402132e67..6038f9947 100644
--- a/java/res/xml/prefs_screen_advanced.xml
+++ b/java/res/xml/prefs_screen_advanced.xml
@@ -43,12 +43,6 @@
android:summary="@string/prefs_enable_emoji_alt_physical_key_summary"
android:defaultValue="true"
android:persistent="true" />
- <!-- title will be set programmatically to embed application name -->
- <CheckBoxPreference
- android:key="pref_enable_metrics_logging"
- android:summary="@string/enable_metrics_logging_summary"
- android:defaultValue="true"
- android:persistent="true" />
<PreferenceScreen
android:fragment="com.android.inputmethod.latin.settings.DebugSettingsFragment"
android:key="screen_debug"
diff --git a/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java
index 394ecead6..c7c29772b 100644
--- a/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java
@@ -23,10 +23,14 @@ import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
+import android.content.res.Resources;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
+import android.preference.SwitchPreference;
+import android.preference.TwoStatePreference;
import android.text.TextUtils;
import android.widget.ListView;
import android.widget.Toast;
@@ -36,6 +40,7 @@ import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.accounts.AccountStateChangedListener;
import com.android.inputmethod.latin.accounts.LoginAccountUtils;
import com.android.inputmethod.latin.define.ProductionFlags;
+import com.android.inputmethod.latin.utils.ManagedProfileUtils;
import javax.annotation.Nullable;
@@ -74,7 +79,7 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
/**
* Enable sync checkbox pref.
*/
- private CheckBoxPreference mEnableSyncPreference;
+ private TwoStatePreference mEnableSyncPreference;
/**
* Enable sync checkbox pref.
@@ -86,32 +91,86 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
*/
private Preference mClearSyncDataPreference;
+ /**
+ * Account switcher preference.
+ */
+ private Preference mAccountSwitcher;
+
@Override
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.prefs_screen_accounts);
- if (!ProductionFlags.ENABLE_ACCOUNT_SIGN_IN) {
- removePreference(PREF_ACCCOUNT_SWITCHER);
- removePreference(PREF_ENABLE_CLOUD_SYNC);
- removePreference(PREF_SYNC_NOW);
- removePreference(PREF_CLEAR_SYNC_DATA);
+ if (ProductionFlags.IS_METRICS_LOGGING_SUPPORTED) {
+ final Preference enableMetricsLogging =
+ findPreference(Settings.PREF_ENABLE_METRICS_LOGGING);
+ final Resources res = getResources();
+ if (enableMetricsLogging != null) {
+ final String enableMetricsLoggingTitle = res.getString(
+ R.string.enable_metrics_logging, getApplicationName());
+ enableMetricsLogging.setTitle(enableMetricsLoggingTitle);
+ }
+ } else {
+ removePreference(Settings.PREF_ENABLE_METRICS_LOGGING);
}
+
if (!ProductionFlags.ENABLE_USER_HISTORY_DICTIONARY_SYNC) {
- removePreference(PREF_ENABLE_CLOUD_SYNC);
- removePreference(PREF_SYNC_NOW);
- removePreference(PREF_CLEAR_SYNC_DATA);
+ removeSyncPreferences();
} else {
- mEnableSyncPreference = (CheckBoxPreference) findPreference(PREF_ENABLE_SYNC_NOW);
- mEnableSyncPreference.setOnPreferenceClickListener(mEnableSyncClickListener);
+ disableSyncPreferences();
+ final AsyncTask<Void, Void, Void> checkManagedProfileTask =
+ new AsyncTask<Void, Void, Void>() {
+ @Override
+ protected Void doInBackground(Void... params) {
+ if (ManagedProfileUtils.hasManagedWorkProfile(getActivity())) {
+ removeSyncPreferences();
+ } else {
+ enableSyncPreferences();
+ }
+ return null;
+ }
+ };
+ checkManagedProfileTask.execute();
+ }
+ }
- mSyncNowPreference = findPreference(PREF_SYNC_NOW);
- mSyncNowPreference.setOnPreferenceClickListener(mSyncNowListener);
+ private void enableSyncPreferences() {
+ mAccountSwitcher = findPreference(PREF_ACCCOUNT_SWITCHER);
+ mAccountSwitcher.setEnabled(true);
- mClearSyncDataPreference = findPreference(PREF_CLEAR_SYNC_DATA);
- mClearSyncDataPreference.setOnPreferenceClickListener(mDeleteSyncDataListener);
- }
+ 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.setOnPreferenceClickListener(mDeleteSyncDataListener);
+ }
+
+ private void disableSyncPreferences() {
+ mAccountSwitcher = findPreference(PREF_ACCCOUNT_SWITCHER);
+ mAccountSwitcher.setEnabled(false);
+
+ mEnableSyncPreference = (TwoStatePreference) findPreference(PREF_ENABLE_SYNC_NOW);
+ mEnableSyncPreference.setEnabled(false);
+
+ mSyncNowPreference = findPreference(PREF_SYNC_NOW);
+ mSyncNowPreference.setEnabled(false);
+
+ mClearSyncDataPreference = findPreference(PREF_CLEAR_SYNC_DATA);
+ mSyncNowPreference.setEnabled(false);
+ }
+
+ private void removeSyncPreferences() {
+ removePreference(PREF_ACCCOUNT_SWITCHER);
+ removePreference(PREF_ENABLE_CLOUD_SYNC);
+ removePreference(PREF_SYNC_NOW);
+ removePreference(PREF_CLEAR_SYNC_DATA);
}
@Override
@@ -126,8 +185,7 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
refreshAccountAndDependentPreferences(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);
- mEnableSyncPreference = (CheckBoxPreference)findPreference(PREF_ENABLE_SYNC_NOW);
- mEnableSyncPreference.setChecked(syncEnabled);
+ mEnableSyncPreference = (TwoStatePreference) findPreference(PREF_ENABLE_SYNC_NOW);
if (syncEnabled) {
mEnableSyncPreference.setSummary(R.string.cloud_sync_summary);
} else {
@@ -147,27 +205,22 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
return;
}
- final Preference accountSwitcher = findPreference(PREF_ACCCOUNT_SWITCHER);
if (currentAccount == null) {
// No account is currently selected; switch enable sync preference off.
- accountSwitcher.setSummary(getString(R.string.no_accounts_selected));
+ mAccountSwitcher.setSummary(getString(R.string.no_accounts_selected));
mEnableSyncPreference.setChecked(false);
} else {
// Set the currently selected account as the summary text.
- accountSwitcher.setSummary(getString(R.string.account_selected, currentAccount));
+ mAccountSwitcher.setSummary(getString(R.string.account_selected, currentAccount));
}
- // Set up on click listener for the account picker preference.
- accountSwitcher.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ mAccountSwitcher.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(final Preference preference) {
final String[] accountsForLogin =
LoginAccountUtils.getAccountsForLogin(getActivity());
- if (accountsForLogin.length == 0) {
- // TODO: Handle account addition.
- Toast.makeText(getActivity(), getString(R.string.account_select_cancel),
- Toast.LENGTH_SHORT).show();
- } else {
+ if (accountsForLogin.length > 0) {
+ // TODO: Add addition of account.
createAccountPicker(accountsForLogin, currentAccount,
new AccountChangedListener(null)).show();
}
@@ -236,9 +289,9 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
/**
* Represents preference that should be changed based on account chosen.
*/
- private CheckBoxPreference mDependentPreference;
+ private TwoStatePreference mDependentPreference;
- AccountChangedListener(final CheckBoxPreference dependentPreference) {
+ AccountChangedListener(final TwoStatePreference dependentPreference) {
mDependentPreference = dependentPreference;
}
@@ -313,7 +366,7 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
class EnableSyncClickListener implements Preference.OnPreferenceClickListener {
@Override
public boolean onPreferenceClick(final Preference preference) {
- final CheckBoxPreference syncPreference = (CheckBoxPreference) preference;
+ final TwoStatePreference syncPreference = (TwoStatePreference) preference;
if (syncPreference.isChecked()) {
// Uncheck for now.
syncPreference.setChecked(false);
diff --git a/java/src/com/android/inputmethod/latin/settings/AdvancedSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/AdvancedSettingsFragment.java
index 9366726e2..f2e1aed4c 100644
--- a/java/src/com/android/inputmethod/latin/settings/AdvancedSettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/AdvancedSettingsFragment.java
@@ -87,22 +87,6 @@ public final class AdvancedSettingsFragment extends SubScreenFragment {
Settings.readKeyPreviewPopupEnabled(prefs, res));
}
- // If metrics logging isn't supported, or account sign in is enabled
- // don't show the logging preference.
- // TODO: Eventually when we enable account sign in by default,
- // we'll remove logging preference from here.
- if (ProductionFlags.IS_METRICS_LOGGING_SUPPORTED) {
- final Preference enableMetricsLogging =
- findPreference(Settings.PREF_ENABLE_METRICS_LOGGING);
- if (enableMetricsLogging != null) {
- final String enableMetricsLoggingTitle = res.getString(
- R.string.enable_metrics_logging, getApplicationName());
- enableMetricsLogging.setTitle(enableMetricsLoggingTitle);
- }
- } else {
- removePreference(Settings.PREF_ENABLE_METRICS_LOGGING);
- }
-
setupKeypressVibrationDurationSettings();
setupKeypressSoundVolumeSettings();
setupKeyLongpressTimeoutSettings();
diff --git a/java/src/com/android/inputmethod/latin/utils/ManagedProfileUtils.java b/java/src/com/android/inputmethod/latin/utils/ManagedProfileUtils.java
new file mode 100644
index 000000000..f0d6d081e
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/utils/ManagedProfileUtils.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.inputmethod.latin.utils;
+
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.os.Build;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.util.Log;
+
+import java.util.List;
+
+/**
+ * Utility for determining if the device has managed profiles.
+ */
+public class ManagedProfileUtils {
+ private static final boolean DEBUG = false;
+ private static final String TAG = ManagedProfileUtils.class.getSimpleName();
+
+ private ManagedProfileUtils() {
+ // This utility class is not publicly instantiable.
+ }
+
+ /**
+ * Note that {@link UserManager#getUserProfiles} has been introduced
+ * in API level 21 (Build.VERSION_CODES.LOLLIPOP).
+ */
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ public static boolean hasManagedWorkProfile(final Context context) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
+ return false;
+ }
+
+ final UserManager userManagerService =
+ (UserManager) context.getSystemService(Context.USER_SERVICE);
+ if (userManagerService != null) {
+ if (DEBUG) {
+ Log.d(TAG, "Detecting managed profile...");
+ }
+ final List<UserHandle> userProfiles = userManagerService.getUserProfiles();
+ if (userProfiles.size() > 1) {
+ if (DEBUG) {
+ Log.d(TAG, "More than one user profile => Managed profile exists.");
+ }
+ return true;
+ }
+ }
+ if (DEBUG) {
+ Log.d(TAG, "Managed profile not detected.");
+ }
+ return false;
+ }
+}