Merge "Import translations. DO NOT MERGE"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 544ecf8..c43d8a3 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1195,6 +1195,8 @@
     <string name="wifi_menu_wps_pbc">WPS Push Button</string>
     <!-- Menu option to do WPS Pin Entry [CHAR LIMIT=20]-->
     <string name="wifi_menu_wps_pin">WPS Pin Entry</string>
+    <!-- Menu option to launch Wi-Fi Direct settings [CHAR LIMIT=20]-->
+    <string name="wifi_menu_p2p">Wi-Fi Direct</string>
     <!-- Menu option to scan Wi-Fi networks -->
     <string name="wifi_menu_scan">Scan</string>
     <!-- Menu option to Wi-Fi advanced settings -->
diff --git a/res/xml/wireless_settings.xml b/res/xml/wireless_settings.xml
index e48ac2d..8531b3e 100644
--- a/res/xml/wireless_settings.xml
+++ b/res/xml/wireless_settings.xml
@@ -55,11 +55,6 @@
         android:title="@string/android_beam_settings_title" />
 
     <PreferenceScreen
-        android:fragment="com.android.settings.wifi.p2p.WifiP2pSettings"
-        android:key="wifi_p2p_settings"
-        android:title="@string/wifi_p2p_settings_title" />
-
-    <PreferenceScreen
         android:key="mobile_network_settings"
         android:title="@string/network_settings_title"
         android:dependency="toggle_airplane">
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 164434c..d76e04b 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -60,6 +60,7 @@
 
 import com.android.settings.R;
 import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.wifi.p2p.WifiP2pSettings;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -84,12 +85,13 @@
     private static final String TAG = "WifiSettings";
     private 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_ADD_NETWORK = Menu.FIRST + 2;
-    private static final int MENU_ID_ADVANCED = Menu.FIRST + 3;
-    private static final int MENU_ID_SCAN = Menu.FIRST + 4;
-    private static final int MENU_ID_CONNECT = Menu.FIRST + 5;
-    private static final int MENU_ID_FORGET = Menu.FIRST + 6;
-    private static final int MENU_ID_MODIFY = Menu.FIRST + 7;
+    private static final int MENU_ID_P2P = Menu.FIRST + 2;
+    private 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;
+    private static final int MENU_ID_FORGET = Menu.FIRST + 7;
+    private static final int MENU_ID_MODIFY = Menu.FIRST + 8;
 
     private static final int WIFI_DIALOG_ID = 1;
     private static final int WPS_PBC_DIALOG_ID = 2;
@@ -306,6 +308,9 @@
             menu.add(Menu.NONE, MENU_ID_WPS_PBC, 0, R.string.wifi_menu_wps_pbc)
                     .setEnabled(wifiIsEnabled)
                     .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+            menu.add(Menu.NONE, MENU_ID_P2P, 0, R.string.wifi_menu_p2p)
+                    .setEnabled(wifiIsEnabled)
+                    .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
             menu.add(Menu.NONE, MENU_ID_ADD_NETWORK, 0, R.string.wifi_add_network)
                     .setEnabled(wifiIsEnabled)
                     .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
@@ -344,6 +349,17 @@
             case MENU_ID_WPS_PBC:
                 showDialog(WPS_PBC_DIALOG_ID);
                 return true;
+            case MENU_ID_P2P:
+                if (getActivity() instanceof PreferenceActivity) {
+                    ((PreferenceActivity) getActivity()).startPreferencePanel(
+                            WifiP2pSettings.class.getCanonicalName(),
+                            null,
+                            R.string.wifi_p2p_settings_title, null,
+                            this, 0);
+                } else {
+                    startFragment(this, WifiP2pSettings.class.getCanonicalName(), -1, null);
+                }
+                return true;
             case MENU_ID_WPS_PIN:
                 showDialog(WPS_PIN_DIALOG_ID);
                 return true;
diff --git a/src/com/android/settings/wifi/p2p/WifiP2pSettings.java b/src/com/android/settings/wifi/p2p/WifiP2pSettings.java
index 369506e..a823ffa 100644
--- a/src/com/android/settings/wifi/p2p/WifiP2pSettings.java
+++ b/src/com/android/settings/wifi/p2p/WifiP2pSettings.java
@@ -175,7 +175,7 @@
     public void onResume() {
         super.onResume();
         getActivity().registerReceiver(mReceiver, mIntentFilter);
-        startSearch();
+        mWifiP2pManager.requestPeers(mChannel, WifiP2pSettings.this);
     }
 
     @Override
@@ -296,9 +296,11 @@
         mPeers = peers;
         mConnectedDevices = 0;
         for (WifiP2pDevice peer: peers.getDeviceList()) {
+            if (DBG) Log.d(TAG, " peer " + peer);
             mPeersGroup.addPreference(new WifiP2pPeer(getActivity(), peer));
             if (peer.status == WifiP2pDevice.CONNECTED) mConnectedDevices++;
         }
+        if (DBG) Log.d(TAG, " mConnectedDevices " + mConnectedDevices);
     }
 
     private void handleP2pStateChanged() {
@@ -316,7 +318,7 @@
             mPeersGroup.setEnabled(true);
             preferenceScreen.addPreference(mPeersGroup);
 
-            startSearch();
+            if (mConnectedDevices == 0) startSearch();
         }
     }