|
|
@ -1,6 +1,5 @@
|
|
|
|
package com.xinyingpower.microphoto;
|
|
|
|
package com.xinyingpower.microphoto;
|
|
|
|
|
|
|
|
|
|
|
|
import android.Manifest;
|
|
|
|
|
|
|
|
import android.app.AlarmManager;
|
|
|
|
import android.app.AlarmManager;
|
|
|
|
import android.app.Notification;
|
|
|
|
import android.app.Notification;
|
|
|
|
import android.app.NotificationChannel;
|
|
|
|
import android.app.NotificationChannel;
|
|
|
@ -11,32 +10,22 @@ import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
|
|
|
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.IBinder;
|
|
|
|
|
|
|
|
import android.os.PowerManager;
|
|
|
|
import android.os.SystemClock;
|
|
|
|
import android.os.SystemClock;
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
|
|
|
|
import androidx.core.app.NotificationCompat;
|
|
|
|
import androidx.core.app.NotificationCompat;
|
|
|
|
|
|
|
|
|
|
|
|
import android.telephony.CellLocation;
|
|
|
|
import android.telephony.SubscriptionManager;
|
|
|
|
import android.telephony.PhoneStateListener;
|
|
|
|
|
|
|
|
import android.telephony.ServiceState;
|
|
|
|
|
|
|
|
import android.telephony.SignalStrength;
|
|
|
|
|
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
import android.telephony.cdma.CdmaCellLocation;
|
|
|
|
|
|
|
|
import android.telephony.gsm.GsmCellLocation;
|
|
|
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.format.DateFormat;
|
|
|
|
import android.text.format.DateFormat;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.widget.RemoteViews;
|
|
|
|
import android.widget.RemoteViews;
|
|
|
|
import android.widget.Toast;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
|
|
import com.dowse.camera.client.DSCameraManager;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
@ -52,62 +41,45 @@ public class MicroPhotoService extends Service {
|
|
|
|
static {
|
|
|
|
static {
|
|
|
|
System.loadLibrary("microphoto");
|
|
|
|
System.loadLibrary("microphoto");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final String ALARM_EVENT = "com.xinyingpower.mp.MicroPhotoService.AlarmReceiver";
|
|
|
|
private static String ALARM_EVENT = "com.xinyingpower.mp.MicroPhotoService.AlarmReceiver";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int NOTIFICATION_ID_FOREGROUND_SERVICE = 8466503;
|
|
|
|
public static final int NOTIFICATION_ID_FOREGROUND_SERVICE = 8466503;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final String ACTION_START = "ACT_START";
|
|
|
|
public static final String ACTION_START = "ACT_START";
|
|
|
|
public static final String ACTION_STOP = "ACT_STOP";
|
|
|
|
public static final String ACTION_STOP = "ACT_STOP";
|
|
|
|
|
|
|
|
|
|
|
|
public static final String ACTION_MAIN = "ACT_MAIN";
|
|
|
|
public static final String ACTION_MAIN = "ACT_MAIN";
|
|
|
|
|
|
|
|
private static final String ACTION_HEARTBEAT = "ACT_HB";
|
|
|
|
private static String ACTION_HEARTBEAT = "ACT_HB";
|
|
|
|
private static final String ACTION_TAKE_PHOTO = "ACT_TP";
|
|
|
|
private static String ACTION_TAKE_PHOTO = "ACT_TP";
|
|
|
|
private static final String ACTION_TAKE_PHOTO_MANUALLY = "ACT_TP_M";
|
|
|
|
private static 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 String ACTION_TIMEOUT = "ACT_TIMEOUT";
|
|
|
|
private static final String EXTRA_PARAM_PRESET = "Preset";
|
|
|
|
|
|
|
|
private static final String EXTRA_PARAM_PHOTO_OR_VIDEO = "PhotoOrVideo";
|
|
|
|
private static String EXTRA_PARAM_CHANNEL = "Channel";
|
|
|
|
private static final String EXTRA_PARAM_SCHEDULES = "Schedules";
|
|
|
|
private static String EXTRA_PARAM_PRESET = "Preset";
|
|
|
|
private static final String EXTRA_PARAM_SCHEDULE = "Schedule_";
|
|
|
|
private static String EXTRA_PARAM_PHOTO_OR_VIDEO = "PhotoOrVideo";
|
|
|
|
private static final String EXTRA_PARAM_TIME = "Time";
|
|
|
|
private static String EXTRA_PARAM_SCHEDULES = "Schedules";
|
|
|
|
|
|
|
|
private static String EXTRA_PARAM_SCHEDULE = "Schedule_";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String EXTRA_PARAM_TIME = "Time";
|
|
|
|
|
|
|
|
// private static String EXTRA_PARAM_FILENAME = "FileName";
|
|
|
|
// private static String EXTRA_PARAM_FILENAME = "FileName";
|
|
|
|
|
|
|
|
private static final String EXTRA_PARAM_TIMER_UID = "TimerUid";
|
|
|
|
private static String EXTRA_PARAM_TIMER_UID = "TimerUid";
|
|
|
|
|
|
|
|
// private static String EXTRA_PARAM_TIMER_TYPE = "TimerType";
|
|
|
|
// private static String EXTRA_PARAM_TIMER_TYPE = "TimerType";
|
|
|
|
private static String EXTRA_PARAM_TIMEOUT = "Timeout";
|
|
|
|
private static final String EXTRA_PARAM_TIMEOUT = "Timeout";
|
|
|
|
|
|
|
|
private static final String EXTRA_PARAM_TIMES = "Times";
|
|
|
|
private final static String FOREGROUND_CHANNEL_ID = "foreground_channel_id";
|
|
|
|
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 class STATE_SERVICE {
|
|
|
|
public static final int CONNECTED = 10;
|
|
|
|
public static final int CONNECTED = 10;
|
|
|
|
public static final int NOT_CONNECTED = 0;
|
|
|
|
public static final int NOT_CONNECTED = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private AlarmManager mAlarmManager;
|
|
|
|
|
|
|
|
private NotificationManager mNotificationManager;
|
|
|
|
private NotificationManager mNotificationManager;
|
|
|
|
|
|
|
|
private final Map<String, PowerManager.WakeLock> mWakeLocks = new HashMap<>();
|
|
|
|
private int mHeartbeatDuration = 0; // 5m: 5 * 60 * 1000
|
|
|
|
private int mHeartbeatDuration = 0; // 5m: 5 * 60 * 1000
|
|
|
|
private long mNextHeartbeatTime = 0;
|
|
|
|
private long mNextHeartbeatTime = 0;
|
|
|
|
|
|
|
|
private final Map<Long, PendingIntent> mTimers = new HashMap<>();
|
|
|
|
private Map<Long, PendingIntent> mTimers = new HashMap<>();
|
|
|
|
|
|
|
|
private static int stateService = STATE_SERVICE.NOT_CONNECTED;
|
|
|
|
private static int stateService = STATE_SERVICE.NOT_CONNECTED;
|
|
|
|
|
|
|
|
|
|
|
|
public MicroPhotoService() {
|
|
|
|
public MicroPhotoService() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public IBinder onBind(Intent intent) {
|
|
|
|
public IBinder onBind(Intent intent) {
|
|
|
|
// TODO: Return the communication channel to the service.
|
|
|
|
// TODO: Return the communication channel to the service.
|
|
|
|
throw new UnsupportedOperationException("Not yet implemented");
|
|
|
|
throw new UnsupportedOperationException("Not yet implemented");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
|
|
|
public void onCreate() {
|
|
|
|
super.onCreate();
|
|
|
|
super.onCreate();
|
|
|
@ -115,9 +87,11 @@ public class MicroPhotoService extends Service {
|
|
|
|
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
|
|
|
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
|
|
|
stateService = STATE_SERVICE.NOT_CONNECTED;
|
|
|
|
stateService = STATE_SERVICE.NOT_CONNECTED;
|
|
|
|
|
|
|
|
|
|
|
|
getPhoneState(this.getApplicationContext());
|
|
|
|
DeviceUtil.getPhoneState(this.getApplicationContext());
|
|
|
|
|
|
|
|
|
|
|
|
alarmReceiver = new AlarmReceiver(this);
|
|
|
|
alarmReceiver = new AlarmReceiver(this);
|
|
|
|
|
|
|
|
screenactionreceiver = new ScreenActionReceiver();
|
|
|
|
|
|
|
|
|
|
|
|
// 注册广播接受者
|
|
|
|
// 注册广播接受者
|
|
|
|
IntentFilter intentFilter = new IntentFilter(ACTION_HEARTBEAT);
|
|
|
|
IntentFilter intentFilter = new IntentFilter(ACTION_HEARTBEAT);
|
|
|
|
intentFilter.addAction(ACTION_TAKE_PHOTO);
|
|
|
|
intentFilter.addAction(ACTION_TAKE_PHOTO);
|
|
|
@ -133,69 +107,51 @@ public class MicroPhotoService extends Service {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
if (aci.getShowIntent().isBroadcast()) {
|
|
|
|
if (aci.getShowIntent().isBroadcast()) {
|
|
|
|
// alarmManager.cancel(aci.getShowIntent());
|
|
|
|
// alarmManager.cancel(aci.getShowIntent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// alarmManager.cancel();
|
|
|
|
// alarmManager.cancel();
|
|
|
|
|
|
|
|
|
|
|
|
boolean res = false;
|
|
|
|
// boolean res = false;
|
|
|
|
/*
|
|
|
|
|
|
|
|
res = DSCameraManager.getInstace().init();
|
|
|
|
|
|
|
|
ChannelPicParam picParam = new ChannelPicParam();
|
|
|
|
|
|
|
|
picParam.setColor(1);
|
|
|
|
|
|
|
|
picParam.setWidth(1920);
|
|
|
|
|
|
|
|
picParam.setHeight(1080);
|
|
|
|
|
|
|
|
picParam.setCompress_radio(40);
|
|
|
|
|
|
|
|
DSCameraManager.getInstace().setPicParam(1, picParam);
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Environment.getExternalStoragePublicDirectory(String)
|
|
|
|
// Environment.getExternalStoragePublicDirectory(String)
|
|
|
|
File path = new File(Environment.getExternalStorageDirectory(), "com.xyp.mp/");
|
|
|
|
|
|
|
|
if (!path.exists()) {
|
|
|
|
|
|
|
|
path.mkdirs();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// File path = getApplicationContext().getFilesDir();
|
|
|
|
|
|
|
|
String appPath = path.getAbsolutePath();
|
|
|
|
|
|
|
|
Log.i(TAG, "AppPath=" + appPath);
|
|
|
|
|
|
|
|
// String ip = "180.166.218.222";
|
|
|
|
|
|
|
|
String ip = "47.96.238.157";
|
|
|
|
|
|
|
|
// int port = 40032;
|
|
|
|
|
|
|
|
// String ip = "192.168.50.50";
|
|
|
|
|
|
|
|
int port = 6891;
|
|
|
|
|
|
|
|
String cmdid = "XY-ANDROIDSIM-002";
|
|
|
|
|
|
|
|
init(appPath, ip, port, cmdid);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// registerHeartbeatTimer(getHeartbeatDuration());
|
|
|
|
// registerHeartbeatTimer(getHeartbeatDuration());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onDestroy() {
|
|
|
|
|
|
|
|
|
|
|
|
Date date = new Date();
|
|
|
|
stateService = STATE_SERVICE.NOT_CONNECTED;
|
|
|
|
long nowTs = date.getTime() / 1000;
|
|
|
|
|
|
|
|
date.setHours(0);
|
|
|
|
|
|
|
|
date.setMinutes(0);
|
|
|
|
|
|
|
|
date.setSeconds(0);
|
|
|
|
|
|
|
|
long startTime = date.getTime() / 1000;
|
|
|
|
|
|
|
|
long baseTime = nowTs - startTime;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
registerCaptureSchedule(startTime, baseTime);
|
|
|
|
uninit(mHandler);
|
|
|
|
|
|
|
|
mHandler = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// registerPhotoTimer();
|
|
|
|
unregisterReceiver(alarmReceiver);
|
|
|
|
}
|
|
|
|
unregisterReceiver(screenactionreceiver);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(Map.Entry<String, PowerManager.WakeLock> entry : mWakeLocks.entrySet()) {
|
|
|
|
|
|
|
|
entry.getValue().release();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mWakeLocks.clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
|
|
|
}
|
|
|
|
public static class AlarmReceiver extends BroadcastReceiver {
|
|
|
|
public static class AlarmReceiver extends BroadcastReceiver {
|
|
|
|
|
|
|
|
|
|
|
|
private MicroPhotoService mService;
|
|
|
|
private MicroPhotoService mService;
|
|
|
|
|
|
|
|
public AlarmReceiver() {
|
|
|
|
|
|
|
|
mService = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
public AlarmReceiver(MicroPhotoService service) {
|
|
|
|
public AlarmReceiver(MicroPhotoService service) {
|
|
|
|
mService = service;
|
|
|
|
mService = service;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
String action = intent.getAction();
|
|
|
|
String action = intent.getAction();
|
|
|
|
if (TextUtils.equals(ACTION_HEARTBEAT, action)) {
|
|
|
|
if (TextUtils.equals(ACTION_HEARTBEAT, action)) {
|
|
|
|
Log.i(TAG, "receiver ACTION=" + action);
|
|
|
|
Log.i(TAG, "HB Timer Fired ACTION=" + action);
|
|
|
|
mService.sendHeartbeat();
|
|
|
|
mService.sendHeartbeat(mService.mHandler);
|
|
|
|
mService.registerHeartbeatTimer();
|
|
|
|
mService.registerHeartbeatTimer();
|
|
|
|
} else if (TextUtils.equals(ACTION_TAKE_PHOTO, action)) {
|
|
|
|
} else if (TextUtils.equals(ACTION_TAKE_PHOTO, action)) {
|
|
|
|
long ts = intent.getLongExtra(EXTRA_PARAM_TIME, 0);
|
|
|
|
long ts = intent.getLongExtra(EXTRA_PARAM_TIME, 0);
|
|
|
@ -207,7 +163,8 @@ public class MicroPhotoService extends Service {
|
|
|
|
int channel = (int) ((val & 0xFF0000L) >> 16);
|
|
|
|
int channel = (int) ((val & 0xFF0000L) >> 16);
|
|
|
|
int preset = (int) ((val & 0xFF00L) >> 8);
|
|
|
|
int preset = (int) ((val & 0xFF00L) >> 8);
|
|
|
|
|
|
|
|
|
|
|
|
mService.notifyToTakePhoto(channel, preset, ts, mService.buildPhotoDir(channel), mService.buildPhotoFileName(channel, preset, ts), true);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -228,23 +185,34 @@ public class MicroPhotoService extends Service {
|
|
|
|
boolean photoOrVideo = intent.getBooleanExtra(EXTRA_PARAM_PHOTO_OR_VIDEO, true);
|
|
|
|
boolean photoOrVideo = intent.getBooleanExtra(EXTRA_PARAM_PHOTO_OR_VIDEO, true);
|
|
|
|
long ts = System.currentTimeMillis() / 1000;
|
|
|
|
long ts = System.currentTimeMillis() / 1000;
|
|
|
|
|
|
|
|
|
|
|
|
mService.notifyToTakePhoto(channel, preset, ts, mService.buildPhotoDir(channel), mService.buildPhotoFileName(channel, preset, ts), photoOrVideo);
|
|
|
|
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)) {
|
|
|
|
} else if (TextUtils.equals(ACTION_TIMEOUT, action)) {
|
|
|
|
long uid = intent.getLongExtra(EXTRA_PARAM_TIMER_UID, 0);
|
|
|
|
long uid = intent.getLongExtra(EXTRA_PARAM_TIMER_UID, 0);
|
|
|
|
Log.i(TAG, "Timeout:" + uid);
|
|
|
|
long expectedTimes = intent.getLongExtra(EXTRA_PARAM_TIMES, 0);
|
|
|
|
mService.fireTimeout(uid);
|
|
|
|
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);
|
|
|
|
Long uidObj = Long.valueOf(uid);
|
|
|
|
|
|
|
|
if ((expectedTimes == 0) || (elapsedTimes < expectedTimes)) {
|
|
|
|
|
|
|
|
int timeout = intent.getIntExtra(EXTRA_PARAM_TIMEOUT, 0);
|
|
|
|
|
|
|
|
|
|
|
|
PendingIntent pendingIntent = mService.mTimers.get(uidObj);
|
|
|
|
PendingIntent pendingIntent = mService.mTimers.get(uidObj);
|
|
|
|
|
|
|
|
|
|
|
|
if (pendingIntent != null) {
|
|
|
|
if (pendingIntent != null) {
|
|
|
|
mService.registerTimer(pendingIntent, uid, timeout);
|
|
|
|
mService.registerTimer(pendingIntent, uid, timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
mService.mTimers.remove(uidObj);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void registerHeartbeatTimer(int duration) {
|
|
|
|
private void registerHeartbeatTimer(int duration) {
|
|
|
|
int orgHeartbeatDuration = mHeartbeatDuration;
|
|
|
|
int orgHeartbeatDuration = mHeartbeatDuration;
|
|
|
|
mHeartbeatDuration = duration;
|
|
|
|
mHeartbeatDuration = duration;
|
|
|
@ -253,7 +221,6 @@ public class MicroPhotoService extends Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void registerHeartbeatTimer() {
|
|
|
|
private void registerHeartbeatTimer() {
|
|
|
|
|
|
|
|
|
|
|
|
// 创建延迟意图
|
|
|
|
// 创建延迟意图
|
|
|
@ -268,7 +235,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
// alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + timeout, pendingIntent);
|
|
|
|
// 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();
|
|
|
|
Intent alarmIntent = new Intent();
|
|
|
@ -277,33 +244,39 @@ public class MicroPhotoService extends Service {
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_SCHEDULES, cnt);
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_SCHEDULES, cnt);
|
|
|
|
String channelStr = "";
|
|
|
|
String channelStr = "";
|
|
|
|
for (int idx = 0; idx < cnt; idx++) {
|
|
|
|
for (int idx = 0; idx < cnt; idx++) {
|
|
|
|
|
|
|
|
long val = schedules.get(idx).longValue();
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_SCHEDULE + idx, 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);
|
|
|
|
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();
|
|
|
|
long currentTimeMillis = System.currentTimeMillis();
|
|
|
|
Date date = new Date(currentTimeMillis + timeout);
|
|
|
|
Date date = new Date(currentTimeMillis + timeout);
|
|
|
|
String dateStr = (String) DateFormat.format("MM-dd kk:mm:ss", date);
|
|
|
|
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);
|
|
|
|
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>();
|
|
|
|
// private HashMap<Long, Integer> mTimers = new HashMap<Long, Integer>();
|
|
|
|
|
|
|
|
public boolean registerTimer(long uid, int timeout, long times) {
|
|
|
|
public boolean registerTimer(long uid, int timeout) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建延迟意图
|
|
|
|
// 创建延迟意图
|
|
|
|
Intent alarmIntent = new Intent();
|
|
|
|
Intent alarmIntent = new Intent();
|
|
|
|
alarmIntent.setAction(ACTION_TIMEOUT);
|
|
|
|
alarmIntent.setAction(ACTION_TIMEOUT);
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_TIMER_UID, uid);
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_TIMER_UID, uid);
|
|
|
|
alarmIntent.putExtra(EXTRA_PARAM_TIMEOUT, timeout);
|
|
|
|
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);
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
|
|
|
|
@ -311,6 +284,28 @@ public class MicroPhotoService extends Service {
|
|
|
|
return registerTimer(pendingIntent, uid, timeout);
|
|
|
|
return registerTimer(pendingIntent, uid, timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setDefaultDataSubId(int subId) {
|
|
|
|
|
|
|
|
SubscriptionManager subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Method method = subscriptionManager.getClass().getDeclaredMethod("setDefaultDataSubId", int.class);
|
|
|
|
|
|
|
|
method.invoke(subscriptionManager, subId);
|
|
|
|
|
|
|
|
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
|
|
|
|
|
Method method1 = telephonyManager.getClass().getDeclaredMethod("setDataEnabled", boolean.class);
|
|
|
|
|
|
|
|
method1.invoke(telephonyManager, true);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
Log.e(TAG, "wjz debug setDefaultDataSubId: error is " + e.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getDefaultDataSubId() {
|
|
|
|
|
|
|
|
SubscriptionManager subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Method method = subscriptionManager.getClass().getDeclaredMethod("getDefaultDataSubscriptionId");
|
|
|
|
|
|
|
|
return (int) method.invoke(subscriptionManager);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
Log.e(TAG, "wjz debug getDefaultDataSubId: error is " + e.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
public boolean registerTimer(PendingIntent pendingIntent, long uid, int timeout) {
|
|
|
|
public boolean registerTimer(PendingIntent pendingIntent, long uid, int timeout) {
|
|
|
|
|
|
|
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
|
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
@ -320,7 +315,6 @@ public class MicroPhotoService extends Service {
|
|
|
|
Log.i(TAG, "RegTimer:" + uid + " timeout=" + timeout);
|
|
|
|
Log.i(TAG, "RegTimer:" + uid + " timeout=" + timeout);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean unregisterTimer(long uid) {
|
|
|
|
public boolean unregisterTimer(long uid) {
|
|
|
|
|
|
|
|
|
|
|
|
Long uidObj = Long.valueOf(uid);
|
|
|
|
Long uidObj = Long.valueOf(uid);
|
|
|
@ -336,10 +330,9 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean registerCaptureSchedule(long startTime, long baseTime) {
|
|
|
|
private boolean registerCaptureSchedule(long startTime, long baseTime) {
|
|
|
|
|
|
|
|
|
|
|
|
long[] photoTimeData = getPhotoTimeData();
|
|
|
|
long[] photoTimeData = getPhotoTimeData(mHandler);
|
|
|
|
if (photoTimeData == null) {
|
|
|
|
if (photoTimeData == null) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -373,9 +366,16 @@ public class MicroPhotoService extends Service {
|
|
|
|
preset = (short) ((val & 0xFF00L) >> 8);
|
|
|
|
preset = (short) ((val & 0xFF00L) >> 8);
|
|
|
|
|
|
|
|
|
|
|
|
schedules.add(Long.valueOf(val));
|
|
|
|
schedules.add(Long.valueOf(val));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.i(TAG, "PhotoTimer Reg: CH=" + channel + " PR=" + preset);
|
|
|
|
} else if (ts > currentTs) {
|
|
|
|
} else if (ts > currentTs) {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
channel = (short) ((val & 0xFF0000L) >> 16);
|
|
|
|
|
|
|
|
preset = (short) ((val & 0xFF00L) >> 8);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.i(TAG, "PhotoTimer Reg: CH=" + channel + " PR=" + preset);
|
|
|
|
schedules.add(Long.valueOf(val));
|
|
|
|
schedules.add(Long.valueOf(val));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -398,11 +398,14 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
|
|
public static void takePhoto(Context context, int channel, int preset, boolean photoOrVideo) {
|
|
|
|
public static void takePhoto(Context context, int channel, int preset, boolean photoOrVideo) {
|
|
|
|
|
|
|
|
|
|
|
|
Intent intent = new Intent(ACTION_TAKE_PHOTO_MANUALLY);
|
|
|
|
List<Long> schedules = new ArrayList<>();
|
|
|
|
intent.putExtra(EXTRA_PARAM_CHANNEL, channel);
|
|
|
|
long ts = System.currentTimeMillis() / 1000;
|
|
|
|
intent.putExtra(EXTRA_PARAM_PRESET, preset);
|
|
|
|
long val = (ts << 24);
|
|
|
|
intent.putExtra(EXTRA_PARAM_PHOTO_OR_VIDEO, photoOrVideo);
|
|
|
|
val |= ((long)channel << 16);
|
|
|
|
context.sendBroadcast(intent);
|
|
|
|
val |= ((long)preset << 8);
|
|
|
|
|
|
|
|
schedules.add(Long.valueOf(val));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
registerPhotoTimer(context, channel, preset, System.currentTimeMillis() / 1000, 0, schedules);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -420,13 +423,42 @@ public class MicroPhotoService extends Service {
|
|
|
|
Log.d(TAG, "Received user starts foreground intent");
|
|
|
|
Log.d(TAG, "Received user starts foreground intent");
|
|
|
|
startForeground(NOTIFICATION_ID_FOREGROUND_SERVICE, prepareNotification());
|
|
|
|
startForeground(NOTIFICATION_ID_FOREGROUND_SERVICE, prepareNotification());
|
|
|
|
|
|
|
|
|
|
|
|
// Start the locker receiver
|
|
|
|
connect();
|
|
|
|
final ScreenActionReceiver screenactionreceiver = new ScreenActionReceiver();
|
|
|
|
|
|
|
|
registerReceiver(screenactionreceiver, screenactionreceiver.getFilter());
|
|
|
|
registerReceiver(screenactionreceiver, screenactionreceiver.getFilter());
|
|
|
|
|
|
|
|
|
|
|
|
connect();
|
|
|
|
|
|
|
|
|
|
|
|
// 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 + " protocol" + protocol);
|
|
|
|
|
|
|
|
mHandler = init(appPath, ip, port, cmdid, protocol);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Start the locker receiver
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mHandler !=0) {
|
|
|
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
|
|
|
long nowTs = date.getTime() / 1000;
|
|
|
|
|
|
|
|
date.setHours(0);
|
|
|
|
|
|
|
|
date.setMinutes(0);
|
|
|
|
|
|
|
|
date.setSeconds(0);
|
|
|
|
|
|
|
|
long startTime = date.getTime() / 1000;
|
|
|
|
|
|
|
|
long baseTime = nowTs - startTime;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
registerCaptureSchedule(startTime, baseTime);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// registerPhotoTimer();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case ACTION_STOP:
|
|
|
|
case ACTION_STOP:
|
|
|
|
|
|
|
|
unregisterReceiver(screenactionreceiver);
|
|
|
|
|
|
|
|
|
|
|
|
stopForeground(true);
|
|
|
|
stopForeground(true);
|
|
|
|
stopSelf();
|
|
|
|
stopSelf();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -438,6 +470,31 @@ public class MicroPhotoService extends Service {
|
|
|
|
return START_NOT_STICKY;
|
|
|
|
return START_NOT_STICKY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void requestWakelock(String name, long timeout) {
|
|
|
|
|
|
|
|
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wl2 != null) {
|
|
|
|
|
|
|
|
wl2.release();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timeout == 0) wl.acquire();
|
|
|
|
|
|
|
|
else wl.acquire(timeout);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void releaseWakelock(String name) {
|
|
|
|
|
|
|
|
PowerManager.WakeLock wl = null;
|
|
|
|
|
|
|
|
synchronized (mWakeLocks) {
|
|
|
|
|
|
|
|
wl = mWakeLocks.get(name);
|
|
|
|
|
|
|
|
mWakeLocks.remove(name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wl != null) {
|
|
|
|
|
|
|
|
wl.release();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void connect() {
|
|
|
|
private void connect() {
|
|
|
|
// after 10 seconds its connected
|
|
|
|
// after 10 seconds its connected
|
|
|
|
new android.os.Handler().postDelayed(
|
|
|
|
new android.os.Handler().postDelayed(
|
|
|
@ -510,173 +567,62 @@ public class MicroPhotoService extends Service {
|
|
|
|
.setContentIntent(pendingIntent);
|
|
|
|
.setContentIntent(pendingIntent);
|
|
|
|
|
|
|
|
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
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();
|
|
|
|
return notificationBuilder.build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected String getNetworkType() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ConnectionManager instance
|
|
|
|
public static String buildAppDir(Context contxt) {
|
|
|
|
ConnectivityManager connectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
|
|
|
|
|
NetworkInfo ni = connectivityManager.getActiveNetworkInfo();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If not connected, "-" will be displayed
|
|
|
|
File[] paths = contxt.getExternalFilesDirs(null);
|
|
|
|
if (ni == null || !ni.isConnected()) return "";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If Connected to Wifi
|
|
|
|
|
|
|
|
if (ni.getType() == ConnectivityManager.TYPE_WIFI) return "WIFI";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If Connected to Mobile
|
|
|
|
|
|
|
|
String subTypeName = "";
|
|
|
|
|
|
|
|
if (ni.getType() == ConnectivityManager.TYPE_MOBILE) {
|
|
|
|
|
|
|
|
int subType = ni.getSubtype();
|
|
|
|
|
|
|
|
switch (subType) {
|
|
|
|
|
|
|
|
case TelephonyManager.NETWORK_TYPE_GPRS:
|
|
|
|
|
|
|
|
case TelephonyManager.NETWORK_TYPE_EDGE:
|
|
|
|
|
|
|
|
case TelephonyManager.NETWORK_TYPE_CDMA:
|
|
|
|
|
|
|
|
case TelephonyManager.NETWORK_TYPE_1xRTT:
|
|
|
|
|
|
|
|
case TelephonyManager.NETWORK_TYPE_IDEN:
|
|
|
|
|
|
|
|
case TelephonyManager.NETWORK_TYPE_GSM:
|
|
|
|
|
|
|
|
subTypeName = "2G";
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TelephonyManager.NETWORK_TYPE_UMTS:
|
|
|
|
|
|
|
|
case TelephonyManager.NETWORK_TYPE_EVDO_0:
|
|
|
|
|
|
|
|
case TelephonyManager.NETWORK_TYPE_EVDO_A:
|
|
|
|
|
|
|
|
case TelephonyManager.NETWORK_TYPE_HSDPA:
|
|
|
|
|
|
|
|
case TelephonyManager.NETWORK_TYPE_HSUPA:
|
|
|
|
|
|
|
|
case TelephonyManager.NETWORK_TYPE_HSPA:
|
|
|
|
|
|
|
|
case TelephonyManager.NETWORK_TYPE_EVDO_B:
|
|
|
|
|
|
|
|
case TelephonyManager.NETWORK_TYPE_EHRPD:
|
|
|
|
|
|
|
|
case TelephonyManager.NETWORK_TYPE_HSPAP:
|
|
|
|
|
|
|
|
case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
|
|
|
|
|
|
|
|
subTypeName = "3G";
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TelephonyManager.NETWORK_TYPE_LTE:
|
|
|
|
|
|
|
|
case TelephonyManager.NETWORK_TYPE_IWLAN:
|
|
|
|
|
|
|
|
case 19:
|
|
|
|
|
|
|
|
subTypeName = "4G";
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TelephonyManager.NETWORK_TYPE_NR:
|
|
|
|
|
|
|
|
subTypeName = "5G";
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
subTypeName = "";
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return subTypeName;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void getPhoneState(Context context) {
|
|
|
|
if (paths == null || paths.length == 0) {
|
|
|
|
final TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
|
return null;
|
|
|
|
PhoneStateListener MyPhoneListener = new PhoneStateListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
//获取对应网络的ID,这个方法在这个程序中没什么用处
|
|
|
|
|
|
|
|
public void onCellLocationChanged(CellLocation location) {
|
|
|
|
|
|
|
|
if (location instanceof GsmCellLocation) {
|
|
|
|
|
|
|
|
int CID = ((GsmCellLocation) location).getCid();
|
|
|
|
|
|
|
|
} else if (location instanceof CdmaCellLocation) {
|
|
|
|
|
|
|
|
int ID = ((CdmaCellLocation) location).getBaseStationId();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//系统自带的服务监听器,实时监听网络状态
|
|
|
|
File path = paths[0];
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onServiceStateChanged(ServiceState serviceState) {
|
|
|
|
|
|
|
|
super.onServiceStateChanged(serviceState);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//这个是我们的主角,就是获取对应网络信号强度
|
|
|
|
if (!path.exists() && !path.mkdirs()) {
|
|
|
|
@Override
|
|
|
|
return null;
|
|
|
|
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
|
|
|
|
|
|
|
|
//这个ltedbm 是4G信号的值
|
|
|
|
|
|
|
|
String signalinfo = signalStrength.toString();
|
|
|
|
|
|
|
|
String[] parts = signalinfo.split(" ");
|
|
|
|
|
|
|
|
String ltedbm = parts[9];
|
|
|
|
|
|
|
|
//这个dbm 是2G和3G信号的值
|
|
|
|
|
|
|
|
int asu = signalStrength.getGsmSignalStrength();
|
|
|
|
|
|
|
|
int dbm = -113 + 2 * asu;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_LTE) {
|
|
|
|
|
|
|
|
Log.i("NetWorkUtil", "网络:LTE 信号强度:" + ltedbm + "======Detail:" + signalinfo);
|
|
|
|
|
|
|
|
} else if (telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSDPA ||
|
|
|
|
|
|
|
|
telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSPA ||
|
|
|
|
|
|
|
|
telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSUPA ||
|
|
|
|
|
|
|
|
telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS) {
|
|
|
|
|
|
|
|
String bin;
|
|
|
|
|
|
|
|
if (dbm > -75) {
|
|
|
|
|
|
|
|
bin = "网络很好";
|
|
|
|
|
|
|
|
} else if (dbm > -85) {
|
|
|
|
|
|
|
|
bin = "网络不错";
|
|
|
|
|
|
|
|
} else if (dbm > -95) {
|
|
|
|
|
|
|
|
bin = "网络还行";
|
|
|
|
|
|
|
|
} else if (dbm > -100) {
|
|
|
|
|
|
|
|
bin = "网络很差";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
bin = "网络错误";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Log.i("NetWorkUtil", "网络:WCDMA 信号值:" + dbm + "========强度:" + bin + "======Detail:" + signalinfo);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String bin;
|
|
|
|
|
|
|
|
if (asu < 0 || asu >= 99) bin = "网络错误";
|
|
|
|
|
|
|
|
else if (asu >= 16) bin = "网络很好";
|
|
|
|
|
|
|
|
else if (asu >= 8) bin = "网络不错";
|
|
|
|
|
|
|
|
else if (asu >= 4) bin = "网络还行";
|
|
|
|
|
|
|
|
else bin = "网络很差";
|
|
|
|
|
|
|
|
Log.i("NetWorkUtil", "网络:GSM 信号值:" + dbm + "========强度:" + bin + "======Detail:" + signalinfo);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
super.onSignalStrengthsChanged(signalStrength);
|
|
|
|
String p = path.getAbsolutePath();
|
|
|
|
|
|
|
|
if (!p.endsWith(File.separator)) {
|
|
|
|
|
|
|
|
p += File.separator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return p;
|
|
|
|
telephonyManager.listen(MyPhoneListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String buildPhotoDir(Context contxt, int channel) {
|
|
|
|
|
|
|
|
// File path = new File(Environment.getExternalStorageDirectory(), "com.xinyingpower.mp/photos/");
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
String appDir = buildAppDir(contxt);
|
|
|
|
public boolean takePhoto(short channel, short preset, String path) {
|
|
|
|
if (appDir == null) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
boolean res = DSCameraManager.getInstace().takePhoto(path, channel, 0, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!res) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int idx = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
res = DSCameraManager.getInstace().isCameraServiceOK();
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Thread.sleep(1000L);
|
|
|
|
|
|
|
|
} catch (InterruptedException ex) {
|
|
|
|
|
|
|
|
// ex.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while(idx < 6);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (DSCameraManager.getInstace().isCameraServiceOK()) {
|
|
|
|
File path = new File(appDir, "photos/");
|
|
|
|
res = DSCameraManager.getInstace().takePhoto(path, channel, 0, 0);
|
|
|
|
|
|
|
|
|
|
|
|
if (!path.exists() && !path.mkdirs()) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String p = path.getAbsolutePath();
|
|
|
|
|
|
|
|
if (!p.endsWith(File.separator)) {
|
|
|
|
|
|
|
|
p += File.separator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
return p;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
private String buildPhotoFileName(int channel, int preset, long ts) {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onDestroy() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stateService = STATE_SERVICE.NOT_CONNECTED;
|
|
|
|
String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
|
|
|
|
|
|
|
String photoFile = "img_" + Integer.toString(channel) + "_" + Integer.toHexString(preset).toUpperCase() + "_" + date + ".jpg";
|
|
|
|
|
|
|
|
return photoFile;
|
|
|
|
|
|
|
|
|
|
|
|
uninit();
|
|
|
|
|
|
|
|
DSCameraManager.getInstace().unInit();
|
|
|
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected boolean updateTime(long timeInMillis) {
|
|
|
|
public boolean updateTime(long timeInMillis) {
|
|
|
|
boolean res = false;
|
|
|
|
boolean res = false;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// Calendar c = Calendar.getInstance();
|
|
|
|
// Calendar c = Calendar.getInstance();
|
|
|
@ -690,37 +636,24 @@ public class MicroPhotoService extends Service {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String buildPhotoDir(int channel) {
|
|
|
|
/*
|
|
|
|
File path = new File(Environment.getExternalStorageDirectory(), "com.xyp.mp/photos/");
|
|
|
|
TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
|
|
|
|
|
// for example value of first element
|
|
|
|
if (!path.exists() && !path.mkdirs()) {
|
|
|
|
CellInfoGsm cellInfoGsm = (CellInfoGsm)telephonyManager.getAllCellInfo().get(0);
|
|
|
|
return null;
|
|
|
|
CellSignalStrengthGsm cellSignalStrengthGsm = cellInfoGsm.getCellSignalStrength();
|
|
|
|
}
|
|
|
|
cellSignalStrengthGsm.getDbm();
|
|
|
|
String p = path.getAbsolutePath();
|
|
|
|
*/
|
|
|
|
if (!p.endsWith(File.separator)) {
|
|
|
|
|
|
|
|
p += File.separator;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return p;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String buildPhotoFileName(int channel, int preset, long ts) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
|
|
|
|
|
|
|
String photoFile = "img_" + Integer.toString(channel) + "_" + Integer.toHexString(preset).toUpperCase() + "_" + date + ".jpg";
|
|
|
|
|
|
|
|
return photoFile;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected native boolean 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();
|
|
|
|
protected native long getHeartbeatDuration(long handler);
|
|
|
|
protected native long[] getPhotoTimeData();
|
|
|
|
protected native long[] getPhotoTimeData(long handler);
|
|
|
|
protected native long[] getNextScheduleItem();
|
|
|
|
// protected native long[] getNextScheduleItem(long handler);
|
|
|
|
protected native boolean notifyToTakePhoto(int channel, int preset, long scheduleTime, String path, String fileName, boolean sendToCma);
|
|
|
|
protected native boolean notifyToTakePhoto(long handler, int channel, int preset, long scheduleTime, String path, String fileName, boolean sendToCma);
|
|
|
|
protected native boolean sendHeartbeat();
|
|
|
|
protected native boolean sendHeartbeat(long handler);
|
|
|
|
protected native boolean fireTimeout(long uid);
|
|
|
|
protected native boolean fireTimeout(long handler, long uid, long times);
|
|
|
|
protected native boolean uninit();
|
|
|
|
protected native boolean uninit(long handler);
|
|
|
|
protected long mHandler = 0;
|
|
|
|
protected long mHandler = 0;
|
|
|
|
|
|
|
|
|
|
|
|
private AlarmReceiver alarmReceiver = null;
|
|
|
|
private AlarmReceiver alarmReceiver = null;
|
|
|
|
|
|
|
|
private ScreenActionReceiver screenactionreceiver = null;
|
|
|
|
}
|
|
|
|
}
|