Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 3.7.10 #107

Merged
merged 69 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
2f81dbf
Add coroner query
Oct 13, 2022
d6c2a1a
Add coroner client and queries
Oct 31, 2022
86476b3
Add response processing, change API
Nov 6, 2022
8106a93
Extract coroner client to separate package
Nov 14, 2022
0e7ac0f
Remove coroner client from library tests
Nov 14, 2022
a7cb174
Remove coroner client
Nov 14, 2022
65feba4
Add multiple filters
Nov 15, 2022
aaba046
Multiple filters
Nov 17, 2022
8008525
Default CI
Nov 17, 2022
7634f87
CI params
Nov 17, 2022
fdcc58a
Check app context null
Nov 17, 2022
ee9c2d1
Test exception
Nov 17, 2022
0de1d74
Add rethrow
Nov 17, 2022
d6d900d
Move exception
Nov 17, 2022
66b5a58
Always init Backtrace client
Nov 17, 2022
48b8b8a
Fix echo
vlussenburg Nov 18, 2022
47652f3
Remove RunWith since this test has no tests
vlussenburg Nov 22, 2022
7caf64a
Remove testexecption
vlussenburg Nov 22, 2022
4181d6b
Removed hardcoded values
Nov 23, 2022
92b6fa3
Fixed Dumpwithoutcrash, disabled unhandledException, reanbled ANR
Nov 23, 2022
2e24c1f
Skip testing on old emulator for now
vlussenburg Nov 23, 2022
96e149d
Get rid of defunct actions
vlussenburg Nov 23, 2022
416c647
Replace streams with loops
Nov 24, 2022
60a51db
Enable testing on old devices
Nov 24, 2022
bdd1e33
Fix error message
Nov 28, 2022
931ef86
Add sleep
Nov 28, 2022
d949c4a
Fix instrumented tests
Nov 28, 2022
10f698a
Increase timeout
Nov 28, 2022
c6867af
Increase timeout
Nov 28, 2022
c0ce77e
Merge branch 'master' into feature/integration-tests-verification
vlussenburg Nov 28, 2022
f410e28
update to latest commmit on backtrace branch
Nov 29, 2022
0d27d36
Merge branch 'master' into feature/integration-tests-verification
Mar 29, 2023
fbf6b1e
Merge branch 'release-candidate/3.7.6' into feature/integration-tests…
Apr 1, 2023
c50c3fc
Update crashpad
Apr 1, 2023
db8ee5c
Import fixes
Apr 1, 2023
5c6ea83
Fix import
Apr 1, 2023
a155f2d
Fix Coroner vars
Apr 1, 2023
c1977f2
Merge branch 'release-candidate/3.7.6' into feature/integration-verif…
Apr 1, 2023
15fea10
Reformat code
Apr 1, 2023
ce235ac
Code improvements
Apr 1, 2023
077e45b
Add serializer tests
Apr 1, 2023
eba34da
Improve settings.gradle
Apr 1, 2023
6ad5d5f
Remove unused code
Apr 1, 2023
0e56d4e
Update dependencies
Apr 1, 2023
ad72b8f
Add finals
Apr 8, 2023
88e6f0d
Unit test config
Apr 8, 2023
008c12d
Add unit tests
Apr 11, 2023
5252466
Add unit tests
Apr 11, 2023
8868e0e
Move consts to build config
Apr 17, 2023
46a1fc6
Remove unused file
Apr 17, 2023
58fd1ee
Fix default value
Apr 17, 2023
7e3893b
Move to secrets
Apr 17, 2023
a8a72b8
Fix
Apr 24, 2023
647456d
Merge branch 'master' into feature/integration-verification-tests
May 8, 2023
ee62bc1
Remove todos
May 8, 2023
9a9db4d
Rename variable
May 14, 2023
e91ed35
Add extra brackets
May 14, 2023
e353728
Rename variable
May 14, 2023
70e2a24
Improve error msg
May 14, 2023
7c3bbd1
Use Json objects instead of string
Jun 29, 2023
6ea904e
Refactor
Jun 29, 2023
24a807d
Move frames to new file
Jul 1, 2023
2f714d4
Fix unit test
Jul 1, 2023
06d7ca2
Revert "Fix unit test"
Jul 2, 2023
1c9e023
Rename variable
Jul 19, 2023
555ae9e
Merge branch 'release-candidate/3.7.8' into feature/integration-verif…
Aug 2, 2023
b683771
Add info about 3.7.8 to CHANGELOG.md
Aug 10, 2023
44ec45b
Merge pull request #94 from backtrace-labs/feature/integration-verifi…
BartoszLitwiniuk Aug 10, 2023
4872b06
Merge branch 'release-candidate/3.7.8' into release-3.7.10
Oct 9, 2023
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
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ jobs:

- name: Write to local.properties
run: |
echo BACKTRACE_SUBMISSION_URL=\"https://submit.backtrace.io/yolo/2dd86e8e779d1fc7e22e7b19a9489abeedec3b1426abe7e2209888e92362fba4/json\" > ./local.properties
echo BACKTRACE_SUBMISSION_URL=\"${{ secrets.BACKTRACE_SUBMISSION_URL }}\" >> ./local.properties
echo BACKTRACE_CORONER_URL=\"${{ secrets.BACKTRACE_CORONER_URL }}\" >> ./local.properties
echo BACKTRACE_CORONER_TOKEN=\"${{ secrets.BACKTRACE_CORONER_TOKEN }}\" >> ./local.properties

- name: Build and check
run: ./gradlew assembleDebug assembleDebugAndroidTest build check
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Backtrace Android Release Notes

## Version 3.7.10
- Add integration tests
- Move common http response processing method to helper class
- Remove unused code
- Add abstraction to gson serialization
- Improve example-app Main Activity to work in same way on different Android versions

## Version 3.7.9

- Fixed problem when thread is trying to delete already deleted record from db context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ public BacktraceResult onRequest(BacktraceData data) {
};
backtraceClient.setOnRequestHandler(rh);


//WHEN
for (final String message : messages) {
backtraceClient.send(new Exception(message), new OnServerResponseEventListener() {
Expand All @@ -318,4 +317,4 @@ public void onEvent(BacktraceResult backtraceResult) {
fail(ex.getMessage());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,34 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import backtraceio.library.common.serialization.BacktraceGsonBuilder;
import backtraceio.library.models.BacktraceResult;

/**
* Helper class for serialize and deserialize objects
*/
public class BacktraceSerializeHelper {

/**
* Deserialize JSON into BacktraceResult object
*
* @param json JSON string which will be deserialized
* @return object created during deserialization of given json string
*/
public static BacktraceResult backtraceResultFromJson(String json) {
return new Gson().fromJson(json, BacktraceResult.class);
}

/**
* Serialize given object to JSON string
*
* @param object object which will be serialized
* @return serialized object in JSON string format
*/
public static String toJson(Object object) {
Gson gson = buildGson();
return gson.toJson(object);
return BacktraceSerializeHelper.toJson(new BacktraceGsonBuilder().buildGson(), object);
}

public static <T> T fromJson(String json, Class<T> type) {
Gson gson = buildGson();
return gson.fromJson(json, type);
return BacktraceSerializeHelper.fromJson(new BacktraceGsonBuilder().buildGson(), json, type);
}

public static String toJson(Gson gson, Object object) {
return gson.toJson(object);
}

private static Gson buildGson() {
return new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_DASHES).create();
public static <T> T fromJson(Gson gson, String json, Class<T> type) {
return gson.fromJson(json, type);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package backtraceio.library.common.serialization;

import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class BacktraceGsonBuilder implements CustomGsonBuilder {

@Override
public Gson buildGson() {
return new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_DASHES).create();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package backtraceio.library.common.serialization;

import com.google.gson.Gson;

public interface CustomGsonBuilder {
Gson buildGson();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package backtraceio.library.http;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;

import backtraceio.library.logger.BacktraceLogger;

public class HttpHelper {
private static final String LOG_TAG = HttpHelper.class.getSimpleName();

/**
* Read response message from HTTP response
*
* @param urlConnection current HTTP connection
* @return response from HTTP request
* @throws IOException
*/
public static String getResponseMessage(HttpURLConnection urlConnection) throws IOException {
BacktraceLogger.d(LOG_TAG, "Reading response from HTTP request");

InputStream inputStream;
if (urlConnection.getResponseCode() < HttpURLConnection.HTTP_BAD_REQUEST) {
inputStream = urlConnection.getInputStream();
} else {
inputStream = urlConnection.getErrorStream();
}

BufferedReader br = new BufferedReader(new InputStreamReader(
inputStream));

StringBuilder responseStringBuilder = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
responseStringBuilder.append(line);
}
br.close();
return responseStringBuilder.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ public class BacktraceApi implements Api {
*/
private final String reportSubmissionUrl;

/**
* URL to unique events endpoint
*/
private String uniqueEventsSubmissionUrl;

/**
* URL to summed events endpoint
*/
private String summedEventsSubmissionUrl;

/**
* Event triggered when server respond with error
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package backtraceio.library.services;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
Expand All @@ -14,6 +10,7 @@
import backtraceio.library.common.MultiFormRequestHelper;
import backtraceio.library.common.RequestHelper;
import backtraceio.library.events.OnServerErrorEventListener;
import backtraceio.library.http.HttpHelper;
import backtraceio.library.logger.BacktraceLogger;
import backtraceio.library.models.BacktraceResult;
import backtraceio.library.models.json.BacktraceReport;
Expand Down Expand Up @@ -76,12 +73,12 @@ static BacktraceResult sendReport(String serverUrl, String json, List<String> at
BacktraceLogger.d(LOG_TAG, "Received response status from Backtrace API for HTTP request is: " + statusCode);

if (statusCode == HttpURLConnection.HTTP_OK) {
result = BacktraceSerializeHelper.backtraceResultFromJson(
getResponse(urlConnection)
result = BacktraceSerializeHelper.fromJson(
HttpHelper.getResponseMessage(urlConnection), BacktraceResult.class
);
result.setBacktraceReport(report);
} else {
String message = getResponse(urlConnection);
String message = HttpHelper.getResponseMessage(urlConnection);
message = (BacktraceStringHelper.isNullOrEmpty(message)) ?
urlConnection.getResponseMessage() : message;
throw new HttpException(statusCode, String.format("%s: %s", statusCode, message));
Expand Down Expand Up @@ -150,7 +147,7 @@ public static EventsResult sendEvents(String serverUrl, String json, EventsPaylo
if (statusCode == HttpURLConnection.HTTP_OK) {
result = new EventsResult(payload, urlConnection.getResponseMessage(), BacktraceResultStatus.Ok, statusCode);
} else {
String message = getResponse(urlConnection);
String message = HttpHelper.getResponseMessage(urlConnection);
message = (BacktraceStringHelper.isNullOrEmpty(message)) ?
urlConnection.getResponseMessage() : message;
throw new HttpException(statusCode, String.format("%s: %s", statusCode, message));
Expand All @@ -176,33 +173,4 @@ public static EventsResult sendEvents(String serverUrl, String json, EventsPaylo
}
return result;
}

/**
* Read response message from HTTP response
*
* @param urlConnection current HTTP connection
* @return response from HTTP request
* @throws IOException
*/
private static String getResponse(HttpURLConnection urlConnection) throws IOException {
BacktraceLogger.d(LOG_TAG, "Reading response from HTTP request");

InputStream inputStream;
if (urlConnection.getResponseCode() < HttpURLConnection.HTTP_BAD_REQUEST) {
inputStream = urlConnection.getInputStream();
} else {
inputStream = urlConnection.getErrorStream();
}

BufferedReader br = new BufferedReader(new InputStreamReader(
inputStream));

StringBuilder responseSB = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
responseSB.append(line);
}
br.close();
return responseSB.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package backtraceio.library;

import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertNull;

import junit.framework.Assert;

import org.junit.Test;

import backtraceio.library.common.BacktraceSerializeHelper;
import backtraceio.library.models.BacktraceResult;
import backtraceio.library.models.json.BacktraceReport;
import backtraceio.library.models.types.BacktraceResultStatus;

public class BacktraceSerializeHelperTest {
@Test
public void testSerialization() {
// GIVEN
BacktraceResult backtraceResult = new BacktraceResult(null, "result-message", BacktraceResultStatus.Ok);
// WHEN
String json = BacktraceSerializeHelper.toJson(backtraceResult);
// THEN
assertEquals("{\"message\":\"result-message\",\"status\":\"Ok\"}", json);
}

@Test
public void testDeserialization() {
// GIVEN
String json = "{\"_rxid\": \"12345\", \"message\":\"result-message\",\"status\":\"Ok\"}";

// WHEN
BacktraceResult result = BacktraceSerializeHelper.fromJson(json ,BacktraceResult.class);

// THEN
assertNotNull(result);
assertEquals("result-message", result.message);
assertEquals("12345", result.rxId);
assertEquals(BacktraceResultStatus.Ok, result.status);
assertNull(result.getBacktraceReport());
}
}
1 change: 1 addition & 0 deletions coroner-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
15 changes: 15 additions & 0 deletions coroner-client/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
id 'java-library'
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.code.gson:gson:2.10'
testImplementation 'junit:junit:4.13.2'
testImplementation group: 'org.mockito', name: 'mockito-core', version: '5.2.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package backtraceio.coroner;

import com.google.gson.JsonObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import backtraceio.coroner.common.HttpClient;
import backtraceio.coroner.query.CoronerQueries;
import backtraceio.coroner.query.CoronerQueryFields;
import backtraceio.coroner.response.CoronerApiResponse;
import backtraceio.coroner.response.CoronerHttpException;
import backtraceio.coroner.response.CoronerResponse;
import backtraceio.coroner.response.CoronerResponseException;

public class CoronerClient {
private final HttpClient coronerHttpClient;
private final CoronerQueries coronerQueries;
private final List<String> DEFAULT_ATTRIBUTES = Arrays.asList(
CoronerQueryFields.FOLD_CALLSTACK,
CoronerQueryFields.FOLD_GUID,
CoronerQueryFields.FOLD_CLASSIFIERS
);

public CoronerClient(final String apiUrl, final String coronerToken) {
this(new CoronerHttpClient(apiUrl, coronerToken));
}

public CoronerClient(HttpClient httpClient) {
this.coronerHttpClient = httpClient;
this.coronerQueries = new CoronerQueries();
}

public CoronerResponse rxIdFilter(final String rxId) throws CoronerResponseException, CoronerHttpException, IOException {
return this.rxIdFilter(rxId, new ArrayList<>());
}

public CoronerResponse rxIdFilter(final String rxId, final List<String> customAttributes) throws CoronerResponseException, CoronerHttpException, IOException {
final List<String> attributes = concatAttributes(customAttributes);

final JsonObject coronerQuery = this.coronerQueries.filterByRxId(rxId, attributes);

return makeRequest(coronerQuery);
}

public CoronerResponse errorTypeTimestampFilter(final String errorType, final String timestampLeast, final String timestampMost, final List<String> customAttributes) throws CoronerResponseException, IOException, CoronerHttpException {
final List<String> attributes = concatAttributes(customAttributes);

final JsonObject coronerQuery = this.coronerQueries.filterByErrorTypeAndTimestamp(errorType, timestampLeast, timestampMost, attributes);

return makeRequest(coronerQuery);
}

private List<String> concatAttributes(final List<String> customAttributes) {
final List<String> result = new ArrayList<>(customAttributes);
result.addAll(DEFAULT_ATTRIBUTES);
return result;
}

private CoronerResponse makeRequest(final JsonObject coronerQuery) throws CoronerResponseException, IOException, CoronerHttpException {
final CoronerApiResponse response = this.coronerHttpClient.get(coronerQuery.toString());

if (response.error != null) {
throw new CoronerResponseException(response.getError());
}

return response.getResponse();
}
}
Loading
Loading