|
|
|
@ -1,6 +1,5 @@
|
|
|
|
|
package com.xinyingpower.microphoto;
|
|
|
|
|
|
|
|
|
|
import android.Manifest;
|
|
|
|
|
import android.app.AlarmManager;
|
|
|
|
|
import android.app.Notification;
|
|
|
|
|
import android.app.NotificationChannel;
|
|
|
|
@ -11,25 +10,14 @@ import android.content.BroadcastReceiver;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.IntentFilter;
|
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
|
import android.net.ConnectivityManager;
|
|
|
|
|
import android.net.NetworkInfo;
|
|
|
|
|
import android.os.Environment;
|
|
|
|
|
import android.os.IBinder;
|
|
|
|
|
import android.os.PowerManager;
|
|
|
|
|
import android.os.SystemClock;
|
|
|
|
|
|
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
|
import androidx.core.app.NotificationCompat;
|
|
|
|
|
|
|
|
|
|
import android.telephony.CellLocation;
|
|
|
|
|
import android.telephony.PhoneStateListener;
|
|
|
|
|
import android.telephony.ServiceState;
|
|
|
|
|
import android.telephony.SignalStrength;
|
|
|
|
|
import android.telephony.SubscriptionManager;
|
|
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
|
import android.telephony.cdma.CdmaCellLocation;
|
|
|
|
|
import android.telephony.gsm.GsmCellLocation;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.text.format.DateFormat;
|
|
|
|
|
import android.util.Log;
|
|
|
|
@ -43,7 +31,6 @@ import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
@ -54,63 +41,45 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
static {
|
|
|
|
|
System.loadLibrary("microphoto");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String ALARM_EVENT = "com.xinyingpower.mp.MicroPhotoService.AlarmReceiver";
|
|
|
|
|
|
|
|
|
|
private static final String ALARM_EVENT = "com.xinyingpower.mp.MicroPhotoService.AlarmReceiver";
|
|
|
|
|
public static final int NOTIFICATION_ID_FOREGROUND_SERVICE = 8466503;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 String ACTION_HEARTBEAT = "ACT_HB";
|
|
|
|
|
private static String ACTION_TAKE_PHOTO = "ACT_TP";
|
|
|
|
|
private static String ACTION_TAKE_PHOTO_MANUALLY = "ACT_TP_M";
|
|
|
|
|
|
|
|
|
|
private static String ACTION_TIMEOUT = "ACT_TIMEOUT";
|
|
|
|
|
|
|
|
|
|
private static String EXTRA_PARAM_CHANNEL = "Channel";
|
|
|
|
|
private static String EXTRA_PARAM_PRESET = "Preset";
|
|
|
|
|
private static String EXTRA_PARAM_PHOTO_OR_VIDEO = "PhotoOrVideo";
|
|
|
|
|
private static String EXTRA_PARAM_SCHEDULES = "Schedules";
|
|
|
|
|
private static String EXTRA_PARAM_SCHEDULE = "Schedule_";
|
|
|
|
|
|
|
|
|
|
private static String EXTRA_PARAM_TIME = "Time";
|
|
|
|
|
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";
|
|
|
|
|
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";
|
|
|
|
|
private static final String EXTRA_PARAM_SCHEDULES = "Schedules";
|
|
|
|
|
private static final String EXTRA_PARAM_SCHEDULE = "Schedule_";
|
|
|
|
|
private static final String EXTRA_PARAM_TIME = "Time";
|
|
|
|
|
// private static String EXTRA_PARAM_FILENAME = "FileName";
|
|
|
|
|
|
|
|
|
|
private static String EXTRA_PARAM_TIMER_UID = "TimerUid";
|
|
|
|
|
private static final String EXTRA_PARAM_TIMER_UID = "TimerUid";
|
|
|
|
|
// private static String EXTRA_PARAM_TIMER_TYPE = "TimerType";
|
|
|
|
|
private static String EXTRA_PARAM_TIMEOUT = "Timeout";
|
|
|
|
|
|
|
|
|
|
private final static String FOREGROUND_CHANNEL_ID = "foreground_channel_id";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String EXTRA_PARAM_TIMEOUT = "Timeout";
|
|
|
|
|
private static final String EXTRA_PARAM_TIMES = "Times";
|
|
|
|
|
private static final String EXTRA_PARAM_ELASPED_TIMES = "ElapsedTimes";
|
|
|
|
|
private static final String FOREGROUND_CHANNEL_ID = "foreground_channel_id";
|
|
|
|
|
public static class STATE_SERVICE {
|
|
|
|
|
public static final int CONNECTED = 10;
|
|
|
|
|
public static final int NOT_CONNECTED = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private NotificationManager mNotificationManager;
|
|
|
|
|
|
|
|
|
|
private Map<String, PowerManager.WakeLock> mWakeLocks = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
private final Map<String, PowerManager.WakeLock> mWakeLocks = new HashMap<>();
|
|
|
|
|
private int mHeartbeatDuration = 0; // 5m: 5 * 60 * 1000
|
|
|
|
|
private long mNextHeartbeatTime = 0;
|
|
|
|
|
|
|
|
|
|
private Map<Long, PendingIntent> mTimers = new HashMap<>();
|
|
|
|
|
private final Map<Long, PendingIntent> mTimers = new HashMap<>();
|
|
|
|
|
private static int stateService = STATE_SERVICE.NOT_CONNECTED;
|
|
|
|
|
|
|
|
|
|
public MicroPhotoService() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public IBinder onBind(Intent intent) {
|
|
|
|
|
// TODO: Return the communication channel to the service.
|
|
|
|
|
throw new UnsupportedOperationException("Not yet implemented");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onCreate() {
|
|
|
|
|
super.onCreate();
|
|
|
|
@ -121,6 +90,8 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
DeviceUtil.getPhoneState(this.getApplicationContext());
|
|
|
|
|
|
|
|
|
|
alarmReceiver = new AlarmReceiver(this);
|
|
|
|
|
screenactionreceiver = new ScreenActionReceiver();
|
|
|
|
|
|
|
|
|
|
// 注册广播接受者
|
|
|
|
|
IntentFilter intentFilter = new IntentFilter(ACTION_HEARTBEAT);
|
|
|
|
|
intentFilter.addAction(ACTION_TAKE_PHOTO);
|
|
|
|
@ -136,19 +107,20 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
if (aci.getShowIntent().isBroadcast()) {
|
|
|
|
|
// alarmManager.cancel(aci.getShowIntent());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
// alarmManager.cancel();
|
|
|
|
|
|
|
|
|
|
boolean res = false;
|
|
|
|
|
// boolean res = false;
|
|
|
|
|
// Environment.getExternalStoragePublicDirectory(String)
|
|
|
|
|
|
|
|
|
|
// registerHeartbeatTimer(getHeartbeatDuration());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onDestroy() {
|
|
|
|
|
|
|
|
|
@ -158,6 +130,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
mHandler = 0;
|
|
|
|
|
|
|
|
|
|
unregisterReceiver(alarmReceiver);
|
|
|
|
|
unregisterReceiver(screenactionreceiver);
|
|
|
|
|
|
|
|
|
|
for(Map.Entry<String, PowerManager.WakeLock> entry : mWakeLocks.entrySet()) {
|
|
|
|
|
entry.getValue().release();
|
|
|
|
@ -166,22 +139,18 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class AlarmReceiver extends BroadcastReceiver {
|
|
|
|
|
|
|
|
|
|
private MicroPhotoService mService;
|
|
|
|
|
|
|
|
|
|
public AlarmReceiver() {
|
|
|
|
|
mService = null;
|
|
|
|
|
}
|
|
|
|
|
public AlarmReceiver(MicroPhotoService service) {
|
|
|
|
|
mService = service;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
String action = intent.getAction();
|
|
|
|
|
if (TextUtils.equals(ACTION_HEARTBEAT, action)) {
|
|
|
|
|
Log.i(TAG, "receiver ACTION=" + action);
|
|
|
|
|
Log.i(TAG, "HB Timer Fired ACTION=" + action);
|
|
|
|
|
mService.sendHeartbeat(mService.mHandler);
|
|
|
|
|
mService.registerHeartbeatTimer();
|
|
|
|
|
} else if (TextUtils.equals(ACTION_TAKE_PHOTO, action)) {
|
|
|
|
@ -194,6 +163,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
int channel = (int) ((val & 0xFF0000L) >> 16);
|
|
|
|
|
int preset = (int) ((val & 0xFF00L) >> 8);
|
|
|
|
|
|
|
|
|
|
Log.i(TAG, "PhotoTimer Fired: CH=" + channel + " PR=" + preset);
|
|
|
|
|
mService.notifyToTakePhoto(mService.mHandler, channel, preset, ts, mService.buildPhotoDir(mService.getApplicationContext(), channel), mService.buildPhotoFileName(channel, preset, ts), true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -215,24 +185,34 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
boolean photoOrVideo = intent.getBooleanExtra(EXTRA_PARAM_PHOTO_OR_VIDEO, true);
|
|
|
|
|
long ts = System.currentTimeMillis() / 1000;
|
|
|
|
|
|
|
|
|
|
Log.i(TAG, "Take Photo CH=" + channel + " PR=" + preset);
|
|
|
|
|
Log.i(TAG, "Take Photo CH=" + channel + " PR=" + preset + " Mannually");
|
|
|
|
|
mService.notifyToTakePhoto(mService.mHandler, channel, preset, ts, mService.buildPhotoDir(mService.getApplicationContext(), channel), mService.buildPhotoFileName(channel, preset, ts), photoOrVideo);
|
|
|
|
|
} else if (TextUtils.equals(ACTION_TIMEOUT, action)) {
|
|
|
|
|
long uid = intent.getLongExtra(EXTRA_PARAM_TIMER_UID, 0);
|
|
|
|
|
Log.i(TAG, "Timeout:" + uid);
|
|
|
|
|
mService.fireTimeout(mService.mHandler, uid);
|
|
|
|
|
long expectedTimes = intent.getLongExtra(EXTRA_PARAM_TIMES, 0);
|
|
|
|
|
long elapsedTimes = intent.getLongExtra(EXTRA_PARAM_ELASPED_TIMES, 0);
|
|
|
|
|
elapsedTimes++;
|
|
|
|
|
|
|
|
|
|
Log.i(TAG, "Timeout uid=" + uid + " expectedTimes=" + expectedTimes + " Times=" + elapsedTimes);
|
|
|
|
|
mService.fireTimeout(mService.mHandler, uid, elapsedTimes);
|
|
|
|
|
|
|
|
|
|
intent.putExtra(EXTRA_PARAM_ELASPED_TIMES, elapsedTimes);
|
|
|
|
|
|
|
|
|
|
int timeout = intent.getIntExtra(EXTRA_PARAM_TIMEOUT, 0);
|
|
|
|
|
Long uidObj = Long.valueOf(uid);
|
|
|
|
|
if ((expectedTimes == 0) || (elapsedTimes < expectedTimes)) {
|
|
|
|
|
int timeout = intent.getIntExtra(EXTRA_PARAM_TIMEOUT, 0);
|
|
|
|
|
|
|
|
|
|
PendingIntent pendingIntent = mService.mTimers.get(uidObj);
|
|
|
|
|
|
|
|
|
|
if (pendingIntent != null) {
|
|
|
|
|
mService.registerTimer(pendingIntent, uid, timeout);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
mService.mTimers.remove(uidObj);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void registerHeartbeatTimer(int duration) {
|
|
|
|
|
int orgHeartbeatDuration = mHeartbeatDuration;
|
|
|
|
|
mHeartbeatDuration = duration;
|
|
|
|
@ -241,7 +221,6 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void registerHeartbeatTimer() {
|
|
|
|
|
|
|
|
|
|
// 创建延迟意图
|
|
|
|
@ -256,7 +235,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
// alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + timeout, pendingIntent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void registerPhotoTimer(int channel, int preset, long ts, long timeout, List<Long> schedules) {
|
|
|
|
|
private static void registerPhotoTimer(Context context, int channel, int preset, long ts, long timeout, List<Long> schedules) {
|
|
|
|
|
|
|
|
|
|
// 创建延迟意图
|
|
|
|
|
Intent alarmIntent = new Intent();
|
|
|
|
@ -265,33 +244,39 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_SCHEDULES, cnt);
|
|
|
|
|
String channelStr = "";
|
|
|
|
|
for (int idx = 0; idx < cnt; idx++) {
|
|
|
|
|
long val = schedules.get(idx).longValue();
|
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_SCHEDULE + idx, schedules.get(idx).longValue());
|
|
|
|
|
channelStr += schedules.get(idx).toString() + " ";
|
|
|
|
|
channelStr += "CH=" + ((val & 0XFF0000) >> 16) + "-PR=" + ((val & 0XFF00) >> 8) + " ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_TIME, ts);
|
|
|
|
|
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);
|
|
|
|
|
|
|
|
|
|
long currentTimeMillis = System.currentTimeMillis();
|
|
|
|
|
Date date = new Date(currentTimeMillis + timeout);
|
|
|
|
|
String dateStr = (String) DateFormat.format("MM-dd kk:mm:ss", date);
|
|
|
|
|
Log.d(TAG, "Register Photo Timer: " + dateStr + " currentTimeMillis=" + currentTimeMillis + " timeout=" + timeout + " Channels=" + channelStr);
|
|
|
|
|
Log.d(TAG, "PhotoTimer Reg: " + dateStr + " currentTimeMillis=" + currentTimeMillis + " timeout=" + timeout + " Channels=" + channelStr);
|
|
|
|
|
|
|
|
|
|
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeout, pendingIntent);
|
|
|
|
|
}
|
|
|
|
|
private void registerPhotoTimer(int channel, int preset, long ts, long timeout, List<Long> schedules) {
|
|
|
|
|
|
|
|
|
|
// private HashMap<Long, Integer> mTimers = new HashMap<Long, Integer>();
|
|
|
|
|
registerPhotoTimer(this.getApplicationContext(), channel, preset, ts, timeout, schedules);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean registerTimer(long uid, int timeout) {
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
|
@ -311,7 +296,6 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
Log.e(TAG, "wjz debug setDefaultDataSubId: error is " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int getDefaultDataSubId() {
|
|
|
|
|
SubscriptionManager subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
|
|
|
|
try {
|
|
|
|
@ -322,7 +306,6 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean registerTimer(PendingIntent pendingIntent, long uid, int timeout) {
|
|
|
|
|
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
|
@ -332,7 +315,6 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
Log.i(TAG, "RegTimer:" + uid + " timeout=" + timeout);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean unregisterTimer(long uid) {
|
|
|
|
|
|
|
|
|
|
Long uidObj = Long.valueOf(uid);
|
|
|
|
@ -348,7 +330,6 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean registerCaptureSchedule(long startTime, long baseTime) {
|
|
|
|
|
|
|
|
|
|
long[] photoTimeData = getPhotoTimeData(mHandler);
|
|
|
|
@ -386,7 +367,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
schedules.add(Long.valueOf(val));
|
|
|
|
|
|
|
|
|
|
Log.i(TAG, "Reg Photo Timer: CH=" + channel + " PR=" + preset);
|
|
|
|
|
Log.i(TAG, "PhotoTimer Reg: CH=" + channel + " PR=" + preset);
|
|
|
|
|
} else if (ts > currentTs) {
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
@ -394,7 +375,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
channel = (short) ((val & 0xFF0000L) >> 16);
|
|
|
|
|
preset = (short) ((val & 0xFF00L) >> 8);
|
|
|
|
|
|
|
|
|
|
Log.i(TAG, "Reg Photo Timer: CH=" + channel + " PR=" + preset);
|
|
|
|
|
Log.i(TAG, "PhotoTimer Reg: CH=" + channel + " PR=" + preset);
|
|
|
|
|
schedules.add(Long.valueOf(val));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -417,11 +398,14 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
public static void takePhoto(Context context, int channel, int preset, boolean photoOrVideo) {
|
|
|
|
|
|
|
|
|
|
Intent intent = new Intent(ACTION_TAKE_PHOTO_MANUALLY);
|
|
|
|
|
intent.putExtra(EXTRA_PARAM_CHANNEL, channel);
|
|
|
|
|
intent.putExtra(EXTRA_PARAM_PRESET, preset);
|
|
|
|
|
intent.putExtra(EXTRA_PARAM_PHOTO_OR_VIDEO, photoOrVideo);
|
|
|
|
|
context.sendBroadcast(intent);
|
|
|
|
|
List<Long> schedules = new ArrayList<>();
|
|
|
|
|
long ts = System.currentTimeMillis() / 1000;
|
|
|
|
|
long val = (ts << 24);
|
|
|
|
|
val |= ((long)channel << 16);
|
|
|
|
|
val |= ((long)preset << 8);
|
|
|
|
|
schedules.add(Long.valueOf(val));
|
|
|
|
|
|
|
|
|
|
registerPhotoTimer(context, channel, preset, System.currentTimeMillis() / 1000, 0, schedules);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -441,20 +425,23 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
connect();
|
|
|
|
|
|
|
|
|
|
registerReceiver(screenactionreceiver, screenactionreceiver.getFilter());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// File path = getApplicationContext().getFilesDir();
|
|
|
|
|
String appPath = buildAppDir(this.getApplicationContext());
|
|
|
|
|
|
|
|
|
|
String ip = intent.getStringExtra("server");
|
|
|
|
|
int port = intent.getIntExtra("port", 0);
|
|
|
|
|
String cmdid = intent.getStringExtra("cmdid");
|
|
|
|
|
int protocol = intent.getIntExtra("protocol", 0);
|
|
|
|
|
|
|
|
|
|
Log.i(TAG, "AppPath=" + appPath + " Server=" + ip + ":" + port + " cmdid=" + cmdid);
|
|
|
|
|
mHandler = init(appPath, ip, port, cmdid);
|
|
|
|
|
Log.i(TAG, "AppPath=" + appPath + " Server=" + ip + ":" + port + " cmdid=" + cmdid + " protocol" + protocol);
|
|
|
|
|
mHandler = init(appPath, ip, port, cmdid, protocol);
|
|
|
|
|
|
|
|
|
|
// Start the locker receiver
|
|
|
|
|
|
|
|
|
|
registerReceiver(screenactionreceiver, screenactionreceiver.getFilter());
|
|
|
|
|
|
|
|
|
|
if (mHandler !=0) {
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
long nowTs = date.getTime() / 1000;
|
|
|
|
|
date.setHours(0);
|
|
|
|
@ -465,6 +452,8 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
registerCaptureSchedule(startTime, baseTime);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// registerPhotoTimer();
|
|
|
|
|
break;
|
|
|
|
|
case ACTION_STOP:
|
|
|
|
@ -483,7 +472,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
public void requestWakelock(String name, long timeout) {
|
|
|
|
|
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
|
|
|
|
PowerManager.WakeLock wl = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, name);
|
|
|
|
|
PowerManager.WakeLock wl = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, name);
|
|
|
|
|
PowerManager.WakeLock wl2 = null;
|
|
|
|
|
synchronized (mWakeLocks) {
|
|
|
|
|
wl2 = mWakeLocks.replace(name, wl);
|
|
|
|
@ -578,7 +567,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
.setContentIntent(pendingIntent);
|
|
|
|
|
|
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
|
notificationBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
|
|
|
|
|
notificationBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return notificationBuilder.build();
|
|
|
|
@ -655,16 +644,16 @@ CellSignalStrengthGsm cellSignalStrengthGsm = cellInfoGsm.getCellSignalStrength(
|
|
|
|
|
cellSignalStrengthGsm.getDbm();
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
protected native long init(String appPath, String ip, int port, String cmdid);
|
|
|
|
|
protected native long init(String appPath, String ip, int port, String cmdid, int protocol);
|
|
|
|
|
protected native long getHeartbeatDuration(long handler);
|
|
|
|
|
protected native long[] getPhotoTimeData(long handler);
|
|
|
|
|
// protected native long[] getNextScheduleItem(long handler);
|
|
|
|
|
protected native boolean notifyToTakePhoto(long handler, int channel, int preset, long scheduleTime, String path, String fileName, boolean sendToCma);
|
|
|
|
|
protected native boolean sendHeartbeat(long handler);
|
|
|
|
|
protected native boolean fireTimeout(long handler, long uid);
|
|
|
|
|
protected native boolean fireTimeout(long handler, long uid, long times);
|
|
|
|
|
protected native boolean uninit(long handler);
|
|
|
|
|
protected long mHandler = 0;
|
|
|
|
|
|
|
|
|
|
private AlarmReceiver alarmReceiver = null;
|
|
|
|
|
final ScreenActionReceiver screenactionreceiver = new ScreenActionReceiver();
|
|
|
|
|
private ScreenActionReceiver screenactionreceiver = null;
|
|
|
|
|
}
|