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

add wakelock to keep it from sleeping

n8fr84ffba258856f
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index b0e6aa5..4d712d8 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -10,6 +10,7 @@
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
+ <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-sdk
android:minSdkVersion="10"
diff --git a/src/main/java/info/guardianproject/phoneypot/MonitorActivity.java b/src/main/java/info/guardianproject/phoneypot/MonitorActivity.java
index 12be427..166a5ee 100644
--- a/src/main/java/info/guardianproject/phoneypot/MonitorActivity.java
+++ b/src/main/java/info/guardianproject/phoneypot/MonitorActivity.java
@@ -11,6 +11,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
+import android.os.Handler;
import android.support.v4.app.FragmentActivity;
import android.text.InputType;
import android.view.Menu;
@@ -33,11 +34,22 @@ public class MonitorActivity extends FragmentActivity {
preferences = new PreferenceManager(getApplicationContext());
setContentView(R.layout.layout_running);
-
+
+ Toast.makeText(this,"Monitoring will begin in 10 seconds",Toast.LENGTH_LONG).show();
/**
* starting the alert srevice
*/
- startService(new Intent(this, MonitorService.class));
+
+ final Handler handler = new Handler();
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ //Do something after 100ms
+ startService(new Intent(MonitorActivity.this, MonitorService.class));
+
+ }
+ }, 10 * 1000);
+
}
diff --git a/src/main/java/info/guardianproject/phoneypot/service/MonitorService.java b/src/main/java/info/guardianproject/phoneypot/service/MonitorService.java
index 048e8bc..bc93eef 100644
--- a/src/main/java/info/guardianproject/phoneypot/service/MonitorService.java
+++ b/src/main/java/info/guardianproject/phoneypot/service/MonitorService.java
@@ -15,9 +15,12 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
+import android.os.PowerManager;
import android.support.v4.app.NotificationCompat;
import android.telephony.SmsManager;
+import java.util.Date;
+
import info.guardianproject.phoneypot.MonitorActivity;
import info.guardianproject.phoneypot.R;
import info.guardianproject.phoneypot.PreferenceManager;
@@ -81,7 +84,12 @@ public class MonitorService extends Service {
* Messenger interface used by clients to interact
*/
private final Messenger messenger = new Messenger(new MessageHandler());
-
+
+ /*
+ ** Helps keep the service awake when screen is off
+ */
+ PowerManager.WakeLock wakeLock;
+
/**
* Called on service creation, sends a notification
*/
@@ -93,6 +101,11 @@ public class MonitorService extends Service {
startSensors();
showNotification();
+
+ PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
+ wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK,
+ "MyWakelockTag");
+ wakeLock.acquire();
}
/**
@@ -102,6 +115,7 @@ public class MonitorService extends Service {
@Override
public void onDestroy() {
+ wakeLock.release();
stopSensors();
stopForeground(true);
@@ -177,20 +191,25 @@ public class MonitorService extends Service {
if (alertType == mLastAlert)
return;
- String alertMessage = getString(R.string.intrusion_detected);
+ StringBuffer alertMessage = new StringBuffer();
+
+ alertMessage.append(getString(R.string.intrusion_detected));
+
switch (alertType)
{
case MonitorService.ACCELEROMETER_MESSAGE:
- alertMessage += ": Device was moved!";
+ alertMessage.append(": Device was moved!");
break;
case MonitorService.MICROPHONE_MESSAGE:
- alertMessage += ": Noise detected!";
+ alertMessage.append(": Noise detected!");
break;
case MonitorService.CAMERA_MESSAGE:
- alertMessage += ": Camera motion detected!";
+ alertMessage.append(": Camera motion detected!");
break;
}
+ alertMessage.append(" @ " + new Date().toLocaleString());
+
/*
* If SMS mode is on we send an SMS alert to the specified
* number
@@ -198,11 +217,11 @@ public class MonitorService extends Service {
if (prefs.getSmsActivation()) {
//get the manager
SmsManager manager = SmsManager.getDefault();
- manager.sendTextMessage(prefs.getSmsNumber(), null, alertMessage, null, null);
+ manager.sendTextMessage(prefs.getSmsNumber(), null, alertMessage.toString(), null, null);
}
- showNotificationAlert(alertMessage);
+ showNotificationAlert(alertMessage.toString());
mLastAlert = alertType;
}
@@ -230,7 +249,7 @@ public class MonitorService extends Service {
mBuilder.setContentIntent(resultPendingIntent);
- manager.notify(mNotificationAlertId, mBuilder.build());
+ manager.notify(mNotificationAlertId++, mBuilder.build());
}