From c8236b794794890f432a871831e0af58230805ee Mon Sep 17 00:00:00 2001 From: n8fr8 Date: Thu, 2 Nov 2017 21:25:50 -0400 Subject: [PATCH] make sure monitor service is running --- .../phoneypot/service/MonitorService.java | 12 ++++++++++++ .../phoneypot/service/PowerConnectionReceiver.java | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/info/guardianproject/phoneypot/service/MonitorService.java b/src/main/java/info/guardianproject/phoneypot/service/MonitorService.java index beb800ad..144fada2 100644 --- a/src/main/java/info/guardianproject/phoneypot/service/MonitorService.java +++ b/src/main/java/info/guardianproject/phoneypot/service/MonitorService.java @@ -75,6 +75,7 @@ public class MonitorService extends Service { BarometerMonitor mBaroMonitor = null; AmbientLightMonitor mLightMonitor = null; + private boolean mIsRunning = false; /** * Last Event instances */ @@ -150,6 +151,7 @@ public void onDestroy() { stopForeground(true); + } /** @@ -199,8 +201,16 @@ private void showNotification() { } + public boolean isRunning () + { + return mIsRunning = true; + + } + private void startSensors () { + mIsRunning = true; + if (prefs.getAccelerometerSensitivity() != PreferenceManager.OFF) { mAccelManager = new AccelerometerMonitor(this); mBaroMonitor = new BarometerMonitor(this); @@ -215,6 +225,8 @@ private void startSensors () private void stopSensors () { + mIsRunning = false; + if (prefs.getAccelerometerSensitivity() != PreferenceManager.OFF) { mAccelManager.stop(this); mBaroMonitor.stop(this); diff --git a/src/main/java/info/guardianproject/phoneypot/service/PowerConnectionReceiver.java b/src/main/java/info/guardianproject/phoneypot/service/PowerConnectionReceiver.java index f27a3b24..cc23397d 100644 --- a/src/main/java/info/guardianproject/phoneypot/service/PowerConnectionReceiver.java +++ b/src/main/java/info/guardianproject/phoneypot/service/PowerConnectionReceiver.java @@ -26,7 +26,8 @@ public void onReceive(Context context, Intent intent) { boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB; boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC; - if (MonitorService.getInstance() != null) { + if (MonitorService.getInstance() != null + && MonitorService.getInstance().isRunning()) { MonitorService.getInstance().alert(EventTrigger.POWER, context.getString(R.string.status_charging) + isCharging + " USB:" + usbCharge + " AC:" + acCharge); } }