Skip to content
This repository was archived by the owner on Aug 22, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions src/com/welaika/android/errbit/ErrbitNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Errbit Notifier for Android
Copyright (c) 2012 Matteo Piotto <matteo.piotto@welaika.com>
http://welaika.com

based on

Airbrake Notifier for Android
Copyright (c) 2011 James Smith <james@loopj.com>
http://loopj.com
Expand Down Expand Up @@ -54,8 +54,8 @@
* ErrBit Notifier
*
* Logs exceptions to Errbit
*
* Based on https://github.com/loopj/airbrake-android/ v.1.3.0
*
* Based on https://github.com/loopj/airbrake-android/ v.1.3.0
*/
public class ErrbitNotifier {
private static final String LOG_TAG = "ErrbitNotifier";
Expand All @@ -70,6 +70,7 @@ public class ErrbitNotifier {

private static final String ENVIRONMENT_PRODUCTION = "production";
private static final String ENVIRONMENT_DEFAULT = ENVIRONMENT_PRODUCTION;
private static boolean ssl = false;

// Exception meta-data
private static String environmentName = ENVIRONMENT_DEFAULT;
Expand All @@ -79,7 +80,7 @@ public class ErrbitNotifier {
private static String androidVersion = android.os.Build.VERSION.RELEASE;
private static String brandDevice = android.os.Build.BRAND;
private static String manufacturerDevice = android.os.Build.MANUFACTURER;


// Anything extra the app wants to add
private static Map<String, String> extraData;
Expand All @@ -89,7 +90,7 @@ public class ErrbitNotifier {

// Errbit api key
private static String errbit_endpoint = "http://airbrakeapp.com/notifier_api/v2/notices";

// Exception storage info
private static boolean notifyOnlyProduction = false;
private static String filePath;
Expand Down Expand Up @@ -118,16 +119,27 @@ public static void register(Context context, String endpoint, String apiKey, Str
register(context, endpoint, apiKey, environmentName, true);
}

public static void setSsl(boolean ssl_setting) {
ssl = ssl_setting;
}

public static boolean isSsl() {
return ssl;
}

public static void register(Context context, String endpoint, String apiKey, String environmentName, boolean notifyOnlyProduction) {
// Require an airbrake api key
if(apiKey != null) {
ErrbitNotifier.apiKey = apiKey;
} else {
throw new RuntimeException("ErrBitNotifier requires an API key.");
}


String prefix = isSsl() ? "https" : "http";


if(endpoint != null) {
ErrbitNotifier.errbit_endpoint = "http://" + endpoint + "/notifier_api/v2/notices";
ErrbitNotifier.errbit_endpoint = prefix + "://" + endpoint + "/notifier_api/v2/notices";
} else {
ErrbitNotifier.errbit_endpoint = "http://airbrakeapp.com/notifier_api/v2/notices";
}
Expand All @@ -136,7 +148,7 @@ public static void register(Context context, String endpoint, String apiKey, Str
if(context == null) {
throw new IllegalArgumentException("context cannot be null.");
}

// Fill in environment name if passed
if(environmentName != null) {
ErrbitNotifier.environmentName = environmentName;
Expand Down Expand Up @@ -294,27 +306,27 @@ private static void writeExceptionToDisk(Throwable e, final Map<String,String> m
s.startTag("", "action");
s.endTag("", "action");
s.startTag("", "cgi-data");

s.startTag("", "var");
s.attribute("", "key", "Manufacturer");
s.text(manufacturerDevice);
s.endTag("", "var");

s.startTag("", "var");
s.attribute("", "key", "Device");
s.text(phoneModel);
s.endTag("", "var");

s.startTag("", "var");
s.attribute("", "key", "Brand");
s.text(brandDevice);
s.endTag("", "var");

s.startTag("", "var");
s.attribute("", "key", "Android Version");
s.text(androidVersion);
s.endTag("", "var");

s.startTag("", "var");
s.attribute("", "key", "App Version");
s.text(versionName);
Expand Down Expand Up @@ -401,7 +413,7 @@ private static void sendExceptionData(File file) {

} finally {

// delete the file only if sending was successful
// delete the file only if sending was successful
if ( sent ) {
file.delete();
}
Expand All @@ -410,7 +422,7 @@ private static void sendExceptionData(File file) {
}

} catch(Exception e) {

// unknown exception
Log.v(LOG_TAG, "Exception caught:",e);

Expand All @@ -428,4 +440,4 @@ private static synchronized void flushExceptions() {
}
}
}
}
}