Added video streaming behaviour.

Improved Throughput calculations(Is using native calculations).
Some other fixes
This commit is contained in:
Ziver Koc 2014-08-05 12:55:51 +02:00
parent 257bd59cdb
commit 9cdcd46ed5
9 changed files with 104 additions and 12 deletions

Binary file not shown.

View file

@ -8,8 +8,8 @@ android {
applicationId "com.ericsson.uecontrol"
minSdkVersion 15
targetSdkVersion 19
versionCode 9
versionName "1.0.9"
versionCode 10
versionName "1.0.10"
}
buildTypes {
release {

View file

@ -1,11 +1,13 @@
package com.ericsson.uecontrol.core;
import android.net.TrafficStats;
import com.ericsson.uecontrol.core.util.ThroughputCalculator;
import com.ericsson.uecontrol.gui.MainActivity;
import org.apache.log4j.Logger;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
@ -25,6 +27,8 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
private boolean terminate;
private Thread thread;
private long previousRxBytes = TrafficStats.UNSUPPORTED;
private long previousTxBytes = TrafficStats.UNSUPPORTED;
private ThroughputCalculator downloadSpeed;
private ThroughputCalculator uploadSpeed;
private ThroughputListener throughputListener;
@ -45,7 +49,7 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
int size = in.readInt();
for(int i=0; i<size; i++){
behaviours.add( (UeBehaviour)in.readObject() );
addBehaviour((UeBehaviour) in.readObject());
}
in.close();
}
@ -71,6 +75,7 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
terminate = true;
if(currentlyActive != null);
currentlyActive.terminate();
currentlyActive = null;
}
public boolean isRunning(){
@ -104,17 +109,37 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
@Override
public void handledIncomingData(long size) {
if (!setRealDataUsage()){
// TrafficStat unsupported so try to us estimation instead
downloadSpeed.setHandledData(size);
if(throughputListener != null && downloadSpeed.isUpdated())
}
if (throughputListener != null && downloadSpeed.isUpdated())
throughputListener.throughputUpdate(downloadSpeed.getBitThroughput(), uploadSpeed.getBitThroughput());
}
@Override
public void handledOutgoingData(long size) {
if (!setRealDataUsage()) {
// TrafficStat unsupported so try to us estimation instead
uploadSpeed.setHandledData(size);
if(throughputListener != null && uploadSpeed.isUpdated())
}
if (throughputListener != null && uploadSpeed.isUpdated())
throughputListener.throughputUpdate(downloadSpeed.getBitThroughput(), uploadSpeed.getBitThroughput());
}
protected boolean setRealDataUsage(){
boolean ret = false;
long currentRxBytes = TrafficStats.getUidRxBytes(MainActivity.getUID());
long currentTxBytes = TrafficStats.getUidTxBytes(MainActivity.getUID());
if (currentRxBytes != TrafficStats.UNSUPPORTED && currentTxBytes != TrafficStats.UNSUPPORTED
&& previousRxBytes != TrafficStats.UNSUPPORTED && previousTxBytes != TrafficStats.UNSUPPORTED){
downloadSpeed.setHandledData(currentRxBytes-previousRxBytes);
uploadSpeed.setHandledData(currentTxBytes-previousTxBytes);
ret = true;
}
previousRxBytes = currentRxBytes;
previousTxBytes = currentTxBytes;
return ret;
}
public void setThroughputListener(ThroughputListener listener){
throughputListener = listener;

View file

@ -9,7 +9,7 @@ import com.ericsson.uecontrol.gui.util.Configurator.Configurable;
* Created by ezivkoc on 2014-07-15.
*/
public class UeBehaviourSleep extends UeBehaviour{
private static final int SLEEP_PERIOD = 100;
public static final int SLEEP_PERIOD = 100;
@Configurable("Sleep(millisec)")
private int time;

View file

@ -0,0 +1,51 @@
package com.ericsson.uecontrol.core.behaviour;
import android.media.MediaPlayer;
import com.ericsson.uecontrol.core.UeBehaviour;
import com.ericsson.uecontrol.gui.util.Configurator;
import com.ericsson.uecontrol.gui.util.Configurator.Configurable;
/**
* Created by ezivkoc on 2014-08-05.
*/
public class UeBehaviourVideoStreaming extends UeBehaviour {
@Configurable("Streaming URL")
private String url;
@Override
protected void execute() throws Exception {
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(url);
mp.setScreenOnWhilePlaying(true);
mp.prepareAsync();
mp.start();
int elapsedTime = 0;
while (mp.isPlaying()) {
super.setProgress((float) mp.getCurrentPosition() / mp.getDuration());
super.setHandledIncomingData(0); // Unable to retrieve the amount of incoming data
if (super.stopExecution()) break;
Thread.sleep(UeBehaviourSleep.SLEEP_PERIOD);
}
}finally {
mp.stop();
mp.release();
}
}
@Override
public String getName() {
return "Video Streaming";
}
@Override
public String toString() {
return "Will stream video from: "+url;
}
}

View file

@ -38,12 +38,12 @@ public class ThroughputCalculator {
}
private static final String[] DATA_SIZE = new String[]{"b/s", "kbit/s", "Mbit/s", "Gbit/s"};
private static final String[] DATA_SIZE = new String[]{"b/s", "kbit/s", "Mbit/s", "Gbit/s", "Tbit/s"};
public static String getBitThroughputString(double bitsPerSec){
int index = 0;
double value = bitsPerSec;
for(; value > 1000 && index < DATA_SIZE.length ;index++) {
for(; value > 1000 && index < DATA_SIZE.length-1 ;index++) {
value /= 1000;
}

View file

@ -101,4 +101,11 @@ public class EditActivity extends ListActivity implements AdapterView.OnItemClic
}catch(Exception e){log.error(null, e);}
super.onPause();
}
@Override
protected void onResume() {
adapter.notifyDataSetChanged();
super.onResume();
}
}

View file

@ -4,6 +4,8 @@ import android.app.ActionBar;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
@ -41,11 +43,14 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
private static UeControlExecutor currentExecutor;
private static CSVWriter csvLogger;
private static int uid;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get UID
uid = getApplicationInfo().uid;
// Setup Debugging
setupDebugLogging();
@ -172,6 +177,9 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
csvLogger.write(currentExecutor.getRunningBehaviour().getName(), downThroughput, upThroughput);
}
public static int getUID(){
return uid;
}
@Override

View file

@ -5,6 +5,7 @@
<item>com.ericsson.uecontrol.core.behaviour.UeBehaviourFtpDownload</item>
<item>com.ericsson.uecontrol.core.behaviour.UeBehaviourSleep</item>
<item>com.ericsson.uecontrol.core.behaviour.UeBehaviourSurfing</item>
<item>com.ericsson.uecontrol.core.behaviour.UeBehaviourVideoStreaming</item>
</string-array>
</resources>