diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..68034fd --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,81 @@ +name: "CI" + +on: [push] + +# Cancel running job if a new push is made to the same branch +# https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#concurrency +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + JAVA_VERSION: 17 + # See https://github.com/actions/setup-java?tab=readme-ov-file#supported-distributions + JAVA_DISTRIBUTION: 'adopt' + +jobs: + spotless: + name: "Spotless" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: ${{ env.JAVA_DISTRIBUTION }} + java-version: ${{ env.JAVA_VERSION }} + - run: ./gradlew spotlessCheck + + app-lint: + name: "app:lint" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: ${{ env.JAVA_DISTRIBUTION }} + java-version: ${{ env.JAVA_VERSION }} + - run: ./gradlew app:lint + + provider-lint: + name: "provider:lint" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: ${{ env.JAVA_DISTRIBUTION }} + java-version: ${{ env.JAVA_VERSION }} + - run: ./gradlew provider:lint + + app-assemble-debug: + name: "app:assembleDebug" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: ${{ env.JAVA_DISTRIBUTION }} + java-version: ${{ env.JAVA_VERSION }} + - run: ./gradlew app:assembleDebug + + provider-assemble-debug: + name: "provider:assembleDebug" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: ${{ env.JAVA_DISTRIBUTION }} + java-version: ${{ env.JAVA_VERSION }} + - run: ./gradlew provider:assembleDebug + + provider-test: + name: "provider:test" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: ${{ env.JAVA_DISTRIBUTION }} + java-version: ${{ env.JAVA_VERSION }} + - run: ./gradlew provider:test diff --git a/provider/src/main/java/com/raygun/raygun4android/CrashReporting.java b/provider/src/main/java/com/raygun/raygun4android/CrashReporting.java index 8e385a2..c4de6de 100644 --- a/provider/src/main/java/com/raygun/raygun4android/CrashReporting.java +++ b/provider/src/main/java/com/raygun/raygun4android/CrashReporting.java @@ -3,7 +3,6 @@ import android.content.ComponentName; import android.content.Intent; import android.os.Build; - import com.google.gson.Gson; import com.raygun.raygun4android.logging.RaygunLogger; import com.raygun.raygun4android.messages.crashreporting.RaygunBreadcrumbMessage; @@ -13,7 +12,6 @@ import com.raygun.raygun4android.utils.RaygunFileFilter; import com.raygun.raygun4android.utils.RaygunFileUtils; import com.raygun.raygun4android.utils.RaygunUtils; - import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -70,7 +68,7 @@ static void clearBreadcrumbs() { } private static RaygunBreadcrumbMessage processBreadcrumbLocation( - RaygunBreadcrumbMessage breadcrumb, boolean shouldProcessBreadcrumbLocation) { + RaygunBreadcrumbMessage breadcrumb, boolean shouldProcessBreadcrumbLocation) { if (shouldProcessBreadcrumbLocation && breadcrumb.getClassName() == null) { @@ -83,7 +81,7 @@ private static RaygunBreadcrumbMessage processBreadcrumbLocation( StackTraceElement nextFrame = trace[i + 1]; if (thisFrame.getClassName().contains("com.raygun.raygun4android.") - && !nextFrame.getClassName().contains("com.raygun.raygun4android.")) { + && !nextFrame.getClassName().contains("com.raygun.raygun4android.")) { frame = nextFrame; break; } @@ -92,13 +90,13 @@ private static RaygunBreadcrumbMessage processBreadcrumbLocation( if (frame != null) { return new RaygunBreadcrumbMessage.Builder(breadcrumb.getMessage()) - .category(breadcrumb.getCategory()) - .customData(breadcrumb.getCustomData()) - .level(breadcrumb.getLevel()) - .className(frame.getClassName()) - .methodName(frame.getMethodName()) - .lineNumber(frame.getLineNumber()) - .build(); + .category(breadcrumb.getCategory()) + .customData(breadcrumb.getCustomData()) + .level(breadcrumb.getLevel()) + .className(frame.getClassName()) + .methodName(frame.getMethodName()) + .lineNumber(frame.getLineNumber()) + .build(); } } @@ -141,23 +139,23 @@ static void send(Throwable throwable, List tags, Map customData) { postCachedMessages(); } else { RaygunLogger.w( - "Crash Reporting is not enabled, please enable to use the send() function"); + "Crash Reporting is not enabled, please enable to use the send() function"); } } private static RaygunMessage buildMessage(Throwable throwable) { try { RaygunMessage msg = - RaygunMessageBuilder.instance() - .setEnvironmentDetails(RaygunClient.getApplicationContext()) - .setMachineName(Build.MODEL) - .setExceptionDetails(throwable) - .setClientDetails() - .setAppContext(RaygunClient.getAppContextIdentifier()) - .setVersion(RaygunClient.getVersion()) - .setNetworkInfo(RaygunClient.getApplicationContext()) - .setBreadcrumbs(breadcrumbs) - .build(); + RaygunMessageBuilder.instance() + .setEnvironmentDetails(RaygunClient.getApplicationContext()) + .setMachineName(Build.MODEL) + .setExceptionDetails(throwable) + .setClientDetails() + .setAppContext(RaygunClient.getAppContextIdentifier()) + .setVersion(RaygunClient.getVersion()) + .setNetworkInfo(RaygunClient.getApplicationContext()) + .setBreadcrumbs(breadcrumbs) + .build(); if (RaygunClient.getVersion() != null) { msg.getDetails().setVersion(RaygunClient.getVersion()); @@ -187,24 +185,24 @@ static void attachExceptionHandler() { static void postCachedMessages() { if (RaygunNetworkUtils.hasInternetConnection(RaygunClient.getApplicationContext())) { File[] fileList = - RaygunClient.getApplicationContext() - .getCacheDir() - .listFiles(new RaygunFileFilter()); + RaygunClient.getApplicationContext() + .getCacheDir() + .listFiles(new RaygunFileFilter()); if (fileList != null) { for (File f : fileList) { try { if (RaygunFileUtils.getExtension(f.getName()) - .equalsIgnoreCase(RaygunSettings.DEFAULT_FILE_EXTENSION)) { + .equalsIgnoreCase(RaygunSettings.DEFAULT_FILE_EXTENSION)) { ObjectInputStream ois = null; try { ois = new ObjectInputStream(new FileInputStream(f)); SerializedMessage serializedMessage = - (SerializedMessage) ois.readObject(); + (SerializedMessage) ois.readObject(); enqueueWorkForCrashReportingService( - RaygunClient.getApiKey(), serializedMessage.message); + RaygunClient.getApiKey(), serializedMessage.message); if (!f.delete()) { RaygunLogger.w( - "Couldn't delete cached report (" + f.getName() + ")"); + "Couldn't delete cached report (" + f.getName() + ")"); } } finally { if (ois != null) { @@ -214,33 +212,33 @@ static void postCachedMessages() { } } catch (FileNotFoundException e) { RaygunLogger.e( - "Error loading cached message from filesystem - " + e.getMessage()); + "Error loading cached message from filesystem - " + e.getMessage()); } catch (IOException e) { RaygunLogger.e( - "Error reading cached message from filesystem - " + e.getMessage()); + "Error reading cached message from filesystem - " + e.getMessage()); } catch (ClassNotFoundException e) { RaygunLogger.e( - "Error in handling cached message from filesystem - " - + e.getMessage()); + "Error in handling cached message from filesystem - " + + e.getMessage()); } } } else { RaygunLogger.e( - "Error in handling cached message from filesystem - could not get a list of" - + " files from cache dir"); + "Error in handling cached message from filesystem - could not get a list of" + + " files from cache dir"); } } } private static void enqueueWorkForCrashReportingService(String apiKey, String jsonPayload) { Intent intent = - new Intent(RaygunClient.getApplicationContext(), CrashReportingPostService.class); + new Intent(RaygunClient.getApplicationContext(), CrashReportingPostService.class); intent.setAction( - "com.raygun.raygun4android.intent.action.LAUNCH_CRASHREPORTING_POST_SERVICE"); + "com.raygun.raygun4android.intent.action.LAUNCH_CRASHREPORTING_POST_SERVICE"); intent.setPackage("com.raygun.raygun4android"); intent.setComponent( - new ComponentName( - RaygunClient.getApplicationContext(), CrashReportingPostService.class)); + new ComponentName( + RaygunClient.getApplicationContext(), CrashReportingPostService.class)); intent.putExtra("msg", jsonPayload); intent.putExtra("apikey", apiKey); diff --git a/provider/src/main/java/com/raygun/raygun4android/IRaygunMessageBuilder.java b/provider/src/main/java/com/raygun/raygun4android/IRaygunMessageBuilder.java index 756701f..8792911 100644 --- a/provider/src/main/java/com/raygun/raygun4android/IRaygunMessageBuilder.java +++ b/provider/src/main/java/com/raygun/raygun4android/IRaygunMessageBuilder.java @@ -1,10 +1,8 @@ package com.raygun.raygun4android; import android.content.Context; - import com.raygun.raygun4android.messages.crashreporting.RaygunBreadcrumbMessage; import com.raygun.raygun4android.messages.crashreporting.RaygunMessage; - import java.util.List; import java.util.Map; diff --git a/provider/src/main/java/com/raygun/raygun4android/RUM.java b/provider/src/main/java/com/raygun/raygun4android/RUM.java index 03535eb..86970ae 100644 --- a/provider/src/main/java/com/raygun/raygun4android/RUM.java +++ b/provider/src/main/java/com/raygun/raygun4android/RUM.java @@ -8,7 +8,6 @@ import android.content.Intent; import android.os.Build; import android.os.Bundle; - import com.google.gson.Gson; import com.raygun.raygun4android.logging.RaygunLogger; import com.raygun.raygun4android.messages.rum.RaygunRUMData; @@ -18,7 +17,6 @@ import com.raygun.raygun4android.messages.shared.RaygunUserInfo; import com.raygun.raygun4android.network.RaygunNetworkLogger; import com.raygun.raygun4android.services.RUMPostService; - import java.lang.ref.WeakReference; import java.text.SimpleDateFormat; import java.time.LocalDateTime; @@ -71,8 +69,8 @@ static void attach(Activity mainActivity, boolean networkLogging) { protected static void detach() { if (RUM.rum != null - && RUM.mainActivity.get() != null - && RUM.mainActivity.get().getApplication() != null) { + && RUM.mainActivity.get() != null + && RUM.mainActivity.get().getApplication() != null) { RUM.mainActivity.get().getApplication().unregisterActivityLifecycleCallbacks(RUM.rum); RUM.mainActivity = null; RUM.currentActivity = null; @@ -100,7 +98,7 @@ private static void enqueueWorkForRUMService(String apiKey, String jsonPayload) intent.setAction("com.raygun.raygun4android.intent.action.LAUNCH_RUM_POST_SERVICE"); intent.setPackage("com.raygun.raygun4android"); intent.setComponent( - new ComponentName(RaygunClient.getApplicationContext(), RUMPostService.class)); + new ComponentName(RaygunClient.getApplicationContext(), RUMPostService.class)); intent.putExtra("msg", jsonPayload); intent.putExtra("apikey", apiKey); @@ -118,7 +116,7 @@ public void onActivityCreated(Activity activity, Bundle bundle) { } if (RUM.currentActivity == null - || RUM.currentActivity != null && RUM.currentActivity.get() != activity) { + || RUM.currentActivity != null && RUM.currentActivity.get() != activity) { RUM.currentActivity = new WeakReference<>(activity); RUM.loadingActivity = new WeakReference<>(activity); RUM.startTime = System.nanoTime(); @@ -137,7 +135,7 @@ public void onActivityStarted(Activity activity) { } if (RUM.currentActivity == null - || RUM.currentActivity != null && RUM.currentActivity.get() != activity) { + || RUM.currentActivity != null && RUM.currentActivity.get() != activity) { RUM.currentActivity = new WeakReference<>(activity); RUM.loadingActivity = new WeakReference<>(activity); RUM.startTime = System.nanoTime(); @@ -194,15 +192,14 @@ public void onActivitySaveInstanceState(Activity activity, Bundle bundle) { } @Override - public void onActivityDestroyed(Activity activity) { - } + public void onActivityDestroyed(Activity activity) {} private static String getActivityName(Activity activity) { return activity.getClass().getSimpleName(); } private static void rotateSession( - RaygunUserInfo currentSessionUser, RaygunUserInfo newSessionUser) { + RaygunUserInfo currentSessionUser, RaygunUserInfo newSessionUser) { sendRUMEvent(RaygunSettings.RUM_EVENT_SESSION_END, currentSessionUser); RUM.sessionId = UUID.randomUUID().toString(); sendRUMEvent(RaygunSettings.RUM_EVENT_SESSION_START, newSessionUser); @@ -210,8 +207,8 @@ private static void rotateSession( private static boolean doesNeedSessionRotation() { return RUM.lastSeenTime > 0 - && System.currentTimeMillis() - RUM.lastSeenTime - > RaygunSettings.RUM_SESSION_EXPIRY; + && System.currentTimeMillis() - RUM.lastSeenTime + > RaygunSettings.RUM_SESSION_EXPIRY; } static void updateCurrentSessionUser(RaygunUserInfo userInfo) { @@ -219,7 +216,7 @@ static void updateCurrentSessionUser(RaygunUserInfo userInfo) { if (RUM.currentSessionUser != null) { boolean currentSessionUserIsAnon = RUM.currentSessionUser.getIsAnonymous(); boolean usersAreTheSame = - RUM.currentSessionUser.getIdentifier().equals(userInfo.getIdentifier()); + RUM.currentSessionUser.getIdentifier().equals(userInfo.getIdentifier()); boolean changedUser = !usersAreTheSame && !currentSessionUserIsAnon; if (changedUser) { @@ -258,21 +255,21 @@ private static void sendRUMEvent(String eventName, RaygunUserInfo userInfo) { } RaygunUserInfo user = - userInfo == null ? new RaygunUserInfo(null, null, null, null) : userInfo; + userInfo == null ? new RaygunUserInfo(null, null, null, null) : userInfo; RaygunRUMDataMessage dataMessage = - new RaygunRUMDataMessage.Builder(eventName) - .timestamp(timestamp) - .sessionId(sessionId) - .version(RaygunClient.getVersion()) - .os("Android") - .osVersion(Build.VERSION.RELEASE) - .platform(String.format("%s %s", Build.MANUFACTURER, Build.MODEL)) - .user(user) - .build(); + new RaygunRUMDataMessage.Builder(eventName) + .timestamp(timestamp) + .sessionId(sessionId) + .version(RaygunClient.getVersion()) + .os("Android") + .osVersion(Build.VERSION.RELEASE) + .platform(String.format("%s %s", Build.MANUFACTURER, Build.MODEL)) + .user(user) + .build(); RaygunRUMMessage message = new RaygunRUMMessage(); - message.setEventData(new RaygunRUMDataMessage[]{dataMessage}); + message.setEventData(new RaygunRUMDataMessage[] {dataMessage}); enqueueWorkForRUMService(RaygunClient.getApiKey(), new Gson().toJson(message)); } else { @@ -282,22 +279,22 @@ private static void sendRUMEvent(String eventName, RaygunUserInfo userInfo) { private static void sendRUMEvent(String eventName) { RaygunUserInfo user = - RaygunClient.getUser() == null - ? new RaygunUserInfo(null, null, null, null) - : RaygunClient.getUser(); + RaygunClient.getUser() == null + ? new RaygunUserInfo(null, null, null, null) + : RaygunClient.getUser(); sendRUMEvent(eventName, user); } /** * Sends a RUM timing event to Raygun. The message is sent on a background thread. * - * @param eventType The type of event that occurred. - * @param name The name of the event resource such as the activity name or URL of a network - * call. + * @param eventType The type of event that occurred. + * @param name The name of the event resource such as the activity name or URL of a network + * call. * @param milliseconds The duration of the event in milliseconds. */ public static void sendRUMTimingEvent( - RaygunRUMEventType eventType, String name, long milliseconds) { + RaygunRUMEventType eventType, String name, long milliseconds) { if (RaygunClient.isRUMEnabled()) { if (sessionId == null) { @@ -327,40 +324,40 @@ public static void sendRUMTimingEvent( } RaygunUserInfo user = - RaygunClient.getUser() == null - ? new RaygunUserInfo(null, null, null, null) - : RaygunClient.getUser(); + RaygunClient.getUser() == null + ? new RaygunUserInfo(null, null, null, null) + : RaygunClient.getUser(); RaygunRUMTimingMessage timingMessage = - new RaygunRUMTimingMessage.Builder( - eventType == RaygunRUMEventType.ACTIVITY_LOADED ? "p" : "n") - .duration(milliseconds) - .build(); + new RaygunRUMTimingMessage.Builder( + eventType == RaygunRUMEventType.ACTIVITY_LOADED ? "p" : "n") + .duration(milliseconds) + .build(); RaygunRUMData data = new RaygunRUMData.Builder(name).timing(timingMessage).build(); - RaygunRUMData[] dataArray = new RaygunRUMData[]{data}; + RaygunRUMData[] dataArray = new RaygunRUMData[] {data}; String dataStr = new Gson().toJson(dataArray); RaygunRUMDataMessage dataMessage = - new RaygunRUMDataMessage.Builder(RaygunSettings.RUM_EVENT_TIMING) - .timestamp(timestamp) - .sessionId(sessionId) - .version(RaygunClient.getVersion()) - .os("Android") - .osVersion(Build.VERSION.RELEASE) - .platform(String.format("%s %s", Build.MANUFACTURER, Build.MODEL)) - .user(user) - .data(dataStr) - .build(); + new RaygunRUMDataMessage.Builder(RaygunSettings.RUM_EVENT_TIMING) + .timestamp(timestamp) + .sessionId(sessionId) + .version(RaygunClient.getVersion()) + .os("Android") + .osVersion(Build.VERSION.RELEASE) + .platform(String.format("%s %s", Build.MANUFACTURER, Build.MODEL)) + .user(user) + .data(dataStr) + .build(); RaygunRUMMessage message = new RaygunRUMMessage(); - message.setEventData(new RaygunRUMDataMessage[]{dataMessage}); + message.setEventData(new RaygunRUMDataMessage[] {dataMessage}); enqueueWorkForRUMService(RaygunClient.getApiKey(), new Gson().toJson(message)); } else { RaygunLogger.w( - "RUM is not enabled, please enable to use the sendRUMTimingEvent() function"); + "RUM is not enabled, please enable to use the sendRUMTimingEvent() function"); } } diff --git a/provider/src/main/java/com/raygun/raygun4android/RaygunClient.java b/provider/src/main/java/com/raygun/raygun4android/RaygunClient.java index 8370b74..1d1a238 100644 --- a/provider/src/main/java/com/raygun/raygun4android/RaygunClient.java +++ b/provider/src/main/java/com/raygun/raygun4android/RaygunClient.java @@ -6,13 +6,11 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Bundle; - import com.raygun.raygun4android.logging.RaygunLogger; import com.raygun.raygun4android.logging.TimberRaygunLoggerImplementation; import com.raygun.raygun4android.messages.crashreporting.RaygunBreadcrumbMessage; import com.raygun.raygun4android.messages.shared.RaygunUserInfo; import com.raygun.raygun4android.utils.RaygunFileUtils; - import java.util.List; import java.util.Map; import java.util.UUID; @@ -51,7 +49,7 @@ public static void init(Application application) { * version transmitted will be the value of the versionName attribute in your manifest element. * * @param application The Android application - * @param apiKey An API key that belongs to a Raygun application created in your dashboard + * @param apiKey An API key that belongs to a Raygun application created in your dashboard */ public static void init(Application application, String apiKey) { init(application, apiKey, null); @@ -65,9 +63,9 @@ public static void init(Application application, String apiKey) { * or Raygun for Flutter etc. * * @param applicationContext The Android applicationContext - * @param apiKey An API key that belongs to a Raygun application created in your dashboard - * @param version The version of your application, format x.x.x.x, where x is a positive - * integer. + * @param apiKey An API key that belongs to a Raygun application created in your dashboard + * @param version The version of your application, format x.x.x.x, where x is a positive + * integer. */ public static void init(Context applicationContext, String apiKey, String version) { RaygunClient.applicationContext = applicationContext; @@ -79,9 +77,9 @@ public static void init(Context applicationContext, String apiKey, String versio * version of your application * * @param application The Android application - * @param apiKey An API key that belongs to a Raygun application created in your dashboard - * @param version The version of your application, format x.x.x.x, where x is a positive - * integer. + * @param apiKey An API key that belongs to a Raygun application created in your dashboard + * @param version The version of your application, format x.x.x.x, where x is a positive + * integer. */ public static void init(Application application, String apiKey, String version) { RaygunClient.application = application; @@ -93,7 +91,7 @@ private static void sharedSetup(String apiKey, String version) { TimberRaygunLoggerImplementation.init(); RaygunLogger.d( - "Configuring Raygun4Android (v" + RaygunSettings.RAYGUN_CLIENT_VERSION + ")"); + "Configuring Raygun4Android (v" + RaygunSettings.RAYGUN_CLIENT_VERSION + ")"); if (apiKey == null || apiKey.trim().isEmpty()) { RaygunClient.apiKey = readApiKey(getApplicationContext()); @@ -106,10 +104,10 @@ private static void sharedSetup(String apiKey, String version) { if (version == null || version.trim().isEmpty()) { try { RaygunClient.version = - getApplicationContext() - .getPackageManager() - .getPackageInfo(getApplicationContext().getPackageName(), 0) - .versionName; + getApplicationContext() + .getPackageManager() + .getPackageInfo(getApplicationContext().getPackageName(), 0) + .versionName; } catch (PackageManager.NameNotFoundException e) { RaygunClient.version = "Not Provided"; RaygunLogger.w("Couldn't read application version from calling package"); @@ -125,7 +123,7 @@ private static void sharedSetup(String apiKey, String version) { * Sends an exception-type object to Raygun. * * @param throwable The Throwable object that occurred in your application that will be sent to - * Raygun. + * Raygun. */ public static void send(Throwable throwable) { CrashReporting.send(throwable, null, null); @@ -135,10 +133,10 @@ public static void send(Throwable throwable) { * Sends an exception-type object to Raygun with a list of tags you specify. * * @param throwable The Throwable object that occurred in your application that will be sent to - * Raygun. - * @param tags A list of data that will be attached to the Raygun message and visible on the - * error in the dashboard. This could be a build tag, lifecycle state, debug/production - * version etc. + * Raygun. + * @param tags A list of data that will be attached to the Raygun message and visible on the + * error in the dashboard. This could be a build tag, lifecycle state, debug/production + * version etc. */ public static void send(Throwable throwable, List tags) { CrashReporting.send(throwable, tags, null); @@ -148,14 +146,14 @@ public static void send(Throwable throwable, List tags) { * Sends an exception-type object to Raygun with a list of tags you specify, and a set of custom * data. * - * @param throwable The Throwable object that occurred in your application that will be sent to - * Raygun. - * @param tags A list of data that will be attached to the Raygun message and visible on the - * error in the dashboard. This could be a build tag, lifecycle state, debug/production - * version etc. + * @param throwable The Throwable object that occurred in your application that will be sent to + * Raygun. + * @param tags A list of data that will be attached to the Raygun message and visible on the + * error in the dashboard. This could be a build tag, lifecycle state, debug/production + * version etc. * @param customData A set of custom key-value pairs relating to your application and its - * current state. This is a bucket where you can attach any related data you want to see to - * the error. + * current state. This is a bucket where you can attach any related data you want to see to + * the error. */ public static void send(Throwable throwable, List tags, Map customData) { CrashReporting.send(throwable, tags, customData); @@ -166,15 +164,15 @@ public static void send(Throwable throwable, List tags, Map customData) { * a list of tags you specify, and a set of custom data. * * @param exceptionName The name or description of the exception that occurred in your - * application that will be sent to Raygun. - * @param reason The reason for the exception that occurred in your application that will be - * sent to Raygun. - * @param tags A list of data that will be attached to the Raygun message and visible on the - * error in the dashboard. This could be a build tag, lifecycle state, debug/production - * version etc. - * @param customData A set of custom key-value pairs relating to your application and its - * current state. This is a bucket where you can attach any related data you want to see to - * the error. + * application that will be sent to Raygun. + * @param reason The reason for the exception that occurred in your application that will be + * sent to Raygun. + * @param tags A list of data that will be attached to the Raygun message and visible on the + * error in the dashboard. This could be a build tag, lifecycle state, debug/production + * version etc. + * @param customData A set of custom key-value pairs relating to your application and its + * current state. This is a bucket where you can attach any related data you want to see to + * the error. */ public static void send(String exceptionName, String reason, List tags, Map customData) { CrashReporting.send(new Throwable(exceptionName, new Throwable(reason)), tags, customData); @@ -204,7 +202,7 @@ public static void setUser(String user) { * in/out), be sure to call this again with the updated user name/email address. * * @param userInfo A RaygunUserInfo object containing the user data you want to send in its - * fields. + * fields. */ public static void setUser(RaygunUserInfo userInfo) { if (isRUMEnabled()) { @@ -224,7 +222,7 @@ static RaygunUserInfo getUser() { * convenience. * * @param version The version of your application, format x.x.x.x, where x is a positive - * integer. + * integer. */ public static void setVersion(String version) { if (version != null) { @@ -282,9 +280,7 @@ public static void recordBreadcrumb(RaygunBreadcrumbMessage breadcrumb) { CrashReporting.recordBreadcrumb(breadcrumb); } - /** - * Clears breadcrumbs - */ + /** Clears breadcrumbs */ public static void clearBreadcrumbs() { CrashReporting.clearBreadcrumbs(); } @@ -295,7 +291,7 @@ public static void clearBreadcrumbs() { * application. * * @param shouldProcessBreadcrumbLocation enable or disable the full location processing of - * breadcrumb messages + * breadcrumb messages */ public static void shouldProcessBreadcrumbLocation(boolean shouldProcessBreadcrumbLocation) { CrashReporting.shouldProcessBreadcrumbLocation(shouldProcessBreadcrumbLocation); @@ -341,8 +337,8 @@ public static void setCustomCrashReportingEndpoint(String url) { RaygunSettings.setCrashReportingEndpoint(url); } else { RaygunLogger.w( - "A custom crash reporting endpoint can't be null or empty. Custom endpoint has" - + " NOT been applied and default will be used."); + "A custom crash reporting endpoint can't be null or empty. Custom endpoint has" + + " NOT been applied and default will be used."); } } @@ -356,8 +352,8 @@ public static void setCustomRUMEndpoint(String url) { RaygunSettings.setRUMEndpoint(url); } else { RaygunLogger.w( - "A custom RUM endpoint can't be null or empty. Custom endpoint has NOT been" - + " applied and default will be used."); + "A custom RUM endpoint can't be null or empty. Custom endpoint has NOT been" + + " applied and default will be used."); } } @@ -391,9 +387,7 @@ public static boolean isCrashReportingEnabled() { return crashReportingEnabled; } - /** - * Enables the Raygun Crash Reporting feature with the default exception handler enabled. - */ + /** Enables the Raygun Crash Reporting feature with the default exception handler enabled. */ public static void enableCrashReporting() { enableCrashReporting(true); } @@ -435,7 +429,7 @@ public static void enableRUM(Activity activity) { * Enables the Raygun RUM feature which will automatically report session and view events. * Network logging can be toggled with an additional parameter. * - * @param activity The main/entry activity of the Android app. + * @param activity The main/entry activity of the Android app. * @param networkLogging Automatically report the performance of network requests. */ public static void enableRUM(Activity activity, boolean networkLogging) { @@ -449,21 +443,21 @@ public static void enableRUM(Activity activity, boolean networkLogging) { private static String readApiKey(Context context) { try { ApplicationInfo ai = - context.getPackageManager() - .getApplicationInfo( - context.getPackageName(), PackageManager.GET_META_DATA); + context.getPackageManager() + .getApplicationInfo( + context.getPackageName(), PackageManager.GET_META_DATA); Bundle bundle = ai.metaData; return bundle.getString(RaygunSettings.APIKEY_MANIFEST_FIELD); } catch (PackageManager.NameNotFoundException e) { RaygunLogger.e( - "Couldn't read API key from your AndroidManifest.xml element;" - + " cannot send. Detailed error: " - + e.getMessage()); + "Couldn't read API key from your AndroidManifest.xml element;" + + " cannot send. Detailed error: " + + e.getMessage()); } catch (NullPointerException e) { RaygunLogger.e( - "Couldn't find element for your API key in the" - + " AndroidManifest.xml element; cannot send. Detailed error: " - + e.getMessage()); + "Couldn't find element for your API key in the" + + " AndroidManifest.xml element; cannot send. Detailed error: " + + e.getMessage()); } return null; diff --git a/provider/src/main/java/com/raygun/raygun4android/RaygunMessageBuilder.java b/provider/src/main/java/com/raygun/raygun4android/RaygunMessageBuilder.java index 75cd33b..daab659 100644 --- a/provider/src/main/java/com/raygun/raygun4android/RaygunMessageBuilder.java +++ b/provider/src/main/java/com/raygun/raygun4android/RaygunMessageBuilder.java @@ -1,13 +1,11 @@ package com.raygun.raygun4android; import android.content.Context; - import com.raygun.raygun4android.messages.crashreporting.RaygunBreadcrumbMessage; import com.raygun.raygun4android.messages.crashreporting.RaygunClientMessage; import com.raygun.raygun4android.messages.crashreporting.RaygunEnvironmentMessage; import com.raygun.raygun4android.messages.crashreporting.RaygunErrorMessage; import com.raygun.raygun4android.messages.crashreporting.RaygunMessage; - import java.util.List; import java.util.Map; diff --git a/provider/src/main/java/com/raygun/raygun4android/RaygunSettings.java b/provider/src/main/java/com/raygun/raygun4android/RaygunSettings.java index 6c61577..6de14d9 100644 --- a/provider/src/main/java/com/raygun/raygun4android/RaygunSettings.java +++ b/provider/src/main/java/com/raygun/raygun4android/RaygunSettings.java @@ -1,7 +1,6 @@ package com.raygun.raygun4android; import com.raygun.raygun4android.logging.RaygunLogger; - import java.util.Arrays; import java.util.HashSet; @@ -39,8 +38,7 @@ public class RaygunSettings { private static String crashReportingEndpoint = DEFAULT_CRASHREPORTING_ENDPOINT; private static String rumEndpoint = DEFAULT_RUM_ENDPOINT; - private RaygunSettings() { - } + private RaygunSettings() {} public static String getCrashReportingEndpoint() { return crashReportingEndpoint; @@ -75,10 +73,10 @@ static void setMaxReportsStoredOnDevice(int maxReportsStoredOnDevice) { RaygunSettings.maxReportsStoredOnDevice = maxReportsStoredOnDevice; } else { RaygunLogger.w( - "It's not possible to exceed the value " - + DEFAULT_MAX_REPORTS_STORED_ON_DEVICE - + " for the number of reports stored on the device. The setting has not" - + " been applied."); + "It's not possible to exceed the value " + + DEFAULT_MAX_REPORTS_STORED_ON_DEVICE + + " for the number of reports stored on the device. The setting has not" + + " been applied."); } } diff --git a/provider/src/main/java/com/raygun/raygun4android/SerializedMessage.java b/provider/src/main/java/com/raygun/raygun4android/SerializedMessage.java index 0e8ea49..042fea2 100644 --- a/provider/src/main/java/com/raygun/raygun4android/SerializedMessage.java +++ b/provider/src/main/java/com/raygun/raygun4android/SerializedMessage.java @@ -11,8 +11,7 @@ public class SerializedMessage implements Serializable { public String message; - public SerializedMessage() { - } + public SerializedMessage() {} public SerializedMessage(String message) { this.message = message; diff --git a/provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java b/provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java index f5526b2..28d7b66 100644 --- a/provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java +++ b/provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java @@ -1,7 +1,6 @@ package com.raygun.raygun4android.logging; import com.raygun.raygun4android.RaygunSettings; - import timber.log.Timber; public class RaygunLogger { @@ -43,18 +42,18 @@ public static void responseCode(int responseCode) { break; case RaygunSettings.RESPONSE_CODE_BAD_MESSAGE: RaygunLogger.e( - "Bad message - could not parse the provided JSON. Check all fields are" - + " present, especially both occurredOn (ISO 8601 DateTime) and details" - + " { } at the top level"); + "Bad message - could not parse the provided JSON. Check all fields are" + + " present, especially both occurredOn (ISO 8601 DateTime) and details" + + " { } at the top level"); break; case RaygunSettings.RESPONSE_CODE_INVALID_API_KEY: RaygunLogger.e( - "Invalid API Key - The value specified in the header X-ApiKey did not match" - + " with an application in Raygun"); + "Invalid API Key - The value specified in the header X-ApiKey did not match" + + " with an application in Raygun"); break; case RaygunSettings.RESPONSE_CODE_LARGE_PAYLOAD: RaygunLogger.e( - "Request entity too large - The maximum size of a JSON payload is 128KB"); + "Request entity too large - The maximum size of a JSON payload is 128KB"); break; case RaygunSettings.RESPONSE_CODE_RATE_LIMITED: RaygunLogger.e("Too Many Requests - Plan limit exceeded for month or plan expired"); diff --git a/provider/src/main/java/com/raygun/raygun4android/logging/TimberRaygunLogger.java b/provider/src/main/java/com/raygun/raygun4android/logging/TimberRaygunLogger.java index 1cdde8f..f18006d 100644 --- a/provider/src/main/java/com/raygun/raygun4android/logging/TimberRaygunLogger.java +++ b/provider/src/main/java/com/raygun/raygun4android/logging/TimberRaygunLogger.java @@ -1,6 +1,5 @@ package com.raygun.raygun4android.logging; interface TimberRaygunLogger { - static void init() { - } + static void init() {} } diff --git a/provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/NetworkInfo.java b/provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/NetworkInfo.java index bf3f5d2..d70abc1 100644 --- a/provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/NetworkInfo.java +++ b/provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/NetworkInfo.java @@ -3,7 +3,6 @@ import android.content.Context; import android.net.ConnectivityManager; import android.telephony.TelephonyManager; - import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; @@ -35,7 +34,7 @@ private String readNetworkConnectivityState(Context context) { String result = "Not connected"; ConnectivityManager cm = - (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); android.net.NetworkInfo info = cm.getActiveNetworkInfo(); if (info != null) { @@ -110,7 +109,7 @@ private String readNetworkConnectivityState(Context context) { private void readIPAddress() { try { List interfaces = - Collections.list(NetworkInterface.getNetworkInterfaces()); + Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface intf : interfaces) { List addrs = Collections.list(intf.getInetAddresses()); diff --git a/provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunEnvironmentMessage.java b/provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunEnvironmentMessage.java index 7a4c673..043d692 100644 --- a/provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunEnvironmentMessage.java +++ b/provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunEnvironmentMessage.java @@ -7,9 +7,7 @@ import android.os.StatFs; import android.util.DisplayMetrics; import android.view.WindowManager; - import com.raygun.raygun4android.logging.RaygunLogger; - import java.io.IOException; import java.io.RandomAccessFile; import java.util.Date; @@ -65,21 +63,21 @@ public RaygunEnvironmentMessage(Context context) { DisplayMetrics metrics = new DisplayMetrics(); ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)) - .getDefaultDisplay() - .getMetrics(metrics); + .getDefaultDisplay() + .getMetrics(metrics); windowsBoundWidth = metrics.widthPixels; windowsBoundHeight = metrics.heightPixels; TimeZone tz = TimeZone.getDefault(); Date now = new Date(); utcOffset = - TimeUnit.SECONDS.convert(tz.getOffset(now.getTime()), TimeUnit.MILLISECONDS) - / 3600; + TimeUnit.SECONDS.convert(tz.getOffset(now.getTime()), TimeUnit.MILLISECONDS) + / 3600; locale = context.getResources().getConfiguration().locale.toString(); ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); ActivityManager am = - (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); + (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); am.getMemoryInfo(mi); availablePhysicalMemory = mi.availMem / 0x100000; diff --git a/provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunMessage.java b/provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunMessage.java index d6f150e..2ed73cc 100644 --- a/provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunMessage.java +++ b/provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunMessage.java @@ -2,7 +2,6 @@ import android.annotation.SuppressLint; import android.os.Build; - import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.ZoneId; diff --git a/provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunMessageDetails.java b/provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunMessageDetails.java index b5a4b31..534b99c 100644 --- a/provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunMessageDetails.java +++ b/provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunMessageDetails.java @@ -1,10 +1,8 @@ package com.raygun.raygun4android.messages.crashreporting; import android.content.Context; - import com.google.gson.annotations.SerializedName; import com.raygun.raygun4android.messages.shared.RaygunUserInfo; - import java.util.List; import java.util.Map; diff --git a/provider/src/main/java/com/raygun/raygun4android/messages/shared/RaygunUserInfo.java b/provider/src/main/java/com/raygun/raygun4android/messages/shared/RaygunUserInfo.java index cfcff67..5bcfc3c 100644 --- a/provider/src/main/java/com/raygun/raygun4android/messages/shared/RaygunUserInfo.java +++ b/provider/src/main/java/com/raygun/raygun4android/messages/shared/RaygunUserInfo.java @@ -16,14 +16,14 @@ public class RaygunUserInfo { * Set the current user's info to be transmitted - any parameter can be null if the data is not * available or you do not wish to send it. * - * @param firstName The user's first name - * @param fullName The user's full name - if setting the first name you should set this too - * @param email User's email address + * @param firstName The user's first name + * @param fullName The user's full name - if setting the first name you should set this too + * @param email User's email address * @param identifier Unique identifier for this user. Set this to the internal identifier you - * use to look up users, or a correlation ID for anonymous users if you have one. It doesn't - * have to be unique, but we will treat any duplicated values as the same user. If you use - * their email address here, pass it in as the 'emailAddress' parameter too. If identifier - * is not set and/or null, a uuid will be assigned to this field. + * use to look up users, or a correlation ID for anonymous users if you have one. It doesn't + * have to be unique, but we will treat any duplicated values as the same user. If you use + * their email address here, pass it in as the 'emailAddress' parameter too. If identifier + * is not set and/or null, a uuid will be assigned to this field. */ public RaygunUserInfo(String identifier, String firstName, String fullName, String email) { if (isValidUser(identifier)) { @@ -32,8 +32,8 @@ public RaygunUserInfo(String identifier, String firstName, String fullName, Stri this.email = email; } else { RaygunLogger.i( - "Ignored firstName, fullName and email because created user was deemed" - + " anonymous"); + "Ignored firstName, fullName and email because created user was deemed" + + " anonymous"); } } @@ -42,11 +42,11 @@ public RaygunUserInfo(String identifier, String firstName, String fullName, Stri * user. * * @param identifier Unique identifier for this user. Set this to the internal identifier you - * use to look up users, or a correlation ID for anonymous users if you have one. It doesn't - * have to be unique, but we will treat any duplicated values as the same user. If you use - * their email address here, please use the full constructor and pass it in as the - * 'emailAddress' parameter too. If identifier is not set and/or null, a uuid will be - * assigned to this field. + * use to look up users, or a correlation ID for anonymous users if you have one. It doesn't + * have to be unique, but we will treat any duplicated values as the same user. If you use + * their email address here, please use the full constructor and pass it in as the + * 'emailAddress' parameter too. If identifier is not set and/or null, a uuid will be + * assigned to this field. */ public RaygunUserInfo(String identifier) { isValidUser(identifier); @@ -104,7 +104,7 @@ public String getIdentifier() { private Boolean isValidUser(String identifier) { if (identifier == null || identifier.isEmpty()) { this.identifier = - RaygunNetworkUtils.getDeviceUuid(RaygunClient.getApplicationContext()); + RaygunNetworkUtils.getDeviceUuid(RaygunClient.getApplicationContext()); this.isAnonymous = true; RaygunLogger.i("Created anonymous user"); return false; diff --git a/provider/src/main/java/com/raygun/raygun4android/network/RaygunNetworkLogger.java b/provider/src/main/java/com/raygun/raygun4android/network/RaygunNetworkLogger.java index 9f74ae0..c03b6d5 100644 --- a/provider/src/main/java/com/raygun/raygun4android/network/RaygunNetworkLogger.java +++ b/provider/src/main/java/com/raygun/raygun4android/network/RaygunNetworkLogger.java @@ -4,7 +4,6 @@ import com.raygun.raygun4android.RaygunRUMEventType; import com.raygun.raygun4android.RaygunSettings; import com.raygun.raygun4android.network.http.RaygunUrlStreamHandlerFactory; - import java.net.URL; import java.util.HashMap; import java.util.Iterator; @@ -13,7 +12,7 @@ public class RaygunNetworkLogger { private static final long CONNECTION_TIMEOUT = 60000L; // 1 min private static final HashMap connections = - new HashMap(); + new HashMap(); private static boolean loggingEnabled = true; private static boolean loggingInitialized = false; @@ -42,19 +41,19 @@ public static synchronized void startNetworkCall(String url, long startTime) { } public static synchronized void endNetworkCall( - String url, String requestMethod, long endTime, int statusCode) { + String url, String requestMethod, long endTime, int statusCode) { if (url != null) { String id = sanitiseURL(url); if ((connections.containsKey(id))) { RaygunNetworkRequestInfo request = connections.get(id); if (request != null) { sendNetworkTimingEvent( - request.url, - requestMethod, - request.startTime, - endTime, - statusCode, - null); + request.url, + requestMethod, + request.startTime, + endTime, + statusCode, + null); connections.remove(id); } } @@ -66,13 +65,13 @@ public static synchronized void endNetworkCall( * through. Future updates may include sending the cancelled request timing through with * information showing it was cancelled. * - * @param url URL to cancel + * @param url URL to cancel * @param requestMethod URL to cancel - * @param endTime URL to cancel - * @param exception URL to cancel + * @param endTime URL to cancel + * @param exception URL to cancel */ public static synchronized void cancelNetworkCall( - String url, String requestMethod, long endTime, String exception) { + String url, String requestMethod, long endTime, String exception) { if (url != null) { String id = sanitiseURL(url); connections.remove(id); @@ -80,24 +79,24 @@ public static synchronized void cancelNetworkCall( } private static synchronized void sendNetworkTimingEvent( - String url, - String requestMethod, - long startTime, - long endTime, - int statusCode, - String exception) { + String url, + String requestMethod, + long startTime, + long endTime, + int statusCode, + String exception) { if (!shouldIgnoreURL(url) && loggingEnabled) { url = sanitiseURL(url); RUM.sendRUMTimingEvent( - RaygunRUMEventType.NETWORK_CALL, - requestMethod + " " + url, - endTime - startTime); + RaygunRUMEventType.NETWORK_CALL, + requestMethod + " " + url, + endTime - startTime); } } private static synchronized void removeOldEntries() { Iterator> it = - connections.entrySet().iterator(); + connections.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = it.next(); long startTime = pairs.getValue().startTime; diff --git a/provider/src/main/java/com/raygun/raygun4android/network/RaygunNetworkUtils.java b/provider/src/main/java/com/raygun/raygun4android/network/RaygunNetworkUtils.java index de98f27..9fb2ca7 100644 --- a/provider/src/main/java/com/raygun/raygun4android/network/RaygunNetworkUtils.java +++ b/provider/src/main/java/com/raygun/raygun4android/network/RaygunNetworkUtils.java @@ -6,8 +6,6 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.provider.Settings; - -import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URLConnection; import java.nio.charset.StandardCharsets; @@ -33,10 +31,10 @@ public static int getStatusCode(URLConnection urlConnection) { public static boolean hasInternetConnection(Context appContext) { ConnectivityManager cm = - (ConnectivityManager) - appContext - .getApplicationContext() - .getSystemService(Context.CONNECTIVITY_SERVICE); + (ConnectivityManager) + appContext + .getApplicationContext() + .getSystemService(Context.CONNECTIVITY_SERVICE); if (cm != null) { NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); @@ -54,12 +52,15 @@ public static String getDeviceUuid(Context context) { if (id != null) { return UUID.fromString(id).toString(); } else { - @SuppressLint("HardwareIds") final String androidId = - Settings.Secure.getString( - context.getContentResolver(), Settings.Secure.ANDROID_ID); + @SuppressLint("HardwareIds") + final String androidId = + Settings.Secure.getString( + context.getContentResolver(), Settings.Secure.ANDROID_ID); if (!"9774d56d682e549c".equals(androidId)) { - id = UUID.nameUUIDFromBytes(androidId.getBytes(StandardCharsets.UTF_8)).toString(); + id = + UUID.nameUUIDFromBytes(androidId.getBytes(StandardCharsets.UTF_8)) + .toString(); } else { id = UUID.randomUUID().toString(); } diff --git a/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpUrlConnection.java b/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpUrlConnection.java index 500baac..f40a91b 100644 --- a/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpUrlConnection.java +++ b/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpUrlConnection.java @@ -2,7 +2,6 @@ import com.raygun.raygun4android.network.RaygunNetworkLogger; import com.raygun.raygun4android.network.RaygunNetworkUtils; - import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -21,7 +20,7 @@ final class RaygunHttpUrlConnection extends HttpURLConnection { super(connection.getURL()); connectionInstance = connection; RaygunNetworkLogger.startNetworkCall( - connectionInstance.getURL().toExternalForm(), System.currentTimeMillis()); + connectionInstance.getURL().toExternalForm(), System.currentTimeMillis()); } public void connect() throws IOException { @@ -29,10 +28,10 @@ public void connect() throws IOException { connectionInstance.connect(); } catch (IOException e) { RaygunNetworkLogger.cancelNetworkCall( - url.toExternalForm(), - getRequestMethod(), - System.currentTimeMillis(), - e.getMessage()); + url.toExternalForm(), + getRequestMethod(), + System.currentTimeMillis(), + e.getMessage()); throw e; } } @@ -40,7 +39,7 @@ public void connect() throws IOException { public void disconnect() { int statusCode = RaygunNetworkUtils.getStatusCode(connectionInstance); RaygunNetworkLogger.endNetworkCall( - url.toExternalForm(), getRequestMethod(), System.currentTimeMillis(), statusCode); + url.toExternalForm(), getRequestMethod(), System.currentTimeMillis(), statusCode); if ((connectionInstance instanceof HttpURLConnection)) { ((HttpURLConnection) connectionInstance).disconnect(); @@ -52,10 +51,10 @@ public InputStream getInputStream() throws IOException { return connectionInstance.getInputStream(); } catch (IOException e) { RaygunNetworkLogger.cancelNetworkCall( - url.toExternalForm(), - getRequestMethod(), - System.currentTimeMillis(), - e.getMessage()); + url.toExternalForm(), + getRequestMethod(), + System.currentTimeMillis(), + e.getMessage()); throw e; } } @@ -65,10 +64,10 @@ public OutputStream getOutputStream() throws IOException { return connectionInstance.getOutputStream(); } catch (IOException e) { RaygunNetworkLogger.cancelNetworkCall( - url.toExternalForm(), - getRequestMethod(), - System.currentTimeMillis(), - e.getMessage()); + url.toExternalForm(), + getRequestMethod(), + System.currentTimeMillis(), + e.getMessage()); throw e; } } @@ -90,10 +89,10 @@ public Object getContent() throws IOException { return connectionInstance.getContent(); } catch (IOException e) { RaygunNetworkLogger.cancelNetworkCall( - url.toExternalForm(), - getRequestMethod(), - System.currentTimeMillis(), - e.getMessage()); + url.toExternalForm(), + getRequestMethod(), + System.currentTimeMillis(), + e.getMessage()); throw e; } } @@ -103,10 +102,10 @@ public Object getContent(Class[] types) throws IOException { return connectionInstance.getContent(types); } catch (IOException e) { RaygunNetworkLogger.cancelNetworkCall( - url.toExternalForm(), - getRequestMethod(), - System.currentTimeMillis(), - e.getMessage()); + url.toExternalForm(), + getRequestMethod(), + System.currentTimeMillis(), + e.getMessage()); throw e; } } @@ -180,10 +179,10 @@ public Permission getPermission() throws IOException { return connectionInstance.getPermission(); } catch (IOException e) { RaygunNetworkLogger.cancelNetworkCall( - url.toExternalForm(), - getRequestMethod(), - System.currentTimeMillis(), - e.getMessage()); + url.toExternalForm(), + getRequestMethod(), + System.currentTimeMillis(), + e.getMessage()); throw e; } } diff --git a/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpUrlStreamHandler.java b/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpUrlStreamHandler.java index c0758f1..f8d0efe 100644 --- a/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpUrlStreamHandler.java +++ b/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpUrlStreamHandler.java @@ -2,7 +2,6 @@ import com.raygun.raygun4android.logging.RaygunLogger; import com.raygun.raygun4android.utils.RaygunReflectionUtils; - import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -23,10 +22,10 @@ final class RaygunHttpUrlStreamHandler extends URLStreamHandler { protected URLConnection openConnection(URL url) throws IOException { try { Method method = - RaygunReflectionUtils.findMethod( - originalHandler.getClass(), - "openConnection", - new Class[]{URL.class}); + RaygunReflectionUtils.findMethod( + originalHandler.getClass(), + "openConnection", + new Class[] {URL.class}); method.setAccessible(true); URLConnection urlConnection = (URLConnection) method.invoke(originalHandler, url); @@ -50,14 +49,14 @@ protected URLConnection openConnection(URL url) throws IOException { protected URLConnection openConnection(URL url, Proxy proxy) throws IOException { try { Method method = - RaygunReflectionUtils.findMethod( - originalHandler.getClass(), - "openConnection", - new Class[]{URL.class, Proxy.class}); + RaygunReflectionUtils.findMethod( + originalHandler.getClass(), + "openConnection", + new Class[] {URL.class, Proxy.class}); method.setAccessible(true); URLConnection urlConnection = - (URLConnection) method.invoke(originalHandler, url, proxy); + (URLConnection) method.invoke(originalHandler, url, proxy); if (urlConnection == null) { throw new IOException("Failed to create connection"); diff --git a/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpsUrlConnection.java b/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpsUrlConnection.java index 0b2ceae..64ec1dd 100644 --- a/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpsUrlConnection.java +++ b/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpsUrlConnection.java @@ -2,7 +2,6 @@ import com.raygun.raygun4android.network.RaygunNetworkLogger; import com.raygun.raygun4android.network.RaygunNetworkUtils; - import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,7 +13,6 @@ import java.security.cert.Certificate; import java.util.List; import java.util.Map; - import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLPeerUnverifiedException; @@ -25,7 +23,7 @@ public RaygunHttpsUrlConnection(URLConnection connection) { super(connection.getURL()); connectionInstance = connection; RaygunNetworkLogger.startNetworkCall( - connectionInstance.getURL().toExternalForm(), System.currentTimeMillis()); + connectionInstance.getURL().toExternalForm(), System.currentTimeMillis()); } public void connect() throws IOException { @@ -33,10 +31,10 @@ public void connect() throws IOException { connectionInstance.connect(); } catch (IOException e) { RaygunNetworkLogger.cancelNetworkCall( - url.toExternalForm(), - getRequestMethod(), - System.currentTimeMillis(), - e.getMessage()); + url.toExternalForm(), + getRequestMethod(), + System.currentTimeMillis(), + e.getMessage()); throw e; } } @@ -44,7 +42,7 @@ public void connect() throws IOException { public void disconnect() { int statusCode = RaygunNetworkUtils.getStatusCode(connectionInstance); RaygunNetworkLogger.endNetworkCall( - url.toExternalForm(), getRequestMethod(), System.currentTimeMillis(), statusCode); + url.toExternalForm(), getRequestMethod(), System.currentTimeMillis(), statusCode); if ((connectionInstance instanceof HttpURLConnection)) { ((HttpURLConnection) connectionInstance).disconnect(); @@ -56,10 +54,10 @@ public InputStream getInputStream() throws IOException { return connectionInstance.getInputStream(); } catch (IOException e) { RaygunNetworkLogger.cancelNetworkCall( - url.toExternalForm(), - getRequestMethod(), - System.currentTimeMillis(), - e.getMessage()); + url.toExternalForm(), + getRequestMethod(), + System.currentTimeMillis(), + e.getMessage()); throw e; } } @@ -69,10 +67,10 @@ public OutputStream getOutputStream() throws IOException { return connectionInstance.getOutputStream(); } catch (IOException e) { RaygunNetworkLogger.cancelNetworkCall( - url.toExternalForm(), - getRequestMethod(), - System.currentTimeMillis(), - e.getMessage()); + url.toExternalForm(), + getRequestMethod(), + System.currentTimeMillis(), + e.getMessage()); throw e; } } @@ -94,10 +92,10 @@ public Object getContent() throws IOException { return connectionInstance.getContent(); } catch (IOException e) { RaygunNetworkLogger.cancelNetworkCall( - url.toExternalForm(), - getRequestMethod(), - System.currentTimeMillis(), - e.getMessage()); + url.toExternalForm(), + getRequestMethod(), + System.currentTimeMillis(), + e.getMessage()); throw e; } } @@ -107,10 +105,10 @@ public Object getContent(Class[] types) throws IOException { return connectionInstance.getContent(types); } catch (IOException e) { RaygunNetworkLogger.cancelNetworkCall( - url.toExternalForm(), - getRequestMethod(), - System.currentTimeMillis(), - e.getMessage()); + url.toExternalForm(), + getRequestMethod(), + System.currentTimeMillis(), + e.getMessage()); throw e; } } @@ -184,10 +182,10 @@ public Permission getPermission() throws IOException { return connectionInstance.getPermission(); } catch (IOException e) { RaygunNetworkLogger.cancelNetworkCall( - url.toExternalForm(), - getRequestMethod(), - System.currentTimeMillis(), - e.getMessage()); + url.toExternalForm(), + getRequestMethod(), + System.currentTimeMillis(), + e.getMessage()); throw e; } } diff --git a/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpsUrlStreamHandler.java b/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpsUrlStreamHandler.java index 572c9d0..62be551 100644 --- a/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpsUrlStreamHandler.java +++ b/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpsUrlStreamHandler.java @@ -2,7 +2,6 @@ import com.raygun.raygun4android.logging.RaygunLogger; import com.raygun.raygun4android.utils.RaygunReflectionUtils; - import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -23,10 +22,10 @@ final class RaygunHttpsUrlStreamHandler extends URLStreamHandler { protected URLConnection openConnection(URL url) throws IOException { try { Method method = - RaygunReflectionUtils.findMethod( - originalHandler.getClass(), - "openConnection", - new Class[]{URL.class}); + RaygunReflectionUtils.findMethod( + originalHandler.getClass(), + "openConnection", + new Class[] {URL.class}); method.setAccessible(true); URLConnection urlConnection = (URLConnection) method.invoke(originalHandler, url); @@ -50,14 +49,14 @@ protected URLConnection openConnection(URL url) throws IOException { protected URLConnection openConnection(URL url, Proxy proxy) throws IOException { try { Method method = - RaygunReflectionUtils.findMethod( - originalHandler.getClass(), - "openConnection", - new Class[]{URL.class, Proxy.class}); + RaygunReflectionUtils.findMethod( + originalHandler.getClass(), + "openConnection", + new Class[] {URL.class, Proxy.class}); method.setAccessible(true); URLConnection urlConnection = - (URLConnection) method.invoke(originalHandler, url, proxy); + (URLConnection) method.invoke(originalHandler, url, proxy); if (urlConnection == null) { throw new IOException("Failed to create connection"); diff --git a/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunUrlStreamHandlerFactory.java b/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunUrlStreamHandlerFactory.java index b410c50..4f6b70c 100644 --- a/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunUrlStreamHandlerFactory.java +++ b/provider/src/main/java/com/raygun/raygun4android/network/http/RaygunUrlStreamHandlerFactory.java @@ -1,9 +1,7 @@ package com.raygun.raygun4android.network.http; import android.os.Build; - import com.raygun.raygun4android.logging.RaygunLogger; - import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; import java.util.HashMap; @@ -21,14 +19,14 @@ private void createStreamHandlers() { URLStreamHandler httpHandler = findHandler("http"); if (httpHandler != null) { RaygunHttpUrlStreamHandler raygunHttpHandler = - new RaygunHttpUrlStreamHandler(httpHandler); + new RaygunHttpUrlStreamHandler(httpHandler); handlers.put(raygunHttpHandler.getProtocol(), raygunHttpHandler); } URLStreamHandler httpsHandler = findHandler("https"); if (httpsHandler != null) { RaygunHttpsUrlStreamHandler raygunHttpsHandler = - new RaygunHttpsUrlStreamHandler(httpsHandler); + new RaygunHttpsUrlStreamHandler(httpsHandler); handlers.put(raygunHttpsHandler.getProtocol(), raygunHttpsHandler); } } diff --git a/provider/src/main/java/com/raygun/raygun4android/services/CrashReportingPostService.java b/provider/src/main/java/com/raygun/raygun4android/services/CrashReportingPostService.java index 27368f7..d37260a 100644 --- a/provider/src/main/java/com/raygun/raygun4android/services/CrashReportingPostService.java +++ b/provider/src/main/java/com/raygun/raygun4android/services/CrashReportingPostService.java @@ -4,15 +4,12 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; - import androidx.annotation.NonNull; - import com.raygun.raygun4android.RaygunSettings; import com.raygun.raygun4android.SerializedMessage; import com.raygun.raygun4android.logging.RaygunLogger; import com.raygun.raygun4android.network.RaygunNetworkUtils; import com.raygun.raygun4android.utils.RaygunFileFilter; - import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -24,7 +21,6 @@ import java.util.Date; import java.util.UUID; import java.util.concurrent.TimeUnit; - import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -39,10 +35,10 @@ public class CrashReportingPostService extends RaygunPostService { public static void enqueueWork(Context context, Intent intent) { RaygunLogger.i("Work for CrashReportingPostService has been put in the job queue"); enqueueWork( - context, - CrashReportingPostService.class, - CRASHREPORTING_POSTSERVICE_JOB_ID, - intent); + context, + CrashReportingPostService.class, + CRASHREPORTING_POSTSERVICE_JOB_ID, + intent); } @Override @@ -81,7 +77,7 @@ public void onDestroy() { private void saveMessage(String message) { synchronized (this) { ArrayList cachedFiles = - new ArrayList<>(Arrays.asList(getCacheDir().listFiles(new RaygunFileFilter()))); + new ArrayList<>(Arrays.asList(getCacheDir().listFiles(new RaygunFileFilter()))); if (cachedFiles.size() < RaygunSettings.getMaxReportsStoredOnDevice()) { @SuppressLint("SimpleDateFormat") @@ -89,13 +85,13 @@ private void saveMessage(String message) { String uuid = UUID.randomUUID().toString().replace("-", ""); String timestamp = dateFormat.format(new Date(System.currentTimeMillis())); File fn = - new File( - getCacheDir(), - timestamp - + "-" - + uuid - + "." - + RaygunSettings.DEFAULT_FILE_EXTENSION); + new File( + getCacheDir(), + timestamp + + "-" + + uuid + + "." + + RaygunSettings.DEFAULT_FILE_EXTENSION); try { SerializedMessage serializedMessage = new SerializedMessage(message); @@ -104,15 +100,15 @@ private void saveMessage(String message) { out.close(); } catch (FileNotFoundException e) { RaygunLogger.e( - "Error creating file when caching message to filesystem - " - + e.getMessage()); + "Error creating file when caching message to filesystem - " + + e.getMessage()); } catch (IOException e) { RaygunLogger.e("Error writing message to filesystem - " + e.getMessage()); } } else { RaygunLogger.w( - "Can't write crash report to local disk, maximum number of stored reports" - + " reached."); + "Can't write crash report to local disk, maximum number of stored reports" + + " reached."); } } } @@ -120,10 +116,10 @@ private void saveMessage(String message) { /** * Raw post method that delivers a pre-built Crash Reporting payload to the Raygun API. * - * @param apiKey The API key of the app to deliver to + * @param apiKey The API key of the app to deliver to * @param jsonPayload The JSON representation of a RaygunMessage to be delivered over HTTPS. * @return HTTP result code - 202 if successful, 403 if API key invalid, 400 if bad message - * (invalid properties), 429 if rate limited + * (invalid properties), 429 if rate limited */ private static int postCrashReporting(String apiKey, String jsonPayload) { try { @@ -132,20 +128,20 @@ private static int postCrashReporting(String apiKey, String jsonPayload) { MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8"); OkHttpClient client = - new OkHttpClient.Builder() - .connectTimeout(NETWORK_TIMEOUT, TimeUnit.SECONDS) - .writeTimeout(NETWORK_TIMEOUT, TimeUnit.SECONDS) - .readTimeout(NETWORK_TIMEOUT, TimeUnit.SECONDS) - .build(); + new OkHttpClient.Builder() + .connectTimeout(NETWORK_TIMEOUT, TimeUnit.SECONDS) + .writeTimeout(NETWORK_TIMEOUT, TimeUnit.SECONDS) + .readTimeout(NETWORK_TIMEOUT, TimeUnit.SECONDS) + .build(); RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, jsonPayload); Request request = - new Request.Builder() - .url(endpoint) - .header("X-ApiKey", apiKey) - .post(body) - .build(); + new Request.Builder() + .url(endpoint) + .header("X-ApiKey", apiKey) + .post(body) + .build(); Response response = null; @@ -155,8 +151,8 @@ private static int postCrashReporting(String apiKey, String jsonPayload) { return response.code(); } catch (IOException ioe) { RaygunLogger.e( - "OkHttp POST to Raygun Crash Reporting backend failed - " - + ioe.getMessage()); + "OkHttp POST to Raygun Crash Reporting backend failed - " + + ioe.getMessage()); ioe.printStackTrace(); } finally { if (response != null) { diff --git a/provider/src/main/java/com/raygun/raygun4android/services/RUMPostService.java b/provider/src/main/java/com/raygun/raygun4android/services/RUMPostService.java index fb2a4c3..852b153 100644 --- a/provider/src/main/java/com/raygun/raygun4android/services/RUMPostService.java +++ b/provider/src/main/java/com/raygun/raygun4android/services/RUMPostService.java @@ -3,16 +3,12 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; - import androidx.annotation.NonNull; - import com.raygun.raygun4android.RaygunSettings; import com.raygun.raygun4android.logging.RaygunLogger; import com.raygun.raygun4android.network.RaygunNetworkUtils; - import java.io.IOException; import java.util.concurrent.TimeUnit; - import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -57,10 +53,10 @@ public void onDestroy() { /** * Raw post method that delivers a pre-built RUM payload to the Raygun API. * - * @param apiKey The API key of the app to deliver to + * @param apiKey The API key of the app to deliver to * @param jsonPayload The JSON representation of a ??? to be delivered over HTTPS. * @return HTTP result code - 202 if successful, 403 if API key invalid, 400 if bad message - * (invalid properties) + * (invalid properties) */ private static int postRUM(String apiKey, String jsonPayload) { try { @@ -69,20 +65,20 @@ private static int postRUM(String apiKey, String jsonPayload) { MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8"); OkHttpClient client = - new OkHttpClient.Builder() - .connectTimeout(NETWORK_TIMEOUT, TimeUnit.SECONDS) - .writeTimeout(NETWORK_TIMEOUT, TimeUnit.SECONDS) - .readTimeout(NETWORK_TIMEOUT, TimeUnit.SECONDS) - .build(); + new OkHttpClient.Builder() + .connectTimeout(NETWORK_TIMEOUT, TimeUnit.SECONDS) + .writeTimeout(NETWORK_TIMEOUT, TimeUnit.SECONDS) + .readTimeout(NETWORK_TIMEOUT, TimeUnit.SECONDS) + .build(); RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, jsonPayload); Request request = - new Request.Builder() - .url(endpoint) - .header("X-ApiKey", apiKey) - .post(body) - .build(); + new Request.Builder() + .url(endpoint) + .header("X-ApiKey", apiKey) + .post(body) + .build(); Response response = null; @@ -92,7 +88,7 @@ private static int postRUM(String apiKey, String jsonPayload) { return response.code(); } catch (IOException ioe) { RaygunLogger.e( - "OkHttp POST to Raygun RUM backend failed - " + ioe.getMessage()); + "OkHttp POST to Raygun RUM backend failed - " + ioe.getMessage()); ioe.printStackTrace(); } finally { if (response != null) { diff --git a/provider/src/main/java/com/raygun/raygun4android/services/RaygunPostService.java b/provider/src/main/java/com/raygun/raygun4android/services/RaygunPostService.java index 11c8d67..f3dc612 100644 --- a/provider/src/main/java/com/raygun/raygun4android/services/RaygunPostService.java +++ b/provider/src/main/java/com/raygun/raygun4android/services/RaygunPostService.java @@ -1,13 +1,10 @@ package com.raygun.raygun4android.services; import androidx.core.app.JobIntentService; - import com.raygun.raygun4android.logging.RaygunLogger; import com.raygun.raygun4android.logging.TimberRaygunLoggerImplementation; -/** - * A JobIntentService that can validate Raygun API keys - */ +/** A JobIntentService that can validate Raygun API keys */ public abstract class RaygunPostService extends JobIntentService { /** * Validation to check if an API key has been supplied to the service diff --git a/provider/src/main/java/com/raygun/raygun4android/utils/RaygunFileFilter.java b/provider/src/main/java/com/raygun/raygun4android/utils/RaygunFileFilter.java index 17452d1..391a854 100644 --- a/provider/src/main/java/com/raygun/raygun4android/utils/RaygunFileFilter.java +++ b/provider/src/main/java/com/raygun/raygun4android/utils/RaygunFileFilter.java @@ -1,7 +1,6 @@ package com.raygun.raygun4android.utils; import com.raygun.raygun4android.RaygunSettings; - import java.io.File; import java.io.FileFilter; import java.util.Locale; diff --git a/provider/src/main/java/com/raygun/raygun4android/utils/RaygunFileUtils.java b/provider/src/main/java/com/raygun/raygun4android/utils/RaygunFileUtils.java index b9cdeb2..6b5c9e5 100644 --- a/provider/src/main/java/com/raygun/raygun4android/utils/RaygunFileUtils.java +++ b/provider/src/main/java/com/raygun/raygun4android/utils/RaygunFileUtils.java @@ -1,10 +1,8 @@ package com.raygun.raygun4android.utils; import android.content.Context; - import com.raygun.raygun4android.RaygunSettings; import com.raygun.raygun4android.logging.RaygunLogger; - import java.io.File; public class RaygunFileUtils { @@ -29,7 +27,7 @@ public static void clearCachedReports(Context context) { if (fileList != null) { for (File f : fileList) { if (RaygunFileUtils.getExtension(f.getName()) - .equalsIgnoreCase(RaygunSettings.DEFAULT_FILE_EXTENSION)) { + .equalsIgnoreCase(RaygunSettings.DEFAULT_FILE_EXTENSION)) { if (!f.delete()) { RaygunLogger.w("Couldn't delete cached report (" + f.getName() + ")"); } @@ -37,8 +35,8 @@ public static void clearCachedReports(Context context) { } } else { RaygunLogger.e( - "Error in handling cached message from filesystem - could not get a list of" - + " files from cache dir"); + "Error in handling cached message from filesystem - could not get a list of" + + " files from cache dir"); } } } diff --git a/provider/src/main/java/com/raygun/raygun4android/utils/RaygunReflectionUtils.java b/provider/src/main/java/com/raygun/raygun4android/utils/RaygunReflectionUtils.java index 2104ce3..f405e88 100644 --- a/provider/src/main/java/com/raygun/raygun4android/utils/RaygunReflectionUtils.java +++ b/provider/src/main/java/com/raygun/raygun4android/utils/RaygunReflectionUtils.java @@ -7,7 +7,7 @@ public class RaygunReflectionUtils { public static Method findMethod(Class clazz, String methodName, Class[] args) - throws NoSuchMethodException { + throws NoSuchMethodException { Method methodMatched = null; for (Method m : getAllMethods(clazz)) {