Added option for device or app level throughput.
Started on a file browser dialog for import/export
This commit is contained in:
parent
01896c15e5
commit
9f84e472eb
6 changed files with 80 additions and 29 deletions
20
app/app.iml
20
app/app.iml
|
|
@ -56,7 +56,25 @@
|
|||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Android API 15 Platform" jdkType="Android SDK" />
|
||||
|
|
|
|||
|
|
@ -34,19 +34,21 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
|
|||
private UeBehaviour currentlyActive;
|
||||
private boolean terminate;
|
||||
private Thread thread;
|
||||
private Gson gson;
|
||||
|
||||
private long previousRxBytes = TrafficStats.UNSUPPORTED;
|
||||
private long previousTxBytes = TrafficStats.UNSUPPORTED;
|
||||
private boolean deviceBasedThroughput;
|
||||
private ThroughputCalculator downloadSpeed;
|
||||
private ThroughputCalculator uploadSpeed;
|
||||
private ThroughputListener throughputListener;
|
||||
private Gson gson;
|
||||
|
||||
|
||||
public UeControlExecutor(){
|
||||
behaviours = new ArrayList<UeBehaviour>();
|
||||
downloadSpeed = new ThroughputCalculator();
|
||||
uploadSpeed = new ThroughputCalculator();
|
||||
deviceBasedThroughput = false;
|
||||
|
||||
gson = new GsonBuilder()
|
||||
.registerTypeAdapter(UeBehaviour.class, new AbstractElementAdapter<UeBehaviour>())
|
||||
|
|
@ -62,15 +64,10 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
|
|||
FileReader in = new FileReader(file);
|
||||
Type type = new TypeToken<ArrayList<UeBehaviour>>(){}.getType();
|
||||
ArrayList<UeBehaviour> newBehaviours = gson.fromJson(in, type);
|
||||
behaviours.addAll(newBehaviours);
|
||||
in.close();
|
||||
|
||||
/*ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
|
||||
int size = in.readInt();
|
||||
for(int i=0; i<size; i++){
|
||||
addBehaviour((UeBehaviour) in.readObject());
|
||||
for(UeBehaviour behaviour : newBehaviours){
|
||||
this.addBehaviour(behaviour);
|
||||
}
|
||||
in.close();*/
|
||||
in.close();
|
||||
}
|
||||
public void save(String file) throws IOException {
|
||||
FileWriter out = new FileWriter(file);
|
||||
|
|
@ -78,13 +75,6 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
|
|||
log.debug("Saving behaviours: "+gson.toJson(behaviours, type));
|
||||
gson.toJson(behaviours, type, out);
|
||||
out.close();
|
||||
|
||||
/*ObjectOutput out = new ObjectOutputStream(new FileOutputStream(file));
|
||||
out.writeInt(behaviours.size());
|
||||
for(UeBehaviour behaviour : behaviours){
|
||||
out.writeObject(behaviour);
|
||||
}
|
||||
out.close();*/
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -128,9 +118,6 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
|
|||
|
||||
public boolean isRunning(){
|
||||
return thread != null && thread.isAlive();
|
||||
//if(currentlyActive == null)
|
||||
// return false;
|
||||
//return currentlyActive.isRunning();
|
||||
}
|
||||
|
||||
public void run(){
|
||||
|
|
@ -187,10 +174,16 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
|
|||
}
|
||||
protected boolean setRealDataUsage(){
|
||||
boolean ret = false;
|
||||
long currentRxBytes = TrafficStats.getUidRxBytes(MainActivity.getUID());
|
||||
long currentTxBytes = TrafficStats.getUidTxBytes(MainActivity.getUID());
|
||||
//long currentRxBytes = TrafficStats.getTotalRxBytes();
|
||||
//long currentTxBytes = TrafficStats.getTotalTxBytes();
|
||||
long currentRxBytes = 0;
|
||||
long currentTxBytes = 0;
|
||||
if(deviceBasedThroughput) {
|
||||
currentRxBytes = TrafficStats.getTotalRxBytes();
|
||||
currentTxBytes = TrafficStats.getTotalTxBytes();
|
||||
}
|
||||
else{
|
||||
currentRxBytes = TrafficStats.getUidRxBytes(MainActivity.getUID());
|
||||
currentTxBytes = TrafficStats.getUidTxBytes(MainActivity.getUID());
|
||||
}
|
||||
|
||||
if (currentRxBytes != TrafficStats.UNSUPPORTED && currentTxBytes != TrafficStats.UNSUPPORTED
|
||||
&& previousRxBytes != TrafficStats.UNSUPPORTED && previousTxBytes != TrafficStats.UNSUPPORTED){
|
||||
|
|
@ -206,6 +199,9 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
|
|||
public void setThroughputListener(ThroughputListener listener){
|
||||
throughputListener = listener;
|
||||
}
|
||||
public void setDeviceBasedThroughput(boolean enable){
|
||||
deviceBasedThroughput = enable;
|
||||
}
|
||||
|
||||
public List<UeBehaviour> getBehaviourList() {
|
||||
return behaviours;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import com.ericsson.uecontrol.core.UeControlExecutor;
|
|||
import com.ericsson.uecontrol.core.behaviour.UeBehaviourSleep;
|
||||
import com.ericsson.uecontrol.core.behaviour.UeBehaviourSurfing;
|
||||
import com.ericsson.uecontrol.gui.fragments.BehaviourListFragment;
|
||||
import com.ericsson.uecontrol.gui.fragments.FileBrowserDialog;
|
||||
import com.ericsson.uecontrol.gui.fragments.StatusFragment;
|
||||
import com.ericsson.uecontrol.gui.util.CSVWriter;
|
||||
|
||||
|
|
@ -51,8 +52,12 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// Set static fields
|
||||
|
||||
// Set static fields and preferences
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
|
||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
uid = getApplicationInfo().uid;
|
||||
context = this;
|
||||
|
||||
|
|
@ -66,10 +71,11 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
getFragmentManager().beginTransaction()
|
||||
.replace(R.id.container, new BehaviourListFragment()).commit();
|
||||
|
||||
|
||||
// Setup Executor
|
||||
if(currentExecutor == null) {
|
||||
log.info("Creating new instance of executor");
|
||||
currentExecutor = new UeControlExecutor();
|
||||
currentExecutor.setDeviceBasedThroughput(Boolean.parseBoolean(prefs.getString("throughput_type", "false")));
|
||||
File input = new File(this.getFilesDir(), BEHAVIOUR_SAVE_FILE);
|
||||
if (input.exists()) {
|
||||
try {
|
||||
|
|
@ -91,6 +97,9 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
}
|
||||
|
||||
currentExecutor.setThroughputListener(statusFragment.getThroughputListener());
|
||||
|
||||
|
||||
|
||||
updateExecutionState();
|
||||
}
|
||||
|
||||
|
|
@ -109,8 +118,6 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
// Set log level of a specific logger
|
||||
logConfigurator.setLevel("org.apache", Level.ERROR);
|
||||
logConfigurator.configure();
|
||||
|
||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
|
|
@ -124,6 +131,11 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
Logger.getRootLogger().setLevel(Level.WARN);
|
||||
}
|
||||
}
|
||||
else if(key.equals("throughput_type")){
|
||||
log.info("Device Throughput set to: "+sharedPreferences.getString("throughput_type", "false"));
|
||||
if(currentExecutor != null)
|
||||
currentExecutor.setDeviceBasedThroughput(Boolean.parseBoolean(sharedPreferences.getString("throughput_type", "false")));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -190,6 +202,12 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
Toast.makeText(this, "Stop execution to edit behaviours", Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
else if (id == R.id.action_import) {
|
||||
//TODO:
|
||||
}
|
||||
else if (id == R.id.action_export) {
|
||||
//TODO:
|
||||
}
|
||||
else if (id == R.id.action_settings) {
|
||||
startActivity(new Intent(this, SettingsActivity.class));
|
||||
return true;
|
||||
|
|
@ -197,6 +215,7 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
private void updateExecutionState(){
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
if(action_execute != null) {
|
||||
|
|
@ -253,5 +272,4 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
return uid;
|
||||
}
|
||||
public static Context getContext(){return context;}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,4 +12,12 @@
|
|||
<item>com.ericsson.uecontrol.core.behaviour.UeBehaviourVideoStreaming</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="throughput_types">
|
||||
<item>App Throughput</item>
|
||||
<item>Device Throughput</item>
|
||||
</string-array>
|
||||
<string-array name="throughput_type_values">
|
||||
<item>false</item>
|
||||
<item>true</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
|
@ -32,5 +32,8 @@
|
|||
<string name="pref_screen_on_summ">Keep screen on while execution</string>
|
||||
<string name="pref_screen_on">Keep Screen On</string>
|
||||
<string name="action_mark">Add Mark</string>
|
||||
<string name="action_select">Select</string>
|
||||
<string name="pref_throughput_type">Throughput Type</string>
|
||||
<string name="pref_throughput_type_summ">The type of throughput that should be displayed and logged</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -15,6 +15,14 @@
|
|||
android:summary="@string/pref_logging_path_summ"
|
||||
android:defaultValue="/sdcard/uecontrol/" />
|
||||
|
||||
<ListPreference
|
||||
android:key="throughput_type"
|
||||
android:title="@string/pref_throughput_type"
|
||||
android:summary="@string/pref_throughput_type_summ"
|
||||
android:entries="@array/throughput_types"
|
||||
android:entryValues="@array/throughput_type_values"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="screen_on"
|
||||
android:title="@string/pref_screen_on"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue