From 9e92fc696305d903b8a725aa73bb2369531854c1 Mon Sep 17 00:00:00 2001 From: Menaka Jayawardena Date: Mon, 5 Dec 2016 21:48:22 +0530 Subject: [PATCH] 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); + + } + +}