From 9e92fc696305d903b8a725aa73bb2369531854c1 Mon Sep 17 00:00:00 2001 From: Menaka Jayawardena Date: Mon, 5 Dec 2016 21:48:22 +0530 Subject: [PATCH 1/2] Added classes for reading network data. --- .../sense/event/streams/data/NetworkData.java | 60 +++++++++++++++++++ .../streams/data/NetworkDataReceiver.java | 42 +++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/data/NetworkData.java create mode 100644 components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/data/NetworkDataReceiver.java diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/data/NetworkData.java b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/data/NetworkData.java new file mode 100644 index 0000000000..47b32325c7 --- /dev/null +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/data/NetworkData.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.iot.android.sense.event.streams.data; + +import java.util.Date; + +public class NetworkData { + + //Mobile or Wifi + private String DATA_TYPE; + private long dataReceived; + private long dataSent; + private long timeStamp; + + public NetworkData(long received, long sent) { + this.dataReceived = received; + this.dataSent = sent; + this.timeStamp = new Date().getTime(); + } + + public String getDataType() { + return DATA_TYPE; + } + + public long getDataReceived() { + return dataReceived; + } + + public void setDataReceived(long dataReceived) { + this.dataReceived = dataReceived; + } + + public long getDataSent() { + return dataSent; + } + + public void setDataSent(long dataSent) { + this.dataSent = dataSent; + } + + public long getTimeStamp() { + return timeStamp; + } +} diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/data/NetworkDataReceiver.java b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/data/NetworkDataReceiver.java new file mode 100644 index 0000000000..bcf353ffee --- /dev/null +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/data/NetworkDataReceiver.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.iot.android.sense.event.streams.data; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +import org.wso2.carbon.iot.android.sense.util.SenseDataHolder; + +public class NetworkDataReceiver extends BroadcastReceiver{ + + @Override + public void onReceive(Context context, Intent intent) { + long sent = android.net.TrafficStats.getTotalTxBytes(); + long received = android.net.TrafficStats.getTotalRxBytes(); + Log.d("NetworkData :", "Received: " + sent + " Received : " + received); + + NetworkData networkData = new NetworkData(received, sent); + + SenseDataHolder.getNetworkDataHolder().add(networkData); + + } + +} From 1cb9be42fdeb2b775f03f33d0e25061ef85d4b8f Mon Sep 17 00:00:00 2001 From: Menaka Jayawardena Date: Mon, 5 Dec 2016 21:49:15 +0530 Subject: [PATCH 2/2] Corrected package names. --- .../android/sense/data/publisher/DataPublisherService.java | 6 +++--- .../android/sense/event/streams/SenseDataCollector.java | 7 +++---- .../event/streams/{Location => location}/LocationData.java | 2 +- .../streams/{Location => location}/LocationDataReader.java | 2 +- .../sense/event/streams/{Sensor => sensor}/SensorData.java | 2 +- .../event/streams/{Sensor => sensor}/SensorDataReader.java | 2 +- .../sense/event/streams/{Speed => speed}/SpeedData.java | 2 +- .../event/streams/{Speed => speed}/SpeedDataReader.java | 7 ++----- .../android/sense/speech/detector/util/ProcessWords.java | 3 +-- .../carbon/iot/android/sense/util/SenseDataHolder.java | 6 +++--- 10 files changed, 17 insertions(+), 22 deletions(-) rename components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/{Location => location}/LocationData.java (95%) rename components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/{Location => location}/LocationDataReader.java (99%) rename components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/{Sensor => sensor}/SensorData.java (97%) rename components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/{Sensor => sensor}/SensorDataReader.java (98%) rename components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/{Speed => speed}/SpeedData.java (95%) rename components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/{Speed => speed}/SpeedDataReader.java (96%) diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/DataPublisherService.java b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/DataPublisherService.java index f0bdffae23..0335ffe50b 100755 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/DataPublisherService.java +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/DataPublisherService.java @@ -29,9 +29,9 @@ 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.transport.MQTTTransportHandler; 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.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.application.ApplicationData; import org.wso2.carbon.iot.android.sense.event.streams.audio.AudioData; diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/SenseDataCollector.java b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/SenseDataCollector.java index 726e55fd41..086f7d40ab 100755 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/SenseDataCollector.java +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/SenseDataCollector.java @@ -15,10 +15,9 @@ package org.wso2.carbon.iot.android.sense.event.streams; import android.content.Context; -import org.wso2.carbon.iot.android.sense.event.streams.Location.LocationDataReader; -import org.wso2.carbon.iot.android.sense.event.streams.Sensor.SensorDataReader; -import org.wso2.carbon.iot.android.sense.event.streams.Speed.SpeedDataReader; -import org.wso2.carbon.iot.android.sense.beacon.MonitoringActivity; +import org.wso2.carbon.iot.android.sense.event.streams.location.LocationDataReader; +import org.wso2.carbon.iot.android.sense.event.streams.sensor.SensorDataReader; +import org.wso2.carbon.iot.android.sense.event.streams.speed.SpeedDataReader; import org.wso2.carbon.iot.android.sense.event.streams.audio.AudioDataReader; /** diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Location/LocationData.java b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/location/LocationData.java similarity index 95% rename from components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Location/LocationData.java rename to components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/location/LocationData.java index 3f5de2888f..c534990609 100755 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Location/LocationData.java +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/location/LocationData.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and limitations under the License. * */ -package org.wso2.carbon.iot.android.sense.event.streams.Location; +package org.wso2.carbon.iot.android.sense.event.streams.location; import java.util.Date; diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Location/LocationDataReader.java b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/location/LocationDataReader.java similarity index 99% rename from components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Location/LocationDataReader.java rename to components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/location/LocationDataReader.java index b85969aa47..976e6d0bdc 100755 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Location/LocationDataReader.java +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/location/LocationDataReader.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and limitations under the License. * */ -package org.wso2.carbon.iot.android.sense.event.streams.Location; +package org.wso2.carbon.iot.android.sense.event.streams.location; import android.content.Context; import android.content.Intent; diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Sensor/SensorData.java b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/sensor/SensorData.java similarity index 97% rename from components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Sensor/SensorData.java rename to components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/sensor/SensorData.java index abdfeb1555..a8c0d03643 100755 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Sensor/SensorData.java +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/sensor/SensorData.java @@ -12,7 +12,7 @@ * */ -package org.wso2.carbon.iot.android.sense.event.streams.Sensor; +package org.wso2.carbon.iot.android.sense.event.streams.sensor; import android.hardware.SensorEvent; diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Sensor/SensorDataReader.java b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/sensor/SensorDataReader.java similarity index 98% rename from components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Sensor/SensorDataReader.java rename to components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/sensor/SensorDataReader.java index 9df0447045..0ddc42236d 100755 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Sensor/SensorDataReader.java +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/sensor/SensorDataReader.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and limitations under the License. * */ -package org.wso2.carbon.iot.android.sense.event.streams.Sensor; +package org.wso2.carbon.iot.android.sense.event.streams.sensor; import android.content.Context; import android.content.SharedPreferences; diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Speed/SpeedData.java b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/speed/SpeedData.java similarity index 95% rename from components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Speed/SpeedData.java rename to components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/speed/SpeedData.java index a4e71301c4..2093fcbd44 100644 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Speed/SpeedData.java +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/speed/SpeedData.java @@ -13,7 +13,7 @@ */ -package org.wso2.carbon.iot.android.sense.event.streams.Speed; +package org.wso2.carbon.iot.android.sense.event.streams.speed; import java.util.Date; diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Speed/SpeedDataReader.java b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/speed/SpeedDataReader.java similarity index 96% rename from components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Speed/SpeedDataReader.java rename to components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/speed/SpeedDataReader.java index f306150f4c..f667391258 100644 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/Speed/SpeedDataReader.java +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/event/streams/speed/SpeedDataReader.java @@ -12,10 +12,10 @@ * */ -package org.wso2.carbon.iot.android.sense.event.streams.Speed; +package org.wso2.carbon.iot.android.sense.event.streams.speed; import org.wso2.carbon.iot.android.sense.event.streams.DataReader; -import org.wso2.carbon.iot.android.sense.event.streams.Sensor.SensorData; +import org.wso2.carbon.iot.android.sense.event.streams.sensor.SensorData; import org.wso2.carbon.iot.android.sense.realtimeviewer.sensorlisting.SupportedSensors; import org.wso2.carbon.iot.android.sense.util.SenseDataHolder; import android.content.Context; @@ -37,9 +37,6 @@ import java.util.concurrent.TimeUnit; import android.content.BroadcastReceiver; import android.content.Intent; -import android.app.Activity; -import org.wso2.carbon.iot.android.sense.event.streams.Location.LocationDataReader; - public class SpeedDataReader extends DataReader implements SensorEventListener { diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/speech/detector/util/ProcessWords.java b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/speech/detector/util/ProcessWords.java index 9933904a57..cbd1ed2b52 100755 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/speech/detector/util/ProcessWords.java +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/speech/detector/util/ProcessWords.java @@ -18,9 +18,8 @@ import android.os.AsyncTask; import android.widget.EditText; import org.apache.commons.codec.language.Soundex; -import org.wso2.carbon.iot.android.sense.event.streams.Location.LocationData; import org.wso2.carbon.iot.android.sense.util.SenseDataHolder; -import java.util.ArrayList; + import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/util/SenseDataHolder.java b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/util/SenseDataHolder.java index 34e5470daa..3e2335e91a 100755 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/util/SenseDataHolder.java +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/util/SenseDataHolder.java @@ -14,9 +14,9 @@ package org.wso2.carbon.iot.android.sense.util; import org.wso2.carbon.iot.android.sense.beacon.BeaconScanedData; -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.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.application.ApplicationData; import org.wso2.carbon.iot.android.sense.event.streams.audio.AudioData;