Added video streaming behaviour.
Improved Throughput calculations(Is using native calculations). Some other fixes
This commit is contained in:
parent
257bd59cdb
commit
9cdcd46ed5
9 changed files with 104 additions and 12 deletions
Binary file not shown.
|
|
@ -8,8 +8,8 @@ android {
|
||||||
applicationId "com.ericsson.uecontrol"
|
applicationId "com.ericsson.uecontrol"
|
||||||
minSdkVersion 15
|
minSdkVersion 15
|
||||||
targetSdkVersion 19
|
targetSdkVersion 19
|
||||||
versionCode 9
|
versionCode 10
|
||||||
versionName "1.0.9"
|
versionName "1.0.10"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
package com.ericsson.uecontrol.core;
|
package com.ericsson.uecontrol.core;
|
||||||
|
|
||||||
|
import android.net.TrafficStats;
|
||||||
|
|
||||||
import com.ericsson.uecontrol.core.util.ThroughputCalculator;
|
import com.ericsson.uecontrol.core.util.ThroughputCalculator;
|
||||||
|
import com.ericsson.uecontrol.gui.MainActivity;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
|
|
@ -25,6 +27,8 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
|
||||||
private boolean terminate;
|
private boolean terminate;
|
||||||
private Thread thread;
|
private Thread thread;
|
||||||
|
|
||||||
|
private long previousRxBytes = TrafficStats.UNSUPPORTED;
|
||||||
|
private long previousTxBytes = TrafficStats.UNSUPPORTED;
|
||||||
private ThroughputCalculator downloadSpeed;
|
private ThroughputCalculator downloadSpeed;
|
||||||
private ThroughputCalculator uploadSpeed;
|
private ThroughputCalculator uploadSpeed;
|
||||||
private ThroughputListener throughputListener;
|
private ThroughputListener throughputListener;
|
||||||
|
|
@ -45,7 +49,7 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
|
||||||
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
|
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
|
||||||
int size = in.readInt();
|
int size = in.readInt();
|
||||||
for(int i=0; i<size; i++){
|
for(int i=0; i<size; i++){
|
||||||
behaviours.add( (UeBehaviour)in.readObject() );
|
addBehaviour((UeBehaviour) in.readObject());
|
||||||
}
|
}
|
||||||
in.close();
|
in.close();
|
||||||
}
|
}
|
||||||
|
|
@ -71,6 +75,7 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
|
||||||
terminate = true;
|
terminate = true;
|
||||||
if(currentlyActive != null);
|
if(currentlyActive != null);
|
||||||
currentlyActive.terminate();
|
currentlyActive.terminate();
|
||||||
|
currentlyActive = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRunning(){
|
public boolean isRunning(){
|
||||||
|
|
@ -104,17 +109,37 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handledIncomingData(long size) {
|
public void handledIncomingData(long size) {
|
||||||
|
if (!setRealDataUsage()){
|
||||||
|
// TrafficStat unsupported so try to us estimation instead
|
||||||
downloadSpeed.setHandledData(size);
|
downloadSpeed.setHandledData(size);
|
||||||
|
}
|
||||||
if (throughputListener != null && downloadSpeed.isUpdated())
|
if (throughputListener != null && downloadSpeed.isUpdated())
|
||||||
throughputListener.throughputUpdate(downloadSpeed.getBitThroughput(), uploadSpeed.getBitThroughput());
|
throughputListener.throughputUpdate(downloadSpeed.getBitThroughput(), uploadSpeed.getBitThroughput());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handledOutgoingData(long size) {
|
public void handledOutgoingData(long size) {
|
||||||
|
if (!setRealDataUsage()) {
|
||||||
|
// TrafficStat unsupported so try to us estimation instead
|
||||||
uploadSpeed.setHandledData(size);
|
uploadSpeed.setHandledData(size);
|
||||||
|
}
|
||||||
if (throughputListener != null && uploadSpeed.isUpdated())
|
if (throughputListener != null && uploadSpeed.isUpdated())
|
||||||
throughputListener.throughputUpdate(downloadSpeed.getBitThroughput(), uploadSpeed.getBitThroughput());
|
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){
|
public void setThroughputListener(ThroughputListener listener){
|
||||||
throughputListener = listener;
|
throughputListener = listener;
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import com.ericsson.uecontrol.gui.util.Configurator.Configurable;
|
||||||
* Created by ezivkoc on 2014-07-15.
|
* Created by ezivkoc on 2014-07-15.
|
||||||
*/
|
*/
|
||||||
public class UeBehaviourSleep extends UeBehaviour{
|
public class UeBehaviourSleep extends UeBehaviour{
|
||||||
private static final int SLEEP_PERIOD = 100;
|
public static final int SLEEP_PERIOD = 100;
|
||||||
|
|
||||||
@Configurable("Sleep(millisec)")
|
@Configurable("Sleep(millisec)")
|
||||||
private int time;
|
private int time;
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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){
|
public static String getBitThroughputString(double bitsPerSec){
|
||||||
int index = 0;
|
int index = 0;
|
||||||
double value = bitsPerSec;
|
double value = bitsPerSec;
|
||||||
|
|
||||||
for(; value > 1000 && index < DATA_SIZE.length ;index++) {
|
for(; value > 1000 && index < DATA_SIZE.length-1 ;index++) {
|
||||||
value /= 1000;
|
value /= 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,4 +101,11 @@ public class EditActivity extends ListActivity implements AdapterView.OnItemClic
|
||||||
}catch(Exception e){log.error(null, e);}
|
}catch(Exception e){log.error(null, e);}
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
super.onResume();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import android.app.ActionBar;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
|
@ -41,11 +43,14 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
||||||
|
|
||||||
private static UeControlExecutor currentExecutor;
|
private static UeControlExecutor currentExecutor;
|
||||||
private static CSVWriter csvLogger;
|
private static CSVWriter csvLogger;
|
||||||
|
private static int uid;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
// Get UID
|
||||||
|
uid = getApplicationInfo().uid;
|
||||||
|
|
||||||
// Setup Debugging
|
// Setup Debugging
|
||||||
setupDebugLogging();
|
setupDebugLogging();
|
||||||
|
|
@ -172,6 +177,9 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
||||||
|
|
||||||
csvLogger.write(currentExecutor.getRunningBehaviour().getName(), downThroughput, upThroughput);
|
csvLogger.write(currentExecutor.getRunningBehaviour().getName(), downThroughput, upThroughput);
|
||||||
}
|
}
|
||||||
|
public static int getUID(){
|
||||||
|
return uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
<item>com.ericsson.uecontrol.core.behaviour.UeBehaviourFtpDownload</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>
|
||||||
|
<item>com.ericsson.uecontrol.core.behaviour.UeBehaviourVideoStreaming</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue