Merge "bug:3343038 reset mAppsSize everytime ALL package sizes are computed" into honeycomb
diff --git a/res/values/strings.xml b/res/values/strings.xml
index a5ce776..4107951 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -948,10 +948,14 @@
     <string name="wifi_network_setup">Network Setup</string>
     <!-- Label for the text view for WPS pin input [CHAR LIMIT=50] -->
     <string name="wifi_wps_pin">Enter pin from access point</string>
-    <!-- Title for the WPS pin display dialog [CHAR LIMIT=50] -->
-    <string name="wifi_wps_pin_method_configuration">WPS pin method configuration</string>
-    <!-- Text displayed in the WPS pin display dialog [CHAR LIMIT=50] -->
+    <!-- Title for the WPS setup dialog [CHAR LIMIT=50] -->
+    <string name="wifi_wps_setup_title">WPS Setup</string>
+    <!-- Text displayed in the WPS pin display dialog [CHAR LIMIT=75] -->
     <string name="wifi_wps_pin_output">Enter the pin <xliff:g id="wps_pin">%1$s</xliff:g> on the access point</string>
+    <!-- Text displayed when WPS setup is in progress [CHAR LIMIT=75] -->
+    <string name="wifi_wps_in_progress">WPS is already in progress and can take tens of seconds to complete</string>
+    <!-- Text displayed when WPS fails to start [CHAR LIMIT=75] -->
+    <string name="wifi_wps_failed">Failed to start WPS, please try again</string>
     <!-- Label for the SSID of the network -->
     <string name="wifi_ssid">Network SSID</string>
     <!-- Label for the security of the connection -->
@@ -1009,6 +1013,10 @@
     <!-- Button label to dismiss the dialog -->
     <string name="wifi_cancel">Cancel</string>
 
+    <!-- Errors reported on wifi settings page -->
+    <!-- Toast message indicating WPS overlap detection [CHAR LIMIT=75] -->
+    <string name="wifi_wps_overlap_error">Another WPS session detected, please retry in a few minutes</string>
+
     <!-- Wi-Fi Advanced Settings --> <skip />
     <!-- Wi-Fi settings screen, advanced, settings section.  This is a header shown above advanced wifi settings. -->
     <string name="wifi_advanced_titlebar">Advanced</string>
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index e47660a..ffe48a9 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -37,7 +37,9 @@
 import android.net.wifi.WifiConfiguration;
 import android.net.wifi.WifiInfo;
 import android.net.wifi.WifiManager;
+import android.net.wifi.WpsResult;
 import android.net.wifi.WifiConfiguration.KeyMgmt;
+import android.net.wifi.WpsConfiguration;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
@@ -126,11 +128,12 @@
         mFilter.addAction(WifiManager.LINK_CONFIGURATION_CHANGED_ACTION);
         mFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
         mFilter.addAction(WifiManager.RSSI_CHANGED_ACTION);
+        mFilter.addAction(WifiManager.ERROR_ACTION);
 
         mReceiver = new BroadcastReceiver() {
             @Override
             public void onReceive(Context context, Intent intent) {
-                handleEvent(intent);
+                handleEvent(context, intent);
             }
         };
 
@@ -428,7 +431,7 @@
         return accessPoints;
     }
 
-    private void handleEvent(Intent intent) {
+    private void handleEvent(Context context, Intent intent) {
         String action = intent.getAction();
         if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
             updateWifiState(intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
@@ -460,6 +463,14 @@
             updateConnectionState(info.getDetailedState());
         } else if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) {
             updateConnectionState(null);
+        } else if (WifiManager.ERROR_ACTION.equals(action)) {
+            int errorCode = intent.getIntExtra(WifiManager.EXTRA_ERROR_CODE, 0);
+            switch (errorCode) {
+                case WifiManager.WPS_OVERLAP_ERROR:
+                    Toast.makeText(context, R.string.wifi_wps_overlap_error,
+                            Toast.LENGTH_SHORT).show();
+                    break;
+            }
         }
     }
 
@@ -571,18 +582,32 @@
     }
 
     /* package */ void submit(WifiConfigController configController) {
-        switch(configController.chosenNetworkSetupMethod()) {
+        int networkSetup = configController.chosenNetworkSetupMethod();
+        switch(networkSetup) {
             case WifiConfigController.WPS_PBC:
             case WifiConfigController.WPS_PIN_FROM_ACCESS_POINT:
-                mWifiManager.startWps(configController.getWpsConfig());
-                break;
             case WifiConfigController.WPS_PIN_FROM_DEVICE:
-                String pin = mWifiManager.startWps(configController.getWpsConfig());
-                new AlertDialog.Builder(getActivity())
-                        .setTitle(R.string.wifi_wps_pin_method_configuration)
-                        .setMessage(getResources().getString(R.string.wifi_wps_pin_output, pin))
-                        .setPositiveButton(android.R.string.ok, null)
-                        .show();
+                WpsResult result = mWifiManager.startWps(configController.getWpsConfig());
+                AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity())
+                                        .setTitle(R.string.wifi_wps_setup_title)
+                                        .setPositiveButton(android.R.string.ok, null);
+                switch (result.status) {
+                    case FAILURE:
+                        dialog.setMessage(R.string.wifi_wps_failed);
+                        dialog.show();
+                        break;
+                    case IN_PROGRESS:
+                        dialog.setMessage(R.string.wifi_wps_in_progress);
+                        dialog.show();
+                        break;
+                    default:
+                        if (networkSetup == WifiConfigController.WPS_PIN_FROM_DEVICE) {
+                            dialog.setMessage(getResources().getString(R.string.wifi_wps_pin_output,
+                                    result.pin));
+                            dialog.show();
+                        }
+                        break;
+                }
                 break;
             case WifiConfigController.MANUAL:
                 final WifiConfiguration config = configController.getConfig();