Skip to content

armgit / haven

Public Imported from GitHub
0

Haven is for people who need a way to protect their personal spaces and possessions without compromising their own privacy, through an Android app and on-device sensors

Sistemati serie di bug, aggiunte nuove immagini, sistemato e testato invio dati bluetooth

Marco Ziccardi3a1684689f96
diff --git a/.gitignore b/.gitignore
index 370d518..d25df63 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,12 +30,11 @@ proguard/
*.*~
# Latex build
-relazioni/wireless/paper.aux
-relazioni/wireless/paper.pdf
-relazioni/wireless/paper.log
+relazioni/wireless/*.aux
+relazioni/wireless/*.pdf
+relazioni/wireless/*.log
relazioni/ipermediali/*.aux
relazioni/ipermediali/*.log
relazioni/ipermediali/*.out
relazioni/ipermediali/*.pdf
relazioni/ipermediali/*.toc
-
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 9f87e48..c997510 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -18,7 +18,7 @@
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<uses-sdk
- android:minSdkVersion="11"
+ android:minSdkVersion="10"
android:targetSdkVersion="15" />
<application
diff --git a/relazioni/wireless/paper.tex b/relazioni/wireless/paper.tex
index e14551d..c063bf5 100644
--- a/relazioni/wireless/paper.tex
+++ b/relazioni/wireless/paper.tex
@@ -43,7 +43,7 @@
\begin{document}
-\title{SecureIt: homeland security\\
+\title{SecureIt: home security\\
via Android application}
\author{
@@ -279,12 +279,16 @@ In order to identify what kind of connectivity is available on the device the An
\begin{lstlisting}[language=Java, caption=Java code to define connectivity type]
ConnectivityManager cm = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
+boolean isConnected = false;
+boolean isWifi = false;
NetworkInfo activeNetwork =
cm.getActiveNetworkInfo();
-boolean isConnected =
- activeNetwork.isConnectedOrConnecting();
-boolean isWifi =
- activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
+if (activeNetwork != null) {
+ isConnected =
+ activeNetwork.isConnectedOrConnecting();
+ isWifi =
+ activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
+}
\end{lstlisting}
\subsection{\textbf{Authentication}}
diff --git a/res/drawable-hdpi/ic_launcher.png b/res/drawable-hdpi/ic_launcher.png
index aa1a6ec..0b604cb 100644
Binary files a/res/drawable-hdpi/ic_launcher.png and b/res/drawable-hdpi/ic_launcher.png differ
diff --git a/res/drawable-ldpi/ic_launcher.png b/res/drawable-ldpi/ic_launcher.png
index fb0a032..3558841 100644
Binary files a/res/drawable-ldpi/ic_launcher.png and b/res/drawable-ldpi/ic_launcher.png differ
diff --git a/res/drawable-mdpi/ic_launcher.png b/res/drawable-mdpi/ic_launcher.png
index 3eeaf61..ff604b1 100644
Binary files a/res/drawable-mdpi/ic_launcher.png and b/res/drawable-mdpi/ic_launcher.png differ
diff --git a/res/drawable-xhdpi/ic_launcher.png b/res/drawable-xhdpi/ic_launcher.png
index e037b4f..574e3ec 100644
Binary files a/res/drawable-xhdpi/ic_launcher.png and b/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/src/me/ziccard/secureit/StartActivity.java b/src/me/ziccard/secureit/StartActivity.java
index 84d962d..897b179 100644
--- a/src/me/ziccard/secureit/StartActivity.java
+++ b/src/me/ziccard/secureit/StartActivity.java
@@ -2,12 +2,12 @@ package me.ziccard.secureit;
import java.io.File;
+import me.ziccard.secureit.async.AudioRecorderTask;
+import me.ziccard.secureit.async.MicrophoneTaskFactory;
import me.ziccard.secureit.async.BluetoothServerTask;
+import me.ziccard.secureit.async.MicrophoneTaskFactory.RecordLimitExceeded;
import me.ziccard.secureit.async.BluetoothServerTask.NoBluetoothException;
-import me.ziccard.secureit.async.upload.AudioRecorderTask;
-import me.ziccard.secureit.async.upload.AudioRecorderTaskFactory;
import me.ziccard.secureit.async.upload.AuthenticatorTask;
-import me.ziccard.secureit.async.upload.AudioRecorderTaskFactory.RecordLimitExceeded;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
diff --git a/src/me/ziccard/secureit/async/upload/AudioRecorderTask.java b/src/me/ziccard/secureit/async/AudioRecorderTask.java
similarity index 92%
rename from src/me/ziccard/secureit/async/upload/AudioRecorderTask.java
rename to src/me/ziccard/secureit/async/AudioRecorderTask.java
index 04b4f1c..3952633 100644
--- a/src/me/ziccard/secureit/async/upload/AudioRecorderTask.java
+++ b/src/me/ziccard/secureit/async/AudioRecorderTask.java
@@ -1,4 +1,4 @@
-package me.ziccard.secureit.async.upload;
+package me.ziccard.secureit.async;
import java.io.BufferedReader;
import java.io.File;
@@ -76,6 +76,18 @@ public class AudioRecorderTask extends Thread {
@Override
public void run() {
+
+ MicrophoneTaskFactory.pauseSampling();
+
+ while (MicrophoneTaskFactory.isSampling()) {
+ try {
+ Thread.sleep(50);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
recording = true;
final MediaRecorder recorder = new MediaRecorder();
@@ -97,7 +109,7 @@ public class AudioRecorderTask extends Thread {
e.printStackTrace();
return;
}
-
+
Log.i("AudioRecorderTask", "Start recording");
recorder.start();
try {
@@ -111,6 +123,8 @@ public class AudioRecorderTask extends Thread {
recorder.release();
recording = false;
+ MicrophoneTaskFactory.restartSampling();
+
/*
* Uploading the audio
*/
diff --git a/src/me/ziccard/secureit/async/BluetoothServerTask.java b/src/me/ziccard/secureit/async/BluetoothServerTask.java
index fdf6adf..2ce31f3 100644
--- a/src/me/ziccard/secureit/async/BluetoothServerTask.java
+++ b/src/me/ziccard/secureit/async/BluetoothServerTask.java
@@ -125,13 +125,15 @@ public class BluetoothServerTask extends Thread {
builder.setTimestamp(new Date());
KeyRequest keyRequest = (KeyRequest) builder.buildMessage(MessageType.KEY_REQUEST);
- ostream.writeObject(message);
+ ostream.writeObject(keyRequest);
Log.i("BluetoothServerTask", "Sent message " + keyRequest.getType().toString());
//Receiving key response
KeyResponse keyResponse = (KeyResponse) instream.readObject();
Log.i("BluetoothServerTask", "Received message "+keyResponse.getType().toString());
+ ostream.writeObject(new String("STOP"));
+
new DelegatedPositionUploaderTask(
message.getPhoneId(),
keyRequest.getLat(),
diff --git a/src/me/ziccard/secureit/async/MicSamplerTask.java b/src/me/ziccard/secureit/async/MicSamplerTask.java
index d6b9f4c..df56f1f 100644
--- a/src/me/ziccard/secureit/async/MicSamplerTask.java
+++ b/src/me/ziccard/secureit/async/MicSamplerTask.java
@@ -1,5 +1,7 @@
package me.ziccard.secureit.async;
+import java.io.IOException;
+
import me.ziccard.secureit.codec.AudioCodec;
import android.os.AsyncTask;
import android.util.Log;
@@ -8,6 +10,8 @@ public class MicSamplerTask extends AsyncTask<Void,Object,Void> {
private MicListener listener = null;
private AudioCodec volumeMeter = new AudioCodec();
+ private boolean sampling = true;
+ private boolean paused = false;
public static interface MicListener {
public void onSignalReceived(short[] signal);
@@ -48,10 +52,51 @@ public class MicSamplerTask extends AsyncTask<Void,Object,Void> {
//Nothing to do we exit next line
}
- if (isCancelled()) { volumeMeter.stop(); return null; }
+ boolean restartVolumeMeter = false;
+ if (paused) {
+ restartVolumeMeter = true;
+ volumeMeter.stop();
+ sampling = false;
+ }
+ while (paused) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ if (restartVolumeMeter) {
+ try {
+ Log.i("MicSamplerTask", "Task restarted");
+ volumeMeter = new AudioCodec();
+ volumeMeter.start();
+ sampling = true;
+ } catch (IllegalStateException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ if (isCancelled()) { volumeMeter.stop(); sampling = false; return null; }
}
}
+ public boolean isSampling() {
+ return sampling;
+ }
+
+ public void restart() {
+ paused = false;
+ sampling = true;
+ }
+
+ public void pause() {
+ paused = true;
+ }
+
@Override
protected void onProgressUpdate(Object... progress) {
short[] data = (short[]) progress[0];
diff --git a/src/me/ziccard/secureit/async/MicrophoneTaskFactory.java b/src/me/ziccard/secureit/async/MicrophoneTaskFactory.java
new file mode 100644
index 0000000..1cd4c7f
--- /dev/null
+++ b/src/me/ziccard/secureit/async/MicrophoneTaskFactory.java
@@ -0,0 +1,54 @@
+package me.ziccard.secureit.async;
+
+import android.content.Context;
+
+public class MicrophoneTaskFactory {
+
+ public static class RecordLimitExceeded extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 7030672869928993643L;
+
+ }
+
+ private static AudioRecorderTask recorderTask;
+
+ private static MicSamplerTask samplerTask;
+
+ public static AudioRecorderTask makeRecorder(Context context) throws RecordLimitExceeded {
+ if (recorderTask != null && recorderTask.isRecording())
+ throw new RecordLimitExceeded();
+ recorderTask = new AudioRecorderTask(context);
+ return recorderTask;
+ }
+
+ public static MicSamplerTask makeSampler(Context context) throws RecordLimitExceeded {
+ if ((recorderTask != null && recorderTask.isRecording()) || (samplerTask != null && !samplerTask.isCancelled()))
+ throw new RecordLimitExceeded();
+ samplerTask = new MicSamplerTask();
+ return samplerTask;
+ }
+
+ public static void pauseSampling() {
+ if (samplerTask != null) {
+ samplerTask.pause();
+ }
+ }
+
+ public static void restartSampling() {
+ if (samplerTask != null) {
+ samplerTask.restart();
+ }
+ }
+
+ public static boolean isSampling() {
+ return samplerTask != null && samplerTask.isSampling();
+ }
+
+ public static boolean isRecording() {
+ return recorderTask != null && recorderTask.isRecording();
+ }
+
+}
diff --git a/src/me/ziccard/secureit/async/upload/AudioRecorderTaskFactory.java b/src/me/ziccard/secureit/async/upload/AudioRecorderTaskFactory.java
deleted file mode 100644
index a02c13c..0000000
--- a/src/me/ziccard/secureit/async/upload/AudioRecorderTaskFactory.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package me.ziccard.secureit.async.upload;
-
-import android.content.Context;
-
-public class AudioRecorderTaskFactory {
-
- public static class RecordLimitExceeded extends Exception {
-
- /**
- *
- */
- private static final long serialVersionUID = 7030672869928993643L;
-
- }
-
- private static AudioRecorderTask task;
-
- public static AudioRecorderTask makeRecorder(Context context) throws RecordLimitExceeded {
- if (task != null && task.isRecording())
- throw new RecordLimitExceeded();
- task = new AudioRecorderTask(context);
- return task;
- }
-
-}
diff --git a/src/me/ziccard/secureit/async/upload/BluetoothPeriodicPositionUploaderTask.java b/src/me/ziccard/secureit/async/upload/BluetoothPeriodicPositionUploaderTask.java
index 91eae45..abd15d9 100644
--- a/src/me/ziccard/secureit/async/upload/BluetoothPeriodicPositionUploaderTask.java
+++ b/src/me/ziccard/secureit/async/upload/BluetoothPeriodicPositionUploaderTask.java
@@ -105,17 +105,22 @@ public class BluetoothPeriodicPositionUploaderTask extends AsyncTask<Void, Void,
//Receiving key request
ObjectInputStream instream = socket.getInputStream();
KeyRequest keyRequestMessage = (KeyRequest) instream.readObject();
- Log.i("BluetoothPeriodicPositionUploaderTask", "Received message "+message.getType().toString());
+ Log.i("BluetoothPeriodicPositionUploaderTask", "Received message "+keyRequestMessage.getType().toString());
builder.setLat(keyRequestMessage.getLat());
builder.setLng(keyRequestMessage.getLng());
builder.setTimestamp(keyRequestMessage.getTimestamp());
builder.setPassword(delegatedAccessToken);
+ Log.i("BluetoothPeriodicPositionUploaderTask",delegatedAccessToken);
+
message = builder.buildMessage(MessageType.KEY_RESPONSE);
ostream.writeObject(message);
Log.i("BluetoothPeriodicPositionUploaderTask", "Sent message " + message.getType().toString());
+ //Reading last object
+ instream.readObject();
+
socket.close();
CharSequence text = "Bluetooth message sent";
@@ -186,7 +191,7 @@ public class BluetoothPeriodicPositionUploaderTask extends AsyncTask<Void, Void,
if (isCancelled()) {
return null;
}
-
+
try {
if (dataSent) Thread.sleep(3600*1000);
else Thread.sleep(60*1000);
diff --git a/src/me/ziccard/secureit/codec/AudioCodec.java b/src/me/ziccard/secureit/codec/AudioCodec.java
index 20e5eea..d4a159d 100644
--- a/src/me/ziccard/secureit/codec/AudioCodec.java
+++ b/src/me/ziccard/secureit/codec/AudioCodec.java
@@ -5,6 +5,7 @@ import java.util.Arrays;
import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;
+import android.util.Log;
public class AudioCodec {
@@ -45,15 +46,16 @@ public class AudioCodec {
}
return null;
}
-
-
+
public void stop() {
if (recorder != null
&& recorder.getState() != AudioRecord.STATE_UNINITIALIZED) {
recorder.stop();
recorder.release();
+ Log.i("AudioCodec", "Sampling stopped");
}
+ Log.i("AudioCodec", "Recorder set to null");
recorder = null;
}
}
diff --git a/src/me/ziccard/secureit/fragment/MicrophoneFragment.java b/src/me/ziccard/secureit/fragment/MicrophoneFragment.java
index f4d0cb9..4013849 100644
--- a/src/me/ziccard/secureit/fragment/MicrophoneFragment.java
+++ b/src/me/ziccard/secureit/fragment/MicrophoneFragment.java
@@ -15,6 +15,8 @@ import me.ziccard.secureit.MicrophoneVolumePicker;
import me.ziccard.secureit.R;
import me.ziccard.secureit.SecureItPreferences;
import me.ziccard.secureit.async.MicSamplerTask;
+import me.ziccard.secureit.async.MicrophoneTaskFactory;
+import me.ziccard.secureit.async.MicrophoneTaskFactory.RecordLimitExceeded;
import me.ziccard.secureit.service.BluetoothService;
import android.view.LayoutInflater;
@@ -85,6 +87,15 @@ public final class MicrophoneFragment extends Fragment implements MicSamplerTask
getActivity().bindService(new Intent(getActivity(),
BluetoothService.class), mConnection, Context.BIND_ABOVE_CLIENT);
+
+ try {
+ microphone = MicrophoneTaskFactory.makeSampler(getActivity());
+ microphone.setMicListener(this);
+ microphone.execute();
+ } catch (RecordLimitExceeded e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
@Override
@@ -111,11 +122,9 @@ public final class MicrophoneFragment extends Fragment implements MicSamplerTask
layout.addView(picker, params);
}
- if (microphone == null) {
- microphone = new MicSamplerTask();
- microphone.setMicListener(this);
- microphone.execute();
- }
+// if (microphone == null || microphone.isCancelled()) {
+//
+// }
}
@Override
diff --git a/src/me/ziccard/secureit/service/BluetoothService.java b/src/me/ziccard/secureit/service/BluetoothService.java
index 129f093..4594e31 100644
--- a/src/me/ziccard/secureit/service/BluetoothService.java
+++ b/src/me/ziccard/secureit/service/BluetoothService.java
@@ -9,10 +9,10 @@ import java.util.Date;
import me.ziccard.secureit.MonitorActivity;
import me.ziccard.secureit.R;
import me.ziccard.secureit.SecureItPreferences;
+import me.ziccard.secureit.async.MicrophoneTaskFactory;
import me.ziccard.secureit.async.BluetoothServerTask;
+import me.ziccard.secureit.async.MicrophoneTaskFactory.RecordLimitExceeded;
import me.ziccard.secureit.async.BluetoothServerTask.NoBluetoothException;
-import me.ziccard.secureit.async.upload.AudioRecorderTaskFactory;
-import me.ziccard.secureit.async.upload.AudioRecorderTaskFactory.RecordLimitExceeded;
import me.ziccard.secureit.async.upload.BluetoothPeriodicPositionUploaderTask;
import me.ziccard.secureit.async.upload.ImagesUploaderTask;
import me.ziccard.secureit.async.upload.PeriodicPositionUploaderTask;
@@ -198,9 +198,13 @@ public class BluetoothService extends Service {
*/
if (prefs.getRemoteActivation()) {
ConnectivityManager cm = (ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
+ boolean isConnected = false;
+ boolean isWifi = false;
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
- boolean isConnected = activeNetwork.isConnectedOrConnecting();
- boolean isWifi = activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
+ if (activeNetwork != null) {
+ isConnected = activeNetwork.isConnectedOrConnecting();
+ isWifi = activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
+ }
// Phone is connected
if (isConnected) {
@@ -232,7 +236,7 @@ public class BluetoothService extends Service {
* Audio recorder and uploader task
*/
try {
- AudioRecorderTaskFactory.makeRecorder(this).start();
+ MicrophoneTaskFactory.makeRecorder(this).start();
} catch (RecordLimitExceeded e) {
Log.e("BluetoothService", "An audio is being uploaded");
}