diff options
author | 2015-07-22 16:29:54 -0700 | |
---|---|---|
committer | 2015-07-24 02:00:54 +0000 | |
commit | 707ca7692a8666989b3fbe860bee28115103988e (patch) | |
tree | 7a60a230cb71c5d12eb8a2ca27ff5235bfdf0dce /java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java | |
parent | 604158669b407a40cd0f23538fad4dce5d738f24 (diff) | |
download | latinime-707ca7692a8666989b3fbe860bee28115103988e.tar.gz latinime-707ca7692a8666989b3fbe860bee28115103988e.tar.xz latinime-707ca7692a8666989b3fbe860bee28115103988e.zip |
Handle Cloud Sync and SpellChecker settings when permission changed
This build has been compiled against API 23
This build is approved to go out with the M OTA, but may NOT be released
to the public until the Play Store has enabled API level 23 apps
Version: 4.1.2300x.build_id
1. Disable the settings.
2. Disable the feature.
3. Force reload the facilitator.
Bug: 22564048
Change-Id: Ic09742786c3e4efc034bceee836ae6a1e07307a1
(cherry picked from commit 031d04192080f0368f21c3371d1ec6af87375357)
Diffstat (limited to 'java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java index cb2097826..b39e6b477 100644 --- a/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java +++ b/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java @@ -19,6 +19,7 @@ package com.android.inputmethod.latin.settings; import static com.android.inputmethod.latin.settings.LocalSettingsConstants.PREF_ACCOUNT_NAME; import static com.android.inputmethod.latin.settings.LocalSettingsConstants.PREF_ENABLE_CLOUD_SYNC; +import android.Manifest; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; @@ -40,6 +41,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.permissions.PermissionsUtil; import com.android.inputmethod.latin.utils.ManagedProfileUtils; import java.util.concurrent.atomic.AtomicBoolean; @@ -254,11 +256,14 @@ public final class AccountsSettingsFragment extends SubScreenFragment { if (!ProductionFlags.ENABLE_USER_HISTORY_DICTIONARY_SYNC) { return; } - final String[] accountsForLogin = - LoginAccountUtils.getAccountsForLogin(getActivity()); - final String currentAccount = getSignedInAccountName(); + boolean hasAccountsPermission = PermissionsUtil.checkAllPermissionsGranted( + getActivity(), Manifest.permission.READ_CONTACTS); - if (!mManagedProfileBeingDetected.get() && + final String[] accountsForLogin = hasAccountsPermission ? + LoginAccountUtils.getAccountsForLogin(getActivity()) : new String[0]; + final String currentAccount = hasAccountsPermission ? getSignedInAccountName() : null; + + if (hasAccountsPermission && !mManagedProfileBeingDetected.get() && !mHasManagedProfile.get() && accountsForLogin.length > 0) { // Sync can be used by user; enable all preferences. enableSyncPreferences(accountsForLogin, currentAccount); @@ -266,26 +271,35 @@ public final class AccountsSettingsFragment extends SubScreenFragment { // Sync cannot be used by user; disable all preferences. disableSyncPreferences(); } - refreshSyncSettingsMessaging(mManagedProfileBeingDetected.get(), + refreshSyncSettingsMessaging(hasAccountsPermission, mManagedProfileBeingDetected.get(), mHasManagedProfile.get(), accountsForLogin.length > 0, currentAccount); } /** + * @param hasAccountsPermission whether the app has the permission to read accounts. * @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) { + private void refreshSyncSettingsMessaging(boolean hasAccountsPermission, + 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) { + if (!hasAccountsPermission) { + mEnableSyncPreference.setChecked(false); + mEnableSyncPreference.setSummary(getString(R.string.cloud_sync_summary_disabled)); + mAccountSwitcher.setSummary(""); + return; + } else if (managedProfileBeingDetected) { + // If we are determining eligiblity, we show empty summaries. + // Once we have some deterministic result, we set summaries based on different results. mEnableSyncPreference.setSummary(""); mAccountSwitcher.setSummary(""); } else if (hasManagedProfile) { @@ -462,7 +476,7 @@ public final class AccountsSettingsFragment extends SubScreenFragment { new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, - final int which) { + final int which) { if (which == DialogInterface.BUTTON_POSITIVE) { final Context context = getActivity(); final String[] accountsForLogin = @@ -473,9 +487,9 @@ public final class AccountsSettingsFragment extends SubScreenFragment { .show(); } } - }) - .setNegativeButton(R.string.cloud_sync_cancel, null) - .create(); + }) + .setNegativeButton(R.string.cloud_sync_cancel, null) + .create(); optInDialog.setOnShowListener(this); optInDialog.show(); } |