Added state saving
This commit is contained in:
parent
e020204ce5
commit
580f4fdc3d
7 changed files with 56 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 7
|
versionCode 8
|
||||||
versionName "1.0.7"
|
versionName "1.0.8"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,14 @@ package com.ericsson.uecontrol.core;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for Ue behaviours that can be used by the executor
|
* Base class for Ue behaviours that can be used by the executor
|
||||||
*
|
*
|
||||||
* Created by ezivkoc on 2014-07-15.
|
* Created by ezivkoc on 2014-07-15.
|
||||||
*/
|
*/
|
||||||
public abstract class UeBehaviour {
|
public abstract class UeBehaviour implements Serializable{
|
||||||
private static final Logger log = Logger.getLogger(UeBehaviour.class);
|
private static final Logger log = Logger.getLogger(UeBehaviour.class);
|
||||||
|
|
||||||
private transient boolean running;
|
private transient boolean running;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,13 @@ import com.ericsson.uecontrol.core.util.ThroughputCalculator;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
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;
|
||||||
|
import java.io.ObjectOutput;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -34,11 +41,21 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
|
||||||
b.setDataHandledListener(this);
|
b.setDataHandledListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void read(String file){
|
public void read(String file) throws Exception {
|
||||||
|
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
|
||||||
|
int size = in.readInt();
|
||||||
|
for(int i=0; i<size; i++){
|
||||||
|
behaviours.add( (UeBehaviour)in.readObject() );
|
||||||
}
|
}
|
||||||
public void save(String file){
|
in.close();
|
||||||
|
}
|
||||||
|
public void save(String file) throws IOException {
|
||||||
|
ObjectOutput out = new ObjectOutputStream(new FileOutputStream(file));
|
||||||
|
out.writeInt(behaviours.size());
|
||||||
|
for(UeBehaviour behaviour : behaviours){
|
||||||
|
out.writeObject(behaviour);
|
||||||
|
}
|
||||||
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ import com.ericsson.uecontrol.gui.util.DynamicListView;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -89,4 +90,14 @@ public class EditActivity extends ListActivity implements AdapterView.OnItemClic
|
||||||
dialog.setConfigurator(confer);
|
dialog.setConfigurator(confer);
|
||||||
dialog.show(getFragmentManager(), "behaviour_configurator");
|
dialog.show(getFragmentManager(), "behaviour_configurator");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
try {
|
||||||
|
File input = new File(this.getFilesDir(), MainActivity.BEHAVIOUR_SAVE_FILE);
|
||||||
|
executor.save(input.getAbsolutePath());
|
||||||
|
log.debug("Saved current state");
|
||||||
|
}catch(Exception e){log.error(null, e);}
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ import de.mindpipe.android.logging.log4j.LogConfigurator;
|
||||||
public class MainActivity extends FragmentActivity implements OnSharedPreferenceChangeListener{
|
public class MainActivity extends FragmentActivity implements OnSharedPreferenceChangeListener{
|
||||||
private static final Logger log = Logger.getLogger(MainActivity.class);
|
private static final Logger log = Logger.getLogger(MainActivity.class);
|
||||||
public static final String DEFAULT_LOG_PATH = "/sdcard/uecontrol/";
|
public static final String DEFAULT_LOG_PATH = "/sdcard/uecontrol/";
|
||||||
|
public static final String BEHAVIOUR_SAVE_FILE = "behaviour_list.dat";
|
||||||
|
|
||||||
|
|
||||||
/** Fragments **/
|
/** Fragments **/
|
||||||
private StatusFragment statusFragment;
|
private StatusFragment statusFragment;
|
||||||
|
|
@ -57,11 +59,22 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
||||||
|
|
||||||
|
|
||||||
currentExecutor = new UeControlExecutor();
|
currentExecutor = new UeControlExecutor();
|
||||||
|
currentExecutor.setThroughputListener(statusFragment.getThroughputListener());
|
||||||
|
File input = new File(this.getFilesDir(), BEHAVIOUR_SAVE_FILE);
|
||||||
|
if(input.exists()) {
|
||||||
|
try {
|
||||||
|
log.debug("Reading saved state");
|
||||||
|
currentExecutor.read(input.getAbsolutePath());
|
||||||
|
}catch(Exception e){log.error(null, e);}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
log.debug("No saved state found, creating default behaviours");
|
||||||
currentExecutor.addBehaviour(new UeBehaviourSleep());
|
currentExecutor.addBehaviour(new UeBehaviourSleep());
|
||||||
currentExecutor.addBehaviour(new UeBehaviourSurfing());
|
currentExecutor.addBehaviour(new UeBehaviourSurfing());
|
||||||
currentExecutor.addBehaviour(new UeBehaviourSleep(4000));
|
currentExecutor.addBehaviour(new UeBehaviourSleep(4000));
|
||||||
currentExecutor.setThroughputListener(statusFragment.getThroughputListener());
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setupDebugLogging(){
|
public void setupDebugLogging(){
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
@ -133,12 +146,12 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (id == R.id.action_edit) {
|
else if (id == R.id.action_edit) {
|
||||||
Intent intent = new Intent(this, EditActivity.class);
|
Intent intent = new Intent(this, EditActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (id == R.id.action_settings) {
|
else if (id == R.id.action_settings) {
|
||||||
startActivity(new Intent(this, SettingsActivity.class));
|
startActivity(new Intent(this, SettingsActivity.class));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ public class StatusFragment extends Fragment {
|
||||||
down_speed.setText(ThroughputCalculator.getBitThroughputString(downThroughput));
|
down_speed.setText(ThroughputCalculator.getBitThroughputString(downThroughput));
|
||||||
up_speed.setText(ThroughputCalculator.getBitThroughputString(upThroughput));
|
up_speed.setText(ThroughputCalculator.getBitThroughputString(upThroughput));
|
||||||
rat_type.setText(CSVWriter.getRat(getActivity()));
|
rat_type.setText(CSVWriter.getRat(getActivity()));
|
||||||
|
|
||||||
downGraph.appendData(new GraphViewData(x, downThroughput), true, 120);
|
downGraph.appendData(new GraphViewData(x, downThroughput), true, 120);
|
||||||
upGraph.appendData(new GraphViewData(x, upThroughput), true, 120);
|
upGraph.appendData(new GraphViewData(x, upThroughput), true, 120);
|
||||||
x++;
|
x++;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue