am 5b01c0b3: Merge "Fix bug #15433763 "Sounds & Notifications" appears twice in the shortcut icon picker" into lmp-preview-dev

* commit '5b01c0b3ebf18a22b8ecbe0e09ff39807e574040':
  Fix bug #15433763 "Sounds & Notifications" appears twice in the shortcut icon picker
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index f16ba34..cda4f1a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -169,6 +169,7 @@
         </activity>
 
         <activity android:name=".wifi.WifiSetupActivity"
+                android:taskAffinity="com.android.wizard"
                 android:theme="@style/SetupWizardWifiTheme"
                 android:label="@string/wifi_setup_wizard_title"
                 android:icon="@drawable/empty_icon"
@@ -1512,7 +1513,8 @@
                   android:excludeFromRecents="true"
                   android:theme="@android:style/Theme.Quantum.Light.NoActionBar"
                   android:configChanges="keyboard|keyboardHidden|uiMode"
-                  android:windowSoftInputMode="adjustResize">
+                  android:windowSoftInputMode="adjustResize"
+                  android:screenOrientation="nosensor">
             <intent-filter android:priority="10">
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.HOME" />
diff --git a/res/layout/account_type_preference.xml b/res/layout/account_type_preference.xml
new file mode 100644
index 0000000..f7ba859
--- /dev/null
+++ b/res/layout/account_type_preference.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/accountTypeIcon"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"
+        android:contentDescription="@null" />
diff --git a/res/layout/trust_agent_settings.xml b/res/layout/advanced_security_settings.xml
similarity index 100%
rename from res/layout/trust_agent_settings.xml
rename to res/layout/advanced_security_settings.xml
diff --git a/res/layout/setup_preference.xml b/res/layout/setup_preference.xml
index d0cbc02..dc6130d 100644
--- a/res/layout/setup_preference.xml
+++ b/res/layout/setup_preference.xml
@@ -18,7 +18,7 @@
 -->
 <view
     xmlns:android="http://schemas.android.com/apk/res/android"
-    class="com.android.settings.wifi.WifiSettings$ProportionalOuterFrame"
+    class="com.android.settings.widget.ProportionalOuterFrame"
     android:layout_height="match_parent"
     android:layout_width="match_parent">
 
diff --git a/res/layout/wifi_dialog.xml b/res/layout/wifi_dialog.xml
index 7275c73..d0ae981 100644
--- a/res/layout/wifi_dialog.xml
+++ b/res/layout/wifi_dialog.xml
@@ -197,11 +197,6 @@
                         android:prompt="@string/proxy_settings_title"
                         android:entries="@array/wifi_proxy_settings" />
 
-                <TextView android:id="@+id/proxy_pac_info"
-                        style="@style/wifi_item_content"
-                        android:textStyle="bold"
-                        android:textAlignment="viewStart"
-                        android:visibility="gone"/>
             </LinearLayout>
 
             <LinearLayout android:id="@+id/proxy_warning_limited_support"
@@ -216,6 +211,21 @@
                         android:text="@string/proxy_warning_limited_support" />
             </LinearLayout>
 
+            <LinearLayout android:id="@+id/proxy_pac_field"
+                    style="@style/wifi_section"
+                    android:visibility="gone">
+                <LinearLayout style="@style/wifi_item">
+                    <TextView
+                            style="@style/wifi_item_label"
+                            android:text="@string/proxy_url_title" />
+
+                    <EditText android:id="@+id/proxy_pac"
+                            style="@style/wifi_item_content"
+                            android:hint="@string/proxy_url_hint"
+                            android:inputType="textNoSuggestions"
+                            android:singleLine="true"/>
+                </LinearLayout>
+            </LinearLayout>
             <LinearLayout android:id="@+id/proxy_fields"
                     style="@style/wifi_section"
                     android:visibility="gone">
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 508e799..3695d3a 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -469,6 +469,8 @@
         <item>None</item>
         <!-- Manual HTTP proxy settings are used for the current wifi network [CHAR LIMIT=25] -->
         <item>Manual</item>
+        <!-- Proxy Auto-Config URL that is used for the current wifi network [CHAR LIMIT=25] -->
+        <item>Proxy Auto-Config</item>
     </string-array>
 
     <!-- Locales in this list are displayed with the corresponding
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3f4b706..4fc861a 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -445,8 +445,10 @@
     <!-- HTTP proxy settings. Warning message about limited application support [CHAR LIMIT=100]-->
     <string name="proxy_warning_limited_support">The HTTP proxy is used by the browser but may not be used by the other apps.</string>
 
-    <!-- HTTP proxy settings. Title for Proxy-Auto Config URL.  [CHAR LIMIT=NONE]-->
-    <string name="proxy_url">"PAC URL: "</string>
+    <!-- HTTP proxy settings. Title for Proxy-Auto Config URL.  [CHAR LIMIT=25] -->
+    <string name="proxy_url_title">"PAC URL: "</string>
+    <!-- HTTP proxy settings. Hint for Proxy-Auto Config URL. -->
+    <string name="proxy_url_hint" translatable="false">https://www.example.com/proxy.pac</string>
 
     <!-- Radio Info screen. Label for a status item.  Used for diagnostic info screens, precise translation isn't needed -->
     <string name="radio_info_signal_location_label">Location:</string>
@@ -716,6 +718,8 @@
     <string name="profile_info_settings_title">Profile info</string>
     <!-- Main Settings screen setting option title for the item to take you to the location screen -->
     <string name="location_settings_title">Location</string>
+    <!-- Main Settings screen setting option title for the item to take you to the accounts screen [CHAR LIMIT=22] -->
+    <string name="account_settings_title">Accounts</string>
     <!-- Main Settings screen setting option title for the item to take you to the security screen -->
     <string name="security_settings_title">Security</string>
     <!-- Main Settings screen setting option summary text for the item tot ake you to the security and location screen -->
@@ -1802,6 +1806,10 @@
 
     <!-- Account settings header. [CHAR LIMIT=30] -->
     <string name="account_settings">Accounts</string>
+    <!-- Header for items under the personal user [CHAR LIMIT=30] -->
+    <string name="category_personal">Personal</string>
+    <!-- Header for items under the work user [CHAR LIMIT=30] -->
+    <string name="category_work">Work</string>
 
     <!-- Main Settings screen, setting option name to go into search settings -->
     <string name="search_settings">Search</string>
@@ -3151,10 +3159,12 @@
 
     <!-- Setting Checkbox title whether to show options for wireless display certification -->
     <string name="wifi_display_certification">Wireless display certification</string>
-    <!-- Setting Checkbox title whether to show options for WiFi Verbose Logging -->
+    <!-- Setting Checkbox title whether to enable WiFi Verbose Logging. [CHAR LIMIT=40] -->
     <string name="wifi_verbose_logging">Enable WiFi Verbose Logging</string>
     <!-- setting Checkbox summary whether to show options for wireless display certification  -->
     <string name="wifi_display_certification_summary">Show options for wireless display certification</string>
+    <!-- Setting Checkbox title whether to enable Wifi verbose Logging [CHAR LIMIT=80] -->
+    <string name="wifi_verbose_logging_summary">Increase Wifi logging level, show per SSID RSSI in WiFi Picker</string>
     <!-- Setting Checkbox title whether to allow mock locations -->
     <string name="allow_mock_location">Allow mock locations</string>
     <!-- setting Checkbox summary whether to allow mock locations  -->
@@ -3985,6 +3995,8 @@
     <string name="trusted_credentials">Trusted credentials</string>
     <!-- Summary of preference to display trusted credentials (aka CA certificates) [CHAR LIMIT=NONE] -->
     <string name="trusted_credentials_summary">Display trusted CA certificates</string>
+    <!-- Title of preference group for advance security settings [CHAR LIMIT=30] -->
+    <string name="advanced_security_title">Advanced</string>
     <!-- Title of preference of what type of credential storage this device has: hardware or software [CHAR LIMIT=30] -->
     <string name="credential_storage_type">Storage type</string>
     <!-- Summary text for preference showing what type of credential storage this device has when it is stored in a hardware-backed storage (as opposed to "software only") [CHAR LIMIT=NONE] -->
@@ -4217,6 +4229,8 @@
     <string name="accessibility_sync_enabled">Sync enabled</string>
     <!-- Content description of the disabled sync icon for accessibility. [CHAR LIMIT=NONE] -->
     <string name="accessibility_sync_disabled">Sync disabled</string>
+    <!-- Content description of the in progress sync icon for accessibility. [CHAR LIMIT=NONE] -->
+    <string name="accessibility_sync_in_progress">Syncing now</string>
     <!-- Content description of the disabled sync icon for accessibility. [CHAR LIMIT=NONE] -->
     <string name="accessibility_sync_error">Sync error.</string>
     <!-- Image description for the sync failed icon. -->
diff --git a/res/xml/account_settings.xml b/res/xml/account_settings.xml
new file mode 100644
index 0000000..236a26d
--- /dev/null
+++ b/res/xml/account_settings.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+        android:key="account"
+        android:title="@string/account_settings_title">
+
+        <Preference
+            android:key="add_account"
+            android:title="@string/add_account_label"
+            android:icon="@drawable/ic_menu_add_dark"
+            android:order="2147483648" />
+
+        <PreferenceCategory
+            android:key="account_personal"
+            android:title="@string/category_personal" >
+
+                <Preference
+                    android:key="add_account_personal"
+                    android:title="@string/add_account_label"
+                    android:icon="@drawable/ic_menu_add_dark"
+                    android:order="2147483648" />
+
+        </PreferenceCategory>
+
+        <PreferenceCategory
+            android:key="account_work"
+            android:title="@string/category_work" >
+
+                <Preference
+                    android:key="add_account_work"
+                    android:title="@string/add_account_label"
+                    android:icon="@drawable/ic_menu_add_dark"
+                    android:order="2147483648" />
+
+        </PreferenceCategory>
+
+</PreferenceScreen>
diff --git a/res/xml/dashboard_categories.xml b/res/xml/dashboard_categories.xml
index 44ec960..ab669d1 100644
--- a/res/xml/dashboard_categories.xml
+++ b/res/xml/dashboard_categories.xml
@@ -162,6 +162,15 @@
                 android:icon="@drawable/ic_settings_security"
                 />
 
+        <!-- Account -->
+        <!-- TODO: add accounts icon -->
+        <dashboard-tile
+                android:id="@+id/account_settings"
+                android:title="@string/account_settings_title"
+                android:fragment="com.android.settings.accounts.AccountSettings"
+                android:icon="@null"
+                />
+
         <!-- Language -->
         <dashboard-tile
                 android:id="@+id/language_settings"
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index 1d7d967..d435371 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -109,6 +109,7 @@
         <CheckBoxPreference
             android:key="wifi_verbose_logging"
             android:title="@string/wifi_verbose_logging" />
+            android:summary="@string/wifi_verbose_logging_summary"/>
 
     </PreferenceCategory>
 
diff --git a/res/xml/security_settings_misc.xml b/res/xml/security_settings_misc.xml
index 84ce96c..c8f3e02 100644
--- a/res/xml/security_settings_misc.xml
+++ b/res/xml/security_settings_misc.xml
@@ -47,12 +47,6 @@
                 android:persistent="false"
                 android:fragment="com.android.settings.DeviceAdminSettings"/>
 
-        <Preference android:key="manage_trust_agents"
-                    android:title="@string/manage_trust_agents"
-                    android:summary="@string/manage_trust_agents_summary"
-                    android:persistent="false"
-                    android:fragment="com.android.settings.TrustAgentSettings"/>
-
         <CheckBoxPreference android:key="toggle_install_applications"
                 android:title="@string/install_applications"
                 android:summaryOff="@string/install_unknown_applications"
@@ -64,7 +58,6 @@
                 android:summaryOff="@string/verify_applications_summary"
                 android:summaryOn="@string/verify_applications_summary"
                 android:persistent="false" />
-
     </PreferenceCategory>
 
     <PreferenceCategory android:key="credentials_management"
@@ -99,4 +92,14 @@
                     android:targetClass="com.android.settings.CredentialStorage"/>
         </Preference>
     </PreferenceCategory>
+
+    <PreferenceCategory android:key="advanced_security"
+            android:title="@string/advanced_security_title"
+            android:persistent="false">
+        <Preference android:key="manage_trust_agents"
+                android:title="@string/manage_trust_agents"
+                android:summary="@string/manage_trust_agents_summary"
+                android:persistent="false"
+                android:fragment="com.android.settings.AdvancedSecuritySettings"/>
+    </PreferenceCategory>
 </PreferenceScreen>
diff --git a/src/com/android/settings/AccountPreference.java b/src/com/android/settings/AccountPreference.java
index 2cc013c..7547721 100644
--- a/src/com/android/settings/AccountPreference.java
+++ b/src/com/android/settings/AccountPreference.java
@@ -140,6 +140,8 @@
                 return getContext().getString(R.string.accessibility_sync_disabled);
             case SYNC_ERROR:
                 return getContext().getString(R.string.accessibility_sync_error);
+            case SYNC_IN_PROGRESS:
+                return getContext().getString(R.string.accessibility_sync_in_progress);
             default:
                 Log.e(TAG, "Unknown sync status: " + status);
                 return getContext().getString(R.string.accessibility_sync_error);
diff --git a/src/com/android/settings/TrustAgentSettings.java b/src/com/android/settings/AdvancedSecuritySettings.java
similarity index 66%
rename from src/com/android/settings/TrustAgentSettings.java
rename to src/com/android/settings/AdvancedSecuritySettings.java
index 79cccae..2a8c623 100644
--- a/src/com/android/settings/TrustAgentSettings.java
+++ b/src/com/android/settings/AdvancedSecuritySettings.java
@@ -18,28 +18,17 @@
 
 import com.android.internal.widget.LockPatternUtils;
 
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
-import android.Manifest;
 import android.app.ListFragment;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
-import android.content.res.Resources;
-import android.content.res.TypedArray;
-import android.content.res.XmlResourceParser;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.service.trust.TrustAgentService;
 import android.util.ArrayMap;
 import android.util.ArraySet;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.util.Slog;
-import android.util.Xml;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -48,17 +37,12 @@
 import android.widget.ImageView;
 import android.widget.TextView;
 
-import java.io.IOException;
 import java.util.List;
 
-public class TrustAgentSettings extends ListFragment implements View.OnClickListener {
-    static final String TAG = "TrustAgentSettings";
+public class AdvancedSecuritySettings extends ListFragment implements View.OnClickListener {
+    static final String TAG = "AdvancedSecuritySettings";
 
     private static final String SERVICE_INTERFACE = TrustAgentService.SERVICE_INTERFACE;
-    private static final String TRUST_AGENT_META_DATA = TrustAgentService.TRUST_AGENT_META_DATA;
-
-    private static final String PERMISSION_PROVIDE_AGENT = Manifest.permission.PROVIDE_TRUST_AGENT;
-
 
     private final ArraySet<ComponentName> mActiveAgents = new ArraySet<ComponentName>();
     private final ArrayMap<ComponentName, AgentInfo> mAvailableAgents
@@ -98,7 +82,7 @@
                     container.getContext().getApplicationContext());
         }
         setListAdapter(new AgentListAdapter());
-        return inflater.inflate(R.layout.trust_agent_settings, container, false);
+        return inflater.inflate(R.layout.advanced_security_settings, container, false);
     }
 
     @Override
@@ -125,79 +109,22 @@
 
         for (ResolveInfo resolveInfo : resolveInfos) {
             if (resolveInfo.serviceInfo == null) continue;
-
-            String packageName = resolveInfo.serviceInfo.packageName;
-            if (pm.checkPermission(PERMISSION_PROVIDE_AGENT, packageName)
-                    != PackageManager.PERMISSION_GRANTED) {
-                Log.w(TAG, "Skipping agent because package " + packageName
-                        + " does not have permission " + PERMISSION_PROVIDE_AGENT + ".");
-                continue;
-            }
-
-            ComponentName name = getComponentName(resolveInfo);
+            if (!TrustAgentUtils.checkProvidePermission(resolveInfo, pm)) continue;
+            ComponentName name = TrustAgentUtils.getComponentName(resolveInfo);
             if (!mAvailableAgents.containsKey(name)) {
                 AgentInfo agentInfo = new AgentInfo();
                 agentInfo.label = resolveInfo.loadLabel(pm);
                 agentInfo.icon = resolveInfo.loadIcon(pm);
                 agentInfo.component = name;
-                agentInfo.settings = getSettingsComponentName(pm, resolveInfo);
+                TrustAgentUtils.TrustAgentComponentInfo trustAgentComponentInfo =
+                        TrustAgentUtils.getSettingsComponent(pm, resolveInfo);
+                agentInfo.settings = trustAgentComponentInfo.componentName;
                 mAvailableAgents.put(name, agentInfo);
             }
         }
         ((BaseAdapter) getListAdapter()).notifyDataSetChanged();
     }
 
-    private ComponentName getComponentName(ResolveInfo resolveInfo) {
-        if (resolveInfo == null || resolveInfo.serviceInfo == null) return null;
-        return new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name);
-    }
-
-    private ComponentName getSettingsComponentName(PackageManager pm, ResolveInfo resolveInfo) {
-        if (resolveInfo == null || resolveInfo.serviceInfo == null
-                || resolveInfo.serviceInfo.metaData == null) return null;
-        String cn = null;
-        XmlResourceParser parser = null;
-        Exception caughtException = null;
-        try {
-            parser = resolveInfo.serviceInfo.loadXmlMetaData(pm, TRUST_AGENT_META_DATA);
-            if (parser == null) {
-                Slog.w(TAG, "Can't find " + TRUST_AGENT_META_DATA + " meta-data");
-                return null;
-            }
-            Resources res = pm.getResourcesForApplication(resolveInfo.serviceInfo.applicationInfo);
-            AttributeSet attrs = Xml.asAttributeSet(parser);
-            int type;
-            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                    && type != XmlPullParser.START_TAG) {
-            }
-            String nodeName = parser.getName();
-            if (!"trust-agent".equals(nodeName)) {
-                Slog.w(TAG, "Meta-data does not start with trust-agent tag");
-                return null;
-            }
-            TypedArray sa = res
-                    .obtainAttributes(attrs, com.android.internal.R.styleable.TrustAgent);
-            cn = sa.getString(com.android.internal.R.styleable.TrustAgent_settingsActivity);
-            sa.recycle();
-        } catch (PackageManager.NameNotFoundException e) {
-            caughtException = e;
-        } catch (IOException e) {
-            caughtException = e;
-        } catch (XmlPullParserException e) {
-            caughtException = e;
-        } finally {
-            if (parser != null) parser.close();
-        }
-        if (caughtException != null) {
-            Slog.w(TAG, "Error parsing : " + resolveInfo.serviceInfo.packageName, caughtException);
-            return null;
-        }
-        if (cn != null && cn.indexOf('/') < 0) {
-            cn = resolveInfo.serviceInfo.packageName + "/" + cn;
-        }
-        return cn == null ? null : ComponentName.unflattenFromString(cn);
-    }
-
     @Override
     public void onClick(View view) {
         ViewHolder h = (ViewHolder) view.getTag();
@@ -295,10 +222,10 @@
             h.name = (TextView)v.findViewById(R.id.name);
             h.checkbox = (CheckBox)v.findViewById(R.id.checkbox);
             h.clickable = v.findViewById(R.id.clickable);
-            h.clickable.setOnClickListener(TrustAgentSettings.this);
+            h.clickable.setOnClickListener(AdvancedSecuritySettings.this);
             h.description = (TextView)v.findViewById(R.id.description);
             h.settings = v.findViewById(R.id.settings);
-            h.settings.setOnClickListener(TrustAgentSettings.this);
+            h.settings.setOnClickListener(AdvancedSecuritySettings.this);
             v.setTag(h);
             h.settings.setTag(h);
             h.clickable.setTag(h);
diff --git a/src/com/android/settings/CryptKeeper.java b/src/com/android/settings/CryptKeeper.java
index f819755..d24c741 100644
--- a/src/com/android/settings/CryptKeeper.java
+++ b/src/com/android/settings/CryptKeeper.java
@@ -408,6 +408,7 @@
 
                     final TextView status = (TextView) findViewById(R.id.owner_info);
                     status.setText(owner_info);
+                    status.setSelected(true); // Required for marquee'ing to work
                     passwordEntryInit();
                 }
             }.execute();
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 00d1d89..b35a362 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -41,6 +41,7 @@
 import android.provider.SearchIndexableResource;
 import android.provider.Settings;
 import android.security.KeyStore;
+import android.service.trust.TrustAgentService;
 import android.telephony.TelephonyManager;
 import android.util.Log;
 
@@ -58,6 +59,8 @@
 public class SecuritySettings extends RestrictedSettingsFragment
         implements OnPreferenceChangeListener, DialogInterface.OnClickListener, Indexable {
     static final String TAG = "SecuritySettings";
+    private static final Intent TRUST_AGENT_INTENT =
+            new Intent(TrustAgentService.SERVICE_INTERFACE);
 
     // Lock Settings
     private static final String KEY_UNLOCK_SET_OR_CHANGE = "unlock_set_or_change";
@@ -74,6 +77,7 @@
     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;
+    private static final int CHANGE_TRUST_AGENT_SETTINGS = 126;
 
     // Misc Settings
     private static final String KEY_SIM_LOCK = "sim_lock";
@@ -86,6 +90,7 @@
     private static final String KEY_POWER_INSTANTLY_LOCKS = "power_button_instantly_locks";
     private static final String KEY_CREDENTIALS_MANAGER = "credentials_management";
     private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
+    private static final String KEY_TRUST_AGENT = "trust_agent";
 
     private DevicePolicyManager mDPM;
 
@@ -161,7 +166,7 @@
     /**
      * Important!
      *
-     * Dont forget to update the SecuritySearchIndexProvider if you are doing any change in the
+     * Don't forget to update the SecuritySearchIndexProvider if you are doing any change in the
      * logic or adding/removing preferences here.
      */
     private PreferenceScreen createPreferenceHierarchy() {
@@ -270,7 +275,7 @@
         }
 
         // Application install
-        PreferenceGroup deviceAdminCategory= (PreferenceGroup)
+        PreferenceGroup deviceAdminCategory = (PreferenceGroup)
                 root.findPreference(KEY_DEVICE_ADMIN_CATEGORY);
         mToggleAppInstallation = (CheckBoxPreference) findPreference(
                 KEY_TOGGLE_INSTALL_APPLICATIONS);
@@ -303,6 +308,37 @@
             protectByRestrictions(root.findPreference(KEY_CREDENTIALS_INSTALL));
         }
 
+        // Trust Agent preferences
+        PreferenceGroup securityCategory = (PreferenceGroup)
+                root.findPreference(KEY_SECURITY_CATEGORY);
+        if (securityCategory != null) {
+            PackageManager pm = getPackageManager();
+            List<ResolveInfo> resolveInfos = pm.queryIntentServices(TRUST_AGENT_INTENT,
+                    PackageManager.GET_META_DATA);
+            for (ResolveInfo resolveInfo : resolveInfos) {
+                if (resolveInfo.serviceInfo == null) continue;
+                if (!TrustAgentUtils.checkProvidePermission(resolveInfo, pm)) continue;
+                TrustAgentUtils.TrustAgentComponentInfo trustAgentComponentInfo =
+                        TrustAgentUtils.getSettingsComponent(pm, resolveInfo);
+                if (trustAgentComponentInfo.componentName == null ||
+                        trustAgentComponentInfo.title == null ||
+                        trustAgentComponentInfo.title == "") continue;
+                Preference trustAgentPreference =
+                        new Preference(securityCategory.getContext());
+                trustAgentPreference.setKey(KEY_TRUST_AGENT);
+                trustAgentPreference.setTitle(trustAgentComponentInfo.title);
+                trustAgentPreference.setSummary(trustAgentComponentInfo.summary);
+                // Create intent for this preference.
+                Intent intent = new Intent();
+                intent.setComponent(trustAgentComponentInfo.componentName);
+                intent.setAction(Intent.ACTION_MAIN);
+                trustAgentPreference.setIntent(intent);
+                // Add preference to the settings menu.
+                securityCategory.addPreference(trustAgentPreference);
+                break; // Only render the first one.
+            }
+        }
+
         return root;
     }
 
@@ -522,6 +558,13 @@
         } else if (KEY_TOGGLE_VERIFY_APPLICATIONS.equals(key)) {
             Settings.Global.putInt(getContentResolver(), Settings.Global.PACKAGE_VERIFIER_ENABLE,
                     mToggleVerifyApps.isChecked() ? 1 : 0);
+        } else if (KEY_TRUST_AGENT.equals(key)) {
+            ChooseLockSettingsHelper helper =
+                    new ChooseLockSettingsHelper(this.getActivity(), this);
+            if (!helper.launchConfirmationActivity(CHANGE_TRUST_AGENT_SETTINGS, null, null)) {
+                // If this returns false, it means no password confirmation is required.
+                startActivity(preference.getIntent());
+            }
         } else {
             // If we didn't handle it, let preferences handle it.
             return super.onPreferenceTreeClick(preferenceScreen, preference);
@@ -552,6 +595,14 @@
             // is called by grabbing the value from lockPatternUtils.  We can't set it here
             // because mBiometricWeakLiveliness could be null
             return;
+        } else if (requestCode == CHANGE_TRUST_AGENT_SETTINGS && resultCode == Activity.RESULT_OK) {
+            Preference preference = getPreferenceScreen().findPreference(KEY_TRUST_AGENT);
+            if (preference != null) {
+                Intent intent = preference.getIntent();
+                if (intent != null) {
+                    startActivity(intent);
+                }
+            }
         }
         createPreferenceHierarchy();
     }
diff --git a/src/com/android/settings/TrustAgentUtils.java b/src/com/android/settings/TrustAgentUtils.java
new file mode 100644
index 0000000..31a073c
--- /dev/null
+++ b/src/com/android/settings/TrustAgentUtils.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.settings;
+
+import android.content.ComponentName;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.content.res.XmlResourceParser;
+import android.service.trust.TrustAgentService;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.util.Slog;
+import android.util.Xml;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.IOException;
+
+public class TrustAgentUtils {
+    static final String TAG = "TrustAgentUtils";
+
+    private static final String TRUST_AGENT_META_DATA = TrustAgentService.TRUST_AGENT_META_DATA;
+    private static final String PERMISSION_PROVIDE_AGENT = android.Manifest.permission.PROVIDE_TRUST_AGENT;
+
+    /**
+     * @return true, if the service in resolveInfo has the permission to provide a trust agent.
+     */
+    public static boolean checkProvidePermission(ResolveInfo resolveInfo, PackageManager pm) {
+        String packageName = resolveInfo.serviceInfo.packageName;
+        if (pm.checkPermission(PERMISSION_PROVIDE_AGENT, packageName)
+                != PackageManager.PERMISSION_GRANTED) {
+            Log.w(TAG, "Skipping agent because package " + packageName
+                    + " does not have permission " + PERMISSION_PROVIDE_AGENT + ".");
+            return false;
+        }
+        return true;
+    }
+
+    public static class TrustAgentComponentInfo {
+        ComponentName componentName;
+        String title;
+        String summary;
+    }
+
+    public static ComponentName getComponentName(ResolveInfo resolveInfo) {
+        if (resolveInfo == null || resolveInfo.serviceInfo == null) return null;
+        return new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name);
+    }
+
+    public static TrustAgentComponentInfo getSettingsComponent(
+            PackageManager pm, ResolveInfo resolveInfo) {
+        if (resolveInfo == null || resolveInfo.serviceInfo == null
+                || resolveInfo.serviceInfo.metaData == null) return null;
+        String cn = null;
+        TrustAgentComponentInfo trustAgentComponentInfo = new TrustAgentComponentInfo();
+        XmlResourceParser parser = null;
+        Exception caughtException = null;
+        try {
+            parser = resolveInfo.serviceInfo.loadXmlMetaData(pm, TRUST_AGENT_META_DATA);
+            if (parser == null) {
+                Slog.w(TAG, "Can't find " + TRUST_AGENT_META_DATA + " meta-data");
+                return null;
+            }
+            Resources res = pm.getResourcesForApplication(resolveInfo.serviceInfo.applicationInfo);
+            AttributeSet attrs = Xml.asAttributeSet(parser);
+            int type;
+            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                    && type != XmlPullParser.START_TAG) {
+            }
+            String nodeName = parser.getName();
+            if (!"trust-agent".equals(nodeName)) {
+                Slog.w(TAG, "Meta-data does not start with trust-agent tag");
+                return null;
+            }
+            TypedArray sa =
+                    res.obtainAttributes(attrs, com.android.internal.R.styleable.TrustAgent);
+            trustAgentComponentInfo.summary =
+                    sa.getString(com.android.internal.R.styleable.TrustAgent_summary);
+            trustAgentComponentInfo.title =
+                    sa.getString(com.android.internal.R.styleable.TrustAgent_title);
+            cn = sa.getString(com.android.internal.R.styleable.TrustAgent_settingsActivity);
+            sa.recycle();
+        } catch (PackageManager.NameNotFoundException e) {
+            caughtException = e;
+        } catch (IOException e) {
+            caughtException = e;
+        } catch (XmlPullParserException e) {
+            caughtException = e;
+        } finally {
+            if (parser != null) parser.close();
+        }
+        if (caughtException != null) {
+            Slog.w(TAG, "Error parsing : " + resolveInfo.serviceInfo.packageName, caughtException);
+            return null;
+        }
+        if (cn != null && cn.indexOf('/') < 0) {
+            cn = resolveInfo.serviceInfo.packageName + "/" + cn;
+        }
+        trustAgentComponentInfo.componentName = (cn == null) ? null : ComponentName.unflattenFromString(cn);
+        return trustAgentComponentInfo;
+    }
+}
diff --git a/src/com/android/settings/accounts/AccountSettings.java b/src/com/android/settings/accounts/AccountSettings.java
new file mode 100644
index 0000000..2477877
--- /dev/null
+++ b/src/com/android/settings/accounts/AccountSettings.java
@@ -0,0 +1,249 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.accounts;
+
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.accounts.OnAccountsUpdateListener;
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.os.UserManager;
+import android.preference.Preference;
+import android.preference.Preference.OnPreferenceClickListener;
+import android.preference.PreferenceGroup;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.Utils;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * Settings screen for the account types on the device.
+ * This shows all account types available for personal and work profiles.
+ */
+public class AccountSettings extends SettingsPreferenceFragment
+        implements OnAccountsUpdateListener, OnPreferenceClickListener {
+    public static final String TAG = "AccountSettings";
+
+    private static final String KEY_ACCOUNT = "account";
+    private static final String KEY_ADD_ACCOUNT = "add_account";
+
+    private static final String KEY_CATEGORY_PERSONAL = "account_personal";
+    private static final String KEY_ADD_ACCOUNT_PERSONAL = "add_account_personal";
+    private static final String KEY_CATEGORY_WORK = "account_work";
+
+    private AuthenticatorHelper mAuthenticatorHelper;
+    private boolean mListeningToAccountUpdates;
+
+    private PreferenceGroup mAccountTypesForUser;
+    private Preference mAddAccountForUser;
+
+    private UserManager mUm;
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        mUm = (UserManager) getSystemService(Context.USER_SERVICE);
+
+        mAuthenticatorHelper = new AuthenticatorHelper();
+        mAuthenticatorHelper.updateAuthDescriptions(getActivity());
+        mAuthenticatorHelper.onAccountsUpdated(getActivity(), null);
+
+        // Load the preferences from an XML resource
+        addPreferencesFromResource(R.xml.account_settings);
+
+        if(mUm.isLinkedUser()) {
+            // Restricted user or similar
+            // TODO: Do we disallow modifying accounts for restricted profiles?
+            mAccountTypesForUser = (PreferenceGroup) findPreference(KEY_ACCOUNT);
+            if (mUm.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) {
+                removePreference(KEY_ADD_ACCOUNT);
+            } else {
+                mAddAccountForUser = findPreference(KEY_ADD_ACCOUNT);
+                mAddAccountForUser.setOnPreferenceClickListener(this);
+            }
+            removePreference(KEY_CATEGORY_PERSONAL);
+            removePreference(KEY_CATEGORY_WORK);
+        } else {
+            mAccountTypesForUser = (PreferenceGroup) findPreference(KEY_CATEGORY_PERSONAL);
+            mAddAccountForUser = findPreference(KEY_ADD_ACCOUNT_PERSONAL);
+            mAddAccountForUser.setOnPreferenceClickListener(this);
+
+            // TODO: Show the work accounts also
+            // TODO: Handle the case where there is only one account
+            removePreference(KEY_CATEGORY_WORK);
+            removePreference(KEY_ADD_ACCOUNT);
+        }
+        updateAccountTypes(mAccountTypesForUser);
+    }
+
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        stopListeningToAccountUpdates();
+    }
+
+    @Override
+    public void onAccountsUpdated(Account[] accounts) {
+        // TODO: watch for package upgrades to invalidate cache; see 7206643
+        mAuthenticatorHelper.updateAuthDescriptions(getActivity());
+        mAuthenticatorHelper.onAccountsUpdated(getActivity(), accounts);
+        listenToAccountUpdates();
+        updateAccountTypes(mAccountTypesForUser);
+    }
+
+    @Override
+    public boolean onPreferenceClick(Preference preference) {
+        // Check the preference
+        if (preference == mAddAccountForUser) {
+            Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
+            startActivity(intent);
+            return true;
+        }
+        return false;
+    }
+
+    private void updateAccountTypes(PreferenceGroup preferenceGroup) {
+        preferenceGroup.removeAll();
+        preferenceGroup.setOrderingAsAdded(true);
+        for (AccountPreference preference : getAccountTypePreferences()) {
+            preferenceGroup.addPreference(preference);
+        }
+        if (mAddAccountForUser != null) {
+            preferenceGroup.addPreference(mAddAccountForUser);
+        }
+    }
+
+    private List<AccountPreference> getAccountTypePreferences() {
+        String[] accountTypes = mAuthenticatorHelper.getEnabledAccountTypes();
+        List<AccountPreference> accountTypePreferences =
+                new ArrayList<AccountPreference>(accountTypes.length);
+        for (String accountType : accountTypes) {
+            CharSequence label = mAuthenticatorHelper.getLabelForType(getActivity(), accountType);
+            if (label == null) {
+                continue;
+            }
+
+            Account[] accounts = AccountManager.get(getActivity()).getAccountsByType(accountType);
+            boolean skipToAccount = accounts.length == 1
+                    && !mAuthenticatorHelper.hasAccountPreferences(accountType);
+
+            if (skipToAccount) {
+                Bundle fragmentArguments = new Bundle();
+                fragmentArguments.putParcelable(AccountSyncSettings.ACCOUNT_KEY,
+                        accounts[0]);
+
+                accountTypePreferences.add(new AccountPreference(
+                        getActivity(),
+                        label,
+                        accountType,
+                        AccountSyncSettings.class.getName(),
+                        fragmentArguments));
+            } else {
+                Bundle fragmentArguments = new Bundle();
+                fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType);
+                fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_LABEL,
+                        label.toString());
+
+                accountTypePreferences.add(new AccountPreference(
+                        getActivity(),
+                        label,
+                        accountType,
+                        ManageAccountsSettings.class.getName(),
+                        fragmentArguments));
+            }
+            mAuthenticatorHelper.preloadDrawableForType(getActivity(), accountType);
+        }
+        // Sort by label
+        Collections.sort(accountTypePreferences, new Comparator<AccountPreference>() {
+            @Override
+            public int compare(AccountPreference t1, AccountPreference t2) {
+                return t1.mTitle.toString().compareTo(t2.mTitle.toString());
+            }
+        });
+        return accountTypePreferences;
+    }
+
+    private void listenToAccountUpdates() {
+        if (!mListeningToAccountUpdates) {
+            AccountManager.get(getActivity()).addOnAccountsUpdatedListener(this, null, true);
+            mListeningToAccountUpdates = true;
+        }
+    }
+
+    private void stopListeningToAccountUpdates() {
+        if (mListeningToAccountUpdates) {
+            AccountManager.get(getActivity()).removeOnAccountsUpdatedListener(this);
+            mListeningToAccountUpdates = false;
+        }
+    }
+
+    private class AccountPreference extends Preference implements OnPreferenceClickListener {
+        /**
+         * Title of the tile that is shown to the user.
+         * @attr ref android.R.styleable#PreferenceHeader_title
+         */
+        private final CharSequence mTitle;
+
+        /**
+         * Full class name of the fragment to display when this tile is
+         * selected.
+         * @attr ref android.R.styleable#PreferenceHeader_fragment
+         */
+        private final String mFragment;
+
+        /**
+         * Optional arguments to supply to the fragment when it is
+         * instantiated.
+         */
+        private final Bundle mFragmentArguments;
+
+
+        public AccountPreference(Context context, CharSequence title,
+                String accountType, String fragment, Bundle fragmentArguments) {
+            super(context);
+            mTitle = title;
+            mFragment = fragment;
+            mFragmentArguments = fragmentArguments;
+            setWidgetLayoutResource(R.layout.account_type_preference);
+
+            Drawable drawable = mAuthenticatorHelper.getDrawableForType(context, accountType);
+            setTitle(title);
+            setIcon(drawable);
+
+            setOnPreferenceClickListener(this);
+        }
+
+        @Override
+        public boolean onPreferenceClick(Preference preference) {
+            if (mFragment != null) {
+                Utils.startWithFragment(
+                        getContext(), mFragment, mFragmentArguments, null, 0, mTitle);
+                return true;
+            }
+            return false;
+        }
+    }
+    // TODO Implement a {@link SearchIndexProvider} to allow Indexing and Search of account types
+    // See http://b/15403806
+}
diff --git a/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java b/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java
index d81703e..638818a 100644
--- a/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java
+++ b/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java
@@ -146,7 +146,9 @@
         // should not insert, because either A. the word exists with no shortcut, in which
         // case the exact same thing we want to insert is already there, or B. the word
         // exists with at least one shortcut, in which case it has priority on our word.
-        if (hasWord(newWord, context)) return UserDictionaryAddWordActivity.CODE_ALREADY_PRESENT;
+        if (TextUtils.isEmpty(newShortcut) && hasWord(newWord, context)) {
+            return UserDictionaryAddWordActivity.CODE_ALREADY_PRESENT;
+        }
 
         // Disallow duplicates. If the same word with no shortcut is defined, remove it; if
         // the same word with the same shortcut is defined, remove it; but we don't mind if
diff --git a/src/com/android/settings/search/Index.java b/src/com/android/settings/search/Index.java
index 8ed6074..1b1825c 100644
--- a/src/com/android/settings/search/Index.java
+++ b/src/com/android/settings/search/Index.java
@@ -45,6 +45,7 @@
 
 import java.io.IOException;
 import java.lang.reflect.Field;
+import java.text.Normalizer;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
@@ -54,6 +55,7 @@
 import java.util.Map;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.regex.Pattern;
 
 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE;
 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_RANK;
@@ -150,8 +152,11 @@
 
     private static final List<String> EMPTY_LIST = Collections.<String>emptyList();
 
-
     private static Index sInstance;
+
+    private static final Pattern REMOVE_DIACRITICALS_PATTERN
+            = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
+
     private final AtomicBoolean mIsAvailable = new AtomicBoolean(false);
     private final UpdateData mDataToProcess = new UpdateData();
     private Context mContext;
@@ -920,31 +925,13 @@
             String intentAction, String intentTargetPackage, String intentTargetClass,
             boolean enabled, String key) {
 
-        String updatedTitle;
-        if (title != null) {
-            updatedTitle = title.replaceAll(NON_BREAKING_HYPHEN, HYPHEN);
-        }
-        else {
-            updatedTitle = EMPTY;
-        }
+        final String updatedTitle = normalizeHyphen(title);
+        final String updatedSummaryOn = normalizeHyphen(summaryOn);
+        final String updatedSummaryOff = normalizeHyphen(summaryOff);
 
-        String updatedSummaryOn;
-        if (summaryOn != null) {
-            updatedSummaryOn = summaryOn.replaceAll(NON_BREAKING_HYPHEN, HYPHEN);
-        } else {
-            updatedSummaryOn = EMPTY;
-        }
-
-        String updatedSummaryOff;
-        if (summaryOff != null) {
-            updatedSummaryOff = summaryOff.replaceAll(NON_BREAKING_HYPHEN, HYPHEN);
-        } else {
-            updatedSummaryOff = EMPTY;
-        }
-
-        String normalizedTitle = updatedTitle.replaceAll(HYPHEN, EMPTY);
-        String normalizedSummaryOn = updatedSummaryOn.replaceAll(HYPHEN, EMPTY);
-        String normalizedSummaryOff = updatedSummaryOff.replaceAll(HYPHEN, EMPTY);
+        final String normalizedTitle = normalizeString(updatedTitle);
+        final String normalizedSummaryOn = normalizeString(updatedSummaryOn);
+        final String normalizedSummaryOff = normalizeString(updatedSummaryOff);
 
         updateOneRow(database, locale,
                 updatedTitle, normalizedTitle, updatedSummaryOn, normalizedSummaryOn,
@@ -953,6 +940,17 @@
                 rank, keywords, intentAction, intentTargetPackage, intentTargetClass, enabled, key);
     }
 
+    private static String normalizeHyphen(String input) {
+        return (input != null) ? input.replaceAll(NON_BREAKING_HYPHEN, HYPHEN) : EMPTY;
+    }
+
+    private static String normalizeString(String input) {
+        final String nohyphen = (input != null) ? input.replaceAll(HYPHEN, EMPTY) : EMPTY;
+        final String normalized = Normalizer.normalize(nohyphen, Normalizer.Form.NFD);
+
+        return REMOVE_DIACRITICALS_PATTERN.matcher(normalized).replaceAll("").toLowerCase();
+    }
+
     private void updateOneRow(SQLiteDatabase database, String locale,
             String updatedTitle, String normalizedTitle,
             String updatedSummaryOn, String normalizedSummaryOn,
diff --git a/src/com/android/settings/tts/TextToSpeechSettings.java b/src/com/android/settings/tts/TextToSpeechSettings.java
index 1d4fe71..4a98661 100644
--- a/src/com/android/settings/tts/TextToSpeechSettings.java
+++ b/src/com/android/settings/tts/TextToSpeechSettings.java
@@ -28,6 +28,7 @@
 import android.content.ActivityNotFoundException;
 import android.content.ContentResolver;
 import android.content.Intent;
+import android.os.AsyncTask;
 import android.os.Bundle;
 import android.preference.ListPreference;
 import android.preference.Preference;
@@ -164,6 +165,9 @@
 
         setTtsUtteranceProgressListener();
         initSettings();
+
+        // Prevent restarting the TTS connection on rotation
+        setRetainInstance(true);
     }
 
     @Override
diff --git a/src/com/android/settings/widget/ProportionalOuterFrame.java b/src/com/android/settings/widget/ProportionalOuterFrame.java
new file mode 100644
index 0000000..d23d2c4
--- /dev/null
+++ b/src/com/android/settings/widget/ProportionalOuterFrame.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2011 Google Inc.
+ *
+ * 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.widget;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.RelativeLayout;
+
+import com.android.settings.R;
+
+/**
+ * Used as the outer frame of all setup wizard pages that need to adjust their margins based
+ * on the total size of the available display. (e.g. side margins set to 10% of total width.)
+ */
+public class ProportionalOuterFrame extends RelativeLayout {
+    public ProportionalOuterFrame(Context context) {
+        super(context);
+    }
+
+    public ProportionalOuterFrame(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public ProportionalOuterFrame(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+    }
+
+    /**
+     * Set our margins and title area height proportionally to the available display size
+     */
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        final int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
+        final int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
+        final Resources res = getContext().getResources();
+        final float titleHeight = res.getFraction(R.dimen.setup_title_height, 1, 1);
+        final float sideMargin = res.getFraction(R.dimen.setup_border_width, 1, 1);
+        final int bottom = res.getDimensionPixelSize(R.dimen.setup_margin_bottom);
+        setPaddingRelative((int) (parentWidth * sideMargin), 0,
+                (int) (parentWidth * sideMargin), bottom);
+        final View title = findViewById(R.id.title_area);
+        if (title != null) {
+            title.setMinimumHeight((int) (parentHeight * titleHeight));
+        }
+        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+    }
+}
diff --git a/src/com/android/settings/wifi/AccessPoint.java b/src/com/android/settings/wifi/AccessPoint.java
index 688fc63..4ac9112 100644
--- a/src/com/android/settings/wifi/AccessPoint.java
+++ b/src/com/android/settings/wifi/AccessPoint.java
@@ -28,9 +28,13 @@
 import android.os.Bundle;
 import android.preference.Preference;
 import android.util.Log;
+import android.util.LruCache;
 import android.view.View;
 import android.widget.ImageView;
 
+import java.util.Map;
+
+
 class AccessPoint extends Preference {
     static final String TAG = "Settings.AccessPoint";
 
@@ -74,6 +78,21 @@
     private WifiInfo mInfo;
     private DetailedState mState;
 
+    private static final int VISIBILITY_MAX_AGE_IN_MILLI = 1000000;
+    private static final int VISIBILITY_OUTDATED_AGE_IN_MILLI = 20000;
+    private static final int LOWER_FREQ_24GHZ = 2400;
+    private static final int HIGHER_FREQ_24GHZ = 2500;
+    private static final int LOWER_FREQ_5GHZ = 4900;
+    private static final int HIGHER_FREQ_5GHZ = 5900;
+    private static final int SECOND_TO_MILLI = 1000;
+
+    /** Experiemental: we should be able to show the user the list of BSSIDs and bands
+     *  for that SSID.
+     *  For now this data is used only with Verbose Logging so as to show the band and number
+     *  of BSSIDs on which that network is seen.
+     */
+    public LruCache<String, ScanResult> scanResultCache;
+
     static int getSecurity(WifiConfiguration config) {
         if (config.allowedKeyManagement.get(KeyMgmt.WPA_PSK)) {
             return SECURITY_PSK;
@@ -201,6 +220,9 @@
             pskType = getPskType(result);
         mRssi = result.level;
         mScanResult = result;
+        if (result.seen > mSeen) {
+            mSeen = result.seen;
+        }
     }
 
     @Override
@@ -267,6 +289,13 @@
         if (result.seen > mSeen) {
             mSeen = result.seen;
         }
+        if (WifiSettings.mVerboseLogging > 0) {
+            if (scanResultCache == null) {
+                scanResultCache = new LruCache<String, ScanResult>(32);
+            }
+            scanResultCache.put(result.BSSID, result);
+        }
+
         if (ssid.equals(result.SSID) && security == getSecurity(result)) {
             if (WifiManager.compareSignalLevel(result.level, mRssi) > 0) {
                 int oldLevel = getLevel();
@@ -340,25 +369,84 @@
 
     /** visibility status of the WifiConfiguration
      * @return RSSI and update indicator
-     * TODO: indicate both 2.4 and 5GHz RSSI as well as number of results
+     * TODO: use a string formatter
      * ["rssi 5Ghz", "num results on 5GHz" / "rssi 5Ghz", "num results on 5GHz"]
      * For instance [-40,5/-30,2]
      */
     private String getVisibilityStatus() {
-        String visibility ;
+        StringBuilder visibility = new StringBuilder();
+
         long now = System.currentTimeMillis();
         long age = (now - mSeen);
-        if (age < 1000000) {
+        if (age < VISIBILITY_MAX_AGE_IN_MILLI) {
             //show age in seconds, in the form xx
-            visibility = Long.toString((age / 1000) % 1000);
+            visibility.append(Long.toString((age / SECOND_TO_MILLI) % SECOND_TO_MILLI));
         } else {
             //not seen for more than 1000 seconds
-            visibility = "!";
+            visibility.append("!");
         }
-        if (mRssi != Integer.MAX_VALUE) {
-            visibility = visibility + ", " + Integer.toString(mRssi);
+
+        if (scanResultCache != null) {
+            int rssi5 = WifiConfiguration.INVALID_RSSI;
+            int rssi24 = WifiConfiguration.INVALID_RSSI;
+            int num5 = 0;
+            int num24 = 0;
+            Map<String, ScanResult> list = scanResultCache.snapshot();
+            for (ScanResult result : list.values()) {
+                if (result.seen == 0)
+                    continue;
+
+                if (result.frequency > LOWER_FREQ_5GHZ
+                        && result.frequency < HIGHER_FREQ_5GHZ) {
+                    //strictly speaking: [4915, 5825]
+                    //number of known BSSID on 5GHz band
+                    num5 = num5 + 1;
+                } else if (result.frequency > LOWER_FREQ_24GHZ
+                        && result.frequency < HIGHER_FREQ_24GHZ) {
+                    //strictly speaking: [2412, 2482]
+                    //number of known BSSID on 2.4Ghz band
+                    num24 = num24 + 1;
+                }
+
+                //ignore results seen, older than 20 seconds
+                if (now - result.seen > VISIBILITY_OUTDATED_AGE_IN_MILLI) continue;
+
+                if (result.frequency > LOWER_FREQ_5GHZ
+                        &&result.frequency < HIGHER_FREQ_5GHZ) {
+                    if (result.level > rssi5) {
+                        rssi5 = result.level;
+                    }
+                } else if (result.frequency > LOWER_FREQ_24GHZ
+                        && result.frequency < HIGHER_FREQ_24GHZ) {
+                    if (result.level > rssi24) {
+                        rssi24 = result.level;
+                    }
+                }
+            }
+            visibility.append(" [");
+            if (num24 > 0 || rssi24 > WifiConfiguration.INVALID_RSSI) {
+                visibility.append(Integer.toString(rssi24));
+                visibility.append(",");
+                visibility.append(Integer.toString(num24));
+            }
+            visibility.append(";");
+            if (num5 > 0 || rssi5 > WifiConfiguration.INVALID_RSSI) {
+                visibility.append(Integer.toString(rssi5));
+                visibility.append(",");
+                visibility.append(Integer.toString(num5));
+            }
+            visibility.append("]");
+        } else {
+            if (mRssi != Integer.MAX_VALUE) {
+                visibility.append(", ");
+                visibility.append(Integer.toString(mRssi));
+                if (mScanResult != null) {
+                    visibility.append(", ");
+                    visibility.append(Integer.toString(mScanResult.frequency));
+                }
+            }
         }
-        return visibility;
+        return visibility.toString();
     }
 
     /** Updates the title and summary; may indirectly call notifyChanged()  */
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index 7ccfc6b..8779798 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -29,6 +29,7 @@
 import android.net.NetworkUtils;
 import android.net.ProxyInfo;
 import android.net.RouteInfo;
+import android.net.Uri;
 import android.net.wifi.WifiConfiguration;
 import android.net.wifi.WifiConfiguration.AuthAlgorithm;
 import android.net.wifi.WifiConfiguration.KeyMgmt;
@@ -105,6 +106,7 @@
     /* These values come from "wifi_proxy_settings" resource array */
     public static final int PROXY_NONE = 0;
     public static final int PROXY_STATIC = 1;
+    public static final int PROXY_PAC = 2;
 
     /* These values come from "wifi_eap_method" resource array */
     public static final int WIFI_EAP_METHOD_PEAP = 0;
@@ -130,6 +132,7 @@
     private TextView mProxyHostView;
     private TextView mProxyPortView;
     private TextView mProxyExclusionListView;
+    private TextView mProxyPacView;
 
     private IpAssignment mIpAssignment = IpAssignment.UNASSIGNED;
     private ProxySettings mProxySettings = ProxySettings.UNASSIGNED;
@@ -257,11 +260,7 @@
                     mProxySettingsSpinner.setSelection(PROXY_STATIC);
                     showAdvancedFields = true;
                 } else if (config.getProxySettings() == ProxySettings.PAC) {
-                    mProxySettingsSpinner.setVisibility(View.GONE);
-                    TextView textView = (TextView)mView.findViewById(R.id.proxy_pac_info);
-                    textView.setVisibility(View.VISIBLE);
-                    textView.setText(context.getString(R.string.proxy_url) +
-                            config.getLinkProperties().getHttpProxy().getPacFileUrl());
+                    mProxySettingsSpinner.setSelection(PROXY_PAC);
                     showAdvancedFields = true;
                 } else {
                     mProxySettingsSpinner.setSelection(PROXY_NONE);
@@ -466,11 +465,10 @@
             }
         }
 
-        mProxySettings = (mProxySettingsSpinner != null &&
-                mProxySettingsSpinner.getSelectedItemPosition() == PROXY_STATIC) ?
-                ProxySettings.STATIC : ProxySettings.NONE;
-
-        if (mProxySettings == ProxySettings.STATIC && mProxyHostView != null) {
+        final int selectedPosition = mProxySettingsSpinner.getSelectedItemPosition();
+        mProxySettings = ProxySettings.NONE;
+        if (selectedPosition == PROXY_STATIC && mProxyHostView != null) {
+            mProxySettings = ProxySettings.STATIC;
             String host = mProxyHostView.getText().toString();
             String portStr = mProxyPortView.getText().toString();
             String exclusionList = mProxyExclusionListView.getText().toString();
@@ -488,6 +486,18 @@
             } else {
                 return false;
             }
+        } else if (selectedPosition == PROXY_PAC && mProxyPacView != null) {
+            mProxySettings = ProxySettings.PAC;
+            CharSequence uriSequence = mProxyPacView.getText();
+            if (TextUtils.isEmpty(uriSequence)) {
+                return false;
+            }
+            Uri uri = Uri.parse(uriSequence.toString());
+            if (uri == null) {
+                return false;
+            }
+            ProxyInfo proxyInfo = new ProxyInfo(uri);
+            mLinkProperties.setHttpProxy(proxyInfo);
         }
         return true;
     }
@@ -811,8 +821,9 @@
         }
 
         if (mProxySettingsSpinner.getSelectedItemPosition() == PROXY_STATIC) {
-            mView.findViewById(R.id.proxy_warning_limited_support).setVisibility(View.VISIBLE);
-            mView.findViewById(R.id.proxy_fields).setVisibility(View.VISIBLE);
+            setVisibility(R.id.proxy_warning_limited_support, View.VISIBLE);
+            setVisibility(R.id.proxy_fields, View.VISIBLE);
+            setVisibility(R.id.proxy_pac_field, View.GONE);
             if (mProxyHostView == null) {
                 mProxyHostView = (TextView) mView.findViewById(R.id.proxy_hostname);
                 mProxyHostView.addTextChangedListener(this);
@@ -829,13 +840,34 @@
                     mProxyExclusionListView.setText(proxyProperties.getExclusionListAsString());
                 }
             }
+        } else if (mProxySettingsSpinner.getSelectedItemPosition() == PROXY_PAC) {
+            setVisibility(R.id.proxy_warning_limited_support, View.GONE);
+            setVisibility(R.id.proxy_fields, View.GONE);
+            setVisibility(R.id.proxy_pac_field, View.VISIBLE);
+
+            if (mProxyPacView == null) {
+                mProxyPacView = (TextView) mView.findViewById(R.id.proxy_pac);
+                mProxyPacView.addTextChangedListener(this);
+            }
+            if (config != null) {
+                ProxyInfo proxyInfo = config.getLinkProperties().getHttpProxy();
+                if (proxyInfo != null) {
+                    mProxyPacView.setText(proxyInfo.getPacFileUrl().toString());
+                }
+            }
         } else {
-            mView.findViewById(R.id.proxy_warning_limited_support).setVisibility(View.GONE);
-            mView.findViewById(R.id.proxy_fields).setVisibility(View.GONE);
+            setVisibility(R.id.proxy_warning_limited_support, View.GONE);
+            setVisibility(R.id.proxy_fields, View.GONE);
+            setVisibility(R.id.proxy_pac_field, View.GONE);
         }
     }
 
-
+    private void setVisibility(int id, int visibility) {
+        final View v = mView.findViewById(id);
+        if (v != null) {
+            v.setVisibility(visibility);
+        }
+    }
 
     private void loadCertificates(Spinner spinner, String prefix) {
         final Context context = mConfigUi.getContext();
diff --git a/src/com/android/settings/wifi/WifiEnabler.java b/src/com/android/settings/wifi/WifiEnabler.java
index 9f0b6fa..d190045 100644
--- a/src/com/android/settings/wifi/WifiEnabler.java
+++ b/src/com/android/settings/wifi/WifiEnabler.java
@@ -27,6 +27,7 @@
 import android.os.Handler;
 import android.os.Message;
 import android.provider.Settings;
+import android.view.View;
 import android.widget.CompoundButton;
 import android.widget.Switch;
 import android.widget.Toast;
@@ -88,6 +89,11 @@
         mContext = context;
         mSwitchBar = switchBar;
         mSwitch = switchBar.getSwitch();
+        // This is a trick: as the Wi-Fi initial state is asynchronously coming from the
+        // BroadcastReceiver we cannot have the Switch visible at first otherwise you will notice
+        // its state change later on. So start it as VIEW.GONE and make it View.VISIBLE later
+        // when its state is defined.
+        mSwitch.setVisibility(View.GONE);
 
         mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
         mIntentFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);
@@ -133,6 +139,7 @@
                 mSwitch.setEnabled(true);
                 updateSearchIndex(false);
         }
+        mSwitch.setVisibility(View.VISIBLE);
     }
 
     private void updateSearchIndex(boolean isWiFiOn) {
diff --git a/src/com/android/settings/wifi/WifiPickerActivity.java b/src/com/android/settings/wifi/WifiPickerActivity.java
index 6dea82e..4cb78bd 100644
--- a/src/com/android/settings/wifi/WifiPickerActivity.java
+++ b/src/com/android/settings/wifi/WifiPickerActivity.java
@@ -21,22 +21,28 @@
 
 import android.content.Intent;
 
+import java.lang.Class;
+
 public class WifiPickerActivity extends SettingsActivity implements ButtonBarHandler {
 
     @Override
     public Intent getIntent() {
         Intent modIntent = new Intent(super.getIntent());
         if (!modIntent.hasExtra(EXTRA_SHOW_FRAGMENT)) {
-            modIntent.putExtra(EXTRA_SHOW_FRAGMENT, WifiSettings.class.getName());
+            modIntent.putExtra(EXTRA_SHOW_FRAGMENT, getWifiSettingsClass().getName());
         }
         return modIntent;
     }
 
     @Override
     protected boolean isValidFragment(String fragmentName) {
-        if (WifiSettings.class.getName().equals(fragmentName)
+        if (getWifiSettingsClass().getName().equals(fragmentName)
                 || WifiP2pSettings.class.getName().equals(fragmentName)
                 || AdvancedWifiSettings.class.getName().equals(fragmentName)) return true;
         return false;
     }
+
+    /* package */ Class getWifiSettingsClass() {
+        return WifiSettings.class;
+    }
 }
\ No newline at end of file
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 604275a..3420f36 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -29,7 +29,6 @@
 import com.android.settings.wifi.p2p.WifiP2pSettings;
 
 import android.app.Activity;
-import android.app.AlertDialog;
 import android.app.Dialog;
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -40,7 +39,6 @@
 import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.location.LocationManager;
-import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
 import android.net.NetworkInfo.DetailedState;
 import android.net.wifi.ScanResult;
@@ -54,23 +52,14 @@
 import android.os.Message;
 import android.preference.Preference;
 import android.preference.PreferenceScreen;
-import android.util.AttributeSet;
 import android.util.Log;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
-import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
 import android.widget.AdapterView.AdapterContextMenuInfo;
-import android.widget.Button;
-import android.widget.ImageButton;
-import android.widget.PopupMenu;
-import android.widget.PopupMenu.OnMenuItemClickListener;
-import android.widget.RelativeLayout;
 import android.widget.TextView;
 import android.widget.Toast;
 
@@ -93,10 +82,10 @@
         implements DialogInterface.OnClickListener, Indexable  {
 
     private static final String TAG = "WifiSettings";
-    private static final int MENU_ID_WPS_PBC = Menu.FIRST;
+    /* package */ static final int MENU_ID_WPS_PBC = Menu.FIRST;
     private static final int MENU_ID_WPS_PIN = Menu.FIRST + 1;
     private static final int MENU_ID_P2P = Menu.FIRST + 2;
-    private static final int MENU_ID_ADD_NETWORK = Menu.FIRST + 3;
+    /* package */ static final int MENU_ID_ADD_NETWORK = Menu.FIRST + 3;
     private static final int MENU_ID_ADVANCED = Menu.FIRST + 4;
     private static final int MENU_ID_SCAN = Menu.FIRST + 5;
     private static final int MENU_ID_CONNECT = Menu.FIRST + 6;
@@ -105,10 +94,10 @@
     private static final int MENU_ID_WRITE_NFC = Menu.FIRST + 9;
 
     private static final int WIFI_DIALOG_ID = 1;
-    private static final int WPS_PBC_DIALOG_ID = 2;
+    /* package */ static final int WPS_PBC_DIALOG_ID = 2;
     private static final int WPS_PIN_DIALOG_ID = 3;
-    private static final int WIFI_SKIPPED_DIALOG_ID = 4;
-    private static final int WIFI_AND_MOBILE_SKIPPED_DIALOG_ID = 5;
+    /* package */ static final int WIFI_SKIPPED_DIALOG_ID = 4;
+    /* package */ static final int WIFI_AND_MOBILE_SKIPPED_DIALOG_ID = 5;
     private static final int WRITE_NFC_DIALOG_ID = 6;
 
     // Combo scans can take 5-6s to complete - set to 10s.
@@ -118,14 +107,11 @@
     private static final String SAVE_DIALOG_EDIT_MODE = "edit_mode";
     private static final String SAVE_DIALOG_ACCESS_POINT_STATE = "wifi_ap_state";
 
-    // Activity result when pressing the Skip button
-    private static final int RESULT_SKIP = Activity.RESULT_FIRST_USER;
-
     private final IntentFilter mFilter;
     private final BroadcastReceiver mReceiver;
     private final Scanner mScanner;
 
-    private WifiManager mWifiManager;
+    /* package */ WifiManager mWifiManager;
     private WifiManager.ActionListener mConnectListener;
     private WifiManager.ActionListener mSaveListener;
     private WifiManager.ActionListener mForgetListener;
@@ -145,39 +131,17 @@
 
     private TextView mEmptyView;
 
-    /* Used in Wifi Setup context */
-
-    // this boolean extra specifies whether to disable the Next button when not connected
-    private static final String EXTRA_ENABLE_NEXT_ON_CONNECT = "wifi_enable_next_on_connect";
-
-    // this boolean extra specifies whether to auto finish when connection is established
-    private static final String EXTRA_AUTO_FINISH_ON_CONNECT = "wifi_auto_finish_on_connect";
-
-    // this boolean extra shows a custom button that we can control
-    protected static final String EXTRA_SHOW_CUSTOM_BUTTON = "wifi_show_custom_button";
-
-    // show a text regarding data charges when wifi connection is required during setup wizard
-    protected static final String EXTRA_SHOW_WIFI_REQUIRED_INFO = "wifi_show_wifi_required_info";
-
-    // this boolean extra is set if we are being invoked by the Setup Wizard
-    private static final String EXTRA_IS_FIRST_RUN = "firstRun";
-
-    // should Next button only be enabled when we have a connection?
-    private boolean mEnableNextOnConnection;
-
-    // should activity finish once we have a connection?
-    private boolean mAutoFinishOnConnection;
-
     // Save the dialog details
     private boolean mDlgEdit;
     private AccessPoint mDlgAccessPoint;
     private Bundle mAccessPointSavedState;
 
-    // the action bar uses a different set of controls for Setup Wizard
-    private boolean mSetupWizardMode;
-
     private SwitchBar mSwitchBar;
 
+    /** verbose logging flag. this flag is set thru developer debugging options
+     * and used so as to assist with in-the-field WiFi connectivity debugging  */
+    public static int mVerboseLogging = 0;
+
     /* End of "used in Wifi Setup context" */
 
     public WifiSettings() {
@@ -203,93 +167,6 @@
     }
 
     @Override
-    public void onCreate(Bundle icicle) {
-        // Set this flag early, as it's needed by getHelpResource(), which is called by super
-        mSetupWizardMode = getActivity().getIntent().getBooleanExtra(EXTRA_IS_FIRST_RUN, false);
-        super.onCreate(icicle);
-    }
-
-    @Override
-    public View onCreateView(final LayoutInflater inflater, ViewGroup container,
-            Bundle savedInstanceState) {
-
-        if (mSetupWizardMode) {
-            View view = inflater.inflate(R.layout.setup_preference, container, false);
-            View other = view.findViewById(R.id.other_network);
-            other.setOnClickListener(new OnClickListener() {
-                @Override
-                public void onClick(View v) {
-                    if (mWifiManager.isWifiEnabled()) {
-                        onAddNetworkPressed();
-                    }
-                }
-            });
-            final ImageButton b = (ImageButton) view.findViewById(R.id.more);
-            if (b != null) {
-                b.setOnClickListener(new OnClickListener() {
-                    @Override
-                    public void onClick(View v) {
-                        if (mWifiManager.isWifiEnabled()) {
-                            PopupMenu pm = new PopupMenu(inflater.getContext(), b);
-                            pm.inflate(R.menu.wifi_setup);
-                            pm.setOnMenuItemClickListener(new OnMenuItemClickListener() {
-                                @Override
-                                public boolean onMenuItemClick(MenuItem item) {
-                                    if (R.id.wifi_wps == item.getItemId()) {
-                                        showDialog(WPS_PBC_DIALOG_ID);
-                                        return true;
-                                    }
-                                    return false;
-                                }
-                            });
-                            pm.show();
-                        }
-                    }
-                });
-            }
-
-            Intent intent = getActivity().getIntent();
-            if (intent.getBooleanExtra(EXTRA_SHOW_CUSTOM_BUTTON, false)) {
-                view.findViewById(R.id.button_bar).setVisibility(View.VISIBLE);
-                view.findViewById(R.id.back_button).setVisibility(View.INVISIBLE);
-                view.findViewById(R.id.skip_button).setVisibility(View.INVISIBLE);
-                view.findViewById(R.id.next_button).setVisibility(View.INVISIBLE);
-
-                Button customButton = (Button) view.findViewById(R.id.custom_button);
-                customButton.setVisibility(View.VISIBLE);
-                customButton.setOnClickListener(new OnClickListener() {
-                    @Override
-                    public void onClick(View v) {
-                        boolean isConnected = false;
-                        Activity activity = getActivity();
-                        final ConnectivityManager connectivity = (ConnectivityManager)
-                                activity.getSystemService(Context.CONNECTIVITY_SERVICE);
-                        if (connectivity != null) {
-                            final NetworkInfo info = connectivity.getActiveNetworkInfo();
-                            isConnected = (info != null) && info.isConnected();
-                        }
-                        if (isConnected) {
-                            // Warn of possible data charges
-                            showDialog(WIFI_SKIPPED_DIALOG_ID);
-                        } else {
-                            // Warn of lack of updates
-                            showDialog(WIFI_AND_MOBILE_SKIPPED_DIALOG_ID);
-                        }
-                    }
-                });
-            }
-
-            if (intent.getBooleanExtra(EXTRA_SHOW_WIFI_REQUIRED_INFO, false)) {
-                view.findViewById(R.id.wifi_required_info).setVisibility(View.VISIBLE);
-            }
-
-            return view;
-        } else {
-            return super.onCreateView(inflater, container, savedInstanceState);
-        }
-    }
-
-    @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
 
@@ -347,60 +224,11 @@
             mAccessPointSavedState = savedInstanceState.getBundle(SAVE_DIALOG_ACCESS_POINT_STATE);
         }
 
-        final Activity activity = getActivity();
-        final Intent intent = activity.getIntent();
-
-        // first if we're supposed to finish once we have a connection
-        mAutoFinishOnConnection = intent.getBooleanExtra(EXTRA_AUTO_FINISH_ON_CONNECT, false);
-
-        if (mAutoFinishOnConnection) {
-            // Hide the next button
-            if (hasNextButton()) {
-                getNextButton().setVisibility(View.GONE);
-            }
-
-            final ConnectivityManager connectivity = (ConnectivityManager)
-                    activity.getSystemService(Context.CONNECTIVITY_SERVICE);
-            if (connectivity != null
-                    && connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) {
-                activity.setResult(Activity.RESULT_OK);
-                activity.finish();
-                return;
-            }
-        }
-
-        // if we're supposed to enable/disable the Next button based on our current connection
-        // state, start it off in the right state
-        mEnableNextOnConnection = intent.getBooleanExtra(EXTRA_ENABLE_NEXT_ON_CONNECT, false);
-
-        if (mEnableNextOnConnection) {
-            if (hasNextButton()) {
-                final ConnectivityManager connectivity = (ConnectivityManager)
-                        activity.getSystemService(Context.CONNECTIVITY_SERVICE);
-                if (connectivity != null) {
-                    NetworkInfo info = connectivity.getNetworkInfo(
-                            ConnectivityManager.TYPE_WIFI);
-                    changeNextButtonState(info.isConnected());
-                }
-            }
-        }
-
         addPreferencesFromResource(R.xml.wifi_settings);
 
-        if (mSetupWizardMode) {
-            getView().setSystemUiVisibility(
-                    View.STATUS_BAR_DISABLE_HOME |
-                    View.STATUS_BAR_DISABLE_RECENT |
-                    View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS |
-                    View.STATUS_BAR_DISABLE_CLOCK);
-        }
-
         mEmptyView = (TextView) getView().findViewById(android.R.id.empty);
         getListView().setEmptyView(mEmptyView);
-
-        if (!mSetupWizardMode) {
-            registerForContextMenu(getListView());
-        }
+        registerForContextMenu(getListView());
         setHasOptionsMenu(true);
     }
 
@@ -408,13 +236,16 @@
     public void onStart() {
         super.onStart();
 
-        // On/off switch is hidden for Setup Wizard
-        if (!mSetupWizardMode) {
-            final SettingsActivity activity = (SettingsActivity) getActivity();
+        // On/off switch is hidden for Setup Wizard (returns null)
+        mWifiEnabler = createWifiEnabler();
+    }
 
-            mSwitchBar = activity.getSwitchBar();
-            mWifiEnabler = new WifiEnabler(activity, mSwitchBar);
-        }
+    /**
+     * @return new WifiEnabler or null (as overridden by WifiSettingsForSetupWizard)
+     */
+    /* package */ WifiEnabler createWifiEnabler() {
+        final SettingsActivity activity = (SettingsActivity) getActivity();
+        return new WifiEnabler(activity, activity.getSwitchBar());
     }
 
     @Override
@@ -445,44 +276,41 @@
         // If the user is not allowed to configure wifi, do not show the menu.
         if (isRestrictedAndNotPinProtected()) return;
 
+        addOptionsMenuItems(menu);
+        super.onCreateOptionsMenu(menu, inflater);
+    }
+
+    /**
+     * @param menu
+     */
+    void addOptionsMenuItems(Menu menu) {
         final boolean wifiIsEnabled = mWifiManager.isWifiEnabled();
         TypedArray ta = getActivity().getTheme().obtainStyledAttributes(
                 new int[] {R.attr.ic_menu_add, R.attr.ic_wps});
-        if (mSetupWizardMode) {
-            menu.add(Menu.NONE, MENU_ID_WPS_PBC, 0, R.string.wifi_menu_wps_pbc)
-                    .setIcon(ta.getDrawable(1))
+        menu.add(Menu.NONE, MENU_ID_WPS_PBC, 0, R.string.wifi_menu_wps_pbc)
+                .setIcon(ta.getDrawable(1))
+                .setEnabled(wifiIsEnabled)
+                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+        menu.add(Menu.NONE, MENU_ID_ADD_NETWORK, 0, R.string.wifi_add_network)
+                .setIcon(ta.getDrawable(0))
+                .setEnabled(wifiIsEnabled)
+                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+        menu.add(Menu.NONE, MENU_ID_SCAN, 0, R.string.wifi_menu_scan)
+                //.setIcon(R.drawable.ic_menu_scan_network)
+                .setEnabled(wifiIsEnabled)
+                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+        menu.add(Menu.NONE, MENU_ID_WPS_PIN, 0, R.string.wifi_menu_wps_pin)
+                .setEnabled(wifiIsEnabled)
+                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+        if (mP2pSupported) {
+            menu.add(Menu.NONE, MENU_ID_P2P, 0, R.string.wifi_menu_p2p)
                     .setEnabled(wifiIsEnabled)
-                    .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
-            menu.add(Menu.NONE, MENU_ID_ADD_NETWORK, 0, R.string.wifi_add_network)
-                    .setEnabled(wifiIsEnabled)
-                    .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
-        } else {
-            menu.add(Menu.NONE, MENU_ID_WPS_PBC, 0, R.string.wifi_menu_wps_pbc)
-                    .setIcon(ta.getDrawable(1))
-                    .setEnabled(wifiIsEnabled)
-                    .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
-            menu.add(Menu.NONE, MENU_ID_ADD_NETWORK, 0, R.string.wifi_add_network)
-                    .setIcon(ta.getDrawable(0))
-                    .setEnabled(wifiIsEnabled)
-                    .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
-            menu.add(Menu.NONE, MENU_ID_SCAN, 0, R.string.wifi_menu_scan)
-                    //.setIcon(R.drawable.ic_menu_scan_network)
-                    .setEnabled(wifiIsEnabled)
-                    .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
-            menu.add(Menu.NONE, MENU_ID_WPS_PIN, 0, R.string.wifi_menu_wps_pin)
-                    .setEnabled(wifiIsEnabled)
-                    .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
-            if (mP2pSupported) {
-                menu.add(Menu.NONE, MENU_ID_P2P, 0, R.string.wifi_menu_p2p)
-                        .setEnabled(wifiIsEnabled)
-                        .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
-            }
-            menu.add(Menu.NONE, MENU_ID_ADVANCED, 0, R.string.wifi_menu_advanced)
-                    //.setIcon(android.R.drawable.ic_menu_manage)
                     .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
         }
+        menu.add(Menu.NONE, MENU_ID_ADVANCED, 0, R.string.wifi_menu_advanced)
+                //.setIcon(android.R.drawable.ic_menu_manage)
+                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
         ta.recycle();
-        super.onCreateOptionsMenu(menu, inflater);
     }
 
     @Override
@@ -663,44 +491,6 @@
                 return new WpsDialog(getActivity(), WpsInfo.PBC);
             case WPS_PIN_DIALOG_ID:
                 return new WpsDialog(getActivity(), WpsInfo.DISPLAY);
-            case WIFI_SKIPPED_DIALOG_ID:
-                return new AlertDialog.Builder(getActivity())
-                            .setMessage(R.string.wifi_skipped_message)
-                            .setCancelable(false)
-                            .setNegativeButton(R.string.wifi_skip_anyway,
-                                    new DialogInterface.OnClickListener() {
-                                @Override
-                                public void onClick(DialogInterface dialog, int id) {
-                                    getActivity().setResult(RESULT_SKIP);
-                                    getActivity().finish();
-                                }
-                            })
-                            .setPositiveButton(R.string.wifi_dont_skip,
-                                    new DialogInterface.OnClickListener() {
-                                @Override
-                                public void onClick(DialogInterface dialog, int id) {
-                                }
-                            })
-                            .create();
-            case WIFI_AND_MOBILE_SKIPPED_DIALOG_ID:
-                return new AlertDialog.Builder(getActivity())
-                            .setMessage(R.string.wifi_and_mobile_skipped_message)
-                            .setCancelable(false)
-                            .setNegativeButton(R.string.wifi_skip_anyway,
-                                    new DialogInterface.OnClickListener() {
-                                @Override
-                                public void onClick(DialogInterface dialog, int id) {
-                                    getActivity().setResult(RESULT_SKIP);
-                                    getActivity().finish();
-                                }
-                            })
-                            .setPositiveButton(R.string.wifi_dont_skip,
-                                    new DialogInterface.OnClickListener() {
-                                @Override
-                                public void onClick(DialogInterface dialog, int id) {
-                                }
-                            })
-                            .create();
             case WRITE_NFC_DIALOG_ID:
                 if (mSelectedAccessPoint != null) {
                     mWifiToNfcDialog = new WriteWifiConfigToNfcDialog(
@@ -712,10 +502,8 @@
         return super.onCreateDialog(dialogId);
     }
 
-    /** verbose logging flag is set only thru developer debugging options */
-    public static int mVerboseLogging = 0;
     /**
-     * Shows the latest access points available with supplimental information like
+     * Shows the latest access points available with supplemental information like
      * the strength of network and the security for it.
      */
     private void updateAccessPoints() {
@@ -728,7 +516,7 @@
         }
         final int wifiState = mWifiManager.getWifiState();
 
-        //check if verbose logging has been turned on or off
+        //when we update the screen, check if verbose logging has been turned on or off
         mVerboseLogging = mWifiManager.getVerboseLoggingLevel();
 
         switch (wifiState) {
@@ -880,17 +668,8 @@
             NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(
                     WifiManager.EXTRA_NETWORK_INFO);
             mConnected.set(info.isConnected());
-            changeNextButtonState(info.isConnected());
             updateAccessPoints();
             updateConnectionState(info.getDetailedState());
-            if (mAutoFinishOnConnection && info.isConnected()) {
-                Activity activity = getActivity();
-                if (activity != null) {
-                    activity.setResult(Activity.RESULT_OK);
-                    activity.finish();
-                }
-                return;
-            }
         } else if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) {
             updateConnectionState(null);
         }
@@ -984,18 +763,6 @@
         }
     }
 
-    /**
-     * Renames/replaces "Next" button when appropriate. "Next" button usually exists in
-     * Wifi setup screens, not in usual wifi settings screen.
-     *
-     * @param connected true when the device is connected to a wifi network.
-     */
-    private void changeNextButtonState(boolean connected) {
-        if (mEnableNextOnConnection && hasNextButton()) {
-            getNextButton().setEnabled(connected);
-        }
-    }
-
     @Override
     public void onClick(DialogInterface dialogInterface, int button) {
         if (button == WifiDialog.BUTTON_FORGET && mSelectedAccessPoint != null) {
@@ -1037,7 +804,7 @@
 
     /* package */ void forget() {
         if (mSelectedAccessPoint.networkId == INVALID_NETWORK_ID) {
-            // Should not happen, but a monkey seems to triger it
+            // Should not happen, but a monkey seems to trigger it
             Log.e(TAG, "Failed to forget invalid network " + mSelectedAccessPoint.getConfig());
             return;
         }
@@ -1048,9 +815,6 @@
             mScanner.resume();
         }
         updateAccessPoints();
-
-        // We need to rename/replace "Next" button in wifi setup context.
-        changeNextButtonState(false);
     }
 
     /**
@@ -1102,51 +866,9 @@
 
     @Override
     protected int getHelpResource() {
-        if (mSetupWizardMode) {
-            return 0;
-        }
         return R.string.help_url_wifi;
     }
 
-    /**
-     * Used as the outer frame of all setup wizard pages that need to adjust their margins based
-     * on the total size of the available display. (e.g. side margins set to 10% of total width.)
-     */
-    public static class ProportionalOuterFrame extends RelativeLayout {
-        public ProportionalOuterFrame(Context context) {
-            super(context);
-        }
-        public ProportionalOuterFrame(Context context, AttributeSet attrs) {
-            super(context, attrs);
-        }
-        public ProportionalOuterFrame(Context context, AttributeSet attrs, int defStyle) {
-            super(context, attrs, defStyle);
-        }
-
-        /**
-         * Set our margins and title area height proportionally to the available display size
-         */
-        @Override
-        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
-            int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
-            int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
-            final Resources res = getContext().getResources();
-            float titleHeight = res.getFraction(R.dimen.setup_title_height, 1, 1);
-            float sideMargin = res.getFraction(R.dimen.setup_border_width, 1, 1);
-            int bottom = res.getDimensionPixelSize(R.dimen.setup_margin_bottom);
-            setPaddingRelative(
-                    (int) (parentWidth * sideMargin),
-                    0,
-                    (int) (parentWidth * sideMargin),
-                    bottom);
-            View title = findViewById(R.id.title_area);
-            if (title != null) {
-                title.setMinimumHeight((int) (parentHeight * titleHeight));
-            }
-            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
-        }
-    }
-
     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
         new BaseSearchIndexProvider() {
             @Override
diff --git a/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java b/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java
new file mode 100644
index 0000000..17fca9f
--- /dev/null
+++ b/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java
@@ -0,0 +1,397 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.wifi;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.res.TypedArray;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.ImageButton;
+import android.widget.PopupMenu;
+import android.widget.PopupMenu.OnMenuItemClickListener;
+
+import com.android.settings.R;
+
+/**
+ * This customized version of WifiSettings is shown to the user only during Setup Wizard. Menu
+ * selections are limited, clicking on an access point will auto-advance to the next screen (once
+ * connected), and, if the user opts to skip ahead without a wifi connection, a warning message
+ * alerts of possible carrier data charges or missing software updates.
+ */
+public class WifiSettingsForSetupWizard extends WifiSettings {
+
+    private static final String TAG = "WifiSettingsForSetupWizard";
+
+    /* Used in Wifi Setup context */
+
+    // this boolean extra specifies whether to disable the Next button when not connected
+    private static final String EXTRA_ENABLE_NEXT_ON_CONNECT = "wifi_enable_next_on_connect";
+
+    // this boolean extra specifies whether to auto finish when connection is established
+    private static final String EXTRA_AUTO_FINISH_ON_CONNECT = "wifi_auto_finish_on_connect";
+
+    // this boolean extra shows a custom button that we can control
+    protected static final String EXTRA_SHOW_CUSTOM_BUTTON = "wifi_show_custom_button";
+
+    // show a text regarding data charges when wifi connection is required during setup wizard
+    protected static final String EXTRA_SHOW_WIFI_REQUIRED_INFO = "wifi_show_wifi_required_info";
+
+    // this boolean extra is set if we are being invoked by the Setup Wizard
+    private static final String EXTRA_IS_FIRST_RUN = "firstRun";
+
+    // Activity result when pressing the Skip button
+    private static final int RESULT_SKIP = Activity.RESULT_FIRST_USER;
+
+    // From WizardManager (must match constants maintained there)
+    private static final String ACTION_NEXT = "com.android.wizard.NEXT";
+    private static final String EXTRA_SCRIPT_URI = "scriptUri";
+    private static final String EXTRA_ACTION_ID = "actionId";
+    private static final String EXTRA_RESULT_CODE = "com.android.setupwizard.ResultCode";
+    private static final int NEXT_REQUEST = 10000;
+
+    // should Next button only be enabled when we have a connection?
+    private boolean mEnableNextOnConnection;
+
+    // should activity finish once we have a connection?
+    private boolean mAutoFinishOnConnection;
+
+    private final IntentFilter mFilter;
+    private final BroadcastReceiver mReceiver;
+
+    public WifiSettingsForSetupWizard() {
+        super();
+
+        mFilter = new IntentFilter();
+        mFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
+
+        mReceiver = new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(
+                        WifiManager.EXTRA_NETWORK_INFO);
+                changeNextButtonState(info.isConnected());
+                if (mAutoFinishOnConnection && info.isConnected()) {
+                    Log.d(TAG, "mReceiver.onReceive context=" + context + " intent=" + intent);
+                    finishOrNext(Activity.RESULT_OK);
+                }
+            }
+        };
+    }
+
+    @Override
+    public View onCreateView(final LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+
+        final View view = inflater.inflate(R.layout.setup_preference, container, false);
+        final View other = view.findViewById(R.id.other_network);
+        other.setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                if (mWifiManager.isWifiEnabled()) {
+                    onAddNetworkPressed();
+                }
+            }
+        });
+        final ImageButton b = (ImageButton) view.findViewById(R.id.more);
+        if (b != null) {
+            b.setOnClickListener(new OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    if (mWifiManager.isWifiEnabled()) {
+                        PopupMenu pm = new PopupMenu(inflater.getContext(), b);
+                        pm.inflate(R.menu.wifi_setup);
+                        pm.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+                            @Override
+                            public boolean onMenuItemClick(MenuItem item) {
+                                if (R.id.wifi_wps == item.getItemId()) {
+                                    showDialog(WPS_PBC_DIALOG_ID);
+                                    return true;
+                                }
+                                return false;
+                            }
+                        });
+                        pm.show();
+                    }
+                }
+            });
+        }
+
+        final Intent intent = getActivity().getIntent();
+        if (intent.getBooleanExtra(EXTRA_SHOW_CUSTOM_BUTTON, false)) {
+            view.findViewById(R.id.button_bar).setVisibility(View.VISIBLE);
+            view.findViewById(R.id.back_button).setVisibility(View.INVISIBLE);
+            view.findViewById(R.id.skip_button).setVisibility(View.INVISIBLE);
+            view.findViewById(R.id.next_button).setVisibility(View.INVISIBLE);
+
+            Button customButton = (Button) view.findViewById(R.id.custom_button);
+            customButton.setVisibility(View.VISIBLE);
+            customButton.setOnClickListener(new OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    boolean isConnected = false;
+                    Activity activity = getActivity();
+                    final ConnectivityManager connectivity = (ConnectivityManager)
+                            activity.getSystemService(Context.CONNECTIVITY_SERVICE);
+                    if (connectivity != null) {
+                        final NetworkInfo info = connectivity.getActiveNetworkInfo();
+                        isConnected = (info != null) && info.isConnected();
+                    }
+                    if (isConnected) {
+                        // Warn of possible data charges
+                        showDialog(WIFI_SKIPPED_DIALOG_ID);
+                    } else {
+                        // Warn of lack of updates
+                        showDialog(WIFI_AND_MOBILE_SKIPPED_DIALOG_ID);
+                    }
+                }
+            });
+        }
+
+        if (intent.getBooleanExtra(EXTRA_SHOW_WIFI_REQUIRED_INFO, false)) {
+            view.findViewById(R.id.wifi_required_info).setVisibility(View.VISIBLE);
+        }
+
+        return view;
+    }
+
+    @Override
+    public void onActivityCreated(Bundle savedInstanceState) {
+        super.onActivityCreated(savedInstanceState);
+
+        getView().setSystemUiVisibility(
+                View.STATUS_BAR_DISABLE_HOME |
+                View.STATUS_BAR_DISABLE_RECENT |
+                View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS |
+                View.STATUS_BAR_DISABLE_CLOCK);
+
+        final Activity activity = getActivity();
+        final Intent intent = activity.getIntent();
+
+        // first if we're supposed to finish once we have a connection
+        mAutoFinishOnConnection = intent.getBooleanExtra(EXTRA_AUTO_FINISH_ON_CONNECT, false);
+
+        /*
+         * When entering with a savedInstanceState, we may be returning from a later activity in the
+         * setup flow. It's not clear yet if there are other possible circumstances. It's not
+         * appropriate to refire our activity results, so we skip that here.
+         */
+        if (mAutoFinishOnConnection && null == savedInstanceState) {
+            // Hide the next button
+            if (hasNextButton()) {
+                getNextButton().setVisibility(View.GONE);
+            }
+
+            final ConnectivityManager connectivity = (ConnectivityManager)
+                    activity.getSystemService(Context.CONNECTIVITY_SERVICE);
+            if (connectivity != null
+                    && connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) {
+                Log.d(TAG, "onActivityCreated Auto-finishing");
+                finishOrNext(Activity.RESULT_OK);
+                return;
+            }
+        }
+
+        // if we're supposed to enable/disable the Next button based on our current connection
+        // state, start it off in the right state
+        mEnableNextOnConnection = intent.getBooleanExtra(EXTRA_ENABLE_NEXT_ON_CONNECT, false);
+
+        if (mEnableNextOnConnection) {
+            if (hasNextButton()) {
+                final ConnectivityManager connectivity = (ConnectivityManager)
+                        activity.getSystemService(Context.CONNECTIVITY_SERVICE);
+                if (connectivity != null) {
+                    NetworkInfo info = connectivity.getNetworkInfo(
+                            ConnectivityManager.TYPE_WIFI);
+                    changeNextButtonState(info.isConnected());
+                }
+            }
+        }
+    }
+
+    @Override
+    public Dialog onCreateDialog(int dialogId) {
+        switch (dialogId) {
+            case WIFI_SKIPPED_DIALOG_ID:
+                return new AlertDialog.Builder(getActivity())
+                            .setMessage(R.string.wifi_skipped_message)
+                            .setCancelable(false)
+                            .setNegativeButton(R.string.wifi_skip_anyway,
+                                    new DialogInterface.OnClickListener() {
+                                @Override
+                                public void onClick(DialogInterface dialog, int id) {
+                                    finishOrNext(RESULT_SKIP);
+                                }
+                            })
+                            .setPositiveButton(R.string.wifi_dont_skip,
+                                    new DialogInterface.OnClickListener() {
+                                @Override
+                                public void onClick(DialogInterface dialog, int id) {
+                                }
+                            })
+                            .create();
+            case WIFI_AND_MOBILE_SKIPPED_DIALOG_ID:
+                return new AlertDialog.Builder(getActivity())
+                            .setMessage(R.string.wifi_and_mobile_skipped_message)
+                            .setCancelable(false)
+                            .setNegativeButton(R.string.wifi_skip_anyway,
+                                    new DialogInterface.OnClickListener() {
+                                @Override
+                                public void onClick(DialogInterface dialog, int id) {
+                                    finishOrNext(RESULT_SKIP);
+                                }
+                            })
+                            .setPositiveButton(R.string.wifi_dont_skip,
+                                    new DialogInterface.OnClickListener() {
+                                @Override
+                                public void onClick(DialogInterface dialog, int id) {
+                                }
+                            })
+                            .create();
+        }
+        return super.onCreateDialog(dialogId);
+    }
+
+    @Override
+    public void onResume() {
+        super.onResume();
+        getActivity().registerReceiver(mReceiver, mFilter);
+    }
+
+    @Override
+    public void onPause() {
+        super.onPause();
+        getActivity().unregisterReceiver(mReceiver);
+    }
+
+    @Override
+    public void onActivityResult(int requestCode, int resultCode, Intent data) {
+        if (resultCode == Activity.RESULT_CANCELED) {
+            // Before returning to the settings panel, forget any current access point so it will
+            // not attempt to automatically reconnect and advance
+            // FIXME: when coming back, it would be better to keep the current connection and
+            // override the auto-advance feature
+            final WifiInfo info = mWifiManager.getConnectionInfo();
+            if (null != info) {
+                int netId = info.getNetworkId();
+                if (netId != WifiConfiguration.INVALID_NETWORK_ID) {
+                    mWifiManager.forget(netId, null);
+                }
+            }
+        }
+        super.onActivityResult(requestCode, resultCode, data);
+    }
+
+    @Override
+    public void registerForContextMenu(View view) {
+        // Suppressed during setup wizard
+    }
+
+    @Override
+    /* package */ WifiEnabler createWifiEnabler() {
+        // Not shown during setup wizard
+        return null;
+    }
+
+    @Override
+    /* package */ void addOptionsMenuItems(Menu menu) {
+        final boolean wifiIsEnabled = mWifiManager.isWifiEnabled();
+        final TypedArray ta = getActivity().getTheme()
+                .obtainStyledAttributes(new int[] {R.attr.ic_wps});
+        menu.add(Menu.NONE, MENU_ID_WPS_PBC, 0, R.string.wifi_menu_wps_pbc)
+                .setIcon(ta.getDrawable(0))
+                .setEnabled(wifiIsEnabled)
+                .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
+        menu.add(Menu.NONE, MENU_ID_ADD_NETWORK, 0, R.string.wifi_add_network)
+                .setEnabled(wifiIsEnabled)
+                .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
+        ta.recycle();
+    }
+
+    @Override
+    /* package */ void forget() {
+        super.forget();
+
+        // We need to rename/replace "Next" button in wifi setup context.
+        changeNextButtonState(false);
+    }
+
+    /**
+     * Renames/replaces "Next" button when appropriate. "Next" button usually exists in
+     * Wifi setup screens, not in usual wifi settings screen.
+     *
+     * @param enabled true when the device is connected to a wifi network.
+     */
+    private void changeNextButtonState(boolean enabled) {
+        if (mEnableNextOnConnection && hasNextButton()) {
+            getNextButton().setEnabled(enabled);
+        }
+    }
+
+    /**
+     * Complete this activity and return the results to the caller. If using WizardManager, this
+     * will invoke the next scripted action; otherwise, we simply finish.
+     */
+    private void finishOrNext(int resultCode) {
+        Log.d(TAG, "finishOrNext resultCode=" + resultCode
+                + " isUsingWizardManager=" + isUsingWizardManager());
+        if (isUsingWizardManager()) {
+            sendResultsToSetupWizard(resultCode);
+        } else {
+            Activity activity = getActivity();
+            activity.setResult(resultCode);
+            activity.finish();
+        }
+    }
+
+    private boolean isUsingWizardManager() {
+        return getActivity().getIntent().hasExtra(EXTRA_SCRIPT_URI);
+    }
+
+    /**
+     * Send the results of this activity to WizardManager, which will then send out the next
+     * scripted activity. WizardManager does not actually return an activity result, but if we
+     * invoke WizardManager without requesting a result, the framework will choose not to issue a
+     * call to onActivityResult with RESULT_CANCELED when navigating backward.
+     */
+    private void sendResultsToSetupWizard(int resultCode) {
+        final Intent intent = getActivity().getIntent();
+        final Intent nextIntent = new Intent(ACTION_NEXT);
+        nextIntent.putExtra(EXTRA_SCRIPT_URI, intent.getStringExtra(EXTRA_SCRIPT_URI));
+        nextIntent.putExtra(EXTRA_ACTION_ID, intent.getStringExtra(EXTRA_ACTION_ID));
+        nextIntent.putExtra(EXTRA_RESULT_CODE, resultCode);
+        startActivityForResult(nextIntent, NEXT_REQUEST);
+    }
+}
diff --git a/src/com/android/settings/wifi/WifiSetupActivity.java b/src/com/android/settings/wifi/WifiSetupActivity.java
index 70ee56d..d4811ed 100644
--- a/src/com/android/settings/wifi/WifiSetupActivity.java
+++ b/src/com/android/settings/wifi/WifiSetupActivity.java
@@ -19,6 +19,8 @@
 
 import android.content.res.Resources;
 
+import java.lang.Class;
+
 public class WifiSetupActivity extends WifiPickerActivity implements ButtonBarHandler {
     // Extra containing the resource name of the theme to be used
     private static final String EXTRA_THEME = "theme";
@@ -41,4 +43,9 @@
         }
         super.onApplyThemeResource(theme, resid, first);
     }
+
+    @Override
+    /* package */ Class getWifiSettingsClass() {
+        return WifiSettingsForSetupWizard.class;
+    }
 }