Added CellId for logging.
Added some code for speech
This commit is contained in:
parent
fdaf818312
commit
a031b1c2d9
6 changed files with 164 additions and 3 deletions
|
|
@ -6,7 +6,14 @@ import android.net.ConnectivityManager;
|
|||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.telephony.CellInfo;
|
||||
import android.telephony.CellInfoCdma;
|
||||
import android.telephony.CellInfoGsm;
|
||||
import android.telephony.CellInfoLte;
|
||||
import android.telephony.CellInfoWcdma;
|
||||
import android.telephony.NeighboringCellInfo;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
@ -16,6 +23,7 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ezivkoc on 2014-07-30.
|
||||
|
|
@ -23,7 +31,8 @@ import java.text.SimpleDateFormat;
|
|||
public class CSVWriter {
|
||||
private static final Logger log = Logger.getLogger(CSVWriter.class);
|
||||
public static final String[] HEADINGS = new String[]{
|
||||
"Timestamp", "Behaviour", "RX Throughput(b/s)", "TX Throughput(b/s)", "RAT"
|
||||
"Timestamp", "Behaviour", "RX Throughput(b/s)", "TX Throughput(b/s)",
|
||||
"RAT", "CellIds", "SSID"
|
||||
};
|
||||
public static final String DELIMITER = ";";
|
||||
protected static final SimpleDateFormat fileDateFormater = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
|
||||
|
|
@ -62,6 +71,8 @@ public class CSVWriter {
|
|||
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);
|
||||
writeLine(line.toString());
|
||||
}
|
||||
|
||||
|
|
@ -100,6 +111,71 @@ public class CSVWriter {
|
|||
return netInfo.getTypeName();
|
||||
}
|
||||
|
||||
private static String getCellIds(Context context){
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo netInfo = cm.getActiveNetworkInfo();
|
||||
if(netInfo == null)
|
||||
return "";
|
||||
|
||||
if(netInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
|
||||
TelephonyManager telMan = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
StringBuilder data = new StringBuilder();
|
||||
|
||||
List<NeighboringCellInfo> cellList = telMan.getNeighboringCellInfo();
|
||||
if(cellList != null) {
|
||||
for (int i = 0; i < cellList.size(); i++) {
|
||||
data.append(cellList.get(i).getCid());
|
||||
if (i < cellList.size() - 1)
|
||||
data.append(',');
|
||||
}
|
||||
|
||||
// Use newer api if available
|
||||
if (cellList.isEmpty() && Build.VERSION.SDK_INT >= 17) {
|
||||
List<CellInfo> cellInfoList = telMan.getAllCellInfo();
|
||||
for(int i=0; i<cellInfoList.size(); i++){
|
||||
CellInfo info = cellInfoList.get(i);
|
||||
data.append(getCellId(info));
|
||||
|
||||
if(i<cellInfoList.size()-1)
|
||||
data.append(',');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return data.toString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
private static String getCellId(CellInfo cell){
|
||||
int cid = Integer.MAX_VALUE;
|
||||
if(cell instanceof CellInfoGsm)
|
||||
cid = ((CellInfoGsm) cell).getCellIdentity().getCid();
|
||||
else if(cell instanceof CellInfoCdma)
|
||||
cid = ((CellInfoCdma) cell).getCellIdentity().getBasestationId();
|
||||
else if(Build.VERSION.SDK_INT >= 18 && cell instanceof CellInfoWcdma)
|
||||
cid = ((CellInfoWcdma) cell).getCellIdentity().getCid();
|
||||
else if(cell instanceof CellInfoLte)
|
||||
cid = ((CellInfoLte) cell).getCellIdentity().getCi();
|
||||
|
||||
if(cid == Integer.MAX_VALUE)
|
||||
return "UNKNOWN";
|
||||
else
|
||||
return ""+cid;
|
||||
}
|
||||
|
||||
private static String getSSID(Context context){
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo netInfo = cm.getActiveNetworkInfo();
|
||||
if(netInfo == null || netInfo.getType() == ConnectivityManager.TYPE_WIFI)
|
||||
return "";
|
||||
|
||||
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
WifiInfo wifiInfo = wm.getConnectionInfo();
|
||||
if(wifiInfo == null)
|
||||
return "";
|
||||
return wifiInfo.getSSID().replace("\"", "");
|
||||
}
|
||||
|
||||
protected String getTime(){
|
||||
return dateFormater.format(System.currentTimeMillis());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue