Merge change 26713 into eclair

* changes:
  Set selection in single choice list. Reorder the menu entries to use the menu options as indices into the choice box directly
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 367aa9c..9393057 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -311,6 +311,19 @@
             </intent-filter>
         </activity>
 
+        <activity android:name="PrivacySettings"
+                android:label="@string/privacy_settings_title"
+                android:configChanges="orientation|keyboardHidden"
+                android:clearTaskOnLaunch="true"
+                >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <action android:name="android.settings.PRIVACY_SETTINGS" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.VOICE_LAUNCH" />
+            </intent-filter>
+        </activity>
+
         <activity android:name="IccLockSettings" android:label="@string/sim_lock_settings"
                 android:process="com.android.phone">
             <intent-filter>
@@ -467,7 +480,8 @@
 
         <activity android:name="ActivityPicker"
                 android:label="@string/activity_picker_label"
-                android:theme="@*android:style/Theme.Dialog.Alert">
+                android:theme="@*android:style/Theme.Dialog.Alert"
+                android:finishOnCloseSystemDialogs="true">
             <intent-filter>
                 <action android:name="android.intent.action.PICK_ACTIVITY" />
                 <category android:name="android.intent.category.DEFAULT" />
@@ -570,7 +584,8 @@
         <!-- Standard picker for widgets -->
         <activity android:name="AppWidgetPickActivity"
                 android:label="@string/widget_picker_title"
-                android:theme="@*android:style/Theme.Dialog.Alert">
+                android:theme="@*android:style/Theme.Dialog.Alert"
+                android:finishOnCloseSystemDialogs="true">
             <intent-filter>
                 <action android:name="android.appwidget.action.APPWIDGET_PICK" />
                 <category android:name="android.intent.category.DEFAULT" />
diff --git a/res/drawable-hdpi/ic_settings_privacy.png b/res/drawable-hdpi/ic_settings_privacy.png
new file mode 100644
index 0000000..5fb60c2
--- /dev/null
+++ b/res/drawable-hdpi/ic_settings_privacy.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_settings_privacy.png b/res/drawable-mdpi/ic_settings_privacy.png
new file mode 100644
index 0000000..30ba317
--- /dev/null
+++ b/res/drawable-mdpi/ic_settings_privacy.png
Binary files differ
diff --git a/res/drawable/ic_settings_privacy.png b/res/drawable/ic_settings_privacy.png
new file mode 100755
index 0000000..7e4868c
--- /dev/null
+++ b/res/drawable/ic_settings_privacy.png
Binary files differ
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 88163bd..5e4c5b5 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -174,7 +174,7 @@
     <string name="bluetooth">Bluetooth</string>
     <!-- Bluetooth settings screen, check box label when the Bluetooth device can be seen by others -->
     <string name="bluetooth_visibility">Discoverable</string>
-    <!-- Bluetooth settings screen,  summary after selecting Discoverable check box -->
+    <!-- Bluetooth settings screen, summary after selecting Discoverable check box -->
     <string name="bluetooth_is_discoverable">Discoverable for <xliff:g id="discoverable_time_period">%1$s</xliff:g> seconds\u2026</string>
     <!-- Bluetooth settings screen, Discoverable checkbox summary text -->
     <string name="bluetooth_not_discoverable">Make device discoverable</string>
@@ -712,7 +712,7 @@
     <!-- Wifi network summary when the network is configured previously, capitalized by app -->
     <string name="summary_remembered">remembered</string>
     <!-- Wifi network summary when there was an error connecting -->
-    <string name="summary_connection_failed">Connection unsuccessful, select to try again</string>
+    <string name="summary_connection_failed">Connection unsuccessful, touch to try again</string>
     <!-- Header for the list of wifi networks-->
     <string name="wifi_access_points">Wi-Fi networks</string>
     <!-- Caption for entering the SSID of a wifi network -->
@@ -1165,21 +1165,21 @@
     <!-- Security & location settings screen, setting summary when Use wireless networks check box is selected -->
     <string name="location_neighborhood_level">Location determined by Wi-Fi and/or mobile networks</string>
     <!-- Security & location settings screen, setting check box label if the GPS receiver should be enabled -->
-    <string name="location_gps">Enable GPS satellites</string>
-    <!-- Security & location settings screen, setting summary when Enable GPS satellites check box is selected -->
-    <string name="location_street_level">When locating, accurate to street level (deselect to conserve battery)</string>
-    <!-- Security & location settings screen, setting summary when Enable GPS satellites check box is clear -->
+    <string name="location_gps">Use GPS satellites</string>
+    <!-- Security & location settings screen, setting summary when Use GPS satellites check box is selected -->
+    <string name="location_street_level">When locating, accurate to street level (uncheck to conserve battery)</string>
+    <!-- Security & location settings screen, setting summary when Use GPS satellites check box is clear -->
     <string name="location_gps_disabled">Locate to street-level (requires more battery plus view of sky)</string>
     <!-- Security & location settings screen, setting check box label if Assisted GPS should be enabled -->
-    <string name="assisted_gps">Enable assisted GPS</string>
+    <string name="assisted_gps">Use assisted GPS</string>
     <!-- Security & location settings screen, setting summary when Assisted GPS check box is selected -->
-    <string name="assisted_gps_enabled">Use server to assist GPS (deselect to reduce network usage)</string>
+    <string name="assisted_gps_enabled">Use server to assist GPS (uncheck to reduce network usage)</string>
     <!-- Security & location settings screen, setting summary when Assisted GPS check box is clear -->
-    <string name="assisted_gps_disabled">Use server to assist GPS (select to improve GPS performance)</string>
+    <string name="assisted_gps_disabled">Use server to assist GPS (uncheck to improve GPS performance)</string>
     <!-- Setting title for allow sending location to google -->
-    <string name="use_location_title">Share with Google</string>
-    <!-- Title of dialog to user requesting use of location information to improve services -->
-    <string name="use_location_summary">Allow Google to use location for improved search and other services</string>
+    <string name="use_location_title">Use My Location</string>
+    <!-- Setting summary for allowing Google to use location information for improved search results. -->
+    <string name="use_location_summary">Use My Location for Google search results and other Google services</string>
     <!-- Message of dialog to user requesting use of location information -->
     <string name="use_location_warning_message">Do you want to allow Google to use location for improved search results and other services?</string>
     <!-- Agree -->
@@ -1286,8 +1286,8 @@
         \n<font height="17">\n</font><b>1</b>\u00A0 On the next screen, watch while an example pattern is drawn.
         \n<font height="17">\n</font><b>2</b>\u00A0 When ready, draw your own personal unlock pattern. Experiment with different patterns but connect at least four dots.
         \n<font height="17">\n</font><b>3</b>\u00A0 Redraw your pattern to confirm.
-        \n<font height="17">\n</font><b>Ready to start? Select \u201CNext\u201D</b>.
-        \n<font height="3">\n</font>To leave your phone unprotected, select \u201CCancel\u201D.</font>
+        \n<font height="17">\n</font><b>Ready to start? Touch \u201CNext\u201D</b>.
+        \n<font height="3">\n</font>To leave your phone unprotected, touch \u201CCancel\u201D.</font>
     </string>    
         
     <!-- ChooseLockPatternExample --> <skip />
@@ -1295,7 +1295,7 @@
     <string name="lock_example_title">Example pattern</string>
     <!-- ChooseLockPatternExample, screen hint text at bottom of screen. These are instructions and rules for drawing a good patttern -->
     <string name="lock_example_message">Connect at least four dots.\n
-        \nSelect \u201CNext\u201D when you\u2019re ready to draw your own pattern.
+        \nTouch \u201CNext\u201D when you\u2019re ready to draw your own pattern.
     </string>
 
     <!-- Applications Settings --> <skip />
@@ -1430,9 +1430,9 @@
     <!-- Running services, button to cancel stopping of a service -->
     <string name="confirm_stop_cancel">Cancel</string>
     <!-- Running services, description for a service in the started state -->
-    <string name="service_started_by_app">Started by application: select to stop</string>
+    <string name="service_started_by_app">Started by application: touch to stop</string>
     <!-- Running services, description for a service in the started state -->
-    <string name="service_client_name"><xliff:g id="client_name">%1$s</xliff:g>: select to manage</string>
+    <string name="service_client_name"><xliff:g id="client_name">%1$s</xliff:g>: touch to manage</string>
     <!-- Running services, summary of background processes -->
     <string name="service_background_processes">Avail: <xliff:g id="memory">%2$s</xliff:g> (<xliff:g id="count">%1$d</xliff:g> procs)</string>
     <!-- Running services, summary of foreground processes -->
@@ -1479,7 +1479,7 @@
     all the text you type, including personal data like passwords and credit
     card numbers.  It comes from the application
     <xliff:g id="ime_application_name">%1$s</xliff:g>.
-    Enable this input method?</string>
+    Use this input method?</string>
     
     <!-- User dictionary settings --><skip />
     <!-- User dictionary settings, The titlebar text of the User dictionary settings screen. -->
@@ -1564,7 +1564,7 @@
     <!-- setting Checkbox summary whether to allow mock locations  -->
     <string name="allow_mock_location_summary">Allow mock locations</string>
     <!-- Title of warning dialog about the implications of enabling USB debugging -->
-    <string name="adb_warning_title">Enable USB debugging?</string>
+    <string name="adb_warning_title">Allow USB debugging?</string>
     <!-- Warning text to user about the implications of enabling USB debugging -->
     <string name="adb_warning_message">USB debugging is intended for development purposes only. It can be used to copy data between your computer and your device, install applications on your device without notification, and read log data.</string>
 
@@ -1702,7 +1702,7 @@
     <string name="accessibility_service_security_warning">This accessibility service may be able to collect
         all the text you type, including personal data credit card numbers except passwords.
         It may also log your user interface interactions. It comes from the application
-        <xliff:g id="accessibility_service_name">%1$s</xliff:g>. Enable this accessibility service?</string>
+        <xliff:g id="accessibility_service_name">%1$s</xliff:g>. Use this accessibility service?</string>
     <!-- Warning about disabling accessibility displayed as a dialog message when the user
          selects to disable accessibility. This avoids accidental disabling. -->
     <string name="accessibility_service_disable_warning">Disable accessibility?</string>
@@ -2091,4 +2091,22 @@
     <string name="emergency_tone_title">Emergency tone</string>
     <!-- Sound settings screen, setting option summary text -->
     <string name="emergency_tone_summary">Set behavior when an emergency call is placed</string>
+    
+    <!-- Privacy Settings screen --><skip/>
+    <!-- Privacy settings menu title -->
+    <string name="privacy_settings">Privacy</string>
+    <!-- Privacy settings activity title -->
+    <string name="privacy_settings_title">Privacy settings</string>
+    <!-- Location settings section title -->
+    <string name="location_section_title">Location</string>
+    <!-- Settings section title -->
+    <string name="settings_section_title">Settings</string>
+    <!-- Personal data section title -->
+    <string name="personal_data_section_title">Personal data</string>
+    <!-- Backup settings menu title -->
+    <string name="backup_settings_title">Back up my settings</string>
+    <!-- Dialog title for confirmation to erase backup data from server -->
+    <string name="backup_erase_dialog_title">Settings backup</string>
+    <!-- Dialog title for confirmation to erase backup data from server -->
+    <string name="backup_erase_dialog_message">Are you sure you want to stop backing up your settings and erase all copies on Google servers?</string>
 </resources>
diff --git a/res/xml/device_info_settings.xml b/res/xml/device_info_settings.xml
index 81d33b2..56810b4 100644
--- a/res/xml/device_info_settings.xml
+++ b/res/xml/device_info_settings.xml
@@ -120,13 +120,4 @@
                 android:title="@string/build_number"
                 android:summary="@string/device_info_default"/>
 
-        <!-- Factory reset -->
-        <PreferenceScreen 
-            android:title="@string/master_clear_title" 
-            android:summary="@string/master_clear_summary">
-            <intent android:action="android.intent.action.MAIN"
-                android:targetPackage="com.android.settings"
-                android:targetClass="com.android.settings.MasterClear" />
-        </PreferenceScreen>
-
 </PreferenceScreen>
diff --git a/res/xml/privacy_settings.xml b/res/xml/privacy_settings.xml
new file mode 100644
index 0000000..92955a5
--- /dev/null
+++ b/res/xml/privacy_settings.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <PreferenceCategory android:key="location_category"
+            android:title="@string/location_section_title">
+        <!-- Share location with Google -->
+        <CheckBoxPreference
+                android:key="use_location"
+                android:title="@string/use_location_title"
+                android:persistent="false"
+                android:summary="@string/use_location_summary"/>
+    </PreferenceCategory>
+
+    <PreferenceCategory android:key="settings_category"
+            android:title="@string/settings_section_title">
+        <!-- Backup settings -->
+        <CheckBoxPreference
+                android:key="backup_settings"
+                android:title="@string/backup_settings_title"
+                android:persistent="false" />
+    </PreferenceCategory>
+
+    <PreferenceCategory
+            android:title="@string/personal_data_section_title">
+        <!-- Factory reset -->
+        <PreferenceScreen
+                android:title="@string/master_clear_title"
+                android:summary="@string/master_clear_summary">
+            <intent android:action="android.intent.action.MAIN"
+                    android:targetPackage="com.android.settings"
+                    android:targetClass="com.android.settings.MasterClear" />
+        </PreferenceScreen>
+    </PreferenceCategory>
+
+</PreferenceScreen>
diff --git a/res/xml/security_settings.xml b/res/xml/security_settings.xml
index 1322eaf..1b73584 100644
--- a/res/xml/security_settings.xml
+++ b/res/xml/security_settings.xml
@@ -40,11 +40,6 @@
             android:summaryOn="@string/assisted_gps_enabled"
             android:summaryOff="@string/assisted_gps_disabled"/>
 -->
-        <CheckBoxPreference
-            android:key="use_location"
-            android:title="@string/use_location_title"
-            android:persistent="false"
-            android:summary="@string/use_location_summary"/>
 
     </PreferenceCategory>
             
diff --git a/res/xml/settings.xml b/res/xml/settings.xml
index 769a86f..79a777d 100644
--- a/res/xml/settings.xml
+++ b/res/xml/settings.xml
@@ -50,7 +50,7 @@
                 android:targetClass="com.android.settings.SoundAndDisplaySettings" />
         </com.android.settings.IconPreferenceScreen>
 
-        <!-- Security & Privacy -->
+        <!-- Security & Location -->
 
         <com.android.settings.IconPreferenceScreen
             settings:icon="@drawable/ic_settings_security"
@@ -85,6 +85,18 @@
             <intent android:action="android.settings.SYNC_SETTINGS" />
         </com.android.settings.IconPreferenceScreen>
 
+        <!-- Privacy -->
+
+        <com.android.settings.IconPreferenceScreen
+            settings:icon="@drawable/ic_settings_privacy"
+            android:title="@string/privacy_settings"
+            android:key="privacy_settings">
+            <intent
+                android:action="android.intent.action.MAIN"
+                android:targetPackage="com.android.settings"
+                android:targetClass="com.android.settings.PrivacySettings" />
+        </com.android.settings.IconPreferenceScreen>
+
         <!-- Storage -->
 
         <com.android.settings.IconPreferenceScreen 
diff --git a/src/com/android/settings/PrivacySettings.java b/src/com/android/settings/PrivacySettings.java
new file mode 100644
index 0000000..2edb328
--- /dev/null
+++ b/src/com/android/settings/PrivacySettings.java
@@ -0,0 +1,260 @@
+/*
+ * Copyright (C) 2009 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.AlertDialog;
+import android.app.Dialog;
+import android.backup.IBackupManager;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.SharedPreferences;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.os.Bundle;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceScreen;
+import android.provider.Settings;
+import android.text.method.LinkMovementMethod;
+import android.widget.TextView;
+
+/**
+ * Gesture lock pattern settings.
+ */
+public class PrivacySettings extends PreferenceActivity implements
+        DialogInterface.OnDismissListener, DialogInterface.OnClickListener {
+
+    private static final String PREFS_NAME = "location_prefs";
+    private static final String PREFS_USE_LOCATION = "use_location";
+
+    // Vendor specific
+    private static final String GSETTINGS_PROVIDER = "com.google.android.providers.settings";
+    private static final String LOCATION_CATEGORY = "location_category";
+    private static final String SETTINGS_CATEGORY = "settings_category";
+    private static final String USE_LOCATION = "use_location";
+    private static final String BACKUP_SETTINGS = "backup_settings";
+    private static final String KEY_DONE_USE_LOCATION = "doneLocation";
+    private CheckBoxPreference mUseLocation;
+    private CheckBoxPreference mBackup;
+    private boolean mOkClicked;
+    private Dialog mConfirmDialog;
+
+    private static final int DIALOG_USE_LOCATION = 1;
+    private static final int DIALOG_ERASE_BACKUP = 2;
+    private int     mDialogType;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        addPreferencesFromResource(R.xml.privacy_settings);
+
+        mUseLocation = (CheckBoxPreference) getPreferenceScreen().findPreference(USE_LOCATION);
+        mBackup = (CheckBoxPreference) getPreferenceScreen().findPreference(BACKUP_SETTINGS);
+
+        // Vendor specific
+        try {
+            if (mUseLocation != null) {
+                getPackageManager().getPackageInfo(GSETTINGS_PROVIDER, 0);
+            }
+        } catch (NameNotFoundException nnfe) {
+            getPreferenceScreen().removePreference(findPreference(LOCATION_CATEGORY));
+            getPreferenceScreen().removePreference(findPreference(SETTINGS_CATEGORY));
+        }
+        updateToggles();
+
+        boolean doneUseLocation = savedInstanceState == null
+                ? false : savedInstanceState.getBoolean(KEY_DONE_USE_LOCATION, true);
+        if (!doneUseLocation && (getIntent().getBooleanExtra("SHOW_USE_LOCATION", false)
+                || savedInstanceState != null)) {
+            showUseLocationDialog(true);
+        }
+    }
+
+    @Override
+    public void onStop() {
+        if (mConfirmDialog != null && mConfirmDialog.isShowing()) {
+            mConfirmDialog.dismiss();
+        }
+        mConfirmDialog = null;
+        mDialogType = 0;
+        super.onStop();
+    }
+
+    @Override
+    public void onSaveInstanceState(Bundle icicle) {
+        if (mConfirmDialog != null && mConfirmDialog.isShowing()
+                && mDialogType == DIALOG_USE_LOCATION) {
+            icicle.putBoolean(KEY_DONE_USE_LOCATION, false);
+        }
+        super.onSaveInstanceState(icicle);
+    }
+
+    @Override
+    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
+            Preference preference) {
+        if (preference == mUseLocation) {
+            //normally called on the toggle click
+            if (mUseLocation.isChecked()) {
+                showUseLocationDialog(false);
+            } else {
+                updateUseLocation();
+            }
+        } else if (preference == mBackup) {
+            if (!mBackup.isChecked()) {
+                showEraseBackupDialog();
+            } else {
+                setBackupEnabled(true);
+            }
+        }
+
+        return false;
+    }
+
+    private void showUseLocationDialog(boolean force) {
+        // Show a warning to the user that location data will be shared
+        mOkClicked = false;
+        if (force) {
+            mUseLocation.setChecked(true);
+        }
+
+        if (hasAgreedToUseLocation()) {
+            updateUseLocation();
+            return;
+        }
+
+        mDialogType = DIALOG_USE_LOCATION;
+        CharSequence msg = getResources().getText(R.string.use_location_warning_message);
+        mConfirmDialog = new AlertDialog.Builder(this).setMessage(msg)
+                .setTitle(R.string.use_location_title)
+                .setIcon(android.R.drawable.ic_dialog_alert)
+                .setPositiveButton(R.string.agree, this)
+                .setNegativeButton(R.string.disagree, this)
+                .show();
+        ((TextView)mConfirmDialog.findViewById(android.R.id.message))
+                .setMovementMethod(LinkMovementMethod.getInstance());
+        mConfirmDialog.setOnDismissListener(this);
+    }
+
+    private void showEraseBackupDialog() {
+        // Show a warning to the user that location data will be shared
+        mOkClicked = false;
+        mBackup.setChecked(true);
+
+        mDialogType = DIALOG_ERASE_BACKUP;
+        CharSequence msg = getResources().getText(R.string.backup_erase_dialog_message);
+        mConfirmDialog = new AlertDialog.Builder(this).setMessage(msg)
+                .setTitle(R.string.backup_erase_dialog_title)
+                .setIcon(android.R.drawable.ic_dialog_alert)
+                .setPositiveButton(android.R.string.ok, this)
+                .setNegativeButton(android.R.string.cancel, this)
+                .show();
+        mConfirmDialog.setOnDismissListener(this);
+    }
+
+    /*
+     * Creates toggles for each available location provider
+     */
+    private void updateToggles() {
+        ContentResolver res = getContentResolver();
+        mUseLocation.setChecked(Settings.Secure.getInt(res,
+                Settings.Secure.USE_LOCATION_FOR_SERVICES, 2) == 1);
+        mBackup.setChecked(Settings.Secure.getInt(res,
+                Settings.Secure.BACKUP_ENABLED, 0) == 1);
+    }
+
+    private void updateUseLocation() {
+        boolean use = mUseLocation.isChecked();
+        Settings.Secure.putInt(getContentResolver(),
+                Settings.Secure.USE_LOCATION_FOR_SERVICES, use ? 1 : 0);
+    }
+
+    public void onClick(DialogInterface dialog, int which) {
+        if (which == DialogInterface.BUTTON_POSITIVE) {
+            //updateProviders();
+            mOkClicked = true;
+            if (mDialogType == DIALOG_USE_LOCATION) {
+                setAgreedToUseLocation(true);
+            } else if (mDialogType == DIALOG_ERASE_BACKUP) {
+                setBackupEnabled(false);
+            }
+        } else {
+            if (mDialogType == DIALOG_USE_LOCATION) {
+                // Reset the toggle
+                mUseLocation.setChecked(false);
+            } else if (mDialogType == DIALOG_ERASE_BACKUP) {
+                mBackup.setChecked(true);
+            }
+        }
+        updateUseLocation();
+        mDialogType = 0;
+    }
+
+    public void onDismiss(DialogInterface dialog) {
+        // Assuming that onClick gets called first
+        if (!mOkClicked) {
+            if (mDialogType == DIALOG_USE_LOCATION) {
+                mUseLocation.setChecked(false);
+            }
+        }
+    }
+
+    /**
+     * Checks if the user has agreed to the dialog in the past.
+     */
+    private boolean hasAgreedToUseLocation() {
+        SharedPreferences sp = getSharedPreferences(PREFS_NAME, 0);
+        if (sp == null) {
+            return false;
+        }
+        return sp.getBoolean(PREFS_USE_LOCATION, false);
+    }
+
+    /**
+     * Notes that the user has agreed to the dialog and won't need to be prompted in the
+     * future.
+     */
+    private void setAgreedToUseLocation(boolean agreed) {
+        if (agreed) {
+            SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
+            SharedPreferences.Editor editor = settings.edit();
+            editor.putBoolean(PREFS_USE_LOCATION, true);
+            editor.commit();
+        }
+    }
+
+    /**
+     * Informs the BackupManager of a change in backup state - if backup is disabled,
+     * the data on the server will be erased.
+     * @param enable whether to enable backup
+     */
+    private void setBackupEnabled(boolean enable) {
+        IBackupManager bm = IBackupManager.Stub.asInterface(
+                ServiceManager.getService(Context.BACKUP_SERVICE));
+        if (bm != null) {
+            try {
+                bm.setBackupEnabled(enable);
+            } catch (RemoteException e) {
+                mBackup.setChecked(!enable);
+                return;
+            }
+        }
+        mBackup.setChecked(enable);
+    }
+}
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 3d7a765..cdfd8bd 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -59,8 +59,7 @@
 /**
  * Gesture lock pattern settings.
  */
-public class SecuritySettings extends PreferenceActivity implements
-        DialogInterface.OnDismissListener, DialogInterface.OnClickListener {
+public class SecuritySettings extends PreferenceActivity {
 
     // Lock Settings
 
@@ -96,14 +95,6 @@
 
     private CstorHelper mCstorHelper = new CstorHelper();
 
-    // Vendor specific
-    private static final String GSETTINGS_PROVIDER = "com.google.android.providers.settings";
-    private static final String USE_LOCATION = "use_location";
-    private static final String KEY_DONE_USE_LOCATION = "doneLocation";
-    private CheckBoxPreference mUseLocation;
-    private boolean mOkClicked;
-    private Dialog mUseLocationDialog;
-
     private CheckBoxPreference mNetwork;
     private CheckBoxPreference mGps;
     private CheckBoxPreference mAssistedGps;
@@ -130,17 +121,7 @@
         mNetwork = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_NETWORK);
         mGps = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_GPS);
         mAssistedGps = (CheckBoxPreference) getPreferenceScreen().findPreference(ASSISTED_GPS);
-        mUseLocation = (CheckBoxPreference) getPreferenceScreen().findPreference(USE_LOCATION);
 
-        // Vendor specific
-        try {
-            if (mUseLocation != null
-                    && getPackageManager().getPackageInfo(GSETTINGS_PROVIDER, 0) == null) {
-                ((PreferenceGroup)findPreference(LOCATION_CATEGORY))
-                        .removePreference(mUseLocation);
-            }
-        } catch (NameNotFoundException nnfe) {
-        }
         updateToggles();
 
         // listen for Location Manager settings changes
@@ -150,12 +131,6 @@
                 null);
         mContentQueryMap = new ContentQueryMap(settingsCursor, Settings.System.NAME, true, null);
         mContentQueryMap.addObserver(new SettingsObserver());
-        boolean doneUseLocation = savedInstanceState == null
-                ? false : savedInstanceState.getBoolean(KEY_DONE_USE_LOCATION, true);
-        if (!doneUseLocation && (getIntent().getBooleanExtra("SHOW_USE_LOCATION", false)
-                || savedInstanceState != null)) {
-            showUseLocationDialog(true);
-        }
 
         mCstorHelper.handleIntent(getIntent());
     }
@@ -169,6 +144,14 @@
         inlinePrefCat.setTitle(R.string.lock_settings_title);
         root.addPreference(inlinePrefCat);
 
+        // change pattern lock
+        Intent intent = new Intent();
+        intent.setClassName("com.android.settings",
+                    "com.android.settings.ChooseLockPatternTutorial");
+        mChoosePattern = getPreferenceManager().createPreferenceScreen(this);
+        mChoosePattern.setIntent(intent);
+        inlinePrefCat.addPreference(mChoosePattern);
+
         // autolock toggle
         mLockEnabled = new LockEnabledPref(this);
         mLockEnabled.setTitle(R.string.lockpattern_settings_enable_title);
@@ -188,14 +171,6 @@
         mTactileFeedback.setTitle(R.string.lockpattern_settings_enable_tactile_feedback_title);
         inlinePrefCat.addPreference(mTactileFeedback);
 
-        // change pattern lock
-        Intent intent = new Intent();
-        intent.setClassName("com.android.settings",
-                    "com.android.settings.ChooseLockPatternTutorial");
-        mChoosePattern = getPreferenceManager().createPreferenceScreen(this);
-        mChoosePattern.setIntent(intent);
-        inlinePrefCat.addPreference(mChoosePattern);
-
         int activePhoneType = TelephonyManager.getDefault().getPhoneType();
 
         // do not display SIM lock for CDMA phone
@@ -259,23 +234,6 @@
     }
 
     @Override
-    public void onStop() {
-        if (mUseLocationDialog != null && mUseLocationDialog.isShowing()) {
-            mUseLocationDialog.dismiss();
-        }
-        mUseLocationDialog = null;
-        super.onStop();
-    }
-
-    @Override
-    public void onSaveInstanceState(Bundle icicle) {
-        if (mUseLocationDialog != null && mUseLocationDialog.isShowing()) {
-            icicle.putBoolean(KEY_DONE_USE_LOCATION, false);
-        }
-        super.onSaveInstanceState(icicle);
-    }
-
-    @Override
     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
             Preference preference) {
         final String key = preference.getKey();
@@ -302,13 +260,6 @@
         } else if (preference == mAssistedGps) {
             Settings.Secure.putInt(getContentResolver(), Settings.Secure.ASSISTED_GPS_ENABLED,
                     mAssistedGps.isChecked() ? 1 : 0);
-        } else if (preference == mUseLocation) {
-            //normally called on the toggle click
-            if (mUseLocation.isChecked()) {
-                showUseLocationDialog(false);
-            } else {
-                updateUseLocation();
-            }
         }
 
         return false;
@@ -319,27 +270,6 @@
         startActivity(intent);
     }
 
-    private void showUseLocationDialog(boolean force) {
-        // Show a warning to the user that location data will be shared
-        mOkClicked = false;
-        if (force) {
-            mUseLocation.setChecked(true);
-        }
-
-        if (hasAgreedToUseLocation()) return;
-
-        CharSequence msg = getResources().getText(R.string.use_location_warning_message);
-        mUseLocationDialog = new AlertDialog.Builder(this).setMessage(msg)
-                .setTitle(R.string.use_location_title)
-                .setIcon(android.R.drawable.ic_dialog_alert)
-                .setPositiveButton(R.string.agree, this)
-                .setNegativeButton(R.string.disagree, this)
-                .show();
-        ((TextView)mUseLocationDialog.findViewById(android.R.id.message))
-                .setMovementMethod(LinkMovementMethod.getInstance());
-        mUseLocationDialog.setOnDismissListener(this);
-    }
-
     /*
      * Creates toggles for each available location provider
      */
@@ -355,20 +285,12 @@
                     Settings.Secure.ASSISTED_GPS_ENABLED, 2) == 1);
             mAssistedGps.setEnabled(gpsEnabled);
         }
-        mUseLocation.setChecked(Settings.Secure.getInt(res,
-                Settings.Secure.USE_LOCATION_FOR_SERVICES, 2) == 1);
     }
 
     private boolean isToggled(Preference pref) {
         return ((CheckBoxPreference) pref).isChecked();
     }
 
-    private void updateUseLocation() {
-        boolean use = mUseLocation.isChecked();
-        Settings.Secure.putInt(getContentResolver(),
-                Settings.Secure.USE_LOCATION_FOR_SERVICES, use ? 1 : 0);
-    }
-
     /**
      * For the user to disable keyguard, we first make them verify their
      * existing pattern.
@@ -415,25 +337,6 @@
         }
     }
 
-    public void onClick(DialogInterface dialog, int which) {
-        if (which == DialogInterface.BUTTON_POSITIVE) {
-            //updateProviders();
-            mOkClicked = true;
-            setAgreedToUseLocation(true);
-        } else {
-            // Reset the toggle
-            mUseLocation.setChecked(false);
-        }
-        updateUseLocation();
-    }
-
-    public void onDismiss(DialogInterface dialog) {
-        // Assuming that onClick gets called first
-        if (!mOkClicked) {
-            mUseLocation.setChecked(false);
-        }
-    }
-
     @Override
     protected Dialog onCreateDialog(int id) {
         switch (id) {
@@ -452,23 +355,6 @@
         }
     }
 
-    private boolean hasAgreedToUseLocation() {
-        SharedPreferences sp = getSharedPreferences(PREFS_NAME, 0);
-        if (sp == null) {
-            return false;
-        }
-        return sp.getBoolean(PREFS_USE_LOCATION, false);
-    }
-
-    private void setAgreedToUseLocation(boolean agreed) {
-        if (agreed) {
-            SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
-            SharedPreferences.Editor editor = settings.edit();
-            editor.putBoolean(PREFS_USE_LOCATION, true);
-            editor.commit();
-        }
-    }
-
     private class CstorHelper implements DialogInterface.OnClickListener,
             DialogInterface.OnDismissListener {
         private KeyStore mKeyStore = KeyStore.getInstance();
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index 9999e1c..1203a42 100644
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -16,16 +16,12 @@
 
 package com.android.settings.bluetooth;
 
-import com.android.settings.ProgressCategory;
-import com.android.settings.R;
-import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile;
-
-import java.util.List;
-import java.util.WeakHashMap;
-
 import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothClass;
 import android.bluetooth.BluetoothDevice;
 import android.bluetooth.BluetoothDevicePicker;
+import android.bluetooth.BluetoothUuid;
+import android.bluetooth.ParcelUuid;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
@@ -41,7 +37,13 @@
 import android.view.View;
 import android.view.ContextMenu.ContextMenuInfo;
 import android.widget.AdapterView.AdapterContextMenuInfo;
-import android.util.Log;
+
+import com.android.settings.ProgressCategory;
+import com.android.settings.R;
+import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile;
+
+import java.util.List;
+import java.util.WeakHashMap;
 
 /**
  * BluetoothSettings is the Settings screen for Bluetooth configuration and
@@ -304,20 +306,43 @@
             throw new IllegalStateException("Got onDeviceAdded, but cachedDevice already exists");
         }
 
-        List<Profile> profiles = cachedDevice.getProfiles();
-        if (mFilterType == BluetoothDevicePicker.FILTER_TYPE_TRANSFER){
-            if(profiles.contains(Profile.OPP)){
-                createDevicePreference(cachedDevice);
-            }
-        } else if (mFilterType == BluetoothDevicePicker.FILTER_TYPE_AUDIO) {
-            if((profiles.contains(Profile.A2DP)) || (profiles.contains(Profile.HEADSET))){
-                createDevicePreference(cachedDevice);
-            }
-        } else {
+        if (addDevicePreference(cachedDevice)) {
             createDevicePreference(cachedDevice);
         }
      }
 
+    private boolean addDevicePreference(CachedBluetoothDevice cachedDevice) {
+        ParcelUuid[] uuids = cachedDevice.getDevice().getUuids();
+        BluetoothClass bluetoothClass = cachedDevice.getDevice().getBluetoothClass();
+
+        switch(mFilterType) {
+        case BluetoothDevicePicker.FILTER_TYPE_TRANSFER:
+            if (uuids != null) {
+                if (BluetoothUuid.containsAnyUuid(uuids,
+                        LocalBluetoothProfileManager.OPP_PROFILE_UUIDS))  return true;
+            } else {
+                if (bluetoothClass.doesClassMatch(BluetoothClass.PROFILE_OPP)) return true;
+            }
+            break;
+        case BluetoothDevicePicker.FILTER_TYPE_AUDIO:
+            if (uuids != null) {
+                if (BluetoothUuid.containsAnyUuid(uuids,
+                        LocalBluetoothProfileManager.A2DP_PROFILE_UUIDS))  return true;
+
+                if (BluetoothUuid.containsAnyUuid(uuids,
+                        LocalBluetoothProfileManager.HEADSET_PROFILE_UUIDS))  return true;
+            } else {
+                if (bluetoothClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) return true;
+
+                if (bluetoothClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET)) return true;
+            }
+            break;
+        default:
+            return true;
+        }
+        return false;
+    }
+
     private void createDevicePreference(CachedBluetoothDevice cachedDevice) {
         BluetoothDevicePreference preference = new BluetoothDevicePreference(this, cachedDevice);
         mDeviceList.addPreference(preference);
diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
index e70f85f..0582aa1 100644
--- a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
+++ b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
@@ -610,13 +610,22 @@
             return R.drawable.ic_bt_cellphone;
         }
 
-        if (mProfiles.contains(Profile.A2DP)) {
-            return R.drawable.ic_bt_headphones_a2dp;
-        } else if (mProfiles.contains(Profile.HEADSET)) {
-            return R.drawable.ic_bt_headset_hfp;
+        if (mProfiles.size() > 0) {
+            if (mProfiles.contains(Profile.A2DP)) {
+                return R.drawable.ic_bt_headphones_a2dp;
+            } else if (mProfiles.contains(Profile.HEADSET)) {
+                return R.drawable.ic_bt_headset_hfp;
+            }
         } else {
-            return 0;
+            if (mBtClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) {
+                return R.drawable.ic_bt_headphones_a2dp;
+
+            }
+            if (mBtClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET)) {
+                return R.drawable.ic_bt_headset_hfp;
+            }
         }
+        return 0;
     }
 
     /**
diff --git a/src/com/android/settings/bluetooth/LocalBluetoothManager.java b/src/com/android/settings/bluetooth/LocalBluetoothManager.java
index 775b120..e7be43d 100644
--- a/src/com/android/settings/bluetooth/LocalBluetoothManager.java
+++ b/src/com/android/settings/bluetooth/LocalBluetoothManager.java
@@ -79,6 +79,8 @@
                 return null;
             }
 
+            LocalBluetoothProfileManager.init(INSTANCE);
+
             return INSTANCE;
         }
     }
diff --git a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java
index 2ea1fe7..f3dea85 100644
--- a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java
+++ b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java
@@ -22,6 +22,7 @@
 import android.bluetooth.BluetoothUuid;
 import android.bluetooth.ParcelUuid;
 import android.os.Handler;
+import android.util.Log;
 
 import com.android.settings.R;
 
@@ -37,17 +38,17 @@
 public abstract class LocalBluetoothProfileManager {
     private static final String TAG = "LocalBluetoothProfileManager";
 
-    private static final ParcelUuid[] HEADSET_PROFILE_UUIDS = new ParcelUuid[] {
+    /* package */ static final ParcelUuid[] HEADSET_PROFILE_UUIDS = new ParcelUuid[] {
         BluetoothUuid.HSP,
         BluetoothUuid.Handsfree,
     };
 
-    private static final ParcelUuid[] A2DP_PROFILE_UUIDS = new ParcelUuid[] {
+    /* package */ static final ParcelUuid[] A2DP_PROFILE_UUIDS = new ParcelUuid[] {
         BluetoothUuid.AudioSink,
         BluetoothUuid.AdvAudioDist,
     };
 
-    private static final ParcelUuid[] OPP_PROFILE_UUIDS = new ParcelUuid[] {
+    /* package */ static final ParcelUuid[] OPP_PROFILE_UUIDS = new ParcelUuid[] {
         BluetoothUuid.ObexObjectPush
     };
 
@@ -57,34 +58,35 @@
 
     protected LocalBluetoothManager mLocalManager;
 
-    public static LocalBluetoothProfileManager getProfileManager(LocalBluetoothManager localManager,
-            Profile profile) {
-
-        LocalBluetoothProfileManager profileManager;
-
+    public static void init(LocalBluetoothManager localManager) {
         synchronized (sProfileMap) {
-            profileManager = sProfileMap.get(profile);
+            if (sProfileMap.size() == 0) {
+                LocalBluetoothProfileManager profileManager;
 
-            if (profileManager == null) {
-                switch (profile) {
-                case A2DP:
-                    profileManager = new A2dpProfileManager(localManager);
-                    break;
+                profileManager = new A2dpProfileManager(localManager);
+                sProfileMap.put(Profile.A2DP, profileManager);
 
-                case HEADSET:
-                    profileManager = new HeadsetProfileManager(localManager);
-                    break;
+                profileManager = new HeadsetProfileManager(localManager);
+                sProfileMap.put(Profile.HEADSET, profileManager);
 
-                case OPP:
-                    profileManager = new OppProfileManager(localManager);
-                    break;
-                }
-
-                sProfileMap.put(profile, profileManager);
+                profileManager = new OppProfileManager(localManager);
+                sProfileMap.put(Profile.OPP, profileManager);
             }
         }
+    }
 
-        return profileManager;
+    public static LocalBluetoothProfileManager getProfileManager(LocalBluetoothManager localManager,
+            Profile profile) {
+        // Note: This code assumes that "localManager" is same as the
+        // LocalBluetoothManager that was used to initialize the sProfileMap.
+        // If that every changes, we can't just keep one copy of sProfileMap.
+        synchronized (sProfileMap) {
+            LocalBluetoothProfileManager profileManager = sProfileMap.get(profile);
+            if (profileManager == null) {
+                Log.e(TAG, "profileManager can't be found for " + profile.toString());
+            }
+            return profileManager;
+        }
     }
 
     /**