Turn off cloud sync if we have managed profiles
UserManager#getUserProfiles > 1 implies managed profile. Workflow: - Disable sync prefs - Execute an async task to check for managed profile; if managed profile is found, remove the sync prefs. If not, enable the preference; - Move the logging pref from Advanced to Account & Privacy. Bug:19230544 Change-Id: I4dbd1fe8433b3263ccc74c35dc0ee0bb371122b3main
parent
c83352d527
commit
854edce6dd
|
@ -48,4 +48,11 @@
|
||||||
android:title="@string/clear_sync_data_title"
|
android:title="@string/clear_sync_data_title"
|
||||||
android:summary="@string/clear_sync_data_summary"
|
android:summary="@string/clear_sync_data_summary"
|
||||||
android:dependency="pref_enable_cloud_sync" />
|
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>
|
</PreferenceScreen>
|
||||||
|
|
|
@ -43,12 +43,6 @@
|
||||||
android:summary="@string/prefs_enable_emoji_alt_physical_key_summary"
|
android:summary="@string/prefs_enable_emoji_alt_physical_key_summary"
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:persistent="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
|
<PreferenceScreen
|
||||||
android:fragment="com.android.inputmethod.latin.settings.DebugSettingsFragment"
|
android:fragment="com.android.inputmethod.latin.settings.DebugSettingsFragment"
|
||||||
android:key="screen_debug"
|
android:key="screen_debug"
|
||||||
|
|
|
@ -23,10 +23,14 @@ import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.Preference.OnPreferenceClickListener;
|
import android.preference.Preference.OnPreferenceClickListener;
|
||||||
|
import android.preference.SwitchPreference;
|
||||||
|
import android.preference.TwoStatePreference;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.Toast;
|
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.AccountStateChangedListener;
|
||||||
import com.android.inputmethod.latin.accounts.LoginAccountUtils;
|
import com.android.inputmethod.latin.accounts.LoginAccountUtils;
|
||||||
import com.android.inputmethod.latin.define.ProductionFlags;
|
import com.android.inputmethod.latin.define.ProductionFlags;
|
||||||
|
import com.android.inputmethod.latin.utils.ManagedProfileUtils;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -74,7 +79,7 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
|
||||||
/**
|
/**
|
||||||
* Enable sync checkbox pref.
|
* Enable sync checkbox pref.
|
||||||
*/
|
*/
|
||||||
private CheckBoxPreference mEnableSyncPreference;
|
private TwoStatePreference mEnableSyncPreference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable sync checkbox pref.
|
* Enable sync checkbox pref.
|
||||||
|
@ -86,32 +91,86 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
|
||||||
*/
|
*/
|
||||||
private Preference mClearSyncDataPreference;
|
private Preference mClearSyncDataPreference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Account switcher preference.
|
||||||
|
*/
|
||||||
|
private Preference mAccountSwitcher;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(final Bundle icicle) {
|
public void onCreate(final Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
addPreferencesFromResource(R.xml.prefs_screen_accounts);
|
addPreferencesFromResource(R.xml.prefs_screen_accounts);
|
||||||
|
|
||||||
if (!ProductionFlags.ENABLE_ACCOUNT_SIGN_IN) {
|
if (ProductionFlags.IS_METRICS_LOGGING_SUPPORTED) {
|
||||||
removePreference(PREF_ACCCOUNT_SWITCHER);
|
final Preference enableMetricsLogging =
|
||||||
removePreference(PREF_ENABLE_CLOUD_SYNC);
|
findPreference(Settings.PREF_ENABLE_METRICS_LOGGING);
|
||||||
removePreference(PREF_SYNC_NOW);
|
final Resources res = getResources();
|
||||||
removePreference(PREF_CLEAR_SYNC_DATA);
|
if (enableMetricsLogging != null) {
|
||||||
}
|
final String enableMetricsLoggingTitle = res.getString(
|
||||||
if (!ProductionFlags.ENABLE_USER_HISTORY_DICTIONARY_SYNC) {
|
R.string.enable_metrics_logging, getApplicationName());
|
||||||
removePreference(PREF_ENABLE_CLOUD_SYNC);
|
enableMetricsLogging.setTitle(enableMetricsLoggingTitle);
|
||||||
removePreference(PREF_SYNC_NOW);
|
}
|
||||||
removePreference(PREF_CLEAR_SYNC_DATA);
|
|
||||||
} else {
|
} else {
|
||||||
mEnableSyncPreference = (CheckBoxPreference) findPreference(PREF_ENABLE_SYNC_NOW);
|
removePreference(Settings.PREF_ENABLE_METRICS_LOGGING);
|
||||||
mEnableSyncPreference.setOnPreferenceClickListener(mEnableSyncClickListener);
|
|
||||||
|
|
||||||
mSyncNowPreference = findPreference(PREF_SYNC_NOW);
|
|
||||||
mSyncNowPreference.setOnPreferenceClickListener(mSyncNowListener);
|
|
||||||
|
|
||||||
mClearSyncDataPreference = findPreference(PREF_CLEAR_SYNC_DATA);
|
|
||||||
mClearSyncDataPreference.setOnPreferenceClickListener(mDeleteSyncDataListener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ProductionFlags.ENABLE_USER_HISTORY_DICTIONARY_SYNC) {
|
||||||
|
removeSyncPreferences();
|
||||||
|
} else {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableSyncPreferences() {
|
||||||
|
mAccountSwitcher = findPreference(PREF_ACCCOUNT_SWITCHER);
|
||||||
|
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.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
|
@Override
|
||||||
|
@ -126,8 +185,7 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
|
||||||
refreshAccountAndDependentPreferences(prefs.getString(PREF_ACCOUNT_NAME, null));
|
refreshAccountAndDependentPreferences(prefs.getString(PREF_ACCOUNT_NAME, null));
|
||||||
} else if (TextUtils.equals(key, PREF_ENABLE_CLOUD_SYNC)) {
|
} else if (TextUtils.equals(key, PREF_ENABLE_CLOUD_SYNC)) {
|
||||||
final boolean syncEnabled = prefs.getBoolean(PREF_ENABLE_CLOUD_SYNC, false);
|
final boolean syncEnabled = prefs.getBoolean(PREF_ENABLE_CLOUD_SYNC, false);
|
||||||
mEnableSyncPreference = (CheckBoxPreference)findPreference(PREF_ENABLE_SYNC_NOW);
|
mEnableSyncPreference = (TwoStatePreference) findPreference(PREF_ENABLE_SYNC_NOW);
|
||||||
mEnableSyncPreference.setChecked(syncEnabled);
|
|
||||||
if (syncEnabled) {
|
if (syncEnabled) {
|
||||||
mEnableSyncPreference.setSummary(R.string.cloud_sync_summary);
|
mEnableSyncPreference.setSummary(R.string.cloud_sync_summary);
|
||||||
} else {
|
} else {
|
||||||
|
@ -147,27 +205,22 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Preference accountSwitcher = findPreference(PREF_ACCCOUNT_SWITCHER);
|
|
||||||
if (currentAccount == null) {
|
if (currentAccount == null) {
|
||||||
// No account is currently selected; switch enable sync preference off.
|
// 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);
|
mEnableSyncPreference.setChecked(false);
|
||||||
} else {
|
} else {
|
||||||
// Set the currently selected account as the summary text.
|
// 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.
|
mAccountSwitcher.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
accountSwitcher.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(final Preference preference) {
|
public boolean onPreferenceClick(final Preference preference) {
|
||||||
final String[] accountsForLogin =
|
final String[] accountsForLogin =
|
||||||
LoginAccountUtils.getAccountsForLogin(getActivity());
|
LoginAccountUtils.getAccountsForLogin(getActivity());
|
||||||
if (accountsForLogin.length == 0) {
|
if (accountsForLogin.length > 0) {
|
||||||
// TODO: Handle account addition.
|
// TODO: Add addition of account.
|
||||||
Toast.makeText(getActivity(), getString(R.string.account_select_cancel),
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
} else {
|
|
||||||
createAccountPicker(accountsForLogin, currentAccount,
|
createAccountPicker(accountsForLogin, currentAccount,
|
||||||
new AccountChangedListener(null)).show();
|
new AccountChangedListener(null)).show();
|
||||||
}
|
}
|
||||||
|
@ -236,9 +289,9 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
|
||||||
/**
|
/**
|
||||||
* Represents preference that should be changed based on account chosen.
|
* 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;
|
mDependentPreference = dependentPreference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,7 +353,7 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.clear_sync_data_cancel, null /* OnClickListener */)
|
.setNegativeButton(R.string.cloud_sync_cancel, null /* OnClickListener */)
|
||||||
.create();
|
.create();
|
||||||
confirmationDialog.show();
|
confirmationDialog.show();
|
||||||
return true;
|
return true;
|
||||||
|
@ -313,7 +366,7 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
|
||||||
class EnableSyncClickListener implements Preference.OnPreferenceClickListener {
|
class EnableSyncClickListener implements Preference.OnPreferenceClickListener {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(final Preference preference) {
|
public boolean onPreferenceClick(final Preference preference) {
|
||||||
final CheckBoxPreference syncPreference = (CheckBoxPreference) preference;
|
final TwoStatePreference syncPreference = (TwoStatePreference) preference;
|
||||||
if (syncPreference.isChecked()) {
|
if (syncPreference.isChecked()) {
|
||||||
// Uncheck for now.
|
// Uncheck for now.
|
||||||
syncPreference.setChecked(false);
|
syncPreference.setChecked(false);
|
||||||
|
|
|
@ -87,22 +87,6 @@ public final class AdvancedSettingsFragment extends SubScreenFragment {
|
||||||
Settings.readKeyPreviewPopupEnabled(prefs, res));
|
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();
|
setupKeypressVibrationDurationSettings();
|
||||||
setupKeypressSoundVolumeSettings();
|
setupKeypressSoundVolumeSettings();
|
||||||
setupKeyLongpressTimeoutSettings();
|
setupKeyLongpressTimeoutSettings();
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue