|
|
|
@ -101,6 +101,10 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
public final static int MSG_WHAT_MAX = 1000;
|
|
|
|
|
|
|
|
|
|
public final static int BROADCAST_REQUEST_CODE_HEARTBEAT = 1;
|
|
|
|
|
public final static int BROADCAST_REQUEST_CODE_TAKING_PHOTO = 2;
|
|
|
|
|
public final static int BROADCAST_REQUEST_CODE_GPS = 2;
|
|
|
|
|
|
|
|
|
|
public static final int NOTIFICATION_ID_FOREGROUND_SERVICE = 8466503;
|
|
|
|
|
public static final String ACTION_MSG_BROADCAST = "ACT_MSG_BROADCAST";
|
|
|
|
|
|
|
|
|
@ -422,11 +426,12 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
mService.sendHeartbeat(mService.mNativeHandle, mService.getSignalLevel());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Thread th = new Thread(runnable);
|
|
|
|
|
th.start();
|
|
|
|
|
|
|
|
|
|
mService.registerHeartbeatTimer(mService.mHeartbeatDuration);
|
|
|
|
|
|
|
|
|
|
long expectedHbTime = intent.getLongExtra("HeartbeatTime", 0);
|
|
|
|
|
long timeout = (expectedHbTime != 0) ? (expectedHbTime + mService.mHeartbeatDuration - System.currentTimeMillis()) : mService.mHeartbeatDuration;
|
|
|
|
|
mService.registerHeartbeatTimer(timeout);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
@ -653,7 +658,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
alarmIntent.setAction(ACTION_HEARTBEAT);
|
|
|
|
|
alarmIntent.putExtra("HeartbeatDuration", mHeartbeatDuration);
|
|
|
|
|
alarmIntent.putExtra("HeartbeatTime", triggerTime);
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, BROADCAST_REQUEST_CODE_HEARTBEAT, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
|
|
|
Date date = new Date(triggerTime);
|
|
|
|
|
String dateStr = (String) DateFormat.format("kk:mm:ss", date);
|
|
|
|
@ -696,7 +701,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
|
|
|
|
|
localBroadcastManager.sendBroadcast(intent);
|
|
|
|
|
} else {
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, BROADCAST_REQUEST_CODE_TAKING_PHOTO, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);
|
|
|
|
|
try {
|
|
|
|
@ -705,12 +710,12 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeout, pendingIntent);
|
|
|
|
|
|
|
|
|
|
long currentTimeMillis = System.currentTimeMillis();
|
|
|
|
|
Date date = new Date(currentTimeMillis + timeout);
|
|
|
|
|
String dateStr = (String) DateFormat.format("MM-dd kk:mm:ss", date);
|
|
|
|
|
infoLog( "Timer Reg: " + dateStr + " TS=" + currentTimeMillis + " Timeout=" + timeout + " " + channelStr.toString());
|
|
|
|
|
|
|
|
|
|
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeout, pendingIntent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1405,7 +1410,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
|
intent.setAction(ACTION_GPS_TIMEOUT);
|
|
|
|
|
mPreviousGpsTimer = PendingIntent.getBroadcast(this, 0, intent, 0);
|
|
|
|
|
mPreviousGpsTimer = PendingIntent.getBroadcast(this, BROADCAST_REQUEST_CODE_GPS, intent, 0);
|
|
|
|
|
|
|
|
|
|
alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + mGpsTimeout, mPreviousGpsTimer);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|