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
|
|
@ -0,0 +1,81 @@
|
|||
package com.ericsson.uecontrol.core.behaviour;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.ericsson.uecontrol.core.UeBehaviour;
|
||||
import com.ericsson.uecontrol.gui.MainActivity;
|
||||
import com.ericsson.uecontrol.gui.util.Configurator.Configurable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* This behaviour simulates an idle period for the device.
|
||||
*
|
||||
* Created by ezivkoc on 2014-07-15.
|
||||
*/
|
||||
public class UeBehaviourSpeechCall extends UeBehaviour{
|
||||
public static final int SLEEP_PERIOD = 100;
|
||||
|
||||
@Configurable("Phone Number")
|
||||
private String phoneNumber;
|
||||
@Configurable("Length(Seconds)")
|
||||
private int length;
|
||||
|
||||
|
||||
public UeBehaviourSpeechCall(){
|
||||
this(60);
|
||||
}
|
||||
public UeBehaviourSpeechCall(int milliseconds){
|
||||
length = milliseconds;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void execute() throws InterruptedException {
|
||||
int elapsedTime = 0;
|
||||
while(elapsedTime < length){
|
||||
super.setProgress((float)elapsedTime/length);
|
||||
if(super.stopExecution()) break;
|
||||
Thread.sleep(SLEEP_PERIOD);
|
||||
elapsedTime += SLEEP_PERIOD;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void startCall(){
|
||||
Context context = MainActivity.getContext();
|
||||
Uri number = Uri.parse("tel:" + phoneNumber);
|
||||
Intent intent = new Intent(Intent.ACTION_DIAL, number);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
private void endCall() throws ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
|
||||
Context context = MainActivity.getContext();
|
||||
TelephonyManager tm = (TelephonyManager) context
|
||||
.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
Class c = Class.forName(tm.getClass().getName());
|
||||
Method m = c.getDeclaredMethod("getITelephony");
|
||||
m.setAccessible(true);
|
||||
|
||||
Object telephonyService = m.invoke(tm); // Get the internal ITelephony object
|
||||
c = Class.forName(telephonyService.getClass().getName()); // Get its class
|
||||
m = c.getDeclaredMethod("endCall"); // Get the "endCall()" method
|
||||
m.setAccessible(true); // Make it accessible
|
||||
m.invoke(telephonyService); // invoke endCall()
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Speech Call";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Will make a call for "+ length +" seconds";
|
||||
}
|
||||
}
|
||||
|
|
@ -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