Fixed CSV crash when rotating
This commit is contained in:
parent
d7d729f6c1
commit
76b3790888
3 changed files with 20 additions and 17 deletions
|
|
@ -159,7 +159,7 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
else {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
if(prefs.getBoolean("logging", true))
|
||||
csvLogger = new CSVWriter(this);
|
||||
csvLogger = new CSVWriter();
|
||||
else
|
||||
csvLogger = null;
|
||||
currentExecutor.execute();
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public class StatusFragment extends Fragment {
|
|||
public void run() {
|
||||
down_speed.setText(ThroughputCalculator.getBitThroughputString(downThroughput));
|
||||
up_speed.setText(ThroughputCalculator.getBitThroughputString(upThroughput));
|
||||
rat_type.setText(CSVWriter.getRat(getActivity()));
|
||||
rat_type.setText(CSVWriter.getRat());
|
||||
|
||||
downGraph.appendData(new GraphViewData(x, downThroughput), true, 120);
|
||||
upGraph.appendData(new GraphViewData(x, upThroughput), true, 120);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ import android.telephony.NeighboringCellInfo;
|
|||
import android.telephony.TelephonyManager;
|
||||
import android.telephony.gsm.GsmCellLocation;
|
||||
|
||||
import com.ericsson.uecontrol.gui.MainActivity;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -41,10 +43,9 @@ public class CSVWriter {
|
|||
|
||||
|
||||
private File file;
|
||||
private Context context;
|
||||
|
||||
public CSVWriter(Context context){
|
||||
this.context = context;
|
||||
public CSVWriter(){
|
||||
Context context = MainActivity.getContext();
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String path = prefs.getString("logging_path", "/sdcard/uecontrol/");
|
||||
if(!path.endsWith(File.separator)) path += File.separator;
|
||||
|
|
@ -52,7 +53,6 @@ public class CSVWriter {
|
|||
path,
|
||||
"log_"+fileDateFormater.format(System.currentTimeMillis())+".csv");
|
||||
|
||||
|
||||
// Write Headings
|
||||
StringBuilder line = new StringBuilder();
|
||||
for(String header : HEADINGS){
|
||||
|
|
@ -71,10 +71,10 @@ public class CSVWriter {
|
|||
line.append(behaviour).append(DELIMITER);
|
||||
line.append(down).append(DELIMITER);
|
||||
line.append(up).append(DELIMITER);
|
||||
line.append(getRat(context)).append(DELIMITER);
|
||||
line.append(getCellIds(context)).append(DELIMITER);
|
||||
line.append(getSSID(context)).append(DELIMITER);
|
||||
line.append(getRssi(context)).append(DELIMITER);
|
||||
line.append(getRat()).append(DELIMITER);
|
||||
line.append(getCellIds()).append(DELIMITER);
|
||||
line.append(getSSID()).append(DELIMITER);
|
||||
line.append(getRssi()).append(DELIMITER);
|
||||
writeLine(line.toString());
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +88,8 @@ public class CSVWriter {
|
|||
}
|
||||
}
|
||||
|
||||
public static String getRat(Context context){
|
||||
public static String getRat(){
|
||||
Context context = MainActivity.getContext();
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo netInfo = cm.getActiveNetworkInfo();
|
||||
if(netInfo == null)
|
||||
|
|
@ -112,7 +113,8 @@ public class CSVWriter {
|
|||
|
||||
|
||||
//******************* MOBILE ********************************************
|
||||
private static String getCellIds(Context context){
|
||||
private static String getCellIds(){
|
||||
Context context = MainActivity.getContext();
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo netInfo = cm.getActiveNetworkInfo();
|
||||
if(netInfo == null)
|
||||
|
|
@ -170,7 +172,8 @@ public class CSVWriter {
|
|||
}
|
||||
|
||||
//******************* WIFI ********************************************
|
||||
private static WifiInfo getWifiInfo(Context context){
|
||||
private static WifiInfo getWifiInfo(){
|
||||
Context context = MainActivity.getContext();
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo netInfo = cm.getActiveNetworkInfo();
|
||||
if(netInfo == null || netInfo.getType() != ConnectivityManager.TYPE_WIFI)
|
||||
|
|
@ -180,15 +183,15 @@ public class CSVWriter {
|
|||
WifiInfo wifiInfo = wm.getConnectionInfo();
|
||||
return wifiInfo;
|
||||
}
|
||||
private static String getSSID(Context context){
|
||||
WifiInfo wifiInfo = getWifiInfo(context);
|
||||
private static String getSSID(){
|
||||
WifiInfo wifiInfo = getWifiInfo();
|
||||
if(wifiInfo == null)
|
||||
return "n/a";
|
||||
return wifiInfo.getSSID().replace("\"", "");
|
||||
}
|
||||
|
||||
private static String getRssi(Context context){
|
||||
WifiInfo wifiInfo = getWifiInfo(context);
|
||||
private static String getRssi(){
|
||||
WifiInfo wifiInfo = getWifiInfo();
|
||||
if(wifiInfo == null)
|
||||
return "n/a";
|
||||
return ""+wifiInfo.getRssi();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue