Added CellId for logging.

Added some code for speech
This commit is contained in:
Ziver Koc 2014-08-08 16:17:30 +02:00
parent fdaf818312
commit a031b1c2d9
6 changed files with 164 additions and 3 deletions

View file

@ -59,7 +59,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" /> <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
</content> </content>
<orderEntry type="jdk" jdkName="Android API 15 Platform" jdkType="Android SDK" /> <orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="dom4j-1.6.1" level="project" /> <orderEntry type="library" exported="" name="dom4j-1.6.1" level="project" />
<orderEntry type="library" exported="" name="GraphView-3.1.2" level="project" /> <orderEntry type="library" exported="" name="GraphView-3.1.2" level="project" />

View file

@ -1,7 +1,7 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
android { android {
compileSdkVersion 15 compileSdkVersion 19
buildToolsVersion '19.1.0' buildToolsVersion '19.1.0'
defaultConfig { defaultConfig {

View file

@ -32,6 +32,10 @@
</activity> </activity>
</application> </application>
<uses-sdk android:minSdkVersion="15"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />

View file

@ -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";
}
}

View file

@ -6,7 +6,14 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.net.wifi.WifiInfo; import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.os.Build;
import android.preference.PreferenceManager; 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 android.telephony.TelephonyManager;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -16,6 +23,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.List;
/** /**
* Created by ezivkoc on 2014-07-30. * Created by ezivkoc on 2014-07-30.
@ -23,7 +31,8 @@ import java.text.SimpleDateFormat;
public class CSVWriter { public class CSVWriter {
private static final Logger log = Logger.getLogger(CSVWriter.class); private static final Logger log = Logger.getLogger(CSVWriter.class);
public static final String[] HEADINGS = new String[]{ 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 = ";"; public static final String DELIMITER = ";";
protected static final SimpleDateFormat fileDateFormater = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss"); 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(down).append(DELIMITER);
line.append(up).append(DELIMITER); line.append(up).append(DELIMITER);
line.append(getRat(context)).append(DELIMITER); line.append(getRat(context)).append(DELIMITER);
line.append(getCellIds(context)).append(DELIMITER);
line.append(getSSID(context)).append(DELIMITER);
writeLine(line.toString()); writeLine(line.toString());
} }
@ -100,6 +111,71 @@ public class CSVWriter {
return netInfo.getTypeName(); 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(){ protected String getTime(){
return dateFormater.format(System.currentTimeMillis()); return dateFormater.format(System.currentTimeMillis());
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB