|
|
|
@ -66,13 +66,14 @@ public class MpMasterService extends Service {
|
|
|
|
|
// public static final int NOTIFICATION_ID_FOREGROUND_SERVICE = 0;
|
|
|
|
|
public static final String ACTION_MSG_BROADCAST = "ACT_MSG_BROADCAST";
|
|
|
|
|
|
|
|
|
|
public static final String ACTION_START = "ACT_START";
|
|
|
|
|
public static final String ACTION_STOP = "ACT_STOP";
|
|
|
|
|
public static final String ACTION_MAIN = "ACT_MAIN";
|
|
|
|
|
private static final String ACTION_HEARTBEAT = "ACT_HB";
|
|
|
|
|
private static final String ACTION_TAKE_PHOTO = "ACT_TP";
|
|
|
|
|
private static final String ACTION_TAKE_PHOTO_MANUALLY = "ACT_TP_M";
|
|
|
|
|
private static final String ACTION_TIMEOUT = "ACT_TIMEOUT";
|
|
|
|
|
public static final String ACTION_START = "com.xypower.mpmaster.ACT_START";
|
|
|
|
|
public static final String ACTION_STOP = "com.xypower.mpmaster.ACT_STOP";
|
|
|
|
|
public static final String ACTION_MAIN = "com.xypower.mpmaster.ACT_MAIN";
|
|
|
|
|
|
|
|
|
|
private static final String ACTION_HEARTBEAT = "com.xypower.mpmaster.ACT_HB";
|
|
|
|
|
private static final String ACTION_TAKE_PHOTO = "com.xypower.mpapp.ACT_TP";
|
|
|
|
|
//private static final String ACTION_TAKE_PHOTO_MANUALLY = "ACT_TP_M";
|
|
|
|
|
//private static final String ACTION_TIMEOUT = "ACT_TIMEOUT";
|
|
|
|
|
private static final String EXTRA_PARAM_CHANNEL = "Channel";
|
|
|
|
|
private static final String EXTRA_PARAM_PRESET = "Preset";
|
|
|
|
|
private static final String EXTRA_PARAM_PHOTO_OR_VIDEO = "PhotoOrVideo";
|
|
|
|
@ -148,9 +149,9 @@ public class MpMasterService extends Service {
|
|
|
|
|
{
|
|
|
|
|
mAlarmReceiver = new AlarmReceiver(this);
|
|
|
|
|
IntentFilter intentFilter = new IntentFilter(ACTION_HEARTBEAT);
|
|
|
|
|
intentFilter.addAction(ACTION_TAKE_PHOTO);
|
|
|
|
|
intentFilter.addAction(ACTION_TIMEOUT);
|
|
|
|
|
intentFilter.addAction(ACTION_TAKE_PHOTO_MANUALLY);
|
|
|
|
|
// intentFilter.addAction(ACTION_TAKE_PHOTO);
|
|
|
|
|
// intentFilter.addAction(ACTION_TIMEOUT);
|
|
|
|
|
// intentFilter.addAction(ACTION_TAKE_PHOTO_MANUALLY);
|
|
|
|
|
intentFilter.addAction(ACTION_MSG_BROADCAST);
|
|
|
|
|
registerReceiver(mAlarmReceiver, intentFilter);
|
|
|
|
|
}
|
|
|
|
@ -225,16 +226,6 @@ public class MpMasterService extends Service {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void sendMessage(Context context, int what, int data) {
|
|
|
|
|
Intent intent = new Intent(ACTION_MSG_BROADCAST);
|
|
|
|
|
intent.putExtra("what", what);
|
|
|
|
|
intent.putExtra("data", data);
|
|
|
|
|
intent.setPackage(context.getPackageName());
|
|
|
|
|
// String typeName = AlarmReceiver.class.getTypeName();
|
|
|
|
|
// intent.setComponent( new ComponentName(context.getPackageName(), AlarmReceiver.class.getTypeName()) );
|
|
|
|
|
// context.sendBroadcast(intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void startMaster() {
|
|
|
|
|
String masterUrl = MicroPhotoContext.DEFAULT_MASTER_URL;
|
|
|
|
|
|
|
|
|
@ -326,54 +317,7 @@ public class MpMasterService extends Service {
|
|
|
|
|
|
|
|
|
|
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeout, pendingIntent);
|
|
|
|
|
}
|
|
|
|
|
private void registerPhotoTimer(int channel, int preset, long ts, long timeout, List<Long> schedules) {
|
|
|
|
|
|
|
|
|
|
registerPhotoTimer(this.getApplicationContext(), channel, preset, ts, timeout, schedules);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// private HashMap<Long, Integer> mTimers = new HashMap<Long, Integer>();
|
|
|
|
|
public boolean registerTimer(long uid, int timeout, long times) {
|
|
|
|
|
|
|
|
|
|
// 创建延迟意图
|
|
|
|
|
Intent alarmIntent = new Intent();
|
|
|
|
|
alarmIntent.setAction(ACTION_TIMEOUT);
|
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_TIMER_UID, uid);
|
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_TIMEOUT, timeout);
|
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_TIMES, times);
|
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_ELASPED_TIMES, 0L);
|
|
|
|
|
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
|
|
|
mTimers.put(Long.valueOf(uid), pendingIntent);
|
|
|
|
|
return registerTimer(pendingIntent, uid, timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean registerTimer(PendingIntent pendingIntent, long uid, int timeout) {
|
|
|
|
|
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
|
|
|
|
|
|
|
alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + timeout, pendingIntent);
|
|
|
|
|
|
|
|
|
|
Log.i(TAG, "RegTimer:" + uid + " timeout=" + timeout);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean unregisterTimer(long uid) {
|
|
|
|
|
|
|
|
|
|
Long uidObj = Long.valueOf(uid);
|
|
|
|
|
PendingIntent pendingIntent = mTimers.get(uidObj);
|
|
|
|
|
if (pendingIntent != null) {
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
|
|
|
|
|
|
|
alarmManager.cancel(pendingIntent);
|
|
|
|
|
|
|
|
|
|
mTimers.remove(uidObj);
|
|
|
|
|
Log.i(TAG, "UnregTimer:" + uid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
|
|
|