diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/settings/AccessibilitySettings.java | 59 | ||||
-rw-r--r-- | src/com/android/settings/AccountPreference.java | 34 | ||||
-rw-r--r-- | src/com/android/settings/BiometricWeakLiveliness.java | 136 | ||||
-rw-r--r-- | src/com/android/settings/DataUsageSummary.java | 10 | ||||
-rw-r--r-- | src/com/android/settings/DisplaySettings.java | 56 | ||||
-rw-r--r-- | src/com/android/settings/SecuritySettings.java | 36 | ||||
-rw-r--r-- | src/com/android/settings/Settings.java | 68 | ||||
-rw-r--r-- | src/com/android/settings/accounts/AuthenticatorHelper.java | 13 | ||||
-rw-r--r-- | src/com/android/settings/accounts/ManageAccountsSettings.java | 33 | ||||
-rw-r--r-- | src/com/android/settings/accounts/SyncSettings.java | 174 | ||||
-rw-r--r-- | src/com/android/settings/accounts/SyncSettingsActivity.java | 34 |
11 files changed, 405 insertions, 248 deletions
diff --git a/src/com/android/settings/AccessibilitySettings.java b/src/com/android/settings/AccessibilitySettings.java index d2bfc0d..6167f78 100644 --- a/src/com/android/settings/AccessibilitySettings.java +++ b/src/com/android/settings/AccessibilitySettings.java @@ -36,7 +36,6 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.RemoteException; -import android.os.ServiceManager; import android.os.SystemProperties; import android.preference.CheckBoxPreference; import android.preference.ListPreference; @@ -45,18 +44,14 @@ import android.preference.PreferenceActivity; import android.preference.PreferenceCategory; import android.preference.PreferenceScreen; import android.provider.Settings; -import android.provider.Settings.SettingNotFoundException; import android.text.TextUtils; import android.text.TextUtils.SimpleStringSplitter; -import android.util.Log; import android.view.Gravity; -import android.view.IWindowManager; import android.view.KeyCharacterMap; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; -import android.view.Surface; import android.view.View; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; @@ -65,6 +60,7 @@ import android.widget.Switch; import android.widget.TextView; import com.android.internal.content.PackageMonitor; +import com.android.internal.view.RotationPolicy; import com.android.settings.AccessibilitySettings.ToggleSwitch.OnBeforeCheckedChangeListener; import java.util.HashMap; @@ -78,8 +74,6 @@ import java.util.Set; */ public class AccessibilitySettings extends SettingsPreferenceFragment implements DialogCreatable, Preference.OnPreferenceChangeListener { - private static final String TAG = "AccessibilitySettings"; - private static final String DEFAULT_SCREENREADER_MARKET_LINK = "market://search?q=pname:com.google.android.marvin.talkback"; @@ -151,22 +145,11 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements } }; - private final Uri mLockScreenRotationUri = Uri.withAppendedPath(Settings.System.CONTENT_URI, - Settings.System.ACCELEROMETER_ROTATION); - - private final ContentObserver mSettingsContentObserver = new ContentObserver(mHandler) { + private final RotationPolicy.RotationPolicyListener mRotationPolicyListener = + new RotationPolicy.RotationPolicyListener() { @Override - public void onChange(boolean selfChange, Uri uri) { - if (mLockScreenRotationUri.equals(uri)) { - try { - final boolean lockRotationEnabled = (Settings.System.getInt( - getActivity().getContentResolver(), - Settings.System.ACCELEROMETER_ROTATION) == 0); - mToggleLockScreenRotationPreference.setChecked(lockRotationEnabled); - } catch (SettingNotFoundException e) { - /* ignore */ - } - } + public void onChange() { + updateLockScreenRotationCheckbox(); } }; @@ -200,14 +183,15 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements offerInstallAccessibilitySerivceOnce(); } mSettingsPackageMonitor.register(getActivity(), getActivity().getMainLooper(), false); - getActivity().getContentResolver().registerContentObserver(mLockScreenRotationUri, false, - mSettingsContentObserver); + RotationPolicy.registerRotationPolicyListener(getActivity(), + mRotationPolicyListener); } @Override public void onPause() { mSettingsPackageMonitor.unregister(); - getContentResolver().unregisterContentObserver(mSettingsContentObserver); + RotationPolicy.unregisterRotationPolicyListener(getActivity(), + mRotationPolicyListener); super.onPause(); } @@ -258,17 +242,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements } private void handleLockScreenRotationPreferenceClick() { - try { - IWindowManager wm = IWindowManager.Stub.asInterface( - ServiceManager.getService(Context.WINDOW_SERVICE)); - if (!mToggleLockScreenRotationPreference.isChecked()) { - wm.thawRotation(); - } else { - wm.freezeRotation(Surface.ROTATION_0); - } - } catch (RemoteException exc) { - Log.w(TAG, "Unable to save auto-rotate setting"); - } + RotationPolicy.setRotationLockForAccessibility(getActivity(), + !mToggleLockScreenRotationPreference.isChecked()); } private void handleToggleSpeakPasswordPreferenceClick() { @@ -453,9 +428,7 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements } // Auto-rotate screen - final boolean lockRotationEnabled = Settings.System.getInt(getContentResolver(), - Settings.System.ACCELEROMETER_ROTATION, 0) != 1; - mToggleLockScreenRotationPreference.setChecked(lockRotationEnabled); + updateLockScreenRotationCheckbox(); // Speak passwords. final boolean speakPasswordEnabled = Settings.Secure.getInt(getContentResolver(), @@ -475,6 +448,14 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements mToggleScriptInjectionPreference.setInjectionAllowed(scriptInjectionAllowed); } + private void updateLockScreenRotationCheckbox() { + Context context = getActivity(); + if (context != null) { + mToggleLockScreenRotationPreference.setChecked( + !RotationPolicy.isRotationLocked(context)); + } + } + private void offerInstallAccessibilitySerivceOnce() { // There is always one preference - if no services it is just a message. if (mServicesCategory.getPreference(0) != mNoServicesMessagePreference) { diff --git a/src/com/android/settings/AccountPreference.java b/src/com/android/settings/AccountPreference.java index e7919dd..2cc013c 100644 --- a/src/com/android/settings/AccountPreference.java +++ b/src/com/android/settings/AccountPreference.java @@ -39,16 +39,24 @@ public class AccountPreference extends Preference { private int mStatus; private Account mAccount; private ArrayList<String> mAuthorities; + private ImageView mSyncStatusIcon; + private boolean mShowTypeIcon; public AccountPreference(Context context, Account account, Drawable icon, - ArrayList<String> authorities) { + ArrayList<String> authorities, boolean showTypeIcon) { super(context); mAccount = account; mAuthorities = authorities; + mShowTypeIcon = showTypeIcon; + if (showTypeIcon) { + setIcon(icon); + } else { + setIcon(getSyncStatusIcon(SYNC_DISABLED)); + } setTitle(mAccount.name); setSummary(""); setPersistent(false); - setSyncStatus(SYNC_DISABLED); + setSyncStatus(SYNC_DISABLED, false); } public Account getAccount() { @@ -62,16 +70,22 @@ public class AccountPreference extends Preference { @Override protected void onBindView(View view) { super.onBindView(view); - setSummary(getSyncStatusMessage(mStatus)); - ImageView iconView = (ImageView) view.findViewById(android.R.id.icon); - iconView.setImageResource(getSyncStatusIcon(mStatus)); - iconView.setContentDescription(getSyncContentDescription(mStatus)); + if (!mShowTypeIcon) { + mSyncStatusIcon = (ImageView) view.findViewById(android.R.id.icon); + mSyncStatusIcon.setImageResource(getSyncStatusIcon(mStatus)); + mSyncStatusIcon.setContentDescription(getSyncContentDescription(mStatus)); + } } - public void setSyncStatus(int status) { + public void setSyncStatus(int status, boolean updateSummary) { mStatus = status; - setIcon(getSyncStatusIcon(status)); - setSummary(getSyncStatusMessage(status)); + if (!mShowTypeIcon && mSyncStatusIcon != null) { + mSyncStatusIcon.setImageResource(getSyncStatusIcon(status)); + mSyncStatusIcon.setContentDescription(getSyncContentDescription(mStatus)); + } + if (updateSummary) { + setSummary(getSyncStatusMessage(status)); + } } private int getSyncStatusMessage(int status) { @@ -109,7 +123,7 @@ public class AccountPreference extends Preference { res = R.drawable.ic_sync_red_holo; break; case SYNC_IN_PROGRESS: - res = R.drawable.ic_sync_grey_holo; + res = R.drawable.ic_sync_green_holo; break; default: res = R.drawable.ic_sync_red_holo; diff --git a/src/com/android/settings/BiometricWeakLiveliness.java b/src/com/android/settings/BiometricWeakLiveliness.java deleted file mode 100644 index 6bba77f..0000000 --- a/src/com/android/settings/BiometricWeakLiveliness.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (C) 2012 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.settings; - -import android.app.ActionBar; -import android.app.Activity; -import android.app.Fragment; -import android.os.Bundle; -import android.os.Handler; -import android.content.Intent; -import android.preference.PreferenceActivity; -import android.util.Log; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CompoundButton; -import android.widget.Switch; -import com.android.settings.R; - -import com.android.internal.widget.LockPatternUtils; - -public class BiometricWeakLiveliness extends Fragment - implements CompoundButton.OnCheckedChangeListener { - private static final int CONFIRM_EXISTING_FOR_BIOMETRIC_WEAK_LIVELINESS_OFF = 125; - - private View mView; - private ChooseLockSettingsHelper mChooseLockSettingsHelper; - private LockPatternUtils mLockPatternUtils; - private Switch mActionBarSwitch; - private boolean mSuppressCheckChanged; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Activity activity = getActivity(); - - mActionBarSwitch = new Switch(activity); - mSuppressCheckChanged = false; - - if (activity instanceof PreferenceActivity) { - PreferenceActivity preferenceActivity = (PreferenceActivity) activity; - if (preferenceActivity.onIsHidingHeaders() || !preferenceActivity.onIsMultiPane()) { - final int padding = activity.getResources().getDimensionPixelSize( - R.dimen.action_bar_switch_padding); - mActionBarSwitch.setPadding(0, 0, padding, 0); - activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, - ActionBar.DISPLAY_SHOW_CUSTOM); - activity.getActionBar().setCustomView(mActionBarSwitch, new ActionBar.LayoutParams( - ActionBar.LayoutParams.WRAP_CONTENT, - ActionBar.LayoutParams.WRAP_CONTENT, - Gravity.CENTER_VERTICAL | Gravity.RIGHT)); - activity.getActionBar().setTitle(R.string.biometric_weak_liveliness_title); - } - } - - mActionBarSwitch.setOnCheckedChangeListener(this); - - mLockPatternUtils = new LockPatternUtils(getActivity()); - mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity()); - mActionBarSwitch.setChecked(mLockPatternUtils.isBiometricWeakLivelinessEnabled()); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - mView = inflater.inflate(R.layout.biometric_weak_liveliness, container, false); - initView(mView); - return mView; - } - - private void initView(View view) { - mActionBarSwitch.setOnCheckedChangeListener(this); - mActionBarSwitch.setChecked(mLockPatternUtils.isBiometricWeakLivelinessEnabled()); - } - - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean desiredState) { - if (mSuppressCheckChanged) { - return; - } - mActionBarSwitch.setEnabled(false); - if (desiredState) { - mLockPatternUtils.setBiometricWeakLivelinessEnabled(true); - mActionBarSwitch.setChecked(true); - } else { - // In this case the user has just turned it off, but this action requires them - // to confirm their password. We need to turn the switch back on until - // they've confirmed their password - mActionBarSwitch.setChecked(true); - mActionBarSwitch.requestLayout(); - ChooseLockSettingsHelper helper = - new ChooseLockSettingsHelper(this.getActivity(), this); - if (!helper.launchConfirmationActivity( - CONFIRM_EXISTING_FOR_BIOMETRIC_WEAK_LIVELINESS_OFF, null, null)) { - // If this returns false, it means no password confirmation is required, so - // go ahead and turn it off here. - // Note: currently a backup is required for biometric_weak so this code path - // can't be reached, but is here in case things change in the future - mLockPatternUtils.setBiometricWeakLivelinessEnabled(false); - mActionBarSwitch.setChecked(false); - mActionBarSwitch.requestLayout(); - } - } - mActionBarSwitch.setEnabled(true); - } - - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (requestCode == CONFIRM_EXISTING_FOR_BIOMETRIC_WEAK_LIVELINESS_OFF && - resultCode == Activity.RESULT_OK) { - final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils(); - lockPatternUtils.setBiometricWeakLivelinessEnabled(false); - mSuppressCheckChanged = true; - mActionBarSwitch.setChecked(false); - mSuppressCheckChanged = false; - return; - } - } - -} diff --git a/src/com/android/settings/DataUsageSummary.java b/src/com/android/settings/DataUsageSummary.java index 656d4c4..13512d4 100644 --- a/src/com/android/settings/DataUsageSummary.java +++ b/src/com/android/settings/DataUsageSummary.java @@ -2035,6 +2035,7 @@ public class DataUsageSummary extends Fragment { * Dialog to inform user about changing auto-sync setting */ public static class ConfirmAutoSyncChangeFragment extends DialogFragment { + private static final String SAVE_ENABLING = "enabling"; private boolean mEnabling; public static void show(DataUsageSummary parent, boolean enabling) { @@ -2049,6 +2050,9 @@ public class DataUsageSummary extends Fragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Context context = getActivity(); + if (savedInstanceState != null) { + mEnabling = savedInstanceState.getBoolean(SAVE_ENABLING); + } final AlertDialog.Builder builder = new AlertDialog.Builder(context); if (!mEnabling) { @@ -2069,6 +2073,12 @@ public class DataUsageSummary extends Fragment { return builder.create(); } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putBoolean(SAVE_ENABLING, mEnabling); + } } /** diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java index bad7340..fc162e2 100644 --- a/src/com/android/settings/DisplaySettings.java +++ b/src/com/android/settings/DisplaySettings.java @@ -24,11 +24,8 @@ import android.content.ContentResolver; import android.content.Context; import android.content.res.Configuration; import android.content.res.Resources; -import android.database.ContentObserver; import android.os.Bundle; -import android.os.Handler; import android.os.RemoteException; -import android.os.ServiceManager; import android.preference.CheckBoxPreference; import android.preference.ListPreference; import android.preference.Preference; @@ -36,8 +33,8 @@ import android.preference.PreferenceScreen; import android.provider.Settings; import android.provider.Settings.SettingNotFoundException; import android.util.Log; -import android.view.IWindowManager; +import com.android.internal.view.RotationPolicy; import com.android.settings.DreamSettings; import java.util.ArrayList; @@ -55,7 +52,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements private static final String KEY_NOTIFICATION_PULSE = "notification_pulse"; private static final String KEY_SCREEN_SAVER = "screensaver"; - private CheckBoxPreference mRotationLock; + private CheckBoxPreference mAccelerometer; private ListPreference mFontSizePref; private CheckBoxPreference mNotificationPulse; @@ -64,10 +61,11 @@ public class DisplaySettings extends SettingsPreferenceFragment implements private ListPreference mScreenTimeoutPreference; private Preference mScreenSaverPreference; - private ContentObserver mAccelerometerRotationObserver = new ContentObserver(new Handler()) { + private final RotationPolicy.RotationPolicyListener mRotationPolicyListener = + new RotationPolicy.RotationPolicyListener() { @Override - public void onChange(boolean selfChange) { - updateRotationLockCheckbox(); + public void onChange() { + updateAccelerometerRotationCheckbox(); } }; @@ -78,8 +76,13 @@ public class DisplaySettings extends SettingsPreferenceFragment implements addPreferencesFromResource(R.xml.display_settings); - mRotationLock = (CheckBoxPreference) findPreference(KEY_ACCELEROMETER); - mRotationLock.setPersistent(false); + mAccelerometer = (CheckBoxPreference) findPreference(KEY_ACCELEROMETER); + mAccelerometer.setPersistent(false); + if (RotationPolicy.isRotationLockToggleSupported(getActivity())) { + // If rotation lock is supported, then we do not provide this option in + // Display settings. However, is still available in Accessibility settings. + getPreferenceScreen().removePreference(mAccelerometer); + } mScreenSaverPreference = findPreference(KEY_SCREEN_SAVER); if (mScreenSaverPreference != null @@ -209,20 +212,21 @@ public class DisplaySettings extends SettingsPreferenceFragment implements super.onResume(); updateState(); - getContentResolver().registerContentObserver( - Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION), true, - mAccelerometerRotationObserver); + + RotationPolicy.registerRotationPolicyListener(getActivity(), + mRotationPolicyListener); } @Override public void onPause() { super.onPause(); - getContentResolver().unregisterContentObserver(mAccelerometerRotationObserver); + RotationPolicy.unregisterRotationPolicyListener(getActivity(), + mRotationPolicyListener); } private void updateState() { - updateRotationLockCheckbox(); + updateAccelerometerRotationCheckbox(); readFontSizePreference(mFontSizePref); updateScreenSaverSummary(); } @@ -234,11 +238,10 @@ public class DisplaySettings extends SettingsPreferenceFragment implements : R.string.screensaver_settings_summary_off); } - private void updateRotationLockCheckbox() { + private void updateAccelerometerRotationCheckbox() { if (getActivity() == null) return; - mRotationLock.setChecked(Settings.System.getInt( - getContentResolver(), - Settings.System.ACCELEROMETER_ROTATION, 0) == 0); + + mAccelerometer.setChecked(!RotationPolicy.isRotationLocked(getActivity())); } public void writeFontSizePreference(Object objValue) { @@ -252,18 +255,9 @@ public class DisplaySettings extends SettingsPreferenceFragment implements @Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { - if (preference == mRotationLock) { - try { - IWindowManager wm = IWindowManager.Stub.asInterface( - ServiceManager.getService(Context.WINDOW_SERVICE)); - if (!mRotationLock.isChecked()) { - wm.thawRotation(); - } else { - wm.freezeRotation(-1); - } - } catch (RemoteException exc) { - Log.w(TAG, "Unable to save auto-rotate setting"); - } + if (preference == mAccelerometer) { + RotationPolicy.setRotationLockForAccessibility( + getActivity(), !mAccelerometer.isChecked()); } else if (preference == mNotificationPulse) { boolean value = mNotificationPulse.isChecked(); Settings.System.putInt(getContentResolver(), Settings.System.NOTIFICATION_LIGHT_PULSE, diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java index 6b67730..a12da3e 100644 --- a/src/com/android/settings/SecuritySettings.java +++ b/src/com/android/settings/SecuritySettings.java @@ -62,6 +62,7 @@ public class SecuritySettings extends SettingsPreferenceFragment private static final String KEY_LOCK_AFTER_TIMEOUT = "lock_after_timeout"; private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123; private static final int CONFIRM_EXISTING_FOR_BIOMETRIC_WEAK_IMPROVE_REQUEST = 124; + private static final int CONFIRM_EXISTING_FOR_BIOMETRIC_WEAK_LIVELINESS_OFF = 125; // Misc Settings private static final String KEY_SIM_LOCK = "sim_lock"; @@ -76,7 +77,7 @@ public class SecuritySettings extends SettingsPreferenceFragment private LockPatternUtils mLockPatternUtils; private ListPreference mLockAfter; - private PreferenceScreen mBiometricWeakLiveliness; + private CheckBoxPreference mBiometricWeakLiveliness; private CheckBoxPreference mVisiblePattern; private CheckBoxPreference mTactileFeedback; @@ -162,7 +163,7 @@ public class SecuritySettings extends SettingsPreferenceFragment // biometric weak liveliness mBiometricWeakLiveliness = - (PreferenceScreen) root.findPreference(KEY_BIOMETRIC_WEAK_LIVELINESS); + (CheckBoxPreference) root.findPreference(KEY_BIOMETRIC_WEAK_LIVELINESS); // visible pattern mVisiblePattern = (CheckBoxPreference) root.findPreference(KEY_VISIBLE_PATTERN); @@ -338,9 +339,8 @@ public class SecuritySettings extends SettingsPreferenceFragment final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils(); if (mBiometricWeakLiveliness != null) { - mBiometricWeakLiveliness.setSummary(lockPatternUtils.isBiometricWeakLivelinessEnabled()? - R.string.biometric_weak_liveliness_on_summary: - R.string.biometric_weak_liveliness_off_summary); + mBiometricWeakLiveliness.setChecked( + lockPatternUtils.isBiometricWeakLivelinessEnabled()); } if (mVisiblePattern != null) { mVisiblePattern.setChecked(lockPatternUtils.isVisiblePatternEnabled()); @@ -382,6 +382,26 @@ public class SecuritySettings extends SettingsPreferenceFragment // can't be reached, but is here in case things change in the future startBiometricWeakImprove(); } + } else if (KEY_BIOMETRIC_WEAK_LIVELINESS.equals(key)) { + if (isToggled(preference)) { + lockPatternUtils.setBiometricWeakLivelinessEnabled(true); + } else { + // In this case the user has just unchecked the checkbox, but this action requires + // them to confirm their password. We need to re-check the checkbox until + // they've confirmed their password + mBiometricWeakLiveliness.setChecked(true); + ChooseLockSettingsHelper helper = + new ChooseLockSettingsHelper(this.getActivity(), this); + if (!helper.launchConfirmationActivity( + CONFIRM_EXISTING_FOR_BIOMETRIC_WEAK_LIVELINESS_OFF, null, null)) { + // If this returns false, it means no password confirmation is required, so + // go ahead and uncheck it here. + // Note: currently a backup is required for biometric_weak so this code path + // can't be reached, but is here in case things change in the future + lockPatternUtils.setBiometricWeakLivelinessEnabled(false); + mBiometricWeakLiveliness.setChecked(false); + } + } } else if (KEY_LOCK_ENABLED.equals(key)) { lockPatternUtils.setLockPatternEnabled(isToggled(preference)); } else if (KEY_VISIBLE_PATTERN.equals(key)) { @@ -422,6 +442,12 @@ public class SecuritySettings extends SettingsPreferenceFragment resultCode == Activity.RESULT_OK) { startBiometricWeakImprove(); return; + } else if (requestCode == CONFIRM_EXISTING_FOR_BIOMETRIC_WEAK_LIVELINESS_OFF && + resultCode == Activity.RESULT_OK) { + final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils(); + lockPatternUtils.setBiometricWeakLivelinessEnabled(false); + mBiometricWeakLiveliness.setChecked(false); + return; } createPreferenceHierarchy(); } diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index a8599bf..37b47c2 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -26,6 +26,9 @@ import com.android.settings.deviceinfo.Memory; import com.android.settings.fuelgauge.PowerUsageSummary; import com.android.settings.wifi.WifiEnabler; +import android.accounts.Account; +import android.accounts.AccountManager; +import android.accounts.OnAccountsUpdateListener; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -64,7 +67,8 @@ import java.util.List; /** * Top-level settings activity to handle single pane and double pane UI layout. */ -public class Settings extends PreferenceActivity implements ButtonBarHandler { +public class Settings extends PreferenceActivity + implements ButtonBarHandler, OnAccountsUpdateListener { private static final String LOG_TAG = "Settings"; private static final String META_DATA_KEY_HEADER_ID = @@ -108,6 +112,7 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler { private AuthenticatorHelper mAuthenticatorHelper; private Header mLastHeader; + private boolean mListeningToAccountUpdates; @Override protected void onCreate(Bundle savedInstanceState) { @@ -196,6 +201,14 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler { } } + @Override + public void onDestroy() { + super.onDestroy(); + if (mListeningToAccountUpdates) { + AccountManager.get(this).removeOnAccountsUpdatedListener(this); + } + } + private void switchToHeaderLocal(Header header) { mInLocalHeaderSwitch = true; switchToHeader(header); @@ -426,21 +439,36 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler { List<Header> accountHeaders = new ArrayList<Header>(accountTypes.length); for (String accountType : accountTypes) { CharSequence label = mAuthenticatorHelper.getLabelForType(this, accountType); + Account[] accounts = AccountManager.get(this).getAccountsByType(accountType); + boolean skipToAccount = accounts.length == 1 + && !mAuthenticatorHelper.hasAccountPreferences(accountType); Header accHeader = new Header(); accHeader.title = label; if (accHeader.extras == null) { accHeader.extras = new Bundle(); } - accHeader.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType); - accHeader.breadCrumbTitle = label; - accHeader.breadCrumbShortTitle = label; - accHeader.fragment = ManageAccountsSettings.class.getName(); - accHeader.fragmentArguments = new Bundle(); - accHeader.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, - accountType); - if (!isMultiPane()) { - accHeader.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_LABEL, - label.toString()); + if (skipToAccount) { + accHeader.breadCrumbTitleRes = R.string.account_sync_settings_title; + accHeader.breadCrumbShortTitleRes = R.string.account_sync_settings_title; + accHeader.fragment = AccountSyncSettings.class.getName(); + accHeader.fragmentArguments = new Bundle(); + // Need this for the icon + accHeader.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType); + accHeader.extras.putParcelable(AccountSyncSettings.ACCOUNT_KEY, accounts[0]); + accHeader.fragmentArguments.putParcelable(AccountSyncSettings.ACCOUNT_KEY, + accounts[0]); + } else { + accHeader.breadCrumbTitle = label; + accHeader.breadCrumbShortTitle = label; + accHeader.fragment = ManageAccountsSettings.class.getName(); + accHeader.fragmentArguments = new Bundle(); + accHeader.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType); + accHeader.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, + accountType); + if (!isMultiPane()) { + accHeader.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_LABEL, + label.toString()); + } } accountHeaders.add(accHeader); } @@ -456,6 +484,10 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler { for (Header header : accountHeaders) { target.add(headerIndex++, header); } + if (!mListeningToAccountUpdates) { + AccountManager.get(this).addOnAccountsUpdatedListener(this, null, true); + mListeningToAccountUpdates = true; + } return headerIndex; } @@ -593,9 +625,9 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler { case HEADER_TYPE_NORMAL: view = mInflater.inflate( - com.android.internal.R.layout.preference_header_item, parent, + R.layout.preference_header_item, parent, false); - holder.icon = (ImageView) view.findViewById(com.android.internal.R.id.icon); + holder.icon = (ImageView) view.findViewById(R.id.icon); holder.title = (TextView) view.findViewById(com.android.internal.R.id.title); holder.summary = (TextView) @@ -625,8 +657,8 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler { //$FALL-THROUGH$ case HEADER_TYPE_NORMAL: - if (header.extras != null && header.extras.containsKey( - ManageAccountsSettings.KEY_ACCOUNT_TYPE)) { + if (header.extras != null + && header.extras.containsKey(ManageAccountsSettings.KEY_ACCOUNT_TYPE)) { String accType = header.extras.getString( ManageAccountsSettings.KEY_ACCOUNT_TYPE); ViewGroup.LayoutParams lp = holder.icon.getLayoutParams(); @@ -711,6 +743,12 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler { super.setListAdapter(new HeaderAdapter(this, mHeaders, mAuthenticatorHelper)); } + @Override + public void onAccountsUpdated(Account[] accounts) { + mAuthenticatorHelper.onAccountsUpdated(this, accounts); + invalidateHeaders(); + } + /* * Settings subclasses for launching independently. */ diff --git a/src/com/android/settings/accounts/AuthenticatorHelper.java b/src/com/android/settings/accounts/AuthenticatorHelper.java index 9c17a36..eba785b 100644 --- a/src/com/android/settings/accounts/AuthenticatorHelper.java +++ b/src/com/android/settings/accounts/AuthenticatorHelper.java @@ -23,7 +23,6 @@ import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Resources; import android.graphics.drawable.Drawable; -import android.graphics.drawable.ScaleDrawable; import android.util.Log; import java.util.ArrayList; @@ -32,7 +31,7 @@ import java.util.Map; public class AuthenticatorHelper { - private static final String TAG = "AccountTypesHelper"; + private static final String TAG = "AuthenticatorHelper"; private Map<String, AuthenticatorDescription> mTypeToAuthDescription = new HashMap<String, AuthenticatorDescription>(); private AuthenticatorDescription[] mAuthDescs; @@ -124,4 +123,14 @@ public class AuthenticatorHelper { public AuthenticatorDescription getAccountTypeDescription(String accountType) { return mTypeToAuthDescription.get(accountType); } + + public boolean hasAccountPreferences(final String accountType) { + if (containsAccountType(accountType)) { + AuthenticatorDescription desc = getAccountTypeDescription(accountType); + if (desc != null && desc.accountPreferencesId != 0) { + return true; + } + } + return false; + } } diff --git a/src/com/android/settings/accounts/ManageAccountsSettings.java b/src/com/android/settings/accounts/ManageAccountsSettings.java index 909fd92..a27fbbd 100644 --- a/src/com/android/settings/accounts/ManageAccountsSettings.java +++ b/src/com/android/settings/accounts/ManageAccountsSettings.java @@ -60,6 +60,7 @@ import java.util.HashSet; public class ManageAccountsSettings extends AccountPreferenceBase implements OnAccountsUpdateListener { + private static final String ACCOUNT_KEY = "account"; // to pass to auth settings public static final String KEY_ACCOUNT_TYPE = "account_type"; public static final String KEY_ACCOUNT_LABEL = "account_label"; @@ -74,6 +75,8 @@ public class ManageAccountsSettings extends AccountPreferenceBase private SettingsDialogFragment mDialogFragment; // If an account type is set, then show only accounts of that type private String mAccountType; + // Temporary hack, to deal with backward compatibility + private Account mFirstAccount; @Override public void onCreate(Bundle icicle) { @@ -163,8 +166,8 @@ public class ManageAccountsSettings extends AccountPreferenceBase public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); boolean syncActive = ContentResolver.getCurrentSync() != null; - menu.findItem(MENU_SYNC_NOW_ID).setVisible(!syncActive); - menu.findItem(MENU_SYNC_CANCEL_ID).setVisible(syncActive); + menu.findItem(MENU_SYNC_NOW_ID).setVisible(!syncActive && mFirstAccount != null); + menu.findItem(MENU_SYNC_CANCEL_ID).setVisible(syncActive && mFirstAccount != null); } @Override @@ -271,16 +274,16 @@ public class ManageAccountsSettings extends AccountPreferenceBase } } if (syncIsFailing) { - accountPref.setSyncStatus(AccountPreference.SYNC_ERROR); + accountPref.setSyncStatus(AccountPreference.SYNC_ERROR, true); } else if (syncCount == 0) { - accountPref.setSyncStatus(AccountPreference.SYNC_DISABLED); + accountPref.setSyncStatus(AccountPreference.SYNC_DISABLED, true); } else if (syncCount > 0) { if (syncingNow) { - accountPref.setSyncStatus(AccountPreference.SYNC_IN_PROGRESS); + accountPref.setSyncStatus(AccountPreference.SYNC_IN_PROGRESS, true); } else { - accountPref.setSyncStatus(AccountPreference.SYNC_ENABLED); + accountPref.setSyncStatus(AccountPreference.SYNC_ENABLED, true); if (lastSuccessTime > 0) { - accountPref.setSyncStatus(AccountPreference.SYNC_ENABLED); + accountPref.setSyncStatus(AccountPreference.SYNC_ENABLED, false); date.setTime(lastSuccessTime); final String timeString = formatSyncDate(date); accountPref.setSummary(getResources().getString( @@ -288,7 +291,7 @@ public class ManageAccountsSettings extends AccountPreferenceBase } } } else { - accountPref.setSyncStatus(AccountPreference.SYNC_DISABLED); + accountPref.setSyncStatus(AccountPreference.SYNC_DISABLED, true); } } @@ -299,6 +302,7 @@ public class ManageAccountsSettings extends AccountPreferenceBase public void onAccountsUpdated(Account[] accounts) { if (getActivity() == null) return; getPreferenceScreen().removeAll(); + mFirstAccount = null; addPreferencesFromResource(R.xml.manage_accounts_settings); for (int i = 0, n = accounts.length; i < n; i++) { final Account account = accounts[i]; @@ -320,12 +324,20 @@ public class ManageAccountsSettings extends AccountPreferenceBase if (showAccount) { final Drawable icon = getDrawableForType(account.type); final AccountPreference preference = - new AccountPreference(getActivity(), account, icon, auths); + new AccountPreference(getActivity(), account, icon, auths, false); getPreferenceScreen().addPreference(preference); + if (mFirstAccount == null) { + mFirstAccount = account; + } } } - if (mAccountType != null) { + if (mAccountType != null && mFirstAccount != null) { addAuthenticatorSettings(); + } else { + // There's no account, reset to top-level of settings + Intent settingsTop = new Intent(android.provider.Settings.ACTION_SETTINGS); + settingsTop.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + getActivity().startActivity(settingsTop); } onSyncStateUpdated(); } @@ -347,6 +359,7 @@ public class ManageAccountsSettings extends AccountPreferenceBase prefs.removePreference(prefs.getPreference(i)); continue; } else { + intent.putExtra(ACCOUNT_KEY, mFirstAccount); intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); } } diff --git a/src/com/android/settings/accounts/SyncSettings.java b/src/com/android/settings/accounts/SyncSettings.java new file mode 100644 index 0000000..20c296a --- /dev/null +++ b/src/com/android/settings/accounts/SyncSettings.java @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2008 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.settings.accounts; + +import android.accounts.Account; +import android.accounts.AccountManager; +import android.accounts.OnAccountsUpdateListener; +import android.app.Activity; +import android.content.ContentResolver; +import android.content.Intent; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.preference.CheckBoxPreference; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.PreferenceScreen; +import android.util.Log; + +import com.android.settings.AccountPreference; +import com.android.settings.DialogCreatable; +import com.android.settings.R; + +import java.util.ArrayList; + +public class SyncSettings extends AccountPreferenceBase + implements OnAccountsUpdateListener, DialogCreatable { + + private static final String KEY_SYNC_SWITCH = "sync_switch"; + + private String[] mAuthorities; + + private SettingsDialogFragment mDialogFragment; + private CheckBoxPreference mAutoSyncPreference; + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + + addPreferencesFromResource(R.xml.sync_settings); + mAutoSyncPreference = + (CheckBoxPreference) getPreferenceScreen().findPreference(KEY_SYNC_SWITCH); + mAutoSyncPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + ContentResolver.setMasterSyncAutomatically((Boolean) newValue); + return true; + } + }); + + setHasOptionsMenu(true); + } + + @Override + public void onStart() { + super.onStart(); + Activity activity = getActivity(); + AccountManager.get(activity).addOnAccountsUpdatedListener(this, null, true); + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + final Activity activity = getActivity(); + mAutoSyncPreference.setChecked(ContentResolver.getMasterSyncAutomatically()); + mAuthorities = activity.getIntent().getStringArrayExtra(AUTHORITIES_FILTER_KEY); + + updateAuthDescriptions(); + } + + @Override + public void onStop() { + super.onStop(); + final Activity activity = getActivity(); + AccountManager.get(activity).removeOnAccountsUpdatedListener(this); + } + + @Override + public boolean onPreferenceTreeClick(PreferenceScreen preferences, Preference preference) { + if (preference instanceof AccountPreference) { + startAccountSettings((AccountPreference) preference); + } else { + return false; + } + return true; + } + + private void startAccountSettings(AccountPreference acctPref) { + Intent intent = new Intent("android.settings.ACCOUNT_SYNC_SETTINGS"); + intent.putExtra(AccountSyncSettings.ACCOUNT_KEY, acctPref.getAccount()); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + finish(); + } + + @Override + public void showDialog(int dialogId) { + if (mDialogFragment != null) { + Log.e(TAG, "Old dialog fragment not null!"); + } + mDialogFragment = new SettingsDialogFragment(this, dialogId); + mDialogFragment.show(getActivity().getFragmentManager(), Integer.toString(dialogId)); + } + + private void removeAccountPreferences() { + PreferenceScreen parent = getPreferenceScreen(); + for (int i = 0; i < parent.getPreferenceCount(); ) { + if (parent.getPreference(i) instanceof AccountPreference) { + parent.removePreference(parent.getPreference(i)); + } else { + i++; + } + } + } + + @Override + public void onAccountsUpdated(Account[] accounts) { + if (getActivity() == null) return; + + removeAccountPreferences(); + for (int i = 0, n = accounts.length; i < n; i++) { + final Account account = accounts[i]; + final ArrayList<String> auths = getAuthoritiesForAccountType(account.type); + + boolean showAccount = true; + if (mAuthorities != null && auths != null) { + showAccount = false; + for (String requestedAuthority : mAuthorities) { + if (auths.contains(requestedAuthority)) { + showAccount = true; + break; + } + } + } + + if (showAccount) { + final Drawable icon = getDrawableForType(account.type); + final AccountPreference preference = + new AccountPreference(getActivity(), account, icon, auths, true); + getPreferenceScreen().addPreference(preference); + preference.setSummary(getLabelForType(account.type)); + } + } + onSyncStateUpdated(); + } + + @Override + protected void onAuthDescriptionsUpdated() { + // Update account icons for all account preference items + for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) { + Preference pref = getPreferenceScreen().getPreference(i); + if (pref instanceof AccountPreference) { + AccountPreference accPref = (AccountPreference) + getPreferenceScreen().getPreference(i); + accPref.setIcon(getDrawableForType(accPref.getAccount().type)); + accPref.setSummary(getLabelForType(accPref.getAccount().type)); + } + } + } +} diff --git a/src/com/android/settings/accounts/SyncSettingsActivity.java b/src/com/android/settings/accounts/SyncSettingsActivity.java new file mode 100644 index 0000000..ed0089e --- /dev/null +++ b/src/com/android/settings/accounts/SyncSettingsActivity.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2012 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.settings.accounts; + +import android.content.Intent; +import android.preference.PreferenceActivity; + +/** + * Launcher activity for the SyncSettings fragment. + * + */ +public class SyncSettingsActivity extends PreferenceActivity { + @Override + public Intent getIntent() { + Intent modIntent = new Intent(super.getIntent()); + modIntent.putExtra(EXTRA_SHOW_FRAGMENT, SyncSettings.class.getName()); + modIntent.putExtra(EXTRA_NO_HEADERS, true); + return modIntent; + } +}
\ No newline at end of file |