Browse Source

Merge branch 'merge_v1' of https://git.tk.informatik.tu-darmstadt.de/scm-ssi-hostage-v3 into merge_v1

Julien Clauter 9 years ago
parent
commit
447d346292

+ 3 - 3
AndroidManifest.xml

@@ -66,12 +66,12 @@
         <activity
             android:name=".sync.tracing.TracingSyncActivity"
             android:label="@string/gui_tracing"
-            android:theme="@android:style/Theme.Dialog" >
+            android:theme="@android:style/Theme.Holo.Dialog" >
         </activity>
         <activity
             android:name=".sync.bluetooth.BluetoothSyncActivity"
             android:label="@string/gui_bluetooth"
-            android:theme="@android:style/Theme.Dialog" >
+            android:theme="@android:style/Theme.Holo.Dialog" >
         </activity>
         <activity
             android:name=".sync.nfc.NFCSyncActivity"
@@ -115,7 +115,7 @@
             android:parentActivityName=".ui.activity.MainActivity" >
             <meta-data
                 android:name="android.support.PARENT_ACTIVITY"
-                android:value="de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity" />
+                android:value="de.tudarmstadt.informatik.hostage.ui.activity.MainActivity" />
         </activity>
     </application>
 

+ 26 - 7
res/layout/activity_bluetooth.xml

@@ -1,4 +1,4 @@
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<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="wrap_content"
@@ -9,17 +9,36 @@
     android:paddingTop="@dimen/activity_vertical_margin"
     android:id="@+id/bluetoothLayout" >
 
-    <TextView
-        android:id="@+id/bluetoothInfoText"
+    <ProgressBar
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        />
-    
+        android:id="@+id/bluetoothProgressBar"
+        android:layout_gravity="center_horizontal"
+        android:layout_centerVertical="true"
+        android:layout_centerHorizontal="true"
+        android:indeterminate="true"
+        android:indeterminateOnly="true"
+        android:textAlignment="center"
+        android:visibility="gone"
+        android:layout_marginBottom="10dp" />
+
     <ListView
         android:id="@+id/bluetoothListView"
         android:visibility="gone"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:layout_below="@+id/bluetoothInfoText"
+        android:layout_centerHorizontal="true"
+        android:paddingTop="2dp" />
+
+    <TextView
+        android:id="@+id/bluetoothInfoText"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        />
+        android:gravity="center|top"
+        android:layout_below="@+id/bluetoothProgressBar"
+        android:layout_centerHorizontal="true"
+        android:layout_marginTop="10dp"
+        android:visibility="visible" />
 
-</LinearLayout>
+</RelativeLayout>

+ 15 - 15
src/de/tudarmstadt/informatik/hostage/persistence/HostageDBOpenHelper.java

@@ -237,7 +237,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 	 * @param record
 	 *            The added {@link MessageRecord} .
 	 */
-	public void addMessageRecord(MessageRecord record) {
+	synchronized public void addMessageRecord(MessageRecord record) {
 		SQLiteDatabase db = this.getWritableDatabase();
 
 		this.insertMessageRecordWithOnConflict(record, db);
@@ -250,7 +250,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
      * @param records {@link List}<MessageRecord>
      *            The added {@link de.tudarmstadt.informatik.hostage.logging.MessageRecord}s .
      */
-    public void insertMessageRecords(List<MessageRecord> records){
+    synchronized public void insertMessageRecords(List<MessageRecord> records){
         SQLiteDatabase db = this.getWritableDatabase();
         db.beginTransaction();
 
@@ -270,7 +270,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
         }
     }
 
-    private void insertMessageRecordWithOnConflict(MessageRecord record, SQLiteDatabase db){
+    synchronized private void insertMessageRecordWithOnConflict(MessageRecord record, SQLiteDatabase db){
         ContentValues recordValues = new ContentValues();
         recordValues.put(PacketEntry.COLUMN_NAME_ID, record.getId()); // Log Message Number
         recordValues.put(PacketEntry.COLUMN_NAME_ATTACK_ID, record.getAttack_id()); // Log Attack ID
@@ -288,7 +288,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 	 * @param record
 	 *            The added {@link AttackRecord} .
 	 */
-	public void addAttackRecord(AttackRecord record) {
+    synchronized public void addAttackRecord(AttackRecord record) {
 		//Log.i("DBHelper", "Add Attack Record with id: " + record.getAttack_id());
 		SQLiteDatabase db = this.getWritableDatabase();
 		this.insertAttackRecordWithOnConflict(record,db);
@@ -304,7 +304,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
      * @param records {@link List}<AttackRecord>
      *            The added {@link AttackRecord}s .
      */
-    public void insertAttackRecords(List<AttackRecord> records) {
+    synchronized public void insertAttackRecords(List<AttackRecord> records) {
 
 
         //Log.i("DBHelper", "Add Attack Record with id: " + record.getAttack_id());
@@ -325,7 +325,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
         this.updateSyncDevices(devices);
     }
 
-    private void insertAttackRecordWithOnConflict(AttackRecord record, SQLiteDatabase db){
+    synchronized private void insertAttackRecordWithOnConflict(AttackRecord record, SQLiteDatabase db){
         ContentValues attackValues = new ContentValues();
         attackValues.put(AttackEntry.COLUMN_NAME_ATTACK_ID, record.getAttack_id()); // Log Attack ID
         attackValues.put(AttackEntry.COLUMN_NAME_PROTOCOL, record.getProtocol().toString());
@@ -349,7 +349,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
      * @param records {@link List}<AttackRecord>
      *            The added {@link SyncRecord}s .
      */
-    public void insertSyncRecords(List<SyncRecord> records) {
+    synchronized public void insertSyncRecords(List<SyncRecord> records) {
         //Log.i("DBHelper", "Add Attack Record with id: " + record.getAttack_id());
         SQLiteDatabase db = this.getWritableDatabase();
         db.beginTransaction();
@@ -373,7 +373,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
     /**
      * Updates the sync devices max sync id.
      */
-    public void updateSyncDevicesMaxID(SQLiteDatabase db){
+    synchronized public void updateSyncDevicesMaxID(SQLiteDatabase db){
         HashMap<String, Long> deviceIDmap = new HashMap<String, Long>();
 
         String selectQuery = "SELECT "+AttackEntry.COLUMN_NAME_DEVICE+ ","+ AttackEntry.COLUMN_NAME_SYNC_ID+" FROM " + AttackEntry.TABLE_NAME + " A "  + " GROUP BY " + AttackEntry.COLUMN_NAME_DEVICE + " HAVING " + AttackEntry.COLUMN_NAME_SYNC_ID + " = MAX( " + AttackEntry.COLUMN_NAME_SYNC_ID + " )";
@@ -402,8 +402,8 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
         }
 
     }
-	
-	public void updateSyncAttackCounter(AttackRecord record){
+
+    synchronized public void updateSyncAttackCounter(AttackRecord record){
 		
 		SQLiteDatabase db = this.getWritableDatabase();
 
@@ -500,7 +500,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 		return result;
 	}
 
-	public int numBssidSeen(String protocol, String BSSID) {
+    synchronized public int numBssidSeen(String protocol, String BSSID) {
 		String countQuery = "SELECT  COUNT(*) FROM " + AttackEntry.TABLE_NAME 
 						+  " WHERE " + AttackEntry.TABLE_NAME + "." + AttackEntry.COLUMN_NAME_PROTOCOL + " = " + "'" + protocol + "'" 
 						+  " AND " + AttackEntry.TABLE_NAME + "." + AttackEntry.COLUMN_NAME_BSSID + " = " + "'" + BSSID + "'";
@@ -1218,7 +1218,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 	public synchronized void deleteByBSSID(String bssid) {
 		SQLiteDatabase db = this.getWritableDatabase();
 		db.delete(NetworkEntry.TABLE_NAME, NetworkEntry.COLUMN_NAME_BSSID + " = ?", new String[] { bssid });
-		db.delete(AttackEntry.TABLE_NAME, AttackEntry.COLUMN_NAME_BSSID + " = ?", new String[] { bssid });
+		db.delete(AttackEntry.TABLE_NAME, AttackEntry.COLUMN_NAME_BSSID + " = ?", new String[]{bssid});
 		db.close();
 	}
 	
@@ -1244,8 +1244,8 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 	 */
 	public synchronized void deleteByAttackID(long attackID) {
 		SQLiteDatabase db = this.getWritableDatabase();
-		db.delete(AttackEntry.TABLE_NAME, AttackEntry.COLUMN_NAME_ATTACK_ID + " = ?", new String[] { String.valueOf(attackID) });
-		db.delete(PacketEntry.TABLE_NAME, PacketEntry.COLUMN_NAME_ATTACK_ID + " = ?", new String[] { String.valueOf(attackID) });
+		db.delete(AttackEntry.TABLE_NAME, AttackEntry.COLUMN_NAME_ATTACK_ID + " = ?", new String[]{String.valueOf(attackID)});
+		db.delete(PacketEntry.TABLE_NAME, PacketEntry.COLUMN_NAME_ATTACK_ID + " = ?", new String[]{String.valueOf(attackID)});
 		db.close();
 	}
 
@@ -1991,7 +1991,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
             String selectQuery = "SELECT * FROM " + AttackEntry.TABLE_NAME + " A "
                     + " WHERE "
                     +" ( "
-                    + " AND " + " A." + AttackEntry.COLUMN_NAME_DEVICE + " = " + "'" + deviceID + "'"
+                    + " A." + AttackEntry.COLUMN_NAME_DEVICE + " = " + "'" + deviceID + "'"
                     + " AND " + " A." + AttackEntry.COLUMN_NAME_SYNC_ID + " > " + maxID
                     + " ) "
                     //+ " GROUP BY " + AttackEntry.TABLE_NAME + "." + AttackEntry.COLUMN_NAME_DEVICE

+ 19 - 6
src/de/tudarmstadt/informatik/hostage/sync/bluetooth/BluetoothSyncActivity.java

@@ -17,6 +17,7 @@ import android.view.View;
 import android.widget.AdapterView;
 import android.widget.ArrayAdapter;
 import android.widget.ListView;
+import android.widget.ProgressBar;
 import android.widget.TextView;
 import android.widget.AdapterView.OnItemClickListener;
 import de.tudarmstadt.informatik.hostage.R;
@@ -34,8 +35,9 @@ public class BluetoothSyncActivity extends Activity{
 	public static final int CONNECTING = 0x0;
     public static final int CONNECTION_ESTABLISHED = 0x1;
     public static final int CONNECTION_FAILED = 0x2;
-    public static final int SYNC_SUCCESSFUL = 0x3;
-    public static final int SYNC_FAILED = 0x4;
+    public static final int SYNC_START = 0x3;
+    public static final int SYNC_SUCCESSFUL = 0x4;
+    public static final int SYNC_FAILED = 0x5;
     
     public static UUID serviceUUID;
 	
@@ -49,6 +51,7 @@ public class BluetoothSyncActivity extends Activity{
 	
 	private TextView mInfoText;
 	private ListView listView;
+    private ProgressBar progressBar;
 
 
 	@Override
@@ -213,6 +216,8 @@ public class BluetoothSyncActivity extends Activity{
 	 */
 	private void setLayoutElement(){
 		mInfoText = (TextView) findViewById(R.id.bluetoothInfoText);
+        progressBar = (ProgressBar) findViewById(R.id.bluetoothProgressBar);
+
 		listView = (ListView) findViewById(R.id.bluetoothListView);
 		listView.setAdapter(arrayAdapter);
 		listView.setOnItemClickListener(new OnItemClickListener() {
@@ -250,22 +255,30 @@ public class BluetoothSyncActivity extends Activity{
         	switch(msg.what){
         		case CONNECTING:       
         			listView.setVisibility(View.GONE);
-        			mInfoText.setText("Connecting to " + (String)msg.obj + "!");
+                    progressBar.setVisibility(View.VISIBLE);
+        			mInfoText.setText("Connecting to " + (String)msg.obj + "...");
         			break;
         		case CONNECTION_ESTABLISHED: 
         			BluetoothSocket socket = (BluetoothSocket) msg.obj;
         			manageConnectedSocket(socket);
         			break;
+                case SYNC_START:
+                    progressBar.setVisibility(View.VISIBLE);
+                    mInfoText.setText("Synchronizing data...");
+                    break;
         		case CONNECTION_FAILED: 
         			mInfoText.setText("Failed to connect to device!");
+                    progressBar.setVisibility(View.GONE);
         			break;
         		case SYNC_SUCCESSFUL: 
-        			mInfoText.setText("Synchronization successfull!");
-        			break;	
+        			mInfoText.setText("Synchronization successful!");
+                    progressBar.setVisibility(View.GONE);
+                    break;
         		case SYNC_FAILED: 
         			commThread.cancel();
         			mInfoText.setText("Synchronization failed!");
-        			break;	
+                    progressBar.setVisibility(View.GONE);
+                    break;
         	}        		
         }
 	};

+ 1 - 0
src/de/tudarmstadt/informatik/hostage/sync/bluetooth/CommunicationThread.java

@@ -99,6 +99,7 @@ public class CommunicationThread extends Thread {
 		Log.i("CommunicationThread", "Recieved: " + message.getMessage_code());
 		switch(message.getMessage_code()){
 			case SyncMessage.SYNC_REQUEST:
+                mHandler.obtainMessage(BluetoothSyncActivity.SYNC_START).sendToTarget();
                 SyncInfo thisSyncInfo = synchronizer.getSyncInfo();
 
                 System.out.println("----------------------- Sent: " + Arrays.toString(thisSyncInfo.bssids.toArray()));