Browse Source

WifiDirect connection and pairing is working. Just sending still not really working.

Alexander Brakowski 9 years ago
parent
commit
713777b7a7

+ 38 - 27
AndroidManifest.xml

@@ -11,7 +11,9 @@
     <uses-permission android:name="android.permission.VIBRATE" />
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
@@ -19,15 +21,18 @@
     <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
     <uses-permission android:name="android.permission.NFC" />
     <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
-<!--	<uses-permission android:name="android.permission.BLUETOOTH" />
+    <!--
+    	<uses-permission android:name="android.permission.BLUETOOTH" />
     <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
--->
-	<uses-feature
+    -->
+    <uses-feature
         android:name="android.hardware.nfc"
         android:required="false" />
 
+    <uses-feature android:name="android.hardware.wifi.direct" android:required="true"/>
+
     <application
-		android:name=".HostageApplication"
+        android:name=".HostageApplication"
         android:allowBackup="true"
         android:allowClearUserData="true"
         android:hardwareAccelerated="true"
@@ -39,39 +44,37 @@
         <meta-data
             android:name="com.google.android.gms.version"
             android:value="@integer/google_play_services_lib_version" />
-		<meta-data
-			android:name="com.google.android.maps.v2.API_KEY"
-			android:value="@string/google_maps_api_key_release" />
+        <meta-data
+            android:name="com.google.android.maps.v2.API_KEY"
+            android:value="@string/google_maps_api_key_release" />
 
         <activity
-            android:name="de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity"
+            android:name=".ui2.activity.MainActivity"
             android:configChanges="keyboardHidden|orientation|screenSize"
             android:label="@string/app_name"
-            android:screenOrientation="portrait" > 
-           	<intent-filter>
+            android:screenOrientation="portrait" >
+            <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
+
                 <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>  
-  
+            </intent-filter>
         </activity>
-
         <activity
             android:name=".ui2.activity.ProfileEditActivity"
             android:label="Edit Profile" >
         </activity>
-
         <activity
-            android:name="de.tudarmstadt.informatik.hostage.sync.tracing.TracingSyncActivity"
+            android:name=".sync.tracing.TracingSyncActivity"
             android:label="@string/gui_tracing"
             android:theme="@android:style/Theme.Dialog" >
         </activity>
         <activity
-            android:name="de.tudarmstadt.informatik.hostage.sync.bluetooth.BluetoothSyncActivity"
+            android:name=".sync.bluetooth.BluetoothSyncActivity"
             android:label="@string/gui_bluetooth"
             android:theme="@android:style/Theme.Dialog" >
         </activity>
         <activity
-            android:name="de.tudarmstadt.informatik.hostage.sync.nfc.NFCSync"
+            android:name=".sync.nfc.NFCSync"
             android:label="@string/gui_nfc"
             android:theme="@android:style/Theme.Dialog" >
             <intent-filter>
@@ -84,28 +87,36 @@
         </activity>
 
         <service
-            android:name="de.tudarmstadt.informatik.hostage.Hostage"
+            android:name=".Hostage"
             android:exported="false" >
         </service>
         <service
-            android:name="de.tudarmstadt.informatik.hostage.logging.Logger"
+            android:name=".logging.Logger"
             android:exported="false" >
         </service>
         <service
-            android:name="de.tudarmstadt.informatik.hostage.sync.tracing.TracingSyncService"
+            android:name=".sync.tracing.TracingSyncService"
+            android:exported="false" >
+        </service>
+        <service
+            android:name=".logging.LogExport"
             android:exported="false" >
         </service>
 
-	    <service
-		    android:name="de.tudarmstadt.informatik.hostage.logging.LogExport"
-	        android:exported="false">
-	    </service>
-
-	    <provider
-            android:name="de.tudarmstadt.informatik.hostage.provider.HostageContentProvider"
+        <provider
+            android:name=".provider.HostageContentProvider"
             android:authorities="de.tudarmstadt.informatik.hostage.provider"
             android:exported="false" >
         </provider>
+
+        <activity
+            android:name=".sync.p2p.P2PSyncActivity"
+            android:label="@string/title_activity_p2_psync"
+            android:parentActivityName=".ui2.activity.MainActivity" >
+            <meta-data
+                android:name="android.support.PARENT_ACTIVITY"
+                android:value="de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity" />
+        </activity>
     </application>
 
 </manifest>

+ 164 - 0
res/layout/activity_p2_psync.xml

@@ -0,0 +1,164 @@
+<RelativeLayout 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"
+    android:paddingLeft="@dimen/activity_horizontal_margin"
+    android:paddingRight="@dimen/activity_horizontal_margin"
+    android:paddingTop="@dimen/activity_vertical_margin"
+    android:paddingBottom="@dimen/activity_vertical_margin"
+    tools:context="de.tudarmstadt.informatik.hostage.sync.p2p.P2PSyncActivity">
+
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:textAppearance="?android:attr/textAppearanceMedium"
+        android:text="Your Device"
+        android:id="@+id/textView4"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentStart="true"
+        android:layout_alignRight="@+id/device_info_panel"
+        android:layout_alignEnd="@+id/device_info_panel"
+        android:textStyle="bold" />
+
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:textAppearance="?android:attr/textAppearanceSmall"
+        android:text="Change device name"
+        android:id="@+id/txtP2PChangeDeviceName"
+        android:layout_alignParentTop="true"
+        android:layout_alignParentRight="true"
+        android:layout_alignParentEnd="true"
+        android:textColor="@android:color/holo_blue_dark"
+        android:visibility="gone" />
+
+    <RelativeLayout
+        android:id="@+id/device_info_panel"
+        android:orientation="horizontal"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:background="@drawable/panel_white_bg"
+        android:padding="10dp"
+        android:layout_below="@+id/textView4"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentStart="true"
+        android:layout_marginTop="5dp">
+
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textAppearance="?android:attr/textAppearanceSmall"
+            android:text="Device name"
+            android:id="@+id/textView"
+            android:textStyle="bold" />
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textAppearance="?android:attr/textAppearanceSmall"
+            android:id="@+id/txt_p2p_device_name"
+            android:layout_alignParentRight="true"
+            android:layout_alignParentEnd="true"
+            android:layout_alignParentTop="true"
+            android:layout_toRightOf="@+id/textView"
+            android:layout_toEndOf="@+id/textView"
+            android:gravity="right" />
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textAppearance="?android:attr/textAppearanceSmall"
+            android:text="Device status"
+            android:id="@+id/textView2"
+            android:layout_below="@+id/textView"
+            android:layout_alignParentLeft="true"
+            android:layout_alignParentStart="true"
+            android:textStyle="bold"
+            android:layout_marginTop="6dp" />
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textAppearance="?android:attr/textAppearanceSmall"
+            android:id="@+id/txt_p2p_device_status"
+            android:gravity="right"
+            android:layout_alignRight="@+id/txt_p2p_device_name"
+            android:layout_below="@+id/txt_p2p_device_name"
+            android:layout_toRightOf="@+id/textView2"
+            android:layout_toEndOf="@+id/textView2"
+            android:layout_marginTop="6dp" />
+    </RelativeLayout>
+
+    <ViewAnimator
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:id="@+id/viewAnimator"
+        android:layout_below="@+id/device_info_panel"
+        android:layout_alignParentBottom="true"
+        android:layout_alignParentRight="true"
+        android:layout_alignParentEnd="true"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentStart="true">
+
+        <RelativeLayout
+            android:layout_width="fill_parent"
+            android:layout_height="fill_parent"
+            android:visibility="gone"
+            android:id="@+id/welcomeContainer">
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="We are sorry, but WiFi Direct does not seem to be supported by this device."
+                android:id="@+id/txtP2PNotAvailable"
+                android:textAlignment="center"
+                android:gravity="center_horizontal"
+                android:layout_centerVertical="true"
+                android:layout_alignParentLeft="true"
+                android:layout_alignParentStart="true"
+                android:visibility="gone" />
+
+        </RelativeLayout>
+
+        <RelativeLayout
+            android:layout_width="fill_parent"
+            android:layout_height="fill_parent"
+            android:layout_alignParentBottom="true"
+            android:layout_alignParentRight="true"
+            android:layout_alignParentEnd="true"
+            android:id="@+id/devicesContainer">
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textAppearance="?android:attr/textAppearanceMedium"
+                android:text="Available Devices"
+                android:id="@+id/textView5"
+                android:layout_alignParentTop="true"
+                android:layout_alignParentLeft="true"
+                android:layout_alignParentStart="true"
+                android:textStyle="bold"
+                android:layout_marginTop="10dp"
+                android:layout_marginBottom="6dp" />
+
+            <ListView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:id="@+id/lstP2PDevices"
+                android:layout_below="@+id/textView5" />
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textAppearance="?android:attr/textAppearanceSmall"
+                android:text="Looking for devices..."
+                android:id="@+id/txtP2PSearchProgress"
+                android:layout_centerVertical="true"
+                android:layout_centerHorizontal="true" />
+
+        </RelativeLayout>
+
+    </ViewAnimator>
+
+</RelativeLayout>

+ 1 - 1
res/layout/fragment_about.xml

@@ -72,7 +72,7 @@
 					android:layout_height="wrap_content"
 					android:textAppearance="?android:attr/textAppearanceMedium"
 					android:text="Fabio Arnold"
-					android:id="@+id/textView2"
+					android:id="@+id/txtP2PSubheader"
 					android:layout_gravity="center_horizontal|left"
 					android:singleLine="false" android:autoText="false" android:layout_marginTop="4dp"
 					android:textAlignment="center"/>

+ 1 - 1
res/layout/fragment_connectioninfo_dialog.xml

@@ -35,7 +35,7 @@
 					android:layout_height="wrap_content"
 					android:textAppearance="?android:attr/textAppearanceMedium"
 					android:text="@string/bssid"
-					android:id="@+id/textView2" android:layout_column="0"
+					android:id="@+id/txtP2PSubheader" android:layout_column="0"
 					android:layout_margin="4dp"
 					android:textStyle="bold"/>
 			<TextView

+ 1 - 1
res/layout/fragment_record_detail.xml

@@ -47,7 +47,7 @@
 					android:textAppearance="?android:attr/textAppearanceSmall"
 					android:text="@string/RecordSSID"
 					android:textAllCaps="true"
-					android:id="@+id/textView2"
+					android:id="@+id/txtP2PSubheader"
 					android:gravity="center"
 					android:layout_alignParentTop="true"
 					android:layout_alignParentLeft="true"

+ 2 - 2
res/layout/fragment_settings.xml

@@ -19,7 +19,7 @@
 				android:layout_height="wrap_content"
 				android:textAppearance="?android:attr/textAppearanceMedium"
 				android:text="@string/porthack_installed"
-				android:id="@+id/textView2"
+				android:id="@+id/txtP2PSubheader"
 				android:layout_below="@+id/record_details_text_ssid" android:layout_alignParentLeft="true"
 				android:layout_alignParentStart="true" android:textStyle="bold"/>
 		<TextView
@@ -27,7 +27,7 @@
 				android:layout_height="wrap_content"
 				android:textAppearance="?android:attr/textAppearanceMedium"
 				android:text="@string/yes"
-				android:id="@+id/settings_device_rooted" android:layout_above="@+id/textView2"
+				android:id="@+id/settings_device_rooted" android:layout_above="@+id/txtP2PSubheader"
 				android:layout_alignParentRight="true" android:layout_alignParentEnd="true"/>
 		<TextView
 				android:layout_width="wrap_content"

+ 3 - 3
res/layout/profile_manager_list_item_help.xml

@@ -13,7 +13,7 @@
 			android:layout_height="wrap_content"
 			android:textAppearance="?android:attr/textAppearanceSmall"
 			android:text="@string/profile_help_swipe"
-			android:id="@+id/textView"
+			android:id="@+id/txtP2PSearchProgress"
 			android:layout_alignParentTop="true"
 			android:layout_toRightOf="@+id/imageView"
 			android:layout_marginLeft="15dp"
@@ -27,7 +27,7 @@
 			android:layout_alignParentTop="true"
 			android:layout_alignParentLeft="true"
 			android:layout_alignParentStart="true"
-			android:layout_alignBottom="@+id/textView"
+			android:layout_alignBottom="@+id/txtP2PSearchProgress"
 			android:scaleType="fitCenter"/>
 
 	<FrameLayout
@@ -44,6 +44,6 @@
 			android:layout_alignParentTop="true"
 			android:layout_alignParentRight="true"
 			android:layout_alignParentEnd="true"
-			android:layout_alignBottom="@+id/textView"/>
+			android:layout_alignBottom="@+id/txtP2PSearchProgress"/>
 
 </RelativeLayout>

+ 34 - 0
res/layout/row_devices.xml

@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<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_launcher" />
+    <LinearLayout
+        android:orientation="vertical"
+        android:layout_width="0dip"
+        android:layout_weight="1"
+        android:layout_height="fill_parent">
+        <TextView
+            android:id="@+id/device_name"
+            android:layout_width="fill_parent"
+            android:layout_height="0dip"
+            android:layout_weight="1"
+            android:gravity="center_vertical"
+            android:textStyle="bold" />
+        <TextView
+            android:layout_width="fill_parent"
+            android:layout_height="0dip"
+            android:layout_weight="1"
+            android:id="@+id/device_details"
+            android:singleLine="true"
+            android:ellipsize="marquee" />
+    </LinearLayout>
+</LinearLayout>

+ 8 - 0
res/menu/p2_psync.xml

@@ -0,0 +1,8 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    tools:context="de.tudarmstadt.informatik.hostage.sync.p2p.P2PSyncActivity" >
+    <item android:id="@+id/action_settings"
+        android:title="@string/action_settings"
+        android:orderInCategory="100"
+        android:showAsAction="never" />
+</menu>

+ 6 - 0
res/values-w820dp/dimens.xml

@@ -0,0 +1,6 @@
+<resources>
+    <!-- Example customization of dimensions originally defined in res/values/dimens.xml
+         (such as screen margins) for screens with more than 820dp of available width. This
+         would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
+    <dimen name="activity_horizontal_margin">64dp</dimen>
+</resources>

+ 47 - 59
res/values/strings.xml

@@ -6,23 +6,22 @@
     <string name="action_about">About</string>
     <string name="capital_on">OFF</string>
     <string name="capital_off">ON</string>
-	<string name="title_connection_info">Connection Info</string>
+    <string name="title_connection_info">Connection Info</string>
     <string name="status">Status</string>
     <string name="paranoid">Paranoid Mode</string>
     <string name="details">Connection info</string>
     <string name="not_connected">Not connected</string>
-    <string name="attack">&#160;attack</string>
-    <string name="attacks">&#160;attacks</string>
+    <string name="attack"> attack</string>
+    <string name="attacks"> attacks</string>
     <string name="secure">Secure</string>
     <string name="insecure">Insecure</string>
-    <string name="logged">&#160;logged</string>
-    <string name="recorded">&#160;recorded</string>
+    <string name="logged"> logged</string>
+    <string name="recorded"> recorded</string>
     <string name="zero_attacks">0 attacks recorded</string>
-
     <string name="information">Information</string>
-	<string name="wifi_not_connected_msg">You are not connected to a WiFi network. \n\nPlease connect to one, before trying to activate HosTaGe.</string>
-	<string name="network_not_connected_msg">You are not connected to any network. \n\nPlease connect to one, before trying to activate HosTaGe.</string>
-	<string name="no_network_connection_threatmap_msg">Currently you are not connected to the Internet.\n\nPlease establish a connection to use the Threatmap.</string>
+    <string name="wifi_not_connected_msg">You are not connected to a WiFi network. \n\nPlease connect to one, before trying to activate HosTaGe.</string>
+    <string name="network_not_connected_msg">You are not connected to any network. \n\nPlease connect to one, before trying to activate HosTaGe.</string>
+    <string name="no_network_connection_threatmap_msg">Currently you are not connected to the Internet.\n\nPlease establish a connection to use the Threatmap.</string>
     <string name="profile_no_services_msg">The current active profile does not seem to monitor any services.\n\nPlease activate some services to monitor in the profile.</string>
     <string name="no_portbinder_msg">Your device does not have \'Portbinder\' installed. Due to the limitations of Android OS, you could only use services that are utilizing ports > 1024.\n\nTo enable full functionality of HosTaGe, please make sure your device is rooted and \'Portbinder\' is installed.</string>
     <string name="no_portbinder_msg2">Your device cannot use the full feature of HosTaGe yet. Click \'Help\' to find out how to enable this.</string>
@@ -37,49 +36,42 @@
     <string name="helpPortbinder">Please follow the instructions in our website to install \'Portbinder\'.\n\nAlternatively, you can use the automated installer by pressing the \'Just Help Me!\' button.</string>
     <string name="confirm_msg">This automated installer fetches the appropriate Portbinder binary and installs in a location within the device.\n\nThis automated process will CHANGE some folder permissions to work. Proceed on your own risk.\n\nConfirm to proceed with automated installation of Portbinder?</string>
     <string name="help_me">Just Help Me!</string>
-
-	<string name="profile_needs_name">An profile needs a name. Please type in a name and press save again.</string>
+    <string name="profile_needs_name">An profile needs a name. Please type in a name and press save again.</string>
     <string name="monitor_current_connection">Monitor current connection</string>
     <string name="active_profile">Active profile: </string>
-
     <string name="ssid">SSID:</string>
     <string name="bssid">BSSID:</string>
-	<string name="protocol">Protocol:</string>
-	<string name="timestamp">Timestamp:</string>
-	<string name="location">Location:</string>
+    <string name="protocol">Protocol:</string>
+    <string name="timestamp">Timestamp:</string>
+    <string name="location">Location:</string>
     <string name="internal_ip">Internal IP:</string>
     <string name="external_ip">External IP:</string>
-	<string name="remote_ip">Remote IP:</string>
-	<string name="packet_type">Packet type:</string>
-	<string name="packet_content">Packet content:</string>
-
+    <string name="remote_ip">Remote IP:</string>
+    <string name="packet_type">Packet type:</string>
+    <string name="packet_content">Packet content:</string>
     <string name="services">Services</string>
     <string name="connections">Recorded connections:</string>
     <string name="statistics">Statistics</string>
-    <string name="database">Database</string>    
-	<string name="log_actions">Actions</string>
-	<string name="firstAttack">First Attack:</string>
-	<string name="lastAttack">Last Attack:</string>
-	<string name="clear">Clear</string>
-	<string name="delete">Delete</string>
-	<string name="cancel">Cancel</string>
-	<string name="close">Close</string>
-	<string name="show_records">Show records</string>
-	<string name="dialog_clear_database">Clear all data?</string>	
-	<string name="export_dialog_title">Choose Export Format</string>		
-	<string name="delete_dialog_title">Delete data sets by:</string>	
-	<string name="dialog_clear_database_date">Delete all data before:</string>
-
-	<string name="threatmap_show_records"><u>Show records</u></string>
-	
+    <string name="database">Database</string>
+    <string name="log_actions">Actions</string>
+    <string name="firstAttack">First Attack:</string>
+    <string name="lastAttack">Last Attack:</string>
+    <string name="clear">Clear</string>
+    <string name="delete">Delete</string>
+    <string name="cancel">Cancel</string>
+    <string name="close">Close</string>
+    <string name="show_records">Show records</string>
+    <string name="dialog_clear_database">Clear all data?</string>
+    <string name="export_dialog_title">Choose Export Format</string>
+    <string name="delete_dialog_title">Delete data sets by:</string>
+    <string name="dialog_clear_database_date">Delete all data before:</string>
+    <string name="threatmap_show_records"><u>Show records</u></string>
     <string name="RecordBSSID">BSSID</string>
     <string name="RecordSSID">SSID</string>
     <string name="RecordTimestamp">timestamp</string>
     <string name="RecordProtocol">protocol</string>
-
     <string name="drawer_open">Open navigation drawer</string>
     <string name="drawer_close">Close navigation drawer</string>
-
     <string name="drawer_overview">Overview</string>
     <string name="drawer_threat_map">Threat Map</string>
     <string name="drawer_records">Records</string>
@@ -87,29 +79,23 @@
     <string name="drawer_settings">Settings</string>
     <string name="drawer_profile_manager">Profiles</string>
     <string name="drawer_app_info">Application info</string>
-	<string name="drawer_statistics">Statistics</string>
-	<string name="drawer_help">Help videos</string>
-
+    <string name="drawer_statistics">Statistics</string>
+    <string name="drawer_help">Help videos</string>
     <string name="button_title_apply">Apply</string>
     <string name="button_title_cancel">Cancel</string>
     <string name="shared_preference_path">de.tudarmstadt.informatik.hostage.preferences</string>
     <string name="UUID">9fc4f490-659e-11e3-949a-0800200c9a66</string>
-
     <string name="recorded_attacks">recorded attacks: </string>
     <string name="current_connection">Current connection</string>
     <string name="monitor_services">Monitor services</string>
-
     <string name="device_rooted">Device rooted</string>
     <string name="porthack_installed">Porthack installed</string>
     <string name="yes">Yes</string>
     <string name="no">No</string>
-
     <string name="no_data_notification">No Attacks are recorded. Please check your filter option.</string>
     <string name="no_data_notification_no_filter">No Attacks are recorded.</string>
-
     <string name="TODAY">Today</string>
     <string name="YESTERDAY">Yesterday</string>
-
     <string name="hostage_with_url"><a href="http://www.tk.informatik.tu-darmstadt.de/de/research/secure-smart-infrastructures/hostage">HosTaGe</a></string>
     <string name="hostage_email"><a href="mailto:hostage@tk.informatik.tu-darmstadt.de?Subject=Inquiry">Tell us what do you think about HosTaGe</a></string>
     <string name="hostage_email_only">hostage@tk.informatik.tu-darmstadt.de</string>
@@ -125,7 +111,7 @@
     <string name="delete_profile">Delete profile</string>
     <string name="discard">Discard</string>
     <string name="save">Save</string>
-	<string name="really_want_delete_profiel">Do you really want to delete this profile?</string>
+    <string name="really_want_delete_profiel">Do you really want to delete this profile?</string>
     <string name="rec_protocol">Protocol</string>
     <string name="date">Date</string>
     <string name="ESSID">ESSID</string>
@@ -161,25 +147,24 @@
     <string name="stats_select_protocol_data">Select protocol data to compare</string>
     <string name="stats_per_cent_all">% of all</string>
     <string name="pie_all">All</string>
-
-	<string name="record_details_received">RECEIVED</string>
-	<string name="record_details_sent">SENT</string>
-	<string name="record_details_info" formatted="false">from %s to %s\n%s at %s</string>
-	<string name="record_details_dateformat" formatted="false">MMMM d, yyyy \'at\' H:m:s a</string>
-	<string name="record_details_nocontent">No content</string>
-	<string name="record_details_remote_ip">REMOTE IP</string>
-	<string name="record_details_conversation">Conversation</string>
-	<string name="record_details_confirm_delete">Do you really want to delete this record?</string>
+    <string name="record_details_received">RECEIVED</string>
+    <string name="record_details_sent">SENT</string>
+    <string name="record_details_info" formatted="false">from %s to %s\n%s at %s</string>
+    <string name="record_details_dateformat" formatted="false">MMMM d, yyyy \'at\' H:m:s a</string>
+    <string name="record_details_nocontent">No content</string>
+    <string name="record_details_remote_ip">REMOTE IP</string>
+    <string name="record_details_conversation">Conversation</string>
+    <string name="record_details_confirm_delete">Do you really want to delete this record?</string>
     <string name="profile_vista_desc">This profile will imitate a Windows Vista machine</string>
-	<string name="profile_seven_desc">This profile will imitate a Windows 7 machine</string>
+    <string name="profile_seven_desc">This profile will imitate a Windows 7 machine</string>
     <string name="profile_xp_desc">This profile will activate Windows XP typical services</string>
     <string name="profile_webserv_http_desc">This profile will imitate a simple webserver, which just supports the HTTP protocol</string>
-	<string name="profile_webserv_apache_desc">This profile will imitate an apache web server</string>
-	<string name="profile_webserv_iis_desc">This profile will imitate an IIS web server</string>
+    <string name="profile_webserv_apache_desc">This profile will imitate an apache web server</string>
+    <string name="profile_webserv_iis_desc">This profile will imitate an IIS web server</string>
     <string name="profile_webserv_desc">This profile will imitate a simple webserver, which supports both the HTTP and HTTPS protocol</string>
     <string name="profile_unix_desc">This profile monitors unix typical services</string>
     <string name="profile_linux_desc">This profile will imitate a linux machine by monitoring linux typical services</string>
-	<string name="profile_linux_hard_desc">This profile will imitate a linux machine which has just SSH activated</string>
+    <string name="profile_linux_hard_desc">This profile will imitate a linux machine which has just SSH activated</string>
     <string name="profile_voip_desc">This profile imitates a VOIP Server by monitoring the SIP service</string>
     <string name="profile_random_desc">This profile monitors services randomly</string>
     <string name="profile_paranoid_desc">This profile monitors all available services</string>
@@ -197,4 +182,7 @@
     <string name="rec_via_bt">Via Bluetooth</string>
     <string name="rec_via_nfc">Via NFC</string>
     <string name="rec_via_online">Via Online Database</string>
+    <string name="title_activity_p2_psync">P2PSyncActivity</string>
+    <string name="hello_world">Hello world!</string>
+
 </resources>

+ 47 - 0
src/de/tudarmstadt/informatik/hostage/sync/p2p/P2PBroadcastReceiver.java

@@ -0,0 +1,47 @@
+package de.tudarmstadt.informatik.hostage.sync.p2p;
+
+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;
+
+
+public class P2PBroadcastReceiver extends BroadcastReceiver {
+
+    private WifiP2pManager mManager;
+    private WifiP2pManager.Channel mChannel;
+    private P2PSyncActivity mActivity;
+
+    public P2PBroadcastReceiver(WifiP2pManager manager, WifiP2pManager.Channel channel, P2PSyncActivity activity){
+        this.mManager = manager;
+        this.mChannel = channel;
+        this.mActivity = activity;
+    }
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        String action = intent.getAction();
+
+        if(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)){
+            int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
+            if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
+                mActivity.setWifiDirectAvailable();
+            } else {
+                mActivity.setWifiDirectNotAvailable();
+            }
+        } else if(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)){
+            mManager.requestPeers(mChannel, mActivity);
+        } else if(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)){
+            NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
+
+            if(networkInfo.isConnected()){
+                mManager.requestConnectionInfo(mChannel, mActivity);
+            }
+        } else if(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)){
+            WifiP2pDevice device = (WifiP2pDevice) intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);
+            mActivity.updateThisDevice(device);
+        }
+    }
+}

+ 403 - 0
src/de/tudarmstadt/informatik/hostage/sync/p2p/P2PSyncActivity.java

@@ -0,0 +1,403 @@
+package de.tudarmstadt.informatik.hostage.sync.p2p;
+
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.IntentFilter;
+import android.net.wifi.p2p.WifiP2pConfig;
+import android.net.wifi.p2p.WifiP2pDevice;
+import android.net.wifi.p2p.WifiP2pDeviceList;
+import android.net.wifi.p2p.WifiP2pGroup;
+import android.net.wifi.p2p.WifiP2pInfo;
+import android.net.wifi.p2p.WifiP2pManager;
+import android.os.AsyncTask;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Environment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.ListView;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+import android.widget.ViewAnimator;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.ArrayList;
+import java.util.List;
+
+import de.tudarmstadt.informatik.hostage.R;
+
+public class P2PSyncActivity extends Activity implements WifiP2pManager.PeerListListener, WifiP2pManager.ChannelListener, AdapterView.OnItemClickListener, WifiP2pManager.ConnectionInfoListener {
+    private WifiP2pManager mManager;
+    private WifiP2pManager.Channel mChannel;
+    private BroadcastReceiver mReceiver;
+    private IntentFilter mIntentFilter;
+
+    private List<WifiP2pDevice> peers = new ArrayList<WifiP2pDevice>();
+
+    private TextView mTxtP2PDeviceName;
+    private TextView mTxtP2PDeviceStatus;
+    private ViewAnimator mViewAnimator;
+    private RelativeLayout mDevicesContainer;
+    private TextView mTxtP2PSearchProgress;
+    private ListView mLstP2PDevices;
+    private RelativeLayout mWelcomeContainer;
+    private TextView mTxtP2PNotAvailable;
+    private TextView mTxtP2PChangeDeviceName;
+
+    private WifiP2pDevice mDevice;
+    private WifiP2pDevice mOtherDevice;
+    private WifiP2pInfo mInfo;
+
+    private final int OWNER_SERVER_PORT = 8988;
+    private final int CLIENT_SERVER_PORT = 8989;
+
+    private void extractFromView(){
+        mTxtP2PDeviceName = (TextView) findViewById(R.id.txt_p2p_device_name);
+        mTxtP2PDeviceStatus = (TextView) findViewById(R.id.txt_p2p_device_status);
+        mTxtP2PChangeDeviceName = (TextView) findViewById(R.id.txtP2PChangeDeviceName);
+
+        //mTxtP2PHeader = (TextView) findViewById(R.id.txtP2PHeader);
+        //mTxtP2PSubHeader = (TextView) findViewById(R.id.txtP2PSubheader);
+        //mTxtP2PHelpBack = (TextView) findViewById(R.id.txtP2PHelpBack);
+        mViewAnimator = (ViewAnimator) findViewById(R.id.viewAnimator);
+        mDevicesContainer = (RelativeLayout) findViewById(R.id.devicesContainer);
+        mWelcomeContainer = (RelativeLayout) findViewById(R.id.welcomeContainer);
+        mTxtP2PSearchProgress = (TextView) findViewById(R.id.txtP2PSearchProgress);
+        mLstP2PDevices = (ListView) findViewById(R.id.lstP2PDevices);
+        //mBtnP2PSearch = (Button) findViewById(R.id.btnP2PSearch);
+        mTxtP2PNotAvailable = (TextView) findViewById(R.id.txtP2PNotAvailable);
+    }
+
+    public void discoverPeers(){
+        mManager.discoverPeers(mChannel, new WifiP2pManager.ActionListener() {
+            @Override
+            public void onSuccess() {
+                mViewAnimator.showNext();
+                mTxtP2PSearchProgress.setVisibility(View.VISIBLE);
+
+                setWifiDirectAvailable();
+            }
+
+            @Override
+            public void onFailure(int reason) {
+                if(reason == WifiP2pManager.P2P_UNSUPPORTED) {
+                    setWifiDirectNotAvailable();
+                }
+            }
+        });
+    }
+
+    public void setWifiDirectNotAvailable(){
+        //mBtnP2PSearch.setVisibility(View.GONE);
+        mTxtP2PNotAvailable.setVisibility(View.VISIBLE);
+    }
+
+    public void setWifiDirectAvailable(){
+        //mBtnP2PSearch.setVisibility(View.VISIBLE);
+        mTxtP2PNotAvailable.setVisibility(View.GONE);
+    }
+
+    public void registerListeners(){
+        mTxtP2PChangeDeviceName.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                Method method1 = null;
+                try {
+                    method1 = mManager.getClass().getDeclaredMethod("setDeviceName", WifiP2pManager.Channel.class);
+                    method1.invoke(mManager, mChannel, "Android_fc546");
+                } catch (NoSuchMethodException e) {
+                    e.printStackTrace();
+                } catch (InvocationTargetException e) {
+                    e.printStackTrace();
+                } catch (IllegalAccessException e) {
+                    e.printStackTrace();
+                }
+            }
+        });
+    }
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_p2_psync);
+
+        assert getActionBar() != null;
+        getActionBar().setTitle("WifiDirect Synchronization");
+
+        this.extractFromView();
+        this.registerListeners();
+
+        this.mLstP2PDevices.setAdapter(new WiFiPeerListAdapter(this, R.layout.row_devices, peers));
+        this.mLstP2PDevices.setOnItemClickListener(this);
+
+        mManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
+        mChannel = mManager.initialize(this, getMainLooper(), new WifiP2pManager.ChannelListener() {
+            @Override
+            public void onChannelDisconnected() {
+                System.out.println("---------------------> CHannel disconnect!!!");
+            }
+        });
+
+        mIntentFilter = new IntentFilter();
+        mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
+        mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
+        mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
+        mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
+
+        this.discoverPeers();
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        mReceiver = new P2PBroadcastReceiver(mManager, mChannel, this);
+        registerReceiver(mReceiver, mIntentFilter);
+    }
+
+    @Override
+    protected void onPause() {
+        super.onPause();
+        unregisterReceiver(mReceiver);
+    }
+
+    @Override
+    public void onPeersAvailable(WifiP2pDeviceList peerList){
+        mTxtP2PSearchProgress.setVisibility(View.GONE);
+        peers.clear();
+        peers.addAll(peerList.getDeviceList());
+        ((WiFiPeerListAdapter) mLstP2PDevices.getAdapter()).notifyDataSetChanged();
+        if (peers.size() == 0) {
+            return;
+        }
+    }
+
+    private static String getDeviceStatus(int 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";
+        }
+    }
+
+    public void updateThisDevice(WifiP2pDevice device) {
+        this.mDevice = device;
+
+        mTxtP2PDeviceName.setText(device.deviceName);
+        mTxtP2PDeviceStatus.setText(getDeviceStatus(device.status));
+    }
+
+    @Override
+    public void onChannelDisconnected() {
+
+    }
+
+    @Override
+    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+        final WifiP2pDevice device = (WifiP2pDevice) this.mLstP2PDevices.getAdapter().getItem(position);
+        WifiP2pConfig config = new WifiP2pConfig();
+        config.deviceAddress = device.deviceAddress;
+
+        mManager.connect(mChannel, config, new WifiP2pManager.ActionListener() {
+            @Override
+            public void onSuccess() {
+                mOtherDevice = device;
+            }
+
+            @Override
+            public void onFailure(int reason) {
+                //mOtherDevice = null;
+
+                Toast.makeText(P2PSyncActivity.this, "Could not connect to device. Retry.", Toast.LENGTH_LONG).show();
+            }
+        });
+    }
+
+    @Override
+    public void onConnectionInfoAvailable(WifiP2pInfo info) {
+        mInfo = info;
+        //if(mOtherDevice == null) return;
+
+        if(info.groupFormed && info.isGroupOwner){
+            new FileServerAsyncTask(this, OWNER_SERVER_PORT).execute();
+            //new FileTransferAsyncTask(this, mOtherDevice.deviceAddress, CLIENT_SERVER_PORT).execute();
+        } else if(info.groupFormed){
+            //new FileServerAsyncTask(this, CLIENT_SERVER_PORT).execute();
+            new FileTransferAsyncTask(this, mInfo.groupOwnerAddress.getHostAddress(), OWNER_SERVER_PORT).execute();
+        }
+    }
+
+    public void sendDatabase(boolean isOwner){
+
+    }
+
+    /**
+     * 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) 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) {
+                    if(device.status == WifiP2pDevice.CONNECTED){
+                        mOtherDevice = device;
+                    }
+                    bottom.setText(getDeviceStatus(device.status));
+                }
+            }
+            return v;
+        }
+    }
+
+    public static class FileServerAsyncTask extends AsyncTask<Void, Void, String> {
+        private Context context;
+        private int port;
+
+        /**
+         * @param context
+         */
+        public FileServerAsyncTask(Context context, int port) {
+            this.context = context;
+            this.port = port;
+        }
+        @Override
+        protected String doInBackground(Void... params) {
+            try {
+                ServerSocket serverSocket = new ServerSocket(this.port);
+
+                Socket client = serverSocket.accept();
+                /*final File f = new File(Environment.getExternalStorageDirectory() + "/"
+                        + context.getPackageName() + "/wifip2pshared-" + System.currentTimeMillis()
+                        + ".txt");
+                File dirs = new File(f.getParent());
+                if (!dirs.exists())
+                    dirs.mkdirs();
+                f.createNewFile();*/
+                InputStream inputstream = client.getInputStream();
+                readToToast(inputstream);
+
+                client.getOutputStream().write(("HELLO I HOPE THIS WILL REACH IT'S DESTINATION. I am server").getBytes());
+
+                //copyFile(inputstream, new FileOutputStream(f));
+                serverSocket.close();
+                return "";
+            } catch (IOException e) {
+                return null;
+            }
+        }
+
+
+        public void readToToast(InputStream inputStream){
+            byte buf[] = new byte[1024];
+            StringBuffer bf = new StringBuffer();
+
+            int len;
+            try {
+                while ((len = inputStream.read(buf)) != -1) {
+                    bf.append(buf);
+
+                }
+                inputStream.close();
+            } catch (IOException e) {
+                return;
+            }
+
+            Toast.makeText(context, "Received: " + bf.toString(), Toast.LENGTH_LONG).show();
+        }
+    }
+
+    public static class FileTransferAsyncTask extends AsyncTask<Void, Void, Void> {
+        private Context context;
+        private int port;
+        private String host;
+        private static final int SOCKET_TIMEOUT = 5000;
+
+        /**
+         * @param context
+         */
+        public FileTransferAsyncTask(Context context, String host, int port) {
+            this.context = context;
+            this.host = host;
+            this.port = port;
+        }
+
+        @Override
+        protected Void doInBackground(Void... params) {
+            Socket socket = new Socket();
+
+            try {
+                socket.bind(null);
+                socket.connect(new InetSocketAddress(host, port), SOCKET_TIMEOUT);
+
+                OutputStream stream = socket.getOutputStream();
+
+                stream.write(("HELLO I HOPE THIS WILL REACH IT'S DESTINATION. I am " + host).getBytes());
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+
+            return null;
+        }
+    }
+
+
+    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) {
+            return false;
+        }
+        return true;
+    }
+
+}

+ 6 - 1
src/de/tudarmstadt/informatik/hostage/ui2/fragment/RecordOverviewFragment.java

@@ -45,6 +45,7 @@ import de.tudarmstadt.informatik.hostage.logging.Record;
 import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
 import de.tudarmstadt.informatik.hostage.sync.bluetooth.BluetoothSyncActivity;
 import de.tudarmstadt.informatik.hostage.sync.nfc.NFCSync;
+import de.tudarmstadt.informatik.hostage.sync.p2p.P2PSyncActivity;
 import de.tudarmstadt.informatik.hostage.sync.tracing.TracingSyncActivity;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 import de.tudarmstadt.informatik.hostage.ui2.adapter.RecordListAdapter;
@@ -359,7 +360,8 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
 				builder.setItems(new String[]{
 						MainActivity.getInstance().getString(R.string.rec_via_bt),
 						MainActivity.getInstance().getString(R.string.rec_via_nfc),
-						MainActivity.getInstance().getString(R.string.rec_via_online)
+						MainActivity.getInstance().getString(R.string.rec_via_online),
+                        "Via WifiDirect"
 				}, new DialogInterface.OnClickListener() {
 					@Override
 					public void onClick(DialogInterface dialog, int position) {
@@ -374,6 +376,9 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
 							case 2:
 								getActivity().startActivity(new Intent(getActivity(), TracingSyncActivity.class));
 								break;
+                            case 3:
+                                getActivity().startActivity(new Intent(getActivity(), P2PSyncActivity.class));
+                                break;
 						}
 					}
 				});