|
|
@ -14,6 +14,8 @@ import android.location.Location;
|
|
|
|
import android.location.LocationListener;
|
|
|
|
import android.location.LocationListener;
|
|
|
|
import android.location.LocationManager;
|
|
|
|
import android.location.LocationManager;
|
|
|
|
import android.location.LocationProvider;
|
|
|
|
import android.location.LocationProvider;
|
|
|
|
|
|
|
|
import android.net.ConnectivityManager;
|
|
|
|
|
|
|
|
import android.net.wifi.WifiManager;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.IBinder;
|
|
|
|
import android.os.IBinder;
|
|
|
@ -75,6 +77,7 @@ public class MicroPhotoService extends 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 static int mStateService = STATE_SERVICE.NOT_CONNECTED;
|
|
|
|
|
|
|
|
|
|
|
|
private String mCmdid = "";
|
|
|
|
private String mCmdid = "";
|
|
|
|
private NotificationManager mNotificationManager;
|
|
|
|
private NotificationManager mNotificationManager;
|
|
|
@ -84,7 +87,12 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
|
|
private PositionManager mPositionManager = null;
|
|
|
|
private PositionManager mPositionManager = null;
|
|
|
|
private final Map<Long, PendingIntent> mTimers = new HashMap<>();
|
|
|
|
private final Map<Long, PendingIntent> mTimers = new HashMap<>();
|
|
|
|
private static int stateService = STATE_SERVICE.NOT_CONNECTED;
|
|
|
|
|
|
|
|
|
|
|
|
protected long mHandler = 0;
|
|
|
|
|
|
|
|
private AlarmReceiver mAlarmReceiver = null;
|
|
|
|
|
|
|
|
private ScreenActionReceiver mScreenaAtionReceiver = null;
|
|
|
|
|
|
|
|
private NetworkChangedReceiver mNetworkChangedReceiver = null;
|
|
|
|
|
|
|
|
|
|
|
|
public MicroPhotoService() {
|
|
|
|
public MicroPhotoService() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -97,19 +105,30 @@ public class MicroPhotoService extends Service {
|
|
|
|
super.onCreate();
|
|
|
|
super.onCreate();
|
|
|
|
|
|
|
|
|
|
|
|
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
|
|
|
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
|
|
|
stateService = STATE_SERVICE.NOT_CONNECTED;
|
|
|
|
mStateService = STATE_SERVICE.NOT_CONNECTED;
|
|
|
|
|
|
|
|
|
|
|
|
DeviceUtil.getPhoneState(this.getApplicationContext());
|
|
|
|
DeviceUtil.getPhoneState(this.getApplicationContext());
|
|
|
|
|
|
|
|
|
|
|
|
alarmReceiver = new AlarmReceiver(this);
|
|
|
|
|
|
|
|
screenactionreceiver = new ScreenActionReceiver();
|
|
|
|
mScreenaAtionReceiver = new ScreenActionReceiver();
|
|
|
|
|
|
|
|
|
|
|
|
// 注册广播接受者
|
|
|
|
// 注册广播接受者
|
|
|
|
IntentFilter intentFilter = new IntentFilter(ACTION_HEARTBEAT);
|
|
|
|
{
|
|
|
|
intentFilter.addAction(ACTION_TAKE_PHOTO);
|
|
|
|
mAlarmReceiver = new AlarmReceiver(this);
|
|
|
|
intentFilter.addAction(ACTION_TIMEOUT);
|
|
|
|
IntentFilter intentFilter = new IntentFilter(ACTION_HEARTBEAT);
|
|
|
|
intentFilter.addAction(ACTION_TAKE_PHOTO_MANUALLY);
|
|
|
|
intentFilter.addAction(ACTION_TAKE_PHOTO);
|
|
|
|
registerReceiver(alarmReceiver, intentFilter);
|
|
|
|
intentFilter.addAction(ACTION_TIMEOUT);
|
|
|
|
|
|
|
|
intentFilter.addAction(ACTION_TAKE_PHOTO_MANUALLY);
|
|
|
|
|
|
|
|
registerReceiver(mAlarmReceiver, intentFilter);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mNetworkChangedReceiver = new NetworkChangedReceiver();
|
|
|
|
|
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
|
|
|
|
filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
|
|
|
|
|
|
|
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
|
|
|
|
|
|
|
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
|
|
|
|
|
|
|
registerReceiver(mNetworkChangedReceiver, filter);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
|
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
|
|
|
|
|
|
|
|
@ -136,13 +155,14 @@ public class MicroPhotoService extends Service {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
public void onDestroy() {
|
|
|
|
|
|
|
|
|
|
|
|
stateService = STATE_SERVICE.NOT_CONNECTED;
|
|
|
|
mStateService = STATE_SERVICE.NOT_CONNECTED;
|
|
|
|
|
|
|
|
|
|
|
|
uninit(mHandler);
|
|
|
|
uninit(mHandler);
|
|
|
|
mHandler = 0;
|
|
|
|
mHandler = 0;
|
|
|
|
|
|
|
|
|
|
|
|
unregisterReceiver(alarmReceiver);
|
|
|
|
unregisterReceiver(mAlarmReceiver);
|
|
|
|
unregisterReceiver(screenactionreceiver);
|
|
|
|
unregisterReceiver(mScreenaAtionReceiver);
|
|
|
|
|
|
|
|
unregisterReceiver(mNetworkChangedReceiver);
|
|
|
|
|
|
|
|
|
|
|
|
for(Map.Entry<String, PowerManager.WakeLock> entry : mWakeLocks.entrySet()) {
|
|
|
|
for(Map.Entry<String, PowerManager.WakeLock> entry : mWakeLocks.entrySet()) {
|
|
|
|
entry.getValue().release();
|
|
|
|
entry.getValue().release();
|
|
|
@ -331,6 +351,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
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);
|
|
|
@ -340,6 +361,7 @@ 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);
|
|
|
@ -450,7 +472,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
|
|
connect();
|
|
|
|
connect();
|
|
|
|
|
|
|
|
|
|
|
|
registerReceiver(screenactionreceiver, screenactionreceiver.getFilter());
|
|
|
|
registerReceiver(mScreenaAtionReceiver, mScreenaAtionReceiver.getFilter());
|
|
|
|
|
|
|
|
|
|
|
|
// File path = getApplicationContext().getFilesDir();
|
|
|
|
// File path = getApplicationContext().getFilesDir();
|
|
|
|
String appPath = buildAppDir(this.getApplicationContext());
|
|
|
|
String appPath = buildAppDir(this.getApplicationContext());
|
|
|
@ -486,7 +508,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
// registerPhotoTimer();
|
|
|
|
// registerPhotoTimer();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case ACTION_STOP:
|
|
|
|
case ACTION_STOP:
|
|
|
|
unregisterReceiver(screenactionreceiver);
|
|
|
|
unregisterReceiver(mScreenaAtionReceiver);
|
|
|
|
|
|
|
|
|
|
|
|
stopForeground(true);
|
|
|
|
stopForeground(true);
|
|
|
|
stopSelf();
|
|
|
|
stopSelf();
|
|
|
@ -535,7 +557,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
Log.d(TAG, "Bluetooth Low Energy device is connected!!");
|
|
|
|
Log.d(TAG, "Bluetooth Low Energy device is connected!!");
|
|
|
|
Toast.makeText(getApplicationContext(), "Connected!", Toast.LENGTH_SHORT).show();
|
|
|
|
Toast.makeText(getApplicationContext(), "Connected!", Toast.LENGTH_SHORT).show();
|
|
|
|
stateService = STATE_SERVICE.CONNECTED;
|
|
|
|
mStateService = STATE_SERVICE.CONNECTED;
|
|
|
|
startForeground(NOTIFICATION_ID_FOREGROUND_SERVICE, prepareNotification());
|
|
|
|
startForeground(NOTIFICATION_ID_FOREGROUND_SERVICE, prepareNotification());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 10000);
|
|
|
|
}, 10000);
|
|
|
@ -574,7 +596,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
remoteViews.setOnClickPendingIntent(R.id.btn_stop, pendingStopIntent);
|
|
|
|
remoteViews.setOnClickPendingIntent(R.id.btn_stop, pendingStopIntent);
|
|
|
|
|
|
|
|
|
|
|
|
// if it is connected
|
|
|
|
// if it is connected
|
|
|
|
switch (stateService) {
|
|
|
|
switch (mStateService) {
|
|
|
|
case STATE_SERVICE.NOT_CONNECTED:
|
|
|
|
case STATE_SERVICE.NOT_CONNECTED:
|
|
|
|
remoteViews.setTextViewText(R.id.tv_state, "DISCONNECTED");
|
|
|
|
remoteViews.setTextViewText(R.id.tv_state, "DISCONNECTED");
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -606,7 +628,6 @@ public class MicroPhotoService extends Service {
|
|
|
|
return notificationBuilder.build();
|
|
|
|
return notificationBuilder.build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String buildAppDir(Context contxt) {
|
|
|
|
public static String buildAppDir(Context contxt) {
|
|
|
|
|
|
|
|
|
|
|
|
File[] paths = contxt.getExternalFilesDirs(null);
|
|
|
|
File[] paths = contxt.getExternalFilesDirs(null);
|
|
|
@ -689,6 +710,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void downloadAndInstall(final String url) {
|
|
|
|
public void downloadAndInstall(final String url) {
|
|
|
|
|
|
|
|
|
|
|
|
final Context context = getApplicationContext();
|
|
|
|
final Context context = getApplicationContext();
|
|
|
@ -737,7 +759,7 @@ public class MicroPhotoService extends Service {
|
|
|
|
SysApi.reboot(getApplicationContext());
|
|
|
|
SysApi.reboot(getApplicationContext());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
handler.postDelayed(runnable, 400);
|
|
|
|
handler.postDelayed(runnable, 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void enableGps(boolean enabled) {
|
|
|
|
public void enableGps(boolean enabled) {
|
|
|
|
SysApi.enableGps(getApplicationContext(), enabled);
|
|
|
|
SysApi.enableGps(getApplicationContext(), enabled);
|
|
|
@ -764,9 +786,7 @@ cellSignalStrengthGsm.getDbm();
|
|
|
|
protected native boolean fireTimeout(long handler, long uid, long times);
|
|
|
|
protected native boolean fireTimeout(long handler, long uid, long times);
|
|
|
|
protected native void updatePosition(long handler, double lon, double lat, long ts);
|
|
|
|
protected native void updatePosition(long handler, double lon, double lat, long ts);
|
|
|
|
protected native boolean uninit(long handler);
|
|
|
|
protected native boolean uninit(long handler);
|
|
|
|
protected long mHandler = 0;
|
|
|
|
|
|
|
|
private AlarmReceiver alarmReceiver = null;
|
|
|
|
|
|
|
|
private ScreenActionReceiver screenactionreceiver = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////GPS////////////////////
|
|
|
|
////////////////////////GPS////////////////////
|
|
|
|
private static final String GPS_LOCATION_NAME = android.location.LocationManager.GPS_PROVIDER;
|
|
|
|
private static final String GPS_LOCATION_NAME = android.location.LocationManager.GPS_PROVIDER;
|
|
|
@ -817,7 +837,5 @@ cellSignalStrengthGsm.getDbm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////GPS////////////////////
|
|
|
|
////////////////////////GPS////////////////////
|
|
|
|
}
|
|
|
|
}
|