Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

sending gps, wifi, 3g

  • Loading branch information...
commit 74cf78eb0bb9a6d73723245c0402d242d73605f0 1 parent a51d7c2
Jon Vlachoyiannis authored
View
2  src/com/sfalma/trace/G.java
@@ -39,7 +39,7 @@
public static String APP_VERSION = "unknown";
public static String APP_PACKAGE = "unknown";
//public static String URL = "http://10.39.255.101:8080/api/send";
- public static String URL = "http://192.168.0.1:8000/api/errors";
+ public static String URL = "http://192.168.0.55:8080/api/errors";
public static String TAG = "SfalmaHandler";
public static String ANDROID_VERSION = null;
public static String PHONE_MODEL = null;
View
2  src/com/sfalma/trace/G.template
@@ -39,7 +39,7 @@ public class G {
public static String APP_VERSION = "unknown";
public static String APP_PACKAGE = "unknown";
//public static String URL = "http://10.39.255.101:8080/api/send";
- public static String URL = "http://192.168.0.1:8000/api/errors";
+ public static String URL = "http://192.168.0.55:8080/api/errors";
public static String TAG = "SfalmaHandler";
public static String ANDROID_VERSION = null;
public static String PHONE_MODEL = null;
View
6 src/com/sfalma/trace/Sfalma.java
@@ -38,8 +38,9 @@
import org.json.JSONObject;
public class Sfalma {
+
// FIXME: Use Gson
- public static String createJSON(String app_package, String version, String phoneModel, String android_version, String stackTrace) throws Exception {
+ public static String createJSON(String app_package, String version, String phoneModel, String android_version, String stackTrace, boolean wifi_status, boolean mob_net_status, boolean gps_status) throws Exception {
JSONObject json = new JSONObject();
JSONObject request_json = new JSONObject();
@@ -60,6 +61,9 @@ public static String createJSON(String app_package, String version, String phone
application_json.put("package_version", version);
application_json.put("package_name", app_package);
application_json.put("version", android_version);
+ application_json.put("wifi_on", wifi_status);
+ application_json.put("mobile_net_on", mob_net_status);
+ application_json.put("gps_on", gps_status);
json.put("application_environment", application_json);
client_json.put("version", "sfalma-version-1");
View
55 src/com/sfalma/trace/SfalmaHandler.java
@@ -57,6 +57,11 @@
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;
+import android.net.NetworkInfo;
+import android.net.ConnectivityManager;
+import android.location.LocationManager;
+import android.location.LocationListener;
+import android.location.Location;
/**
* Usage:
@@ -128,7 +133,7 @@ public static boolean setup(Context context, final Processor processor, String a
G.PHONE_MODEL = android.os.Build.MODEL;
// Android version
G.ANDROID_VERSION = android.os.Build.VERSION.RELEASE;
-
+
// Get information about the Package
PackageManager pm = context.getPackageManager();
try {
@@ -159,7 +164,7 @@ public static boolean setup(Context context, final Processor processor, String a
processor.handlerInstalled();
// Third, submit any traces we may have found
- return submit(processor);
+ return submit(processor, context);
}
/**
@@ -199,7 +204,7 @@ public static void notifyContextGone() {
* might want to manually ask the traces to be submitted, for
* example after asking the user's permission.
*/
- public static boolean submit(final Processor processor) {
+ public static boolean submit(final Processor processor, final Context context) {
if (!sSetupCalled)
throw new RuntimeException("you need to call setup() first");
@@ -237,7 +242,7 @@ protected void onPreExecute() {
@Override
protected Object doInBackground(Object... params) {
- submitStackTraces(tracesNowSubmitting);
+ submitStackTraces(tracesNowSubmitting, context);
long rest = sMinDelay - (System.currentTimeMillis() - mTimeStarted);
if (rest > 0)
@@ -268,12 +273,12 @@ protected void processPostExecute(Object result) {
/**
* Version of submit() that doesn't take a processor.
*/
- public static boolean submit() {
+ public static boolean submit(final Context context) {
return submit(new Processor() {
public boolean beginSubmit() { return true; }
public void submitDone() {}
public void handlerInstalled() {}
- });
+ }, context);
}
/**
@@ -451,7 +456,7 @@ else if (phoneModel == null) {
* Look into the files folder to see if there are any "*.stacktrace" files.
* If any are present, submit them to the trace server.
*/
- private static void submitStackTraces(ArrayList<String[]> list) {
+ private static void submitStackTraces(ArrayList<String[]> list, final Context context) {
try {
if (list == null)
return;
@@ -484,7 +489,7 @@ private static void submitStackTraces(ArrayList<String[]> list) {
httpPost.addHeader("X-Sfalma-Api-Key", G.API_KEY);
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
- nvps.add(new BasicNameValuePair("data", Sfalma.createJSON(G.APP_PACKAGE, version, phoneModel, androidVersion, stacktrace)));
+ nvps.add(new BasicNameValuePair("data", Sfalma.createJSON(G.APP_PACKAGE, version, phoneModel, androidVersion, stacktrace, isWifiOn(context), isMobileNetworkOn(context), isGPSOn(context))));
nvps.add(new BasicNameValuePair("hash", Sfalma.MD5(stacktrace)));
httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
@@ -508,4 +513,38 @@ private static void installHandler() {
new DefaultExceptionHandler(currentHandler));
}
}
+
+ private static boolean CheckNetworkConnection(String typeOfConnection, final Context context) {
+ boolean connected = false;
+
+ ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo[] netInfo = cm.getAllNetworkInfo();
+ for (NetworkInfo ni : netInfo) {
+ if (ni.getTypeName().equalsIgnoreCase(typeOfConnection))
+ if (ni.isConnected())
+ connected = true;
+ }
+ return connected;
+ }
+
+ private static boolean isWifiOn(final Context context) {
+ return CheckNetworkConnection("WIFI", context);
+ }
+
+ private static boolean isMobileNetworkOn(final Context context) {
+ return CheckNetworkConnection("MOBILE", context);
+ }
+
+ private static boolean isGPSOn(final Context context) {
+ boolean gps_status = true;
+
+ LocationManager locManager;
+ locManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
+ if (!locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
+ gps_status = false;
+ }
+
+ return gps_status;
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.