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" applicationId "com.ericsson.uecontrol"
minSdkVersion 15 minSdkVersion 15
targetSdkVersion 19 targetSdkVersion 19
versionCode 6 versionCode 7
versionName "1.0.6" versionName "1.0.7"
} }
buildTypes { buildTypes {
release { release {

View file

@ -10,9 +10,9 @@ import org.apache.log4j.Logger;
public abstract class UeBehaviour { public abstract class UeBehaviour {
private static final Logger log = Logger.getLogger(UeBehaviour.class); private static final Logger log = Logger.getLogger(UeBehaviour.class);
private boolean running; private transient boolean running;
private BehaviourExecutionListener execListener; private transient BehaviourExecutionListener execListener;
private DataHandledListener datahandledListener; private transient DataHandledListener datahandledListener;
/** /**
* Starts to run the behaviour, this method will block until the execution is done * 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); b.setDataHandledListener(this);
} }
public void read(String file){
}
public void save(String file){
}
public void execute(){ public void execute(){
if(thread == null || !thread.isAlive()) { if(thread == null || !thread.isAlive()) {
@ -58,6 +65,7 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
public void run(){ public void run(){
while(!terminate) { while(!terminate) {
if(behaviours.isEmpty()) { if(behaviours.isEmpty()) {
currentlyActive = null;
terminate(); terminate();
break; 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; package com.ericsson.uecontrol.core.behaviour;
import android.util.Log;
import com.ericsson.uecontrol.core.UeBehaviour; import com.ericsson.uecontrol.core.UeBehaviour;
import com.ericsson.uecontrol.gui.util.Configurator.Configurable; import com.ericsson.uecontrol.gui.util.Configurator.Configurable;
@ -13,12 +11,12 @@ import java.net.URL;
import java.net.URLConnection; 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. * Created by ezivkoc on 2014-07-15.
*/ */
public class UeBehaviourFtp extends UeBehaviour { public class UeBehaviourFtpDownload extends UeBehaviourFileDownload {
private static final Logger log = Logger.getLogger(UeBehaviourFtp.class); private static final Logger log = Logger.getLogger(UeBehaviourFtpDownload.class);
@Configurable("Host") @Configurable("Host")
private String host; private String host;
@ -31,28 +29,7 @@ public class UeBehaviourFtp extends UeBehaviour {
@Override @Override
protected void execute() throws IOException { protected String getFileUrl() {
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() {
String url = "ftp://"; String url = "ftp://";
if(username != null && !username.isEmpty()) { if(username != null && !username.isEmpty()) {
url += username; url += username;
@ -75,8 +52,4 @@ public class UeBehaviourFtp extends UeBehaviour {
return "FTP Download"; 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 { public class UeBehaviourSurfing extends UeBehaviour {
private static final Logger log = Logger.getLogger(UeBehaviourSurfing.class); private static final Logger log = Logger.getLogger(UeBehaviourSurfing.class);
protected static final int MAX_BUFFER_SIZE = 500000;
@Configurable("Web Address") @Configurable("Web Address")
private String rootUrl; private String rootUrl;
private long estimatedDataLength = -1; private transient long estimatedDataLength = -1;
public UeBehaviourSurfing(){ public UeBehaviourSurfing(){
this("http://google.com"); this("http://google.com");
@ -96,7 +97,10 @@ public class UeBehaviourSurfing extends UeBehaviour {
totalRead += read; totalRead += read;
super.setProgress((float) totalRead / estimatedDataLength); super.setProgress((float) totalRead / estimatedDataLength);
super.setHandledIncomingData(read); super.setHandledIncomingData(read);
if(cont.parsable)
content.append(new String(data, 0, read)); content.append(new String(data, 0, read));
if(content.length() > MAX_BUFFER_SIZE)
break;
} }
if(cont.parsable) if(cont.parsable)
getAdditionalContent(cont.url, content.toString(), urlList); getAdditionalContent(cont.url, content.toString(), urlList);

View file

@ -42,7 +42,7 @@ public class CSVWriter {
if(!path.endsWith(File.separator)) path += File.separator; if(!path.endsWith(File.separator)) path += File.separator;
file = new File( file = new File(
path, path,
"log_"+fileDateFormater.format(System.currentTimeMillis())+".log"); "log_"+fileDateFormater.format(System.currentTimeMillis())+".csv");
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
netInfo = cm.getActiveNetworkInfo(); netInfo = cm.getActiveNetworkInfo();
@ -90,7 +90,10 @@ public class CSVWriter {
case TelephonyManager.NETWORK_TYPE_GPRS: return "GPRS"; case TelephonyManager.NETWORK_TYPE_GPRS: return "GPRS";
case TelephonyManager.NETWORK_TYPE_EDGE: return "EDGE"; case TelephonyManager.NETWORK_TYPE_EDGE: return "EDGE";
case TelephonyManager.NETWORK_TYPE_UMTS: return "UMTS"; case TelephonyManager.NETWORK_TYPE_UMTS: return "UMTS";
case TelephonyManager.NETWORK_TYPE_HSPA: return "HSPA"; 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"; case TelephonyManager.NETWORK_TYPE_LTE: return "LTE";
} }
} }

View file

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