Commit bfc1aa2c authored by akwizgran's avatar akwizgran

Check for deep sleep on alarm and when receiving data.

parent 71a37357
......@@ -23,6 +23,7 @@ class NetworkClient extends Thread {
private final String host;
private final int port, keepaliveIntervalMs, keepaliveBytes;
private final Logger log;
private final SleepMonitor sleepMonitor;
private final PowerManager.WakeLock wakeLock;
private Socket socket = null; // Locking: this
......@@ -39,7 +40,9 @@ class NetworkClient extends Thread {
this.port = port;
this.keepaliveIntervalMs = keepaliveIntervalMs;
this.keepaliveBytes = keepaliveBytes;
log = ((SnoozeApplication) appContext).getLogger();
SnoozeApplication app = (SnoozeApplication) appContext;
log = app.getLogger();
sleepMonitor = app.getSleepMonitor();
PowerManager pm = (PowerManager) appContext.getSystemService(POWER_SERVICE);
if (pm == null) throw new AssertionError();
wakeLock = pm.newWakeLock(PARTIAL_WAKE_LOCK, LOCK_TAG);
......@@ -103,6 +106,7 @@ class NetworkClient extends Thread {
int read = in.read(buf, offset, buf.length - offset);
if (read == -1) break;
log.log("Read " + read + " bytes");
sleepMonitor.run();
offset += read;
}
if (offset < buf.length) break;
......
......@@ -5,16 +5,22 @@ import android.app.Application;
public class SnoozeApplication extends Application {
private volatile Logger log = null;
private volatile SleepMonitor sleepMonitor = null;
@Override
public void onCreate() {
super.onCreate();
log = new Logger(this, getString(R.string.app_name));
log.log("Application created");
new SleepMonitor(log).start();
sleepMonitor = new SleepMonitor(log);
sleepMonitor.start();
}
Logger getLogger() {
return log;
}
SleepMonitor getSleepMonitor() {
return sleepMonitor;
}
}
......@@ -60,6 +60,7 @@ public class SnoozeService extends Service {
private String host = null;
private volatile Logger log = null;
private volatile SleepMonitor sleepMonitor = null;
@Override
public IBinder onBind(Intent intent) {
......@@ -69,7 +70,9 @@ public class SnoozeService extends Service {
@Override
public void onCreate() {
super.onCreate();
log = ((SnoozeApplication) getApplication()).getLogger();
SnoozeApplication app = (SnoozeApplication) getApplication();
log = app.getLogger();
sleepMonitor = app.getSleepMonitor();
log.log("Service created");
registerReceiver(receiver, receiver.getIntentFilter());
if (SDK_INT >= 26) {
......@@ -110,6 +113,7 @@ public class SnoozeService extends Service {
} else if (ACTION_ALARM.equals(i.getAction())) {
AlarmType alarmType = AlarmType.valueOf(i.getStringExtra(EXTRA_ALARM_TYPE));
log.log("Alarm " + alarmType);
sleepMonitor.run();
if (alarm == null) {
log.log("Service recreated by alarm");
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment