Added Web File Download behaviour.

Added buffer limit for surfing behaviour.
Changed name of log files to csv.
This commit is contained in:
Ziver Koc 2014-08-04 13:35:06 +02:00
parent acd7f21f11
commit 7ca05039b5
9 changed files with 95 additions and 45 deletions

Binary file not shown.

View file

@ -8,8 +8,8 @@ android {
applicationId "com.ericsson.uecontrol"
minSdkVersion 15
targetSdkVersion 19
versionCode 6
versionName "1.0.6"
versionCode 7
versionName "1.0.7"
}
buildTypes {
release {

View file

@ -10,9 +10,9 @@ import org.apache.log4j.Logger;
public abstract class UeBehaviour {
private static final Logger log = Logger.getLogger(UeBehaviour.class);
private boolean running;
private BehaviourExecutionListener execListener;
private DataHandledListener datahandledListener;
private transient boolean running;
private transient BehaviourExecutionListener execListener;
private transient DataHandledListener datahandledListener;
/**
* Starts to run the behaviour, this method will block until the execution is done

View file

@ -34,6 +34,13 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
b.setDataHandledListener(this);
}
public void read(String file){
}
public void save(String file){
}
public void execute(){
if(thread == null || !thread.isAlive()) {
@ -58,6 +65,7 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
public void run(){
while(!terminate) {
if(behaviours.isEmpty()) {
currentlyActive = null;
terminate();
break;
}

View file

@ -0,0 +1,61 @@
package com.ericsson.uecontrol.core.behaviour;
import com.ericsson.uecontrol.core.UeBehaviour;
import com.ericsson.uecontrol.gui.util.Configurator.Configurable;
import org.apache.log4j.Logger;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
/**
* This behaviour simulates downloading a file from the web
*
* Created by ezivkoc on 2014-07-15.
*/
public class UeBehaviourFileDownload extends UeBehaviour {
private static final Logger log = Logger.getLogger(UeBehaviourFileDownload.class);
@Configurable("File address")
private String url;
@Override
protected void execute() throws IOException {
URL url = new URL(getFileUrl());
log.debug("Downloading file: " + url);
byte[] data = new byte[100];
URLConnection connection = url.openConnection();
connection.setUseCaches(false);
connection.connect();
InputStream in = connection.getInputStream();
long total = in.available();
long progress = 0;
long read = 0;
while((read = in.read(data)) != -1 && !stopExecution()){
progress += read;
super.setProgress((float)progress/total);
super.setHandledIncomingData(read);
}
}
protected String getFileUrl() {
return url;
}
@Override
public String getName() {
return "File Download";
}
@Override
public String toString() {
return "Will download "+ getFileUrl();
}
}

View file

@ -1,7 +1,5 @@
package com.ericsson.uecontrol.core.behaviour;
import android.util.Log;
import com.ericsson.uecontrol.core.UeBehaviour;
import com.ericsson.uecontrol.gui.util.Configurator.Configurable;
@ -13,12 +11,12 @@ import java.net.URL;
import java.net.URLConnection;
/**
* This behaviour simulates visiting a website
* This behaviour simulates downloading a file from FTP
*
* Created by ezivkoc on 2014-07-15.
*/
public class UeBehaviourFtp extends UeBehaviour {
private static final Logger log = Logger.getLogger(UeBehaviourFtp.class);
public class UeBehaviourFtpDownload extends UeBehaviourFileDownload {
private static final Logger log = Logger.getLogger(UeBehaviourFtpDownload.class);
@Configurable("Host")
private String host;
@ -31,28 +29,7 @@ public class UeBehaviourFtp extends UeBehaviour {
@Override
protected void execute() throws IOException {
URL url = new URL(getFtpUrl());
log.debug("Downloading from FTP: " + url);
byte[] data = new byte[100];
URLConnection connection = url.openConnection();
connection.setUseCaches(false);
connection.connect();
InputStream in = connection.getInputStream();
long total = in.available();
long progress = 0;
long read = 0;
while((read = in.read(data)) != -1 && !stopExecution()){
progress += read;
super.setProgress((float)progress/total);
super.setHandledIncomingData(read);
}
}
private String getFtpUrl() {
protected String getFileUrl() {
String url = "ftp://";
if(username != null && !username.isEmpty()) {
url += username;
@ -75,8 +52,4 @@ public class UeBehaviourFtp extends UeBehaviour {
return "FTP Download";
}
@Override
public String toString() {
return "Will download "+ getFtpUrl();
}
}

View file

@ -26,11 +26,12 @@ import java.util.regex.Pattern;
*/
public class UeBehaviourSurfing extends UeBehaviour {
private static final Logger log = Logger.getLogger(UeBehaviourSurfing.class);
protected static final int MAX_BUFFER_SIZE = 500000;
@Configurable("Web Address")
private String rootUrl;
private long estimatedDataLength = -1;
private transient long estimatedDataLength = -1;
public UeBehaviourSurfing(){
this("http://google.com");
@ -96,7 +97,10 @@ public class UeBehaviourSurfing extends UeBehaviour {
totalRead += read;
super.setProgress((float) totalRead / estimatedDataLength);
super.setHandledIncomingData(read);
content.append(new String(data, 0, read));
if(cont.parsable)
content.append(new String(data, 0, read));
if(content.length() > MAX_BUFFER_SIZE)
break;
}
if(cont.parsable)
getAdditionalContent(cont.url, content.toString(), urlList);

View file

@ -42,7 +42,7 @@ public class CSVWriter {
if(!path.endsWith(File.separator)) path += File.separator;
file = new File(
path,
"log_"+fileDateFormater.format(System.currentTimeMillis())+".log");
"log_"+fileDateFormater.format(System.currentTimeMillis())+".csv");
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
netInfo = cm.getActiveNetworkInfo();
@ -87,11 +87,14 @@ public class CSVWriter {
protected String getRat(){
if(netInfo.getType() == ConnectivityManager.TYPE_MOBILE){
switch(telMan.getNetworkType()){
case TelephonyManager.NETWORK_TYPE_GPRS: return "GPRS";
case TelephonyManager.NETWORK_TYPE_EDGE: return "EDGE";
case TelephonyManager.NETWORK_TYPE_UMTS: return "UMTS";
case TelephonyManager.NETWORK_TYPE_HSPA: return "HSPA";
case TelephonyManager.NETWORK_TYPE_LTE: return "LTE";
case TelephonyManager.NETWORK_TYPE_GPRS: return "GPRS";
case TelephonyManager.NETWORK_TYPE_EDGE: return "EDGE";
case TelephonyManager.NETWORK_TYPE_UMTS: return "UMTS";
case TelephonyManager.NETWORK_TYPE_HSPA:
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_HSUPA: return "HSPA";
case TelephonyManager.NETWORK_TYPE_HSPAP: return "HSPAP";
case TelephonyManager.NETWORK_TYPE_LTE: return "LTE";
}
}
return netInfo.getTypeName();

View file

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="behaviours" >
<item>com.ericsson.uecontrol.core.behaviour.UeBehaviourFtp</item>
<item>com.ericsson.uecontrol.core.behaviour.UeBehaviourFileDownload</item>
<item>com.ericsson.uecontrol.core.behaviour.UeBehaviourFtpDownload</item>
<item>com.ericsson.uecontrol.core.behaviour.UeBehaviourSleep</item>
<item>com.ericsson.uecontrol.core.behaviour.UeBehaviourSurfing</item>
</string-array>