Port WifiDirect P2P sample to template system.
Includes updates to styling and layout.
Change-Id: Ia0a8fb5e886032401f7c2267a3e5bf25be57c87e
diff --git a/connectivity/wifidirect/DirectP2P/Application/.gitignore b/connectivity/wifidirect/DirectP2P/Application/.gitignore
new file mode 100644
index 0000000..6eb878d
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/.gitignore
@@ -0,0 +1,16 @@
+# Copyright 2013 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.
+src/template/
+src/common/
+build.gradle
diff --git a/connectivity/wifidirect/DirectP2P/Application/proguard-project.txt b/connectivity/wifidirect/DirectP2P/Application/proguard-project.txt
new file mode 100644
index 0000000..0d8f171
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/proguard-project.txt
@@ -0,0 +1,20 @@
+ To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/AndroidManifest.xml b/connectivity/wifidirect/DirectP2P/Application/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..f2cd327
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/AndroidManifest.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.wifidirectp2p"
+ android:versionCode="1"
+ android:versionName="1.0">
+
+ <uses-sdk android:minSdkVersion="14"
+ android:targetSdkVersion="20" />
+
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+ <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
+ <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+ <uses-permission android:name="android.permission.READ_PHONE_STATE" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+
+ <!-- Google Play filtering -->
+ <uses-feature android:name="android.hardware.wifi.direct" android:required="true"/>
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name"
+ android:icon="@drawable/ic_launcher"
+ android:theme="@style/AppTheme" >
+
+ <activity android:name=".MainActivity"
+ android:label="@string/app_name" android:launchMode="singleTask">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+ <!-- Used for transferring files after a successful connection -->
+ <service android:enabled="true" android:name=".FileTransferService" />
+
+</manifest>
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/java/com/example/android/wifidirectp2p/DeviceDetailFragment.java b/connectivity/wifidirect/DirectP2P/Application/src/main/java/com/example/android/wifidirectp2p/DeviceDetailFragment.java
new file mode 100644
index 0000000..3987a00
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/java/com/example/android/wifidirectp2p/DeviceDetailFragment.java
@@ -0,0 +1,296 @@
+/*
+ * Copyright (C) 2011 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.example.android.wifidirectp2p;
+
+import android.app.Fragment;
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.net.wifi.WpsInfo;
+import android.net.wifi.p2p.WifiP2pConfig;
+import android.net.wifi.p2p.WifiP2pDevice;
+import android.net.wifi.p2p.WifiP2pInfo;
+import android.net.wifi.p2p.WifiP2pManager.ConnectionInfoListener;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.os.Environment;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import com.example.android.wifidirectp2p.DeviceListFragment.DeviceActionListener;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+/**
+ * A fragment that manages a particular peer and allows interaction with device
+ * i.e. setting up network connection and transferring data.
+ */
+public class DeviceDetailFragment extends Fragment implements ConnectionInfoListener {
+
+ protected static final int CHOOSE_FILE_RESULT_CODE = 20;
+ private View mContentView = null;
+ private WifiP2pDevice device;
+ private WifiP2pInfo info;
+ ProgressDialog progressDialog = null;
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+
+ mContentView = inflater.inflate(R.layout.device_detail, null);
+ mContentView.findViewById(R.id.btn_connect).setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ WifiP2pConfig config = new WifiP2pConfig();
+ config.deviceAddress = device.deviceAddress;
+ config.wps.setup = WpsInfo.PBC;
+ if (progressDialog != null && progressDialog.isShowing()) {
+ progressDialog.dismiss();
+ }
+ progressDialog = ProgressDialog.show(getActivity(), "Press back to cancel",
+ "Connecting to :" + device.deviceAddress, true, true
+// new DialogInterface.OnCancelListener() {
+//
+// @Override
+// public void onCancel(DialogInterface dialog) {
+// ((DeviceActionListener) getActivity()).cancelDisconnect();
+// }
+// }
+ );
+ ((DeviceActionListener) getActivity()).connect(config);
+
+ }
+ });
+
+ mContentView.findViewById(R.id.btn_disconnect).setOnClickListener(
+ new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ ((DeviceActionListener) getActivity()).disconnect();
+ }
+ }
+ );
+
+ mContentView.findViewById(R.id.btn_start_client).setOnClickListener(
+ new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ // Allow user to pick an image from Gallery or other
+ // registered apps
+ Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
+ intent.setType("image/*");
+ startActivityForResult(intent, CHOOSE_FILE_RESULT_CODE);
+ }
+ }
+ );
+
+ return mContentView;
+ }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+
+ // User has picked an image. Transfer it to group owner i.e peer using
+ // FileTransferService.
+ Uri uri = data.getData();
+ TextView statusText = (TextView) mContentView.findViewById(R.id.status_text);
+ statusText.setText("Sending: " + uri);
+ Log.d(MainActivity.TAG, "Intent----------- " + uri);
+ Intent serviceIntent = new Intent(getActivity(), FileTransferService.class);
+ serviceIntent.setAction(FileTransferService.ACTION_SEND_FILE);
+ serviceIntent.putExtra(FileTransferService.EXTRAS_FILE_PATH, uri.toString());
+ serviceIntent.putExtra(FileTransferService.EXTRAS_GROUP_OWNER_ADDRESS,
+ info.groupOwnerAddress.getHostAddress());
+ serviceIntent.putExtra(FileTransferService.EXTRAS_GROUP_OWNER_PORT, 8988);
+ getActivity().startService(serviceIntent);
+ }
+
+ @Override
+ public void onConnectionInfoAvailable(final WifiP2pInfo info) {
+ if (progressDialog != null && progressDialog.isShowing()) {
+ progressDialog.dismiss();
+ }
+ this.info = info;
+ this.getView().setVisibility(View.VISIBLE);
+
+ // The owner IP is now known.
+ TextView view = (TextView) mContentView.findViewById(R.id.group_owner);
+ view.setText(getResources().getString(R.string.group_owner_text)
+ + ((info.isGroupOwner == true) ? getResources().getString(R.string.yes)
+ : getResources().getString(R.string.no)));
+
+ // InetAddress from WifiP2pInfo struct.
+ view = (TextView) mContentView.findViewById(R.id.device_info);
+ view.setText("Group Owner IP - " + info.groupOwnerAddress.getHostAddress());
+
+ // After the group negotiation, we assign the group owner as the file
+ // server. The file server is single threaded, single connection server
+ // socket.
+ if (info.groupFormed && info.isGroupOwner) {
+ new FileServerAsyncTask(getActivity(), mContentView.findViewById(R.id.status_text))
+ .execute();
+ } else if (info.groupFormed) {
+ // The other device acts as the client. In this case, we enable the
+ // get file button.
+ mContentView.findViewById(R.id.btn_start_client).setVisibility(View.VISIBLE);
+ ((TextView) mContentView.findViewById(R.id.status_text)).setText(getResources()
+ .getString(R.string.client_text));
+ }
+
+ // hide the connect button
+ mContentView.findViewById(R.id.btn_connect).setVisibility(View.GONE);
+ }
+
+ /**
+ * Updates the UI with device data
+ *
+ * @param device the device to be displayed
+ */
+ public void showDetails(WifiP2pDevice device) {
+ this.device = device;
+ this.getView().setVisibility(View.VISIBLE);
+ TextView view = (TextView) mContentView.findViewById(R.id.device_address);
+ view.setText(device.deviceAddress);
+ view = (TextView) mContentView.findViewById(R.id.device_info);
+ view.setText(device.toString());
+
+ }
+
+ /**
+ * Clears the UI fields after a disconnect or direct mode disable operation.
+ */
+ public void resetViews() {
+ mContentView.findViewById(R.id.btn_connect).setVisibility(View.VISIBLE);
+ TextView view = (TextView) mContentView.findViewById(R.id.device_address);
+ view.setText(R.string.empty);
+ view = (TextView) mContentView.findViewById(R.id.device_info);
+ view.setText(R.string.empty);
+ view = (TextView) mContentView.findViewById(R.id.group_owner);
+ view.setText(R.string.empty);
+ view = (TextView) mContentView.findViewById(R.id.status_text);
+ view.setText(R.string.empty);
+ mContentView.findViewById(R.id.btn_start_client).setVisibility(View.GONE);
+ this.getView().setVisibility(View.GONE);
+ }
+
+ /**
+ * A simple server socket that accepts connection and writes some data on
+ * the stream.
+ */
+ public static class FileServerAsyncTask extends AsyncTask<Void, Void, String> {
+
+ private Context context;
+ private TextView statusText;
+
+ /**
+ * @param context
+ * @param statusText
+ */
+ public FileServerAsyncTask(Context context, View statusText) {
+ this.context = context;
+ this.statusText = (TextView) statusText;
+ }
+
+ @Override
+ protected String doInBackground(Void... params) {
+ try {
+ ServerSocket serverSocket = new ServerSocket(8988);
+ Log.d(MainActivity.TAG, "Server: Socket opened");
+ Socket client = serverSocket.accept();
+ Log.d(MainActivity.TAG, "Server: connection done");
+ final File f = new File(Environment.getExternalStorageDirectory() + "/"
+ + context.getPackageName() + "/wifip2pshared-" + System.currentTimeMillis()
+ + ".jpg");
+
+ File dirs = new File(f.getParent());
+ if (!dirs.exists())
+ dirs.mkdirs();
+ f.createNewFile();
+
+ Log.d(MainActivity.TAG, "server: copying files " + f.toString());
+ InputStream inputstream = client.getInputStream();
+ copyFile(inputstream, new FileOutputStream(f));
+ serverSocket.close();
+ return f.getAbsolutePath();
+ } catch (IOException e) {
+ Log.e(MainActivity.TAG, e.getMessage());
+ return null;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
+ */
+ @Override
+ protected void onPostExecute(String result) {
+ if (result != null) {
+ statusText.setText("File copied - " + result);
+ Intent intent = new Intent();
+ intent.setAction(Intent.ACTION_VIEW);
+ intent.setDataAndType(Uri.parse("file://" + result), "image/*");
+ context.startActivity(intent);
+ }
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see android.os.AsyncTask#onPreExecute()
+ */
+ @Override
+ protected void onPreExecute() {
+ statusText.setText("Opening a server socket");
+ }
+
+ }
+
+ public static boolean copyFile(InputStream inputStream, OutputStream out) {
+ byte buf[] = new byte[1024];
+ int len;
+ try {
+ while ((len = inputStream.read(buf)) != -1) {
+ out.write(buf, 0, len);
+
+ }
+ out.close();
+ inputStream.close();
+ } catch (IOException e) {
+ Log.d(MainActivity.TAG, e.toString());
+ return false;
+ }
+ return true;
+ }
+
+}
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/java/com/example/android/wifidirectp2p/DeviceListFragment.java b/connectivity/wifidirect/DirectP2P/Application/src/main/java/com/example/android/wifidirectp2p/DeviceListFragment.java
new file mode 100644
index 0000000..0eb6917
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/java/com/example/android/wifidirectp2p/DeviceListFragment.java
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2011 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.example.android.wifidirectp2p;
+
+import android.app.ListFragment;
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.net.wifi.p2p.WifiP2pConfig;
+import android.net.wifi.p2p.WifiP2pDevice;
+import android.net.wifi.p2p.WifiP2pDeviceList;
+import android.net.wifi.p2p.WifiP2pManager.PeerListListener;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+import android.widget.TextView;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A ListFragment that displays available peers on discovery and requests the
+ * parent activity to handle user interaction events
+ */
+public class DeviceListFragment extends ListFragment implements PeerListListener {
+
+ private List<WifiP2pDevice> peers = new ArrayList<WifiP2pDevice>();
+ ProgressDialog progressDialog = null;
+ View mContentView = null;
+ private WifiP2pDevice device;
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ this.setListAdapter(new WiFiPeerListAdapter(getActivity(), R.layout.row_devices, peers));
+
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ mContentView = inflater.inflate(R.layout.device_list, null);
+ return mContentView;
+ }
+
+ /**
+ * @return this device
+ */
+ public WifiP2pDevice getDevice() {
+ return device;
+ }
+
+ private static String getDeviceStatus(int deviceStatus) {
+ Log.d(MainActivity.TAG, "Peer status :" + deviceStatus);
+ switch (deviceStatus) {
+ case WifiP2pDevice.AVAILABLE:
+ return "Available";
+ case WifiP2pDevice.INVITED:
+ return "Invited";
+ case WifiP2pDevice.CONNECTED:
+ return "Connected";
+ case WifiP2pDevice.FAILED:
+ return "Failed";
+ case WifiP2pDevice.UNAVAILABLE:
+ return "Unavailable";
+ default:
+ return "Unknown";
+
+ }
+ }
+
+ /**
+ * Initiate a connection with the peer.
+ */
+ @Override
+ public void onListItemClick(ListView l, View v, int position, long id) {
+ WifiP2pDevice device = (WifiP2pDevice) getListAdapter().getItem(position);
+ ((DeviceActionListener) getActivity()).showDetails(device);
+ }
+
+ /**
+ * Array adapter for ListFragment that maintains WifiP2pDevice list.
+ */
+ private class WiFiPeerListAdapter extends ArrayAdapter<WifiP2pDevice> {
+
+ private List<WifiP2pDevice> items;
+
+ /**
+ * @param context
+ * @param textViewResourceId
+ * @param objects
+ */
+ public WiFiPeerListAdapter(Context context, int textViewResourceId,
+ List<WifiP2pDevice> objects) {
+ super(context, textViewResourceId, objects);
+ items = objects;
+
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View v = convertView;
+ if (v == null) {
+ LayoutInflater vi = (LayoutInflater) getActivity().getSystemService(
+ Context.LAYOUT_INFLATER_SERVICE);
+ v = vi.inflate(R.layout.row_devices, null);
+ }
+ WifiP2pDevice device = items.get(position);
+ if (device != null) {
+ TextView top = (TextView) v.findViewById(R.id.device_name);
+ TextView bottom = (TextView) v.findViewById(R.id.device_details);
+ if (top != null) {
+ top.setText(device.deviceName);
+ }
+ if (bottom != null) {
+ bottom.setText(getDeviceStatus(device.status));
+ }
+ }
+
+ return v;
+
+ }
+ }
+
+ /**
+ * Update UI for this device.
+ *
+ * @param device WifiP2pDevice object
+ */
+ public void updateThisDevice(WifiP2pDevice device) {
+ this.device = device;
+ TextView view = (TextView) mContentView.findViewById(R.id.my_name);
+ view.setText(device.deviceName);
+ view = (TextView) mContentView.findViewById(R.id.my_status);
+ view.setText(getDeviceStatus(device.status));
+ }
+
+ @Override
+ public void onPeersAvailable(WifiP2pDeviceList peerList) {
+ if (progressDialog != null && progressDialog.isShowing()) {
+ progressDialog.dismiss();
+ }
+ peers.clear();
+ peers.addAll(peerList.getDeviceList());
+ ((WiFiPeerListAdapter) getListAdapter()).notifyDataSetChanged();
+ if (peers.size() == 0) {
+ Log.d(MainActivity.TAG, "No devices found");
+ return;
+ }
+
+ }
+
+ public void clearPeers() {
+ peers.clear();
+ ((WiFiPeerListAdapter) getListAdapter()).notifyDataSetChanged();
+ }
+
+ /**
+ *
+ */
+ public void onInitiateDiscovery() {
+ if (progressDialog != null && progressDialog.isShowing()) {
+ progressDialog.dismiss();
+ }
+ progressDialog = ProgressDialog.show(getActivity(), "Press back to cancel", "finding peers", true,
+ true, new DialogInterface.OnCancelListener() {
+
+ @Override
+ public void onCancel(DialogInterface dialog) {
+
+ }
+ }
+ );
+ }
+
+ /**
+ * An interface-callback for the activity to listen to fragment interaction
+ * events.
+ */
+ public interface DeviceActionListener {
+
+ void showDetails(WifiP2pDevice device);
+
+ void cancelDisconnect();
+
+ void connect(WifiP2pConfig config);
+
+ void disconnect();
+ }
+
+}
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/java/com/example/android/wifidirectp2p/FileTransferService.java b/connectivity/wifidirect/DirectP2P/Application/src/main/java/com/example/android/wifidirectp2p/FileTransferService.java
new file mode 100644
index 0000000..1956c52
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/java/com/example/android/wifidirectp2p/FileTransferService.java
@@ -0,0 +1,86 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+
+package com.example.android.wifidirectp2p;
+
+import android.app.IntentService;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.util.Log;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+
+/**
+ * A service that process each file transfer request i.e Intent by opening a
+ * socket connection with the WiFi Direct Group Owner and writing the file
+ */
+public class FileTransferService extends IntentService {
+
+ private static final int SOCKET_TIMEOUT = 5000;
+ public static final String ACTION_SEND_FILE = "com.example.android.wifidirectp2p.SEND_FILE";
+ public static final String EXTRAS_FILE_PATH = "file_url";
+ public static final String EXTRAS_GROUP_OWNER_ADDRESS = "go_host";
+ public static final String EXTRAS_GROUP_OWNER_PORT = "go_port";
+
+ public FileTransferService(String name) {
+ super(name);
+ }
+
+ public FileTransferService() {
+ super("FileTransferService");
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see android.app.IntentService#onHandleIntent(android.content.Intent)
+ */
+ @Override
+ protected void onHandleIntent(Intent intent) {
+
+ Context context = getApplicationContext();
+ if (intent.getAction().equals(ACTION_SEND_FILE)) {
+ String fileUri = intent.getExtras().getString(EXTRAS_FILE_PATH);
+ String host = intent.getExtras().getString(EXTRAS_GROUP_OWNER_ADDRESS);
+ Socket socket = new Socket();
+ int port = intent.getExtras().getInt(EXTRAS_GROUP_OWNER_PORT);
+
+ try {
+ Log.d(MainActivity.TAG, "Opening client socket - ");
+ socket.bind(null);
+ socket.connect((new InetSocketAddress(host, port)), SOCKET_TIMEOUT);
+
+ Log.d(MainActivity.TAG, "Client socket - " + socket.isConnected());
+ OutputStream stream = socket.getOutputStream();
+ ContentResolver cr = context.getContentResolver();
+ InputStream is = null;
+ try {
+ is = cr.openInputStream(Uri.parse(fileUri));
+ } catch (FileNotFoundException e) {
+ Log.d(MainActivity.TAG, e.toString());
+ }
+ DeviceDetailFragment.copyFile(is, stream);
+ Log.d(MainActivity.TAG, "Client: Data written");
+ } catch (IOException e) {
+ Log.e(MainActivity.TAG, e.getMessage());
+ } finally {
+ if (socket != null) {
+ if (socket.isConnected()) {
+ try {
+ socket.close();
+ } catch (IOException e) {
+ // Give up
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ }
+ }
+}
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/java/com/example/android/wifidirectp2p/MainActivity.java b/connectivity/wifidirect/DirectP2P/Application/src/main/java/com/example/android/wifidirectp2p/MainActivity.java
new file mode 100644
index 0000000..896ebdf
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/java/com/example/android/wifidirectp2p/MainActivity.java
@@ -0,0 +1,252 @@
+/*
+ * Copyright (C) 2011 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.example.android.wifidirectp2p;
+
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.net.wifi.p2p.WifiP2pConfig;
+import android.net.wifi.p2p.WifiP2pDevice;
+import android.net.wifi.p2p.WifiP2pManager;
+import android.net.wifi.p2p.WifiP2pManager.ActionListener;
+import android.net.wifi.p2p.WifiP2pManager.Channel;
+import android.net.wifi.p2p.WifiP2pManager.ChannelListener;
+import android.os.Bundle;
+import android.provider.Settings;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.Toast;
+
+import com.example.android.wifidirectp2p.DeviceListFragment.DeviceActionListener;
+
+/**
+ * An activity that uses WiFi Direct APIs to discover and connect with available
+ * devices. WiFi Direct APIs are asynchronous and rely on callback mechanism
+ * using interfaces to notify the application of operation success or failure.
+ * The application should also register a BroadcastReceiver for notification of
+ * WiFi state related events.
+ */
+public class MainActivity extends Activity implements ChannelListener, DeviceActionListener {
+
+ public static final String TAG = "wifidirectdemo";
+ private WifiP2pManager manager;
+ private boolean isWifiP2pEnabled = false;
+ private boolean retryChannel = false;
+
+ private final IntentFilter intentFilter = new IntentFilter();
+ private Channel channel;
+ private BroadcastReceiver receiver = null;
+
+ /**
+ * @param isWifiP2pEnabled the isWifiP2pEnabled to set
+ */
+ public void setIsWifiP2pEnabled(boolean isWifiP2pEnabled) {
+ this.isWifiP2pEnabled = isWifiP2pEnabled;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+
+ // add necessary intent values to be matched.
+
+ intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
+ intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
+ intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
+ intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
+
+ manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
+ channel = manager.initialize(this, getMainLooper(), null);
+ }
+
+ /**
+ * register the BroadcastReceiver with the intent values to be matched
+ */
+ @Override
+ public void onResume() {
+ super.onResume();
+ receiver = new WiFiDirectBroadcastReceiver(manager, channel, this);
+ registerReceiver(receiver, intentFilter);
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ unregisterReceiver(receiver);
+ }
+
+ /**
+ * Remove all peers and clear all fields. This is called on
+ * BroadcastReceiver receiving a state change event.
+ */
+ public void resetData() {
+ DeviceListFragment fragmentList = (DeviceListFragment) getFragmentManager()
+ .findFragmentById(R.id.frag_list);
+ DeviceDetailFragment fragmentDetails = (DeviceDetailFragment) getFragmentManager()
+ .findFragmentById(R.id.frag_detail);
+ if (fragmentList != null) {
+ fragmentList.clearPeers();
+ }
+ if (fragmentDetails != null) {
+ fragmentDetails.resetViews();
+ }
+ }
+
+ public void showWirelessSettings(View v) {
+ if (manager != null && channel != null) {
+
+ // Since this is the system wireless settings activity, it's
+ // not going to send us a result. We will be notified by
+ // WiFiDeviceBroadcastReceiver instead.
+
+ startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
+ } else {
+ Log.e(TAG, "channel or manager is null");
+ }
+ }
+
+ public void enableDiscovery(View v) {
+ if (!isWifiP2pEnabled) {
+ Toast.makeText(MainActivity.this, R.string.p2p_off_warning,
+ Toast.LENGTH_SHORT).show();
+ return;
+ }
+ final DeviceListFragment fragment = (DeviceListFragment) getFragmentManager()
+ .findFragmentById(R.id.frag_list);
+ fragment.onInitiateDiscovery();
+ manager.discoverPeers(channel, new ActionListener() {
+
+ @Override
+ public void onSuccess() {
+ Toast.makeText(MainActivity.this, "Discovery Initiated",
+ Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
+ public void onFailure(int reasonCode) {
+ Toast.makeText(MainActivity.this, "Discovery Failed : " + reasonCode,
+ Toast.LENGTH_SHORT).show();
+ }
+ });
+
+ }
+
+
+ @Override
+ public void showDetails(WifiP2pDevice device) {
+ DeviceDetailFragment fragment = (DeviceDetailFragment) getFragmentManager()
+ .findFragmentById(R.id.frag_detail);
+ fragment.showDetails(device);
+
+ }
+
+ @Override
+ public void connect(WifiP2pConfig config) {
+ manager.connect(channel, config, new ActionListener() {
+
+ @Override
+ public void onSuccess() {
+ // WiFiDirectBroadcastReceiver will notify us. Ignore for now.
+ }
+
+ @Override
+ public void onFailure(int reason) {
+ Toast.makeText(MainActivity.this, "Connect failed. Retry.",
+ Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+
+ @Override
+ public void disconnect() {
+ final DeviceDetailFragment fragment = (DeviceDetailFragment) getFragmentManager()
+ .findFragmentById(R.id.frag_detail);
+ fragment.resetViews();
+ manager.removeGroup(channel, new ActionListener() {
+
+ @Override
+ public void onFailure(int reasonCode) {
+ Log.d(TAG, "Disconnect failed. Reason :" + reasonCode);
+
+ }
+
+ @Override
+ public void onSuccess() {
+ fragment.getView().setVisibility(View.GONE);
+ }
+
+ });
+ }
+
+ @Override
+ public void onChannelDisconnected() {
+ // we will try once more
+ if (manager != null && !retryChannel) {
+ Toast.makeText(this, "Channel lost. Trying again", Toast.LENGTH_LONG).show();
+ resetData();
+ retryChannel = true;
+ manager.initialize(this, getMainLooper(), this);
+ } else {
+ Toast.makeText(this,
+ "Severe! Channel is probably lost premanently. Try Disable/Re-Enable P2P.",
+ Toast.LENGTH_LONG).show();
+ }
+ }
+
+ @Override
+ public void cancelDisconnect() {
+
+ /*
+ * A cancel abort request by user. Disconnect i.e. removeGroup if
+ * already connected. Else, request WifiP2pManager to abort the ongoing
+ * request
+ */
+ if (manager != null) {
+ final DeviceListFragment fragment = (DeviceListFragment) getFragmentManager()
+ .findFragmentById(R.id.frag_list);
+ if (fragment.getDevice() == null
+ || fragment.getDevice().status == WifiP2pDevice.CONNECTED) {
+ disconnect();
+ } else if (fragment.getDevice().status == WifiP2pDevice.AVAILABLE
+ || fragment.getDevice().status == WifiP2pDevice.INVITED) {
+
+ manager.cancelConnect(channel, new ActionListener() {
+
+ @Override
+ public void onSuccess() {
+ Toast.makeText(MainActivity.this, "Aborting connection",
+ Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
+ public void onFailure(int reasonCode) {
+ Toast.makeText(MainActivity.this,
+ "Connect abort request failed. Reason Code: " + reasonCode,
+ Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+ }
+
+ }
+}
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/java/com/example/android/wifidirectp2p/WiFiDirectBroadcastReceiver.java b/connectivity/wifidirect/DirectP2P/Application/src/main/java/com/example/android/wifidirectp2p/WiFiDirectBroadcastReceiver.java
new file mode 100644
index 0000000..df6671f
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/java/com/example/android/wifidirectp2p/WiFiDirectBroadcastReceiver.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2011 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.example.android.wifidirectp2p;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.net.NetworkInfo;
+import android.net.wifi.p2p.WifiP2pDevice;
+import android.net.wifi.p2p.WifiP2pManager;
+import android.net.wifi.p2p.WifiP2pManager.Channel;
+import android.net.wifi.p2p.WifiP2pManager.PeerListListener;
+import android.util.Log;
+
+/**
+ * A BroadcastReceiver that notifies of important wifi p2p events.
+ */
+public class WiFiDirectBroadcastReceiver extends BroadcastReceiver {
+
+ private WifiP2pManager manager;
+ private Channel channel;
+ private MainActivity activity;
+
+ /**
+ * @param manager WifiP2pManager system service
+ * @param channel Wifi p2p channel
+ * @param activity activity associated with the receiver
+ */
+ public WiFiDirectBroadcastReceiver(WifiP2pManager manager, Channel channel,
+ MainActivity activity) {
+ super();
+ this.manager = manager;
+ this.channel = channel;
+ this.activity = activity;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see android.content.BroadcastReceiver#onReceive(android.content.Context,
+ * android.content.Intent)
+ */
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
+
+ // UI update to indicate wifi p2p status.
+ int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
+ if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
+ // Wifi Direct mode is enabled
+ activity.setIsWifiP2pEnabled(true);
+ } else {
+ activity.setIsWifiP2pEnabled(false);
+ activity.resetData();
+
+ }
+ Log.d(MainActivity.TAG, "P2P state changed - " + state);
+ } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
+
+ // request available peers from the wifi p2p manager. This is an
+ // asynchronous call and the calling activity is notified with a
+ // callback on PeerListListener.onPeersAvailable()
+ if (manager != null) {
+ manager.requestPeers(channel, (PeerListListener) activity.getFragmentManager()
+ .findFragmentById(R.id.frag_list));
+ }
+ Log.d(MainActivity.TAG, "P2P peers changed");
+ } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
+
+ if (manager == null) {
+ return;
+ }
+
+ NetworkInfo networkInfo = (NetworkInfo) intent
+ .getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
+
+ if (networkInfo.isConnected()) {
+
+ // we are connected with the other device, request connection
+ // info to find group owner IP
+
+ DeviceDetailFragment fragment = (DeviceDetailFragment) activity
+ .getFragmentManager().findFragmentById(R.id.frag_detail);
+ manager.requestConnectionInfo(channel, fragment);
+ } else {
+ // It's a disconnect
+ activity.resetData();
+ }
+ } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
+ DeviceListFragment fragment = (DeviceListFragment) activity.getFragmentManager()
+ .findFragmentById(R.id.frag_list);
+ fragment.updateThisDevice((WifiP2pDevice) intent.getParcelableExtra(
+ WifiP2pManager.EXTRA_WIFI_P2P_DEVICE));
+
+ }
+ }
+}
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-hdpi/ic_launcher.png b/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..2182749
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-hdpi/ic_wifi.png b/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-hdpi/ic_wifi.png
new file mode 100644
index 0000000..b768a95
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-hdpi/ic_wifi.png
Binary files differ
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-ldpi/ic_launcher.png b/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-ldpi/ic_launcher.png
new file mode 100644
index 0000000..002dae2
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-ldpi/ic_launcher.png
Binary files differ
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-mdpi/ic_launcher.png b/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..90a2b64
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-mdpi/ic_wifi.png b/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-mdpi/ic_wifi.png
new file mode 100644
index 0000000..e13fb0f
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-mdpi/ic_wifi.png
Binary files differ
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-xhdpi/ic_launcher.png b/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..870f999
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-xhdpi/ic_wifi.png b/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-xhdpi/ic_wifi.png
new file mode 100644
index 0000000..ecb6564
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-xhdpi/ic_wifi.png
Binary files differ
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-xxhdpi/ic_launcher.png b/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..70b9024
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-xxhdpi/ic_wifi.png b/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-xxhdpi/ic_wifi.png
new file mode 100644
index 0000000..91ecfbe
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/res/drawable-xxhdpi/ic_wifi.png
Binary files differ
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/res/layout/device_detail.xml b/connectivity/wifidirect/DirectP2P/Application/src/main/res/layout/device_detail.xml
new file mode 100644
index 0000000..e559937
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/res/layout/device_detail.xml
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+Copyright 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.
+-->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="fill_parent"
+ android:orientation="horizontal"
+ android:visibility="gone">
+
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/status_text"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_gravity="center"
+ android:layout_margin="@dimen/margin_small"></TextView>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+
+ <Button
+ android:id="@+id/btn_connect"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/connect_peer_button" />
+
+ <Button
+ android:id="@+id/btn_disconnect"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/disconnect_peer_button" />
+
+ <Button
+ android:id="@+id/btn_start_client"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/get_file_button"
+ android:visibility="gone" />
+ </LinearLayout>
+
+ <TextView
+ android:id="@+id/device_address"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+
+ <TextView
+ android:id="@+id/device_info"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+
+ <TextView
+ android:id="@+id/group_owner"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+
+ <TextView
+ android:id="@+id/group_ip"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+ </LinearLayout>
+</FrameLayout>
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/res/layout/device_list.xml b/connectivity/wifidirect/DirectP2P/Application/src/main/res/layout/device_list.xml
new file mode 100644
index 0000000..cf27dcc
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/res/layout/device_list.xml
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+Copyright 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.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:padding="@dimen/margin_medium">
+
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:onClick="showWirelessSettings"
+ android:text="Open WiFi Settings" />
+
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:onClick="enableDiscovery"
+ android:text="Start Discovery" />
+
+ <TextView
+ style="@style/SubHeading"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center_vertical"
+ android:text="@string/label_me" />
+
+ <!-- Self information -->
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:padding="3dip">
+
+ <ImageView
+ android:id="@+id/icon"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_marginRight="2dp"
+ android:src="@drawable/ic_wifi" />
+
+ <LinearLayout
+ android:layout_width="0dp"
+ android:layout_height="fill_parent"
+ android:layout_weight="1"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/my_name"
+ android:layout_width="fill_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:gravity="center_vertical" />
+
+ <TextView
+ android:id="@+id/my_status"
+ android:layout_width="fill_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:ellipsize="marquee"
+ android:singleLine="true" />
+ </LinearLayout>
+ </LinearLayout>
+
+ <TextView
+ style="@style/SubHeading"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center_vertical"
+ android:text="@string/label_peers" />
+
+
+ <!-- Available peers -->
+ <ListView
+ android:id="@id/android:list"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_weight="1"
+ android:drawSelectorOnTop="false" />
+
+ <TextView
+ android:id="@id/android:empty"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_gravity="center"
+ android:text="@string/empty_message" />
+</LinearLayout>
+
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/res/layout/main.xml b/connectivity/wifidirect/DirectP2P/Application/src/main/res/layout/main.xml
new file mode 100644
index 0000000..e5b94e3
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/res/layout/main.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+Copyright 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.
+-->
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ >
+
+ <LinearLayout
+ android:id="@+id/linearLayout1"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:orientation="vertical"
+ android:paddingBottom="@dimen/vertical_page_margin"
+ android:paddingLeft="@dimen/horizontal_page_margin"
+ android:paddingRight="@dimen/horizontal_page_margin"
+ android:paddingTop="@dimen/vertical_page_margin">
+
+ <TextView
+ style="@style/SubText"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/intro_message" />
+
+ <fragment
+ android:id="@+id/frag_list"
+ class="com.example.android.wifidirectp2p.DeviceListFragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ tools:layout="@layout/row_devices"></fragment>
+
+ <fragment
+ android:id="@+id/frag_detail"
+ class="com.example.android.wifidirectp2p.DeviceDetailFragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ tools:layout="@layout/device_detail"></fragment>
+ </LinearLayout>
+</ScrollView>
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/res/layout/row_devices.xml b/connectivity/wifidirect/DirectP2P/Application/src/main/res/layout/row_devices.xml
new file mode 100644
index 0000000..2ceaea5
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/res/layout/row_devices.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+Copyright 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.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="?android:attr/listPreferredItemHeight"
+ android:background="?android:attr/activatedBackgroundIndicator"
+ android:padding="6dip">
+
+ <ImageView
+ android:id="@+id/icon"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_marginRight="2dip"
+ android:src="@drawable/ic_wifi" />
+
+ <LinearLayout
+ android:layout_width="0dip"
+ android:layout_height="fill_parent"
+ android:layout_weight="1"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/device_name"
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1"
+ android:gravity="center_vertical" />
+
+ <TextView
+ android:id="@+id/device_details"
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1"
+ android:ellipsize="marquee"
+ android:singleLine="true" />
+ </LinearLayout>
+</LinearLayout>
\ No newline at end of file
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/res/values/colors.xml b/connectivity/wifidirect/DirectP2P/Application/src/main/res/values/colors.xml
new file mode 100644
index 0000000..2070cb0
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/res/values/colors.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+Copyright 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.
+-->
+<resources>
+ <color name="teal">#009688</color>
+ <color name="black_87">#DD000000</color>
+</resources>
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/res/values/strings.xml b/connectivity/wifidirect/DirectP2P/Application/src/main/res/values/strings.xml
new file mode 100644
index 0000000..91dcc5d
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/res/values/strings.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+Copyright 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.
+-->
+<resources>
+ <string name="connect_peer_button">Connect</string>
+ <string name="disconnect_peer_button">Disconnect</string>
+ <string name="get_file_button">Launch Gallery</string>
+ <string name="empty"></string>
+ <string name="yes">yes</string>
+ <string name="no">no</string>
+ <string name="client_text">This device will act as a client. Click on Gallery button to pick a local(stored) file</string>
+ <string name="empty_message">No devices found. Turn on P2P and perform discovery from the Action Bar</string>
+ <string name="p2p_off_warning">Enable P2P from the system settings above</string>
+ <string name="group_owner_text">"Am I the Group Owner? "</string>
+ <string name="label_me">This Device</string>
+ <string name="label_peers">Peers</string>
+</resources>
diff --git a/connectivity/wifidirect/DirectP2P/Application/src/main/res/values/styles.xml b/connectivity/wifidirect/DirectP2P/Application/src/main/res/values/styles.xml
new file mode 100644
index 0000000..47fd3fb
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/src/main/res/values/styles.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+Copyright 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.
+-->
+<resources>
+
+ <style name="SubHeading" parent="Widget">
+ <item name="android:layout_marginBottom">@dimen/margin_tiny</item>
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:textColor">@color/teal</item>
+ <item name="android:textSize">20sp</item>
+ <item name="android:layout_marginTop">@dimen/margin_medium</item>
+ </style>
+
+ <style name="SubText" parent="Widget">
+ <item name="android:textAppearance">?android:textAppearanceSmall</item>
+ <item name="android:textColor">@color/black_87</item>
+ </style>
+</resources>
\ No newline at end of file
diff --git a/connectivity/wifidirect/DirectP2P/Application/tests/AndroidManifest.xml b/connectivity/wifidirect/DirectP2P/Application/tests/AndroidManifest.xml
new file mode 100644
index 0000000..a636d3d
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/tests/AndroidManifest.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2013 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 name must be unique so suffix with "tests" so package loader doesn't ignore us -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.wifidirectp2p.tests"
+ android:versionCode="1"
+ android:versionName="1.0">
+
+ <uses-sdk
+ android:minSdkVersion="18"
+ android:targetSdkVersion="19" />
+
+ <!-- We add an application tag here just so that we can indicate that
+ this package needs to link against the android.test library,
+ which is needed when building test cases. -->
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <!--
+ Specifies the instrumentation test runner used to run the tests.
+ -->
+ <instrumentation
+ android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.example.android.wifidirectp2p"
+ android:label="Tests for com.example.android.wifidirectp2p" />
+
+</manifest>
\ No newline at end of file
diff --git a/connectivity/wifidirect/DirectP2P/Application/tests/src/com/example/android/wifidirectp2p/tests/SampleTests.java b/connectivity/wifidirect/DirectP2P/Application/tests/src/com/example/android/wifidirectp2p/tests/SampleTests.java
new file mode 100644
index 0000000..895f2c1
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/Application/tests/src/com/example/android/wifidirectp2p/tests/SampleTests.java
@@ -0,0 +1,76 @@
+/*
+* Copyright 2013 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.
+*/
+/*
+* Copyright (C) 2013 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.example.android.wifidirectp2p.tests;
+
+import com.example.android.wifidirectp2p.*;
+
+import android.test.ActivityInstrumentationTestCase2;
+
+/**
+* Tests for DirectP2P sample.
+*/
+public class SampleTests extends ActivityInstrumentationTestCase2<MainActivity> {
+
+ private MainActivity mTestActivity;
+ private DirectP2PFragment mTestFragment;
+
+ public SampleTests() {
+ super(MainActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // Starts the activity under test using the default Intent with:
+ // action = {@link Intent#ACTION_MAIN}
+ // flags = {@link Intent#FLAG_ACTIVITY_NEW_TASK}
+ // All other fields are null or empty.
+ mTestActivity = getActivity();
+ mTestFragment = (DirectP2PFragment)
+ mTestActivity.getSupportFragmentManager().getFragments().get(1);
+ }
+
+ /**
+ * Test if the test fixture has been set up correctly.
+ */
+ public void testPreconditions() {
+ //Try to add a message to add context to your assertions. These messages will be shown if
+ //a tests fails and make it easy to understand why a test failed
+ assertNotNull("mTestActivity is null", mTestActivity);
+ assertNotNull("mTestFragment is null", mTestFragment);
+ }
+
+ /**
+ * Add more tests below.
+ */
+
+}
\ No newline at end of file
diff --git a/connectivity/wifidirect/DirectP2P/build.gradle b/connectivity/wifidirect/DirectP2P/build.gradle
new file mode 100644
index 0000000..18f393f
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/build.gradle
@@ -0,0 +1,11 @@
+
+// BEGIN_EXCLUDE
+import com.example.android.samples.build.SampleGenPlugin
+apply plugin: SampleGenPlugin
+
+samplegen {
+ pathToBuild "../../../../../build"
+ pathToSamplesCommon "../../../common"
+}
+apply from: "../../../../../build/build.gradle"
+// END_EXCLUDE
diff --git a/connectivity/wifidirect/DirectP2P/buildSrc/build.gradle b/connectivity/wifidirect/DirectP2P/buildSrc/build.gradle
new file mode 100644
index 0000000..7cebf71
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/buildSrc/build.gradle
@@ -0,0 +1,15 @@
+repositories {
+ mavenCentral()
+}
+dependencies {
+ compile 'org.freemarker:freemarker:2.3.20'
+}
+
+sourceSets {
+ main {
+ groovy {
+ srcDir new File(rootDir, "../../../../../../build/buildSrc/src/main/groovy")
+ }
+ }
+}
+
diff --git a/connectivity/wifidirect/DirectP2P/gradle/wrapper/gradle-wrapper.jar b/connectivity/wifidirect/DirectP2P/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..8c0fb64
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/gradle/wrapper/gradle-wrapper.jar
Binary files differ
diff --git a/connectivity/wifidirect/DirectP2P/gradle/wrapper/gradle-wrapper.properties b/connectivity/wifidirect/DirectP2P/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..1b32573
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Wed Apr 10 15:27:10 PDT 2013
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
\ No newline at end of file
diff --git a/connectivity/wifidirect/DirectP2P/gradlew b/connectivity/wifidirect/DirectP2P/gradlew
new file mode 100755
index 0000000..91a7e26
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/connectivity/wifidirect/DirectP2P/gradlew.bat b/connectivity/wifidirect/DirectP2P/gradlew.bat
new file mode 100644
index 0000000..aec9973
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/connectivity/wifidirect/DirectP2P/packaging.yaml b/connectivity/wifidirect/DirectP2P/packaging.yaml
new file mode 100644
index 0000000..838f8ab
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/packaging.yaml
@@ -0,0 +1,15 @@
+# GOOGLE SAMPLE PACKAGING DATA
+#
+# This file is used by Google as part of our samples packaging process.
+# End users may safely ignore this file. It has no relevance to other systems.
+---
+
+status: PUBLISHED
+technologies: [Android]
+categories: [Connectivity]
+languages: [Java]
+solutions: [Mobile]
+github: googlesamples/android-DirectP2P
+level: BEGINNER
+icon: DirectP2PSample/src/main/res/drawable-xxhdpi/ic_launcher.png
+license: apache2-android
diff --git a/connectivity/wifidirect/DirectP2P/screenshots/1-main.png b/connectivity/wifidirect/DirectP2P/screenshots/1-main.png
new file mode 100644
index 0000000..b14399b
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/screenshots/1-main.png
Binary files differ
diff --git a/connectivity/wifidirect/DirectP2P/screenshots/2-discovery.png b/connectivity/wifidirect/DirectP2P/screenshots/2-discovery.png
new file mode 100644
index 0000000..090af81
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/screenshots/2-discovery.png
Binary files differ
diff --git a/connectivity/wifidirect/DirectP2P/screenshots/3-client.png b/connectivity/wifidirect/DirectP2P/screenshots/3-client.png
new file mode 100644
index 0000000..6dc58a4
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/screenshots/3-client.png
Binary files differ
diff --git a/connectivity/wifidirect/DirectP2P/screenshots/big_icon.png b/connectivity/wifidirect/DirectP2P/screenshots/big_icon.png
new file mode 100644
index 0000000..3b85da4
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/screenshots/big_icon.png
Binary files differ
diff --git a/connectivity/wifidirect/DirectP2P/settings.gradle b/connectivity/wifidirect/DirectP2P/settings.gradle
new file mode 100644
index 0000000..9464a35
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/settings.gradle
@@ -0,0 +1 @@
+include 'Application'
diff --git a/connectivity/wifidirect/DirectP2P/template-params.xml b/connectivity/wifidirect/DirectP2P/template-params.xml
new file mode 100644
index 0000000..859fda7
--- /dev/null
+++ b/connectivity/wifidirect/DirectP2P/template-params.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<sample>
+ <name>DirectP2P</name>
+ <group>Connectivity</group>
+ <package>com.example.android.wifidirectp2p</package>
+
+ <!-- change minSdk if needed-->
+ <minSdk>14</minSdk>
+
+ <!-- Include additional dependencies here.-->
+ <!-- dependency>com.google.android.gms:play-services:5.0.+</dependency -->
+
+ <strings>
+ <intro>
+ <![CDATA[
+ This is a demo application highlighting how to make peer to peer network connections with
+ the Wi-Fi Direct APIs.\n\nThe application allows you to transfer jpeg images from the
+ gallery after a successful connection.
+ The source code for this demo app shows how to accomplish three key things
+ with Wi-Fi Direct APIs: Discovering peers, connecting using Wi-Fi Direct APIs, and
+ finding group details post connection, so that a
+ TCP socket can be opened to transfer files.\n
+ If you are developing an application that uses the Wi-Fi Direct APIs, remember that the
+ feature is supported only on Android 4.0 (API level 14) and higher versions of
+ the platform.
+ ]]>
+ </intro>
+ </strings>
+
+ <template src="base" />
+
+ <common src="logger" />
+ <common src="activities"/>
+ <metadata>
+ <status>PUBLISHED</status>
+ <categories>Connectivity</categories>
+ <technologies>Android</technologies>
+ <languages>Java</languages>
+ <solutions>Mobile</solutions>
+ <level>ADVANCED</level>
+ <icon>screenshots/big_icon.png</icon>
+ <screenshots>
+ <img>screenshots/1-main.png</img>
+ <img>screenshots/2-discovery.png</img>
+ <img>screenshots/3-client.png</img>
+ </screenshots>
+ <api_refs>
+ <android>android.net.wifi.p2p.WifiP2pManager</android>
+ <android>android.net.wifi.p2p.WifiP2pDevice</android>
+ <android>android.net.wifi.p2p.WifiP2pConfig</android>
+ </api_refs>
+ <description>
+<![CDATA[
+Sample demonstrating the use of Wi-Fi Direct APIs for communication available on Android 4.0 (API level 14) and higher.
+Shows the use of the Peer to Peer APIs to set up bi-directional connectivity between two devices
+to send an image.
+]]>
+ </description>
+ <intro>
+<![CDATA[
+This is a demo application highlighting how to make peer to peer network connections with
+the Wi-Fi Direct APIs.\n\nThe application allows you to transfer jpeg images from the
+gallery after a successful connection.
+
+The source code for this demo app shows how to accomplish three key things
+with Wi-Fi Direct APIs: Discovering peers, connecting using Wi-Fi Direct APIs, and
+finding group details post connection, so that a TCP socket can be opened to transfer files.
+
+If you are developing an application that uses the Wi-Fi Direct APIs, remember that the
+feature is supported only on Android 4.0 (API level 14) and higher versions of
+the platform.
+]]>
+ </intro>
+</metadata>
+</sample>