|
|
@ -20,7 +20,6 @@ import android.hardware.Sensor;
|
|
|
|
import android.os.IBinder;
|
|
|
|
import android.os.IBinder;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONObject;
|
|
|
@ -29,17 +28,17 @@ import org.wso2.carbon.iot.android.sense.constants.SenseConstants;
|
|
|
|
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.AndroidSenseMQTTHandler;
|
|
|
|
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.AndroidSenseMQTTHandler;
|
|
|
|
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.MQTTTransportHandler;
|
|
|
|
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.MQTTTransportHandler;
|
|
|
|
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.TransportHandlerException;
|
|
|
|
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.TransportHandlerException;
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.location.LocationData;
|
|
|
|
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.sensor.SensorData;
|
|
|
|
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.speed.SpeedData;
|
|
|
|
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.activity.ActivityData;
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.activity.ActivityData;
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.application.ApplicationData;
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.application.ApplicationData;
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.audio.AudioData;
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.audio.AudioData;
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.battery.BatteryData;
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.battery.BatteryData;
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.call.CallData;
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.call.CallData;
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.data.NetworkData;
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.data.NetworkData;
|
|
|
|
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.location.LocationData;
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.screen.ScreenData;
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.screen.ScreenData;
|
|
|
|
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.sensor.SensorData;
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.sms.SmsData;
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.sms.SmsData;
|
|
|
|
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.speed.SpeedData;
|
|
|
|
import org.wso2.carbon.iot.android.sense.speech.detector.util.ProcessWords;
|
|
|
|
import org.wso2.carbon.iot.android.sense.speech.detector.util.ProcessWords;
|
|
|
|
import org.wso2.carbon.iot.android.sense.speech.detector.util.WordData;
|
|
|
|
import org.wso2.carbon.iot.android.sense.speech.detector.util.WordData;
|
|
|
|
import org.wso2.carbon.iot.android.sense.util.LocalRegistry;
|
|
|
|
import org.wso2.carbon.iot.android.sense.util.LocalRegistry;
|
|
|
@ -65,257 +64,250 @@ public class DataPublisherService extends Service {
|
|
|
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
|
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
|
|
context = this;
|
|
|
|
context = this;
|
|
|
|
Log.d(TAG, "service started");
|
|
|
|
Log.d(TAG, "service started");
|
|
|
|
// Runnable runnable = new Runnable() {
|
|
|
|
try {
|
|
|
|
// @Override
|
|
|
|
List<Event> events = new ArrayList<>();
|
|
|
|
// public void run() {
|
|
|
|
//retrieve sensor data.
|
|
|
|
try {
|
|
|
|
List<SensorData> sensorDataMap = SenseDataHolder.getSensorDataHolder();
|
|
|
|
List<Event> events = new ArrayList<>();
|
|
|
|
if (!sensorDataMap.isEmpty()) {
|
|
|
|
//retrieve sensor data.
|
|
|
|
for (SensorData sensorData : sensorDataMap) {
|
|
|
|
List<SensorData> sensorDataMap = SenseDataHolder.getSensorDataHolder();
|
|
|
|
Event event = new Event();
|
|
|
|
if (!sensorDataMap.isEmpty()) {
|
|
|
|
event.setTimestamp(sensorData.getTimestamp());
|
|
|
|
for (SensorData sensorData : sensorDataMap) {
|
|
|
|
switch (sensorData.getSensorType()) {
|
|
|
|
Event event = new Event();
|
|
|
|
case Sensor.TYPE_ACCELEROMETER:
|
|
|
|
event.setTimestamp(sensorData.getTimestamp());
|
|
|
|
event.setAccelerometer(sensorData.getSensorValues());
|
|
|
|
switch (sensorData.getSensorType()) {
|
|
|
|
events.add(event);
|
|
|
|
case Sensor.TYPE_ACCELEROMETER:
|
|
|
|
break;
|
|
|
|
event.setAccelerometer(sensorData.getSensorValues());
|
|
|
|
case Sensor.TYPE_MAGNETIC_FIELD:
|
|
|
|
events.add(event);
|
|
|
|
event.setMagnetic(sensorData.getSensorValues());
|
|
|
|
break;
|
|
|
|
events.add(event);
|
|
|
|
case Sensor.TYPE_MAGNETIC_FIELD:
|
|
|
|
break;
|
|
|
|
event.setMagnetic(sensorData.getSensorValues());
|
|
|
|
case Sensor.TYPE_GYROSCOPE:
|
|
|
|
events.add(event);
|
|
|
|
event.setGyroscope(sensorData.getSensorValues());
|
|
|
|
break;
|
|
|
|
events.add(event);
|
|
|
|
case Sensor.TYPE_GYROSCOPE:
|
|
|
|
break;
|
|
|
|
event.setGyroscope(sensorData.getSensorValues());
|
|
|
|
case Sensor.TYPE_LIGHT:
|
|
|
|
events.add(event);
|
|
|
|
event.setLight(sensorData.getSensorValues()[0]);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case Sensor.TYPE_LIGHT:
|
|
|
|
case Sensor.TYPE_PRESSURE:
|
|
|
|
event.setLight(sensorData.getSensorValues()[0]);
|
|
|
|
event.setPressure(sensorData.getSensorValues()[0]);
|
|
|
|
break;
|
|
|
|
events.add(event);
|
|
|
|
case Sensor.TYPE_PRESSURE:
|
|
|
|
break;
|
|
|
|
event.setPressure(sensorData.getSensorValues()[0]);
|
|
|
|
case Sensor.TYPE_PROXIMITY:
|
|
|
|
events.add(event);
|
|
|
|
event.setProximity(sensorData.getSensorValues()[0]);
|
|
|
|
break;
|
|
|
|
events.add(event);
|
|
|
|
case Sensor.TYPE_PROXIMITY:
|
|
|
|
break;
|
|
|
|
event.setProximity(sensorData.getSensorValues()[0]);
|
|
|
|
case Sensor.TYPE_GRAVITY:
|
|
|
|
events.add(event);
|
|
|
|
event.setGravity(sensorData.getSensorValues());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Sensor.TYPE_GRAVITY:
|
|
|
|
|
|
|
|
event.setGravity(sensorData.getSensorValues());
|
|
|
|
|
|
|
|
events.add(event);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Sensor.TYPE_GAME_ROTATION_VECTOR:
|
|
|
|
|
|
|
|
event.setRotation(sensorData.getSensorValues());
|
|
|
|
|
|
|
|
events.add(event);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SenseDataHolder.resetSensorDataHolder();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//retrieve battery data.
|
|
|
|
|
|
|
|
List<BatteryData> batteryDataMap = SenseDataHolder.getBatteryDataHolder();
|
|
|
|
|
|
|
|
if (!batteryDataMap.isEmpty()) {
|
|
|
|
|
|
|
|
for (BatteryData batteryData : batteryDataMap) {
|
|
|
|
|
|
|
|
Event event = new Event();
|
|
|
|
|
|
|
|
event.setTimestamp(batteryData.getTimestamp());
|
|
|
|
|
|
|
|
event.setBattery(batteryData.getLevel());
|
|
|
|
|
|
|
|
event.setBatteryTemperature(batteryData.getTemperature());
|
|
|
|
|
|
|
|
event.setBatteryStatus(batteryData.getStatus());
|
|
|
|
|
|
|
|
event.setBatteryState(batteryData.getState().toString());
|
|
|
|
|
|
|
|
events.add(event);
|
|
|
|
events.add(event);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Sensor.TYPE_GAME_ROTATION_VECTOR:
|
|
|
|
|
|
|
|
event.setRotation(sensorData.getSensorValues());
|
|
|
|
|
|
|
|
events.add(event);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SenseDataHolder.resetBatteryDataHolder();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SenseDataHolder.resetSensorDataHolder();
|
|
|
|
|
|
|
|
|
|
|
|
//retrieve location data.
|
|
|
|
//retrieve battery data.
|
|
|
|
List<LocationData> locationDataMap = SenseDataHolder.getLocationDataHolder();
|
|
|
|
List<BatteryData> batteryDataMap = SenseDataHolder.getBatteryDataHolder();
|
|
|
|
|
|
|
|
if (!batteryDataMap.isEmpty()) {
|
|
|
|
|
|
|
|
for (BatteryData batteryData : batteryDataMap) {
|
|
|
|
|
|
|
|
Event event = new Event();
|
|
|
|
|
|
|
|
event.setTimestamp(batteryData.getTimestamp());
|
|
|
|
|
|
|
|
event.setBattery(batteryData.getLevel());
|
|
|
|
|
|
|
|
event.setBatteryTemperature(batteryData.getTemperature());
|
|
|
|
|
|
|
|
event.setBatteryStatus(batteryData.getStatus());
|
|
|
|
|
|
|
|
event.setBatteryState(batteryData.getState().toString());
|
|
|
|
|
|
|
|
events.add(event);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SenseDataHolder.resetBatteryDataHolder();
|
|
|
|
|
|
|
|
|
|
|
|
if (!locationDataMap.isEmpty()) {
|
|
|
|
//retrieve location data.
|
|
|
|
for (LocationData locationData : locationDataMap) {
|
|
|
|
List<LocationData> locationDataMap = SenseDataHolder.getLocationDataHolder();
|
|
|
|
Event event = new Event();
|
|
|
|
|
|
|
|
event.setTimestamp(locationData.getTimeStamp());
|
|
|
|
|
|
|
|
event.setGps(new double[]{locationData.getLatitude(), locationData.getLongitude()});
|
|
|
|
|
|
|
|
events.add(event);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SenseDataHolder.resetLocationDataHolder();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//retrieve speed data.
|
|
|
|
if (!locationDataMap.isEmpty()) {
|
|
|
|
List<SpeedData> speedDataMap = SenseDataHolder.getSpeedDataHolder();
|
|
|
|
for (LocationData locationData : locationDataMap) {
|
|
|
|
if (!speedDataMap.isEmpty()) {
|
|
|
|
Event event = new Event();
|
|
|
|
for (SpeedData speedData : speedDataMap) {
|
|
|
|
event.setTimestamp(locationData.getTimeStamp());
|
|
|
|
Event event = new Event();
|
|
|
|
event.setGps(new double[]{locationData.getLatitude(), locationData.getLongitude()});
|
|
|
|
event.setTimestamp(speedData.getTimeStamp());
|
|
|
|
events.add(event);
|
|
|
|
event.setTurns(speedData.getTurns());
|
|
|
|
}
|
|
|
|
event.setSpeed(speedData.getSpeed());
|
|
|
|
}
|
|
|
|
|
|
|
|
SenseDataHolder.resetLocationDataHolder();
|
|
|
|
|
|
|
|
|
|
|
|
events.add(event);
|
|
|
|
//retrieve speed data.
|
|
|
|
}
|
|
|
|
List<SpeedData> speedDataMap = SenseDataHolder.getSpeedDataHolder();
|
|
|
|
}
|
|
|
|
if (!speedDataMap.isEmpty()) {
|
|
|
|
SenseDataHolder.resetSpeedDataHolder();
|
|
|
|
for (SpeedData speedData : speedDataMap) {
|
|
|
|
|
|
|
|
Event event = new Event();
|
|
|
|
|
|
|
|
event.setTimestamp(speedData.getTimeStamp());
|
|
|
|
|
|
|
|
event.setTurns(speedData.getTurns());
|
|
|
|
|
|
|
|
event.setSpeed(speedData.getSpeed());
|
|
|
|
|
|
|
|
|
|
|
|
//retrieve speed data.
|
|
|
|
events.add(event);
|
|
|
|
List<BeaconScanedData> beaconDataMap = SenseDataHolder.getBeaconScanedDataHolder();
|
|
|
|
}
|
|
|
|
if (!speedDataMap.isEmpty()) {
|
|
|
|
}
|
|
|
|
for (BeaconScanedData beaconData : beaconDataMap) {
|
|
|
|
SenseDataHolder.resetSpeedDataHolder();
|
|
|
|
Event event = new Event();
|
|
|
|
|
|
|
|
event.setBeaconMajor(beaconData.getBeaconMajor());
|
|
|
|
|
|
|
|
event.setBeaconMinor(beaconData.getBeaconMinor());
|
|
|
|
|
|
|
|
event.setBeaconProximity(beaconData.getBeaconProximity());
|
|
|
|
|
|
|
|
event.setBeaconUuid(beaconData.getBeaconUuid());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
events.add(event);
|
|
|
|
//retrieve speed data.
|
|
|
|
}
|
|
|
|
List<BeaconScanedData> beaconDataMap = SenseDataHolder.getBeaconScanedDataHolder();
|
|
|
|
}
|
|
|
|
if (!speedDataMap.isEmpty()) {
|
|
|
|
SenseDataHolder.resetSpeedDataHolder();
|
|
|
|
for (BeaconScanedData beaconData : beaconDataMap) {
|
|
|
|
|
|
|
|
Event event = new Event();
|
|
|
|
|
|
|
|
event.setBeaconMajor(beaconData.getBeaconMajor());
|
|
|
|
|
|
|
|
event.setBeaconMinor(beaconData.getBeaconMinor());
|
|
|
|
|
|
|
|
event.setBeaconProximity(beaconData.getBeaconProximity());
|
|
|
|
|
|
|
|
event.setBeaconUuid(beaconData.getBeaconUuid());
|
|
|
|
|
|
|
|
|
|
|
|
//retrieve words
|
|
|
|
events.add(event);
|
|
|
|
ProcessWords.cleanAndPushToWordMap();
|
|
|
|
}
|
|
|
|
List<WordData> wordDatMap = SenseDataHolder.getWordDataHolder();
|
|
|
|
}
|
|
|
|
for (WordData wordData : wordDatMap) {
|
|
|
|
SenseDataHolder.resetSpeedDataHolder();
|
|
|
|
if (wordData.getOccurences() == 0) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
//retrieve words
|
|
|
|
}
|
|
|
|
ProcessWords.cleanAndPushToWordMap();
|
|
|
|
for (int i = 0; i < wordData.getOccurences(); i++) {
|
|
|
|
List<WordData> wordDatMap = SenseDataHolder.getWordDataHolder();
|
|
|
|
Event event = new Event();
|
|
|
|
for (WordData wordData : wordDatMap) {
|
|
|
|
event.setTimestamp(wordData.getTimestamp());
|
|
|
|
if (wordData.getOccurences() == 0) {
|
|
|
|
event.setWord(wordData.getWord());
|
|
|
|
continue;
|
|
|
|
String word = wordData.getWord();
|
|
|
|
}
|
|
|
|
String status = word;
|
|
|
|
for (int i = 0; i < wordData.getOccurences(); i++) {
|
|
|
|
if ((!word.equals(SenseConstants.EVENT_LISTENER_STARTED)) && (!word.equals(SenseConstants
|
|
|
|
Event event = new Event();
|
|
|
|
.EVENT_LISTENER_FINISHED))) {
|
|
|
|
event.setTimestamp(wordData.getTimestamp());
|
|
|
|
status = SenseConstants.EVENT_LISTENER_ONGOING;
|
|
|
|
event.setWord(wordData.getWord());
|
|
|
|
}
|
|
|
|
String word = wordData.getWord();
|
|
|
|
event.setWordStatus(status);
|
|
|
|
String status = word;
|
|
|
|
events.add(event);
|
|
|
|
if ((!word.equals(SenseConstants.EVENT_LISTENER_STARTED)) && (!word.equals(SenseConstants
|
|
|
|
}
|
|
|
|
.EVENT_LISTENER_FINISHED))) {
|
|
|
|
|
|
|
|
status = SenseConstants.EVENT_LISTENER_ONGOING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SenseDataHolder.resetWordDataHolder();
|
|
|
|
event.setWordStatus(status);
|
|
|
|
|
|
|
|
events.add(event);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SenseDataHolder.resetWordDataHolder();
|
|
|
|
|
|
|
|
|
|
|
|
// retrieve call data.
|
|
|
|
// retrieve call data.
|
|
|
|
List<CallData> callDataList = SenseDataHolder.getCallDataHolder();
|
|
|
|
List<CallData> callDataList = SenseDataHolder.getCallDataHolder();
|
|
|
|
if (!callDataList.isEmpty()) {
|
|
|
|
if (!callDataList.isEmpty()) {
|
|
|
|
for (CallData callData : callDataList) {
|
|
|
|
for (CallData callData : callDataList) {
|
|
|
|
Event event = new Event();
|
|
|
|
Event event = new Event();
|
|
|
|
event.setCallNumber(callData.getPhoneNumber());
|
|
|
|
event.setCallNumber(callData.getPhoneNumber());
|
|
|
|
event.setCallType(callData.getType().toString().toLowerCase());
|
|
|
|
event.setCallType(callData.getType().toString().toLowerCase());
|
|
|
|
event.setCallStartTime(callData.getStartTime());
|
|
|
|
event.setCallStartTime(callData.getStartTime());
|
|
|
|
event.setCallEndTime(callData.getEndTime());
|
|
|
|
event.setCallEndTime(callData.getEndTime());
|
|
|
|
event.setTimestamp(callData.getStartTime());
|
|
|
|
event.setTimestamp(callData.getStartTime());
|
|
|
|
|
|
|
|
|
|
|
|
events.add(event);
|
|
|
|
events.add(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SenseDataHolder.resetCallDataHolder();
|
|
|
|
SenseDataHolder.resetCallDataHolder();
|
|
|
|
|
|
|
|
|
|
|
|
// retrieve screen data.
|
|
|
|
// retrieve screen data.
|
|
|
|
List<ScreenData> screenDataList = SenseDataHolder.getScreenDataHolder();
|
|
|
|
List<ScreenData> screenDataList = SenseDataHolder.getScreenDataHolder();
|
|
|
|
if (!screenDataList.isEmpty()) {
|
|
|
|
if (!screenDataList.isEmpty()) {
|
|
|
|
for (ScreenData screenData : screenDataList) {
|
|
|
|
for (ScreenData screenData : screenDataList) {
|
|
|
|
Event event = new Event();
|
|
|
|
Event event = new Event();
|
|
|
|
event.setScreenState(screenData.getAction());
|
|
|
|
event.setScreenState(screenData.getAction());
|
|
|
|
event.setTimestamp(screenData.getTimestamp());
|
|
|
|
event.setTimestamp(screenData.getTimestamp());
|
|
|
|
|
|
|
|
|
|
|
|
events.add(event);
|
|
|
|
events.add(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SenseDataHolder.resetScreenDataHolder();
|
|
|
|
SenseDataHolder.resetScreenDataHolder();
|
|
|
|
|
|
|
|
|
|
|
|
// retrieve audio data.
|
|
|
|
// retrieve audio data.
|
|
|
|
List<AudioData> audioDataList = SenseDataHolder.getAudioDataHolder();
|
|
|
|
List<AudioData> audioDataList = SenseDataHolder.getAudioDataHolder();
|
|
|
|
if (!audioDataList.isEmpty()) {
|
|
|
|
if (!audioDataList.isEmpty()) {
|
|
|
|
for (AudioData audioData : audioDataList) {
|
|
|
|
for (AudioData audioData : audioDataList) {
|
|
|
|
Event event = new Event();
|
|
|
|
Event event = new Event();
|
|
|
|
event.setTimestamp(audioData.getTimestamp());
|
|
|
|
event.setTimestamp(audioData.getTimestamp());
|
|
|
|
event.setAudioPlaying(audioData.isPlaying());
|
|
|
|
event.setAudioPlaying(audioData.isPlaying());
|
|
|
|
event.setHeadsetOn(audioData.isHeadsetOn());
|
|
|
|
event.setHeadsetOn(audioData.isHeadsetOn());
|
|
|
|
event.setMusicVolume(audioData.getMusicVolume());
|
|
|
|
event.setMusicVolume(audioData.getMusicVolume());
|
|
|
|
events.add(event);
|
|
|
|
events.add(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SenseDataHolder.resetAudioDataHolder();
|
|
|
|
SenseDataHolder.resetAudioDataHolder();
|
|
|
|
|
|
|
|
|
|
|
|
// retrieve activity data.
|
|
|
|
// retrieve activity data.
|
|
|
|
List<ActivityData> activityDataList = SenseDataHolder.getActivityDataHolder();
|
|
|
|
List<ActivityData> activityDataList = SenseDataHolder.getActivityDataHolder();
|
|
|
|
if (!activityDataList.isEmpty()) {
|
|
|
|
if (!activityDataList.isEmpty()) {
|
|
|
|
for (ActivityData activityData : activityDataList) {
|
|
|
|
for (ActivityData activityData : activityDataList) {
|
|
|
|
Event event = new Event();
|
|
|
|
Event event = new Event();
|
|
|
|
event.setTimestamp(activityData.getTimestamp());
|
|
|
|
event.setTimestamp(activityData.getTimestamp());
|
|
|
|
event.setActivityType(activityData.getActivity());
|
|
|
|
event.setActivityType(activityData.getActivity());
|
|
|
|
event.setConfidence(activityData.getConfidence());
|
|
|
|
event.setConfidence(activityData.getConfidence());
|
|
|
|
events.add(event);
|
|
|
|
events.add(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SenseDataHolder.resetActivityDataHolder();
|
|
|
|
SenseDataHolder.resetActivityDataHolder();
|
|
|
|
|
|
|
|
|
|
|
|
// retrieve sms data.
|
|
|
|
// retrieve sms data.
|
|
|
|
List<SmsData> smsDataList = SenseDataHolder.getSmsDataHolder();
|
|
|
|
List<SmsData> smsDataList = SenseDataHolder.getSmsDataHolder();
|
|
|
|
if (!smsDataList.isEmpty()) {
|
|
|
|
if (!smsDataList.isEmpty()) {
|
|
|
|
for (SmsData smsData : smsDataList) {
|
|
|
|
for (SmsData smsData : smsDataList) {
|
|
|
|
Event event = new Event();
|
|
|
|
Event event = new Event();
|
|
|
|
event.setTimestamp(smsData.getTimestamp());
|
|
|
|
event.setTimestamp(smsData.getTimestamp());
|
|
|
|
event.setSmsNumber(smsData.getPhoneNumber());
|
|
|
|
event.setSmsNumber(smsData.getPhoneNumber());
|
|
|
|
events.add(event);
|
|
|
|
events.add(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SenseDataHolder.resetSmsDataHolder();
|
|
|
|
SenseDataHolder.resetSmsDataHolder();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// retrieve application data.
|
|
|
|
// retrieve application data.
|
|
|
|
List<ApplicationData> appDataList = SenseDataHolder.getApplicationDataHolder();
|
|
|
|
List<ApplicationData> appDataList = SenseDataHolder.getApplicationDataHolder();
|
|
|
|
if (!appDataList.isEmpty()) {
|
|
|
|
if (!appDataList.isEmpty()) {
|
|
|
|
for (ApplicationData appData : appDataList) {
|
|
|
|
for (ApplicationData appData : appDataList) {
|
|
|
|
Event event = new Event();
|
|
|
|
Event event = new Event();
|
|
|
|
event.setTimestamp(appData.getTimestamp());
|
|
|
|
event.setTimestamp(appData.getTimestamp());
|
|
|
|
event.setPackageName(appData.getPackageName());
|
|
|
|
event.setPackageName(appData.getPackageName());
|
|
|
|
event.setAction(appData.getAction().toString());
|
|
|
|
event.setAction(appData.getAction().toString());
|
|
|
|
events.add(event);
|
|
|
|
events.add(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SenseDataHolder.resetApplicationDataHolder();
|
|
|
|
SenseDataHolder.resetApplicationDataHolder();
|
|
|
|
|
|
|
|
|
|
|
|
//Retrieve network data
|
|
|
|
//Retrieve network data
|
|
|
|
List<NetworkData> networkDataList = SenseDataHolder.getNetworkDataHolder();
|
|
|
|
List<NetworkData> networkDataList = SenseDataHolder.getNetworkDataHolder();
|
|
|
|
if (!networkDataList.isEmpty()) {
|
|
|
|
if (!networkDataList.isEmpty()) {
|
|
|
|
for (NetworkData networkData : networkDataList) {
|
|
|
|
for (NetworkData networkData : networkDataList) {
|
|
|
|
Event event = new Event();
|
|
|
|
Event event = new Event();
|
|
|
|
event.setTimestamp(networkData.getTimeStamp());
|
|
|
|
event.setTimestamp(networkData.getTimeStamp());
|
|
|
|
event.setDataType(networkData.getDataType());
|
|
|
|
event.setDataType(networkData.getDataType());
|
|
|
|
event.setDataReceived(networkData.getDataReceived());
|
|
|
|
event.setDataReceived(networkData.getDataReceived());
|
|
|
|
event.setDataSent(networkData.getDataSent());
|
|
|
|
event.setDataSent(networkData.getDataSent());
|
|
|
|
events.add(event);
|
|
|
|
events.add(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SenseDataHolder.resetNetworkDataHolder();
|
|
|
|
SenseDataHolder.resetNetworkDataHolder();
|
|
|
|
|
|
|
|
|
|
|
|
//publish the data
|
|
|
|
//publish the data
|
|
|
|
if (events.size() > 0 && LocalRegistry.isEnrolled(context)) {
|
|
|
|
if (events.size() > 0 && LocalRegistry.isEnrolled(context)) {
|
|
|
|
String user = LocalRegistry.getUsername(context);
|
|
|
|
String user = LocalRegistry.getUsername(context);
|
|
|
|
String deviceId = LocalRegistry.getDeviceId(context);
|
|
|
|
String deviceId = LocalRegistry.getDeviceId(context);
|
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
|
for (Event event : events) {
|
|
|
|
for (Event event : events) {
|
|
|
|
event.setOwner(user);
|
|
|
|
event.setOwner(user);
|
|
|
|
event.setDeviceId(deviceId);
|
|
|
|
event.setDeviceId(deviceId);
|
|
|
|
jsonArray.put(new JSONObject().put("event", event.getEvent()));
|
|
|
|
jsonArray.put(new JSONObject().put("event", event.getEvent()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MQTTTransportHandler mqttTransportHandler = AndroidSenseMQTTHandler.getInstance(context);
|
|
|
|
MQTTTransportHandler mqttTransportHandler = AndroidSenseMQTTHandler.getInstance(context);
|
|
|
|
if (!mqttTransportHandler.isConnected()) {
|
|
|
|
if (!mqttTransportHandler.isConnected()) {
|
|
|
|
mqttTransportHandler.connect();
|
|
|
|
mqttTransportHandler.connect();
|
|
|
|
}
|
|
|
|
|
|
|
|
String topic = LocalRegistry.getTenantDomain(context) + "/" + SenseConstants.DEVICE_TYPE + "/" + deviceId + "/data";
|
|
|
|
|
|
|
|
mqttTransportHandler.publishDeviceData(user, deviceId, jsonArray.toString(), topic);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
|
|
|
Log.e(TAG, "Json Data Parsing Exception", e);
|
|
|
|
|
|
|
|
} catch (TransportHandlerException e) {
|
|
|
|
|
|
|
|
Log.e(TAG, "Data Publish Failed", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
String topic = LocalRegistry.getTenantDomain(context) + "/" + SenseConstants.DEVICE_TYPE + "/" + deviceId + "/data";
|
|
|
|
// };
|
|
|
|
mqttTransportHandler.publishDeviceData(user, deviceId, jsonArray.toString(), topic);
|
|
|
|
// Thread dataUploaderThread = new Thread(runnable);
|
|
|
|
}
|
|
|
|
// dataUploaderThread.start();
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
|
|
|
Log.e(TAG, "Json Data Parsing Exception", e);
|
|
|
|
|
|
|
|
} catch (TransportHandlerException e) {
|
|
|
|
|
|
|
|
Log.e(TAG, "Data Publish Failed", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
return Service.START_NOT_STICKY;
|
|
|
|
return Service.START_NOT_STICKY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|