Skip to content

Commit 51724e8

Browse files
authored
Merge pull request #480 from Instabug/dev
Release: v13.1.1
2 parents d8017cd + c6f8a1d commit 51724e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2213
-472
lines changed

.circleci/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ commands:
4747
steps:
4848
- run:
4949
name: Install XCUITest Driver
50-
command: appium driver install xcuitest@7.14.0
50+
command: appium driver install xcuitest@4.35.0
5151
- when:
5252
condition:
5353
equal:
@@ -142,7 +142,7 @@ jobs:
142142
executor:
143143
name: android/android-machine
144144
resource-class: xlarge
145-
tag: default
145+
tag: 2024.01.1
146146
steps:
147147
- advanced-checkout/shallow-checkout
148148
- setup_flutter
@@ -154,7 +154,7 @@ jobs:
154154
executor:
155155
name: android/android-machine
156156
resource-class: xlarge
157-
tag: default
157+
tag: 2024.01.1
158158
steps:
159159
- advanced-checkout/shallow-checkout
160160
- setup_captain:

CHANGELOG.md

Lines changed: 140 additions & 65 deletions
Large diffs are not rendered by default.

android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group 'com.instabug.flutter'
2-
version '13.0.0'
2+
version '13.1.1'
33

44
buildscript {
55
repositories {
@@ -41,7 +41,7 @@ android {
4141
}
4242

4343
dependencies {
44-
api 'com.instabug.library:instabug:13.0.0'
44+
api 'com.instabug.library:instabug:13.1.1'
4545

4646
testImplementation 'junit:junit:4.13.2'
4747
testImplementation "org.mockito:mockito-inline:3.12.1"

android/src/main/java/com/instabug/flutter/modules/CrashReportingApi.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package com.instabug.flutter.modules;
22

3-
import android.util.Log;
3+
import static com.instabug.crash.CrashReporting.getFingerprintObject;
44

55
import androidx.annotation.NonNull;
6+
import androidx.annotation.Nullable;
67

78
import com.instabug.crash.CrashReporting;
9+
import com.instabug.crash.models.IBGNonFatalException;
810
import com.instabug.flutter.generated.CrashReportingPigeon;
11+
import com.instabug.flutter.util.ArgsRegistry;
912
import com.instabug.flutter.util.Reflection;
1013
import com.instabug.library.Feature;
1114

1215
import org.json.JSONObject;
1316

1417
import java.lang.reflect.Method;
18+
import java.util.Map;
1519

1620
import io.flutter.plugin.common.BinaryMessenger;
1721

@@ -46,4 +50,24 @@ public void send(@NonNull String jsonCrash, @NonNull Boolean isHandled) {
4650
}
4751
}
4852

53+
@Override
54+
public void sendNonFatalError(@NonNull String jsonCrash, @Nullable Map<String, String> userAttributes, @Nullable String fingerprint, @NonNull String nonFatalExceptionLevel) {
55+
try {
56+
Method method = Reflection.getMethod(Class.forName("com.instabug.crash.CrashReporting"), "reportException", JSONObject.class, boolean.class,
57+
Map.class, JSONObject.class, IBGNonFatalException.Level.class);
58+
final JSONObject exceptionObject = new JSONObject(jsonCrash);
59+
60+
JSONObject fingerprintObj = null;
61+
if (fingerprint != null) {
62+
fingerprintObj = getFingerprintObject(fingerprint);
63+
}
64+
IBGNonFatalException.Level nonFatalExceptionLevelType = ArgsRegistry.nonFatalExceptionLevel.get(nonFatalExceptionLevel);
65+
if (method != null) {
66+
method.invoke(null, exceptionObject, true, userAttributes, fingerprintObj, nonFatalExceptionLevelType);
67+
}
68+
} catch (Exception e) {
69+
e.printStackTrace();
70+
}
71+
}
72+
4973
}

android/src/main/java/com/instabug/flutter/util/ArgsRegistry.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import androidx.annotation.NonNull;
44

5+
import com.instabug.crash.models.IBGNonFatalException;
56
import com.instabug.library.LogLevel;
67
import com.instabug.bug.BugReporting;
78
import com.instabug.bug.invocation.Option;
@@ -56,7 +57,12 @@ public T get(Object key) {
5657
put("ColorTheme.light", InstabugColorTheme.InstabugColorThemeLight);
5758
put("ColorTheme.dark", InstabugColorTheme.InstabugColorThemeDark);
5859
}};
59-
60+
public static ArgsMap<IBGNonFatalException.Level> nonFatalExceptionLevel = new ArgsMap<IBGNonFatalException.Level>() {{
61+
put("NonFatalExceptionLevel.critical", IBGNonFatalException.Level.CRITICAL);
62+
put("NonFatalExceptionLevel.error", IBGNonFatalException.Level.ERROR);
63+
put("NonFatalExceptionLevel.warning", IBGNonFatalException.Level.WARNING);
64+
put("NonFatalExceptionLevel.info", IBGNonFatalException.Level.INFO);
65+
}};
6066
public static final ArgsMap<InstabugFloatingButtonEdge> floatingButtonEdges = new ArgsMap<InstabugFloatingButtonEdge>() {{
6167
put("FloatingButtonEdge.left", InstabugFloatingButtonEdge.LEFT);
6268
put("FloatingButtonEdge.right", InstabugFloatingButtonEdge.RIGHT);

android/src/test/java/com/instabug/flutter/CrashReportingApiTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package com.instabug.flutter;
22

3+
import static com.instabug.crash.CrashReporting.getFingerprintObject;
34
import static com.instabug.flutter.util.GlobalMocks.reflected;
45
import static org.mockito.ArgumentMatchers.any;
56
import static org.mockito.ArgumentMatchers.eq;
67
import static org.mockito.Mockito.mock;
78
import static org.mockito.Mockito.mockStatic;
89

910
import com.instabug.crash.CrashReporting;
11+
import com.instabug.crash.models.IBGNonFatalException;
1012
import com.instabug.flutter.generated.CrashReportingPigeon;
1113
import com.instabug.flutter.modules.CrashReportingApi;
14+
import com.instabug.flutter.util.ArgsRegistry;
1215
import com.instabug.flutter.util.GlobalMocks;
1316
import com.instabug.flutter.util.MockReflected;
1417
import com.instabug.library.Feature;
@@ -19,6 +22,9 @@
1922
import org.junit.Test;
2023
import org.mockito.MockedStatic;
2124

25+
import java.util.HashMap;
26+
import java.util.Map;
27+
2228
import io.flutter.plugin.common.BinaryMessenger;
2329

2430

@@ -77,4 +83,19 @@ public void testSend() {
7783

7884
reflected.verify(() -> MockReflected.crashReportException(any(JSONObject.class), eq(isHandled)));
7985
}
86+
87+
@Test
88+
public void testSendNonFatalError() {
89+
String jsonCrash = "{}";
90+
boolean isHandled = true;
91+
String fingerPrint = "test";
92+
93+
Map<String, String> expectedUserAttributes = new HashMap<>();
94+
String level = ArgsRegistry.nonFatalExceptionLevel.keySet().iterator().next();
95+
JSONObject expectedFingerprint = getFingerprintObject(fingerPrint);
96+
IBGNonFatalException.Level expectedLevel = ArgsRegistry.nonFatalExceptionLevel.get(level);
97+
api.sendNonFatalError(jsonCrash, expectedUserAttributes, fingerPrint, level);
98+
99+
reflected.verify(() -> MockReflected.crashReportException(any(JSONObject.class), eq(isHandled), eq(expectedUserAttributes), eq(expectedFingerprint), eq(expectedLevel)));
100+
}
80101
}

android/src/test/java/com/instabug/flutter/util/GlobalMocks.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
import android.net.Uri;
99
import android.util.Log;
1010

11+
import com.instabug.crash.models.IBGNonFatalException;
12+
1113
import org.json.JSONObject;
1214
import org.mockito.MockedStatic;
1315
import org.mockito.invocation.InvocationOnMock;
1416
import org.mockito.stubbing.Answer;
1517

1618
import java.lang.reflect.Method;
19+
import java.util.Map;
1720

1821
public class GlobalMocks {
1922
public static MockedStatic<ThreadManager> threadManager;
@@ -75,6 +78,15 @@ public static void setUp() throws NoSuchMethodException {
7578
JSONObject.class, boolean.class))
7679
.thenReturn(mCrashReportException);
7780

81+
Method mCrashReportNonFatalException = MockReflected.class.getDeclaredMethod("crashReportException", JSONObject.class, boolean.class,
82+
Map.class, JSONObject.class, IBGNonFatalException.Level.class);
83+
mCrashReportNonFatalException.setAccessible(true);
84+
reflection
85+
.when(() -> Reflection.getMethod(Class.forName("com.instabug.crash.CrashReporting"), "reportException",
86+
JSONObject.class, boolean.class,
87+
Map.class, JSONObject.class, IBGNonFatalException.Level.class))
88+
.thenReturn(mCrashReportNonFatalException);
89+
7890
uri = mockStatic(Uri.class);
7991
uri.when(() -> Uri.fromFile(any())).thenReturn(mock(Uri.class));
8092
}

android/src/test/java/com/instabug/flutter/util/MockReflected.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44

55
import androidx.annotation.Nullable;
66

7+
import com.instabug.crash.models.IBGNonFatalException;
8+
79
import org.json.JSONObject;
810

11+
import java.util.Map;
12+
913
/**
1014
* Includes fake implementations of methods called by reflection.
1115
* Used to verify whether or not a private methods was called.
@@ -36,4 +40,6 @@ public static void apmNetworkLog(long requestStartTime, long requestDuration, St
3640
* CrashReporting.reportException
3741
*/
3842
public static void crashReportException(JSONObject exception, boolean isHandled) {}
43+
public static void crashReportException(JSONObject exception, boolean isHandled, Map<String,String> userAttributes, JSONObject fingerPrint, IBGNonFatalException.Level level) {}
44+
3945
}

e2e/BugReportingTests.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void ManualInvocation()
113113
[Fact]
114114
public void MultipleScreenshotsInReproSteps()
115115
{
116-
ScrollDown();
116+
ScrollDownLittle();
117117

118118
captain.FindByText("Enter screen name").Tap();
119119
captain.Type("My Screen");
@@ -136,12 +136,11 @@ public void MultipleScreenshotsInReproSteps()
136136
[Fact]
137137
public void ChangeReportTypes()
138138
{
139-
ScrollDown();
139+
ScrollUp();
140140
captain.FindByText("Bug", exact: true).Tap();
141141

142142
if (Platform.IsAndroid)
143143
{
144-
ScrollUp();
145144
captain.FindByText("Invoke").Tap();
146145

147146
// Shows bug reporting screen
@@ -153,12 +152,10 @@ public void ChangeReportTypes()
153152

154153
Thread.Sleep(500);
155154

156-
ScrollDown();
157155
}
158156

159157
captain.FindByText("Feedback").Tap();
160158

161-
ScrollUp();
162159
captain.FindByText("Invoke").Tap();
163160

164161
// Shows both bug reporting and feature requests in prompt options
@@ -192,7 +189,7 @@ public void ChangeFloatingButtonEdge()
192189
[Fact]
193190
public void OnDismissCallbackIsCalled()
194191
{
195-
ScrollUp();
192+
ScrollDownLittle();
196193

197194
captain.FindByText("Set On Dismiss Callback").Tap();
198195
captain.FindByText("Invoke").Tap();

e2e/Utils/CaptainTest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ protected void ScrollDown()
3636
);
3737
}
3838

39+
40+
protected void ScrollDownLittle()
41+
{
42+
captain.Swipe(
43+
start: new Point(captain.Window.Size.Width / 2, captain.Window.Size.Height - 200),
44+
end: new Point(captain.Window.Size.Width / 2, captain.Window.Size.Height - 220)
45+
);
46+
}
47+
3948
protected void ScrollUp()
4049
{
4150
captain.Swipe(

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
android:label="Instabug - Flutter"
1717
android:name="${applicationName}"
1818
android:icon="@mipmap/ic_launcher"
19+
android:networkSecurityConfig="@xml/network_security_config"
1920
android:usesCleartextTraffic="true">
2021
<activity
2122
android:name=".MainActivity"

0 commit comments

Comments
 (0)