Skip to content

Commit f8bb491

Browse files
committed
feat(android): add setOverAirVersion API
1 parent 285ecfd commit f8bb491

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.instabug.library.invocation.util.InstabugVideoRecordingButtonPosition;
1818
import com.instabug.library.sessionreplay.model.SessionMetadata;
1919
import com.instabug.library.ui.onboarding.WelcomeMessage;
20+
import com.instabug.library.util.overairversion.OverAirVersionType;
2021

2122
import java.util.ArrayList;
2223
import java.util.HashMap;
@@ -60,6 +61,7 @@ static Map<String, Object> getAll() {
6061
putAll(locales);
6162
putAll(placeholders);
6263
putAll(launchType);
64+
putAll(overAirUpdateService);
6365
}};
6466
}
6567

@@ -246,6 +248,11 @@ static Map<String, Object> getAll() {
246248
put("warm",SessionMetadata.LaunchType.WARM );
247249
put("unknown","unknown");
248250
}};
251+
252+
public static ArgsMap<Integer> overAirUpdateService = new ArgsMap<Integer>() {{
253+
put("expo", OverAirVersionType.EXPO);
254+
put("codePush",OverAirVersionType.CODE_PUSH );
255+
}};
249256

250257
// Temporary workaround to be removed in future release
251258
// This is used for mapping native `LaunchType` values into React Native enum values.

android/src/main/java/com/instabug/reactlibrary/RNInstabug.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import androidx.annotation.NonNull;
77
import androidx.annotation.VisibleForTesting;
88

9+
import com.facebook.react.bridge.ReadableMap;
910
import com.instabug.apm.APM;
1011
import com.instabug.library.Instabug;
1112
import com.instabug.library.LogLevel;
@@ -156,6 +157,11 @@ public static class Builder {
156157
*/
157158
private String codePushVersion;
158159

160+
/**
161+
* The overAirUpdate Version to be used for all reports.
162+
*/
163+
private ReadableMap overAirVersion;
164+
159165
/**
160166
* The events that trigger the SDK's user interface.
161167
*/
@@ -210,6 +216,16 @@ public Builder setCodePushVersion(String codePushVersion) {
210216
return this;
211217
}
212218

219+
/**
220+
* Sets over air update version to be used for all reports.
221+
*
222+
* @param overAirVersion the over air update version and service map.
223+
*/
224+
public Builder setOverAirVersion(ReadableMap overAirVersion) {
225+
this.overAirVersion = overAirVersion;
226+
return this;
227+
}
228+
213229
/**
214230
* Sets the invocation triggering events for the SDK's user interface
215231
*
@@ -237,6 +253,17 @@ public void build() {
237253
instabugBuilder.setCodePushVersion(codePushVersion);
238254
}
239255

256+
if (overAirVersion != null ) {
257+
if (overAirVersion.hasKey("service") && overAirVersion.hasKey("version"))
258+
{
259+
if (overAirVersion.getString("service")!=null && overAirVersion.getString("version")!=null)
260+
{
261+
instabugBuilder.setOverAirVersion(overAirVersion.getString("version"),
262+
ArgsRegistry.overAirUpdateService.get(overAirVersion.getString("service")));
263+
}
264+
}
265+
}
266+
240267
instabugBuilder.build();
241268

242269
// Temporarily disabling APM hot launches

android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ public void init(
144144
final ReadableArray invocationEventValues,
145145
final String logLevel,
146146
final boolean useNativeNetworkInterception,
147-
@Nullable final String codePushVersion
147+
@Nullable final String codePushVersion,
148+
@Nullable final ReadableMap overAirVersion
148149
) {
149150
MainThreadHandler.runOnMainThread(new Runnable() {
150151
@Override
@@ -169,6 +170,16 @@ public void run() {
169170
builder.setCodePushVersion(codePushVersion);
170171
}
171172
}
173+
174+
if(overAirVersion != null ) {
175+
if(Instabug.isBuilt()) {
176+
Instabug.setOverAirVersion(overAirVersion.getString("version"),
177+
ArgsRegistry.overAirUpdateService.get(overAirVersion.getString("service")));
178+
} else {
179+
builder.setOverAirVersion(overAirVersion);
180+
}
181+
}
182+
172183
builder.build();
173184
}
174185
});
@@ -188,6 +199,23 @@ public void run() {
188199
});
189200
}
190201

202+
@ReactMethod
203+
public void setOverAirVersion(@Nullable final ReadableMap overAirVersion) {
204+
MainThreadHandler.runOnMainThread(new Runnable() {
205+
@Override
206+
public void run() {
207+
try {
208+
Instabug.setOverAirVersion(overAirVersion.getString("version"),
209+
ArgsRegistry.overAirUpdateService.get(overAirVersion.getString("service")));
210+
211+
} catch (Exception e) {
212+
System.out.println("Exception caught "+ e);
213+
e.printStackTrace();
214+
}
215+
}
216+
});
217+
}
218+
191219

192220
/**
193221
* Adds tag(s) to issues before sending them

android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.instabug.library.featuresflags.model.IBGFeatureFlag;
2525
import com.instabug.library.internal.module.InstabugLocale;
2626
import com.instabug.library.ui.onboarding.WelcomeMessage;
27+
import com.instabug.library.util.overairversion.OverAirVersionType;
2728
import com.instabug.reactlibrary.utils.MainThreadHandler;
2829

2930
import org.junit.After;
@@ -213,6 +214,21 @@ public void testSetCodePushVersion() {
213214
mockInstabug.verify(() -> Instabug.setCodePushVersion(codePushVersion));
214215
}
215216

217+
@Test
218+
public void testSetOverAirVersion() {
219+
WritableMap mockMap = mock(WritableMap.class);
220+
221+
String version="D0A12345-6789-4B3C-A123-4567ABCDEF0";
222+
223+
when(mockMap.getString("version")).thenReturn(version);
224+
when(mockMap.getString("service")).thenReturn("expo");
225+
226+
rnModule.setOverAirVersion(mockMap);
227+
228+
mockInstabug.verify(() -> Instabug.setOverAirVersion(
229+
version, OverAirVersionType.EXPO));
230+
}
231+
216232
@Test
217233
public void testIdentifyUserWithNoId() {
218234
// given

0 commit comments

Comments
 (0)