|
|
|
@ -86,6 +86,7 @@ import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
|
|
|
|
public class MicroPhotoService extends Service {
|
|
|
|
|
public static final String TAG = "MPLOG";
|
|
|
|
@ -161,6 +162,8 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
private ServiceHandler mHander = null;
|
|
|
|
|
private Messenger mMessenger = null;
|
|
|
|
|
|
|
|
|
|
private static AtomicInteger mPendingIntentFeed = new AtomicInteger();
|
|
|
|
|
|
|
|
|
|
private String mModelName = null;
|
|
|
|
|
|
|
|
|
|
public static boolean isRunning = false;
|
|
|
|
@ -659,15 +662,16 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void registerHeartbeatTimer(long timeout) {
|
|
|
|
|
private void registerHeartbeatTimer(long timeoutMs) {
|
|
|
|
|
|
|
|
|
|
// 创建延迟意图
|
|
|
|
|
long triggerTime = System.currentTimeMillis() + timeout;
|
|
|
|
|
long triggerTime = System.currentTimeMillis() + timeoutMs;
|
|
|
|
|
triggerTime -= (triggerTime % 1000);
|
|
|
|
|
Intent alarmIntent = new Intent();
|
|
|
|
|
alarmIntent.setAction(ACTION_HEARTBEAT);
|
|
|
|
|
alarmIntent.putExtra("HeartbeatDuration", mHeartbeatDuration);
|
|
|
|
|
alarmIntent.putExtra("HeartbeatTime", triggerTime);
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, BROADCAST_REQUEST_CODE_HEARTBEAT, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, mPendingIntentFeed.getAndIncrement(), alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
|
|
|
Date date = new Date(triggerTime);
|
|
|
|
|
String dateStr = (String) DateFormat.format("kk:mm:ss", date);
|
|
|
|
@ -710,7 +714,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
|
|
|
|
|
localBroadcastManager.sendBroadcast(intent);
|
|
|
|
|
} else {
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, BROADCAST_REQUEST_CODE_TAKING_PHOTO, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, mPendingIntentFeed.getAndIncrement(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);
|
|
|
|
|
try {
|
|
|
|
@ -1017,7 +1021,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
alarmIntent.setPackage(context.getPackageName());
|
|
|
|
|
alarmIntent.setAction(ACTION_STOP);
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), 0, alarmIntent, 0);
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), mPendingIntentFeed.getAndIncrement(), alarmIntent, 0);
|
|
|
|
|
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) context.getApplicationContext().getSystemService(ALARM_SERVICE);
|
|
|
|
|
alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 100, pendingIntent);
|
|
|
|
@ -1419,7 +1423,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
|
intent.setAction(ACTION_GPS_TIMEOUT);
|
|
|
|
|
mPreviousGpsTimer = PendingIntent.getBroadcast(this, BROADCAST_REQUEST_CODE_GPS, intent, 0);
|
|
|
|
|
mPreviousGpsTimer = PendingIntent.getBroadcast(this, mPendingIntentFeed.getAndIncrement(), intent, 0);
|
|
|
|
|
|
|
|
|
|
alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + mGpsTimeout, mPreviousGpsTimer);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|