Skip to content

Commit

Permalink
collect more data
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Jun 9, 2016
1 parent 537fbc7 commit 1fc3663
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ captures/

# Keystore files
*.jks
*.keystore

# vim
*.swp
Expand Down
19 changes: 18 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,34 @@ android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

signingConfigs {
config {
if(project.hasProperty('atgSigningConfigKeyPassword')) {
keyAlias 'AndroidTcpdumpGui'
keyPassword atgSigningConfigKeyPassword
storeFile file('../sign/release-keystore.keystore')
storePassword atgSigningConfigKeyPassword
}
}
}

defaultConfig {
applicationId "com.voxlearning.androidtcpdumpgui"
minSdkVersion 11
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}

debug {
signingConfig signingConfigs.config
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
package="com.voxlearning.androidtcpdumpgui">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />


<!-- suppress DeprecatedClassUsageInspection -->
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission
Expand Down Expand Up @@ -38,4 +44,4 @@
<activity android:name=".ViewActivity"></activity>
</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class CaptureFilePath {
static public final String FileName_Comment = "comment.txt";
static public final String FileName_Apps = "apps.txt";
static public final String FileName_Logs = "logs.txt";
static public final String FileName_Gps = "gps.txt";
static public final String FileName_TcpdumpOut = "tcpdump.out.txt";
static public final String FileName_Packets = "packets.pcap";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.location.Location;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

Expand Down Expand Up @@ -129,12 +133,12 @@ public void start(Context context, String intf, String expr) {

if(!dirRunning.exists()) {
Log.e(TAG, "can not mkdir " + dirRunning.getPath());
Toast.makeText(context, "Can not write to external storage. Broken sdcard or memory?", Toast.LENGTH_LONG).show();
return;
}


try {
recordStart();
recordStart(context);

String fnPackets = CaptureFilePath.OutputDirRunningFilePath(CaptureFilePath.FileName_Packets);
String fnTcpdumpOut = CaptureFilePath.OutputDirRunningFilePath(CaptureFilePath.FileName_TcpdumpOut);
Expand Down Expand Up @@ -255,10 +259,44 @@ public void recordAppName(String appName) {
recordLog("app: " + appName);
}

private void recordStart() {
private void recordStart(Context context) {
String fn = CaptureFilePath.OutputDirRunningFilePath(CaptureFilePath.FileName_Start);
Io.writeFile(fn, "" + System.currentTimeMillis());
recordLog("start");

StringBuilder sb = new StringBuilder();
sb.append("MANUFACTURER=").append(Build.MANUFACTURER).append("; ")
.append("MODEL=").append(Build.MODEL).append("; ")
.append("SERIAL=").append(Build.SERIAL).append("\n")
;
sb.append("FINGERPRINT=").append(Build.FINGERPRINT).append("\n");
sb.append("RadioVersion=").append(Build.getRadioVersion()).append("\n");

TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String tmDevice = "", tmSerial = "", androidId = "";
try {
tmDevice = tm.getDeviceId();
}catch (Exception ignored){}
try {
tmSerial = tm.getSimSerialNumber();
}catch (Exception ignored){}
try{
androidId = android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
}catch (Exception ignored){}

sb.append("DeviceId=").append(tmDevice).append("; ")
.append("AndroidId=").append(androidId).append("; ")
.append("SimSerialNumber=").append(tmSerial).append("\n");


NetworkInfo ni = null;
try {
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
ni = cm.getActiveNetworkInfo();
}
catch (Exception ignored) { }
sb.append("NetworkInfo=").append(ni == null ? "null" : ni.toString()).append("\n");

recordLog("start\n" + sb.toString());
}

private void recordStop() {
Expand All @@ -267,18 +305,19 @@ private void recordStop() {
recordLog("stop");
}

public void recordComment(String s) {
String fn = CaptureFilePath.OutputDirRunningFilePath(CaptureFilePath.FileName_Comment);
Io.writeFileAppend(fn, nowLogString() + " " + s + "\n");
recordLog("comment: " + s);
}

public void recordLog(String s) {
String fn = CaptureFilePath.OutputDirRunningFilePath(CaptureFilePath.FileName_Logs);
Io.writeFileAppend(fn, nowLogString() + " " + s + "\n");
Log.d(TAG, "recordLog: " + s);
}

public void recordGps(Location location) {
String fn = CaptureFilePath.OutputDirRunningFilePath(CaptureFilePath.FileName_Gps);
String s = location == null ? "(unknown-location)" : location.toString();

Io.writeFileAppend(fn, nowLogString() + " " + s + "\n");
Log.d(TAG, "recordGps: " + s);
}

static public class Stats {
public long mStartTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
package com.voxlearning.androidtcpdumpgui;

import android.Manifest;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.SystemClock;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog;
import android.util.Log;

public class CaptureService extends Service {
public class CaptureService extends Service implements LocationListener {

static private final String TAG = "CaptureService";

Expand All @@ -23,6 +33,7 @@ public class CaptureService extends Service {

private CaptureManager mCaptureManager;
private AlarmManager mAlarmManager;
private LocationManager mLocationManager;

static final public int AlarmInterval_RestartService = 30 * 1000;
static final public int DelayInterval_PeriodWork = 5 * 1000;
Expand All @@ -33,21 +44,21 @@ public class CaptureService extends Service {
public void onCreate() {
mCaptureManager = new CaptureManager();
mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
gpsStart();
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

if (intent != null) {
if(ServiceAction_CaptureStart.equals(intent.getAction())) {
if (ServiceAction_CaptureStart.equals(intent.getAction())) {
Log.d(TAG, "capture start");
periodWork();
}
else if(ServiceAction_PeriodWork.equals(intent.getAction())) {
} else if (ServiceAction_PeriodWork.equals(intent.getAction())) {
Log.d(TAG, "period work");
periodWork();
}
else if(ServiceAction_CaptureStop.equals(intent.getAction())) {
} else if (ServiceAction_CaptureStop.equals(intent.getAction())) {
Log.d(TAG, "capture stop");
stopSelf();
}
Expand All @@ -65,6 +76,67 @@ public IBinder onBind(Intent intent) {
return null;
}




private static final long GPS_MIN_DISTANCE_UPDATE = 10; // The minimum distance to change Updates in meters
private static final long GPS_MIN_DURATION_UPDATE = 30 * 1000; // The minimum time between updates in milliseconds

@Override
public void onLocationChanged(Location location) {
mCaptureManager.recordGps(location);
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
mCaptureManager.recordLog("gps status changed: provider=" + provider + ", status=" + status);
}

@Override
public void onProviderEnabled(String provider) {
gpsStop();
gpsStart();
}

@Override
public void onProviderDisabled(String provider) {
gpsStop();
gpsStart();
}

public void gpsStart() {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}

if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {

mCaptureManager.recordLog("gps start with last known location:" + LocationManager.GPS_PROVIDER);
mCaptureManager.recordGps(mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER));
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_MIN_DURATION_UPDATE, GPS_MIN_DISTANCE_UPDATE, this);

} else if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {

mCaptureManager.recordLog("gps start with last known location:" + LocationManager.NETWORK_PROVIDER);
mCaptureManager.recordGps(mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER));
mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, GPS_MIN_DURATION_UPDATE, GPS_MIN_DISTANCE_UPDATE, this);

}
}

public void gpsStop() {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}

mCaptureManager.recordLog("gps stop");
mLocationManager.removeUpdates(this);
}





static public class PeriodWorkHandler extends Handler {

private Context mContext;
Expand Down
Loading

0 comments on commit 1fc3663

Please sign in to comment.