Skip to content

Commit 13d4680

Browse files
authored
[MOB-10329] Fix non-working String Keys on Android (#273)
* Remove Class parameter in `getDeserializedValue` * Update `getDeserializedValue` method calls * Update `getDeserializedValue` calls in tests * Update CHANGELOG.md
1 parent f7d5540 commit 13d4680

File tree

4 files changed

+27
-35
lines changed

4 files changed

+27
-35
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Unreleased
22

33
* Adds BugReporting.setVideoRecordingFloatingButtonPosition API
4+
* Fixes an issue with some string keys not working on Android
45

56
## 11.2.0 (2022-09-08)
67

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,14 @@ final class ArgsRegistry {
7474
* - {@code key} is not null
7575
* - {@code key} does exist in the registry
7676
* - The value assigned to the {@code key} is not null
77-
* - The value assigned to the {@code key} is assignable from and can be casted to {@code clazz}
78-
* (i.e. Foo value = getDeserializedValue("key", Foo.class))
7977
*
8078
* @param key the key whose associated value is to be returned
81-
* @param clazz the type in which the value should be deserialized to
8279
* @return the value deserialized if all the assertions were successful, null otherwise
8380
*/
84-
static <T> T getDeserializedValue(String key, Class<T> clazz) {
81+
static <T> T getDeserializedValue(String key) {
8582
if (key != null && ARGS.containsKey(key)) {
8683
Object constant = ARGS.get(key);
87-
if (constant != null && constant.getClass().isAssignableFrom(clazz)) {
84+
if (constant != null) {
8885
return (T) constant;
8986
}
9087
}

android/src/main/java/com/instabug/flutter/InstabugFlutterPlugin.java

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void startWithToken(String token, ArrayList<String> invocationEvents) {
159159
InstabugInvocationEvent[] invocationEventsArray = new InstabugInvocationEvent[invocationEvents.size()];
160160
for (int i = 0; i < invocationEvents.size(); i++) {
161161
String key = invocationEvents.get(i);
162-
invocationEventsArray[i] = ArgsRegistry.getDeserializedValue(key, InstabugInvocationEvent.class);
162+
invocationEventsArray[i] = ArgsRegistry.getDeserializedValue(key);
163163
}
164164

165165
final Application application = (Application) context;
@@ -177,8 +177,7 @@ public void startWithToken(String token, ArrayList<String> invocationEvents) {
177177
* beta.
178178
*/
179179
public void showWelcomeMessageWithMode(String welcomeMessageMode) {
180-
WelcomeMessage.State resolvedWelcomeMessageMode = ArgsRegistry.getDeserializedValue(welcomeMessageMode,
181-
WelcomeMessage.State.class);
180+
WelcomeMessage.State resolvedWelcomeMessageMode = ArgsRegistry.getDeserializedValue(welcomeMessageMode);
182181
Instabug.showWelcomeMessage(resolvedWelcomeMessageMode);
183182
}
184183

@@ -207,7 +206,7 @@ public void logOut() {
207206
* @param instabugLocale
208207
*/
209208
public void setLocale(String instabugLocale) {
210-
Locale resolvedLocale = ArgsRegistry.getDeserializedValue(instabugLocale, Locale.class);
209+
Locale resolvedLocale = ArgsRegistry.getDeserializedValue(instabugLocale);
211210
Instabug.setLocale(resolvedLocale);
212211
}
213212

@@ -279,7 +278,7 @@ public void clearAllLogs() {
279278
* @param colorTheme an InstabugColorTheme to set the SDK's UI to.
280279
*/
281280
public void setColorTheme(String colorTheme) {
282-
InstabugColorTheme resolvedTheme = ArgsRegistry.getDeserializedValue(colorTheme, InstabugColorTheme.class);
281+
InstabugColorTheme resolvedTheme = ArgsRegistry.getDeserializedValue(colorTheme);
283282
if (resolvedTheme != null) {
284283
Instabug.setColorTheme(resolvedTheme);
285284
}
@@ -292,8 +291,7 @@ public void setColorTheme(String colorTheme) {
292291
* @param floatingButtonOffset offset for the position on the y-axis.
293292
*/
294293
public void setFloatingButtonEdge(String floatingButtonEdge, int floatingButtonOffset) {
295-
InstabugFloatingButtonEdge resolvedFloatingButtonEdge = ArgsRegistry.getDeserializedValue(floatingButtonEdge,
296-
InstabugFloatingButtonEdge.class);
294+
InstabugFloatingButtonEdge resolvedFloatingButtonEdge = ArgsRegistry.getDeserializedValue(floatingButtonEdge);
297295
BugReporting.setFloatingButtonEdge(resolvedFloatingButtonEdge);
298296
BugReporting.setFloatingButtonOffset(floatingButtonOffset);
299297
}
@@ -304,7 +302,7 @@ public void setFloatingButtonEdge(String floatingButtonEdge, int floatingButtonO
304302
* @param videoRecordingButtonPosition position of the video recording floating button on the screen.
305303
*/
306304
public void setVideoRecordingFloatingButtonPosition(String videoRecordingButtonPosition) {
307-
InstabugVideoRecordingButtonPosition resolvedVideoRecordingButtonPosition = ArgsRegistry.getDeserializedValue(videoRecordingButtonPosition, InstabugVideoRecordingButtonPosition.class);
305+
InstabugVideoRecordingButtonPosition resolvedVideoRecordingButtonPosition = ArgsRegistry.getDeserializedValue(videoRecordingButtonPosition);
308306
BugReporting.setVideoRecordingFloatingButtonPosition(resolvedVideoRecordingButtonPosition);
309307
}
310308

@@ -432,8 +430,7 @@ public void logUserEventWithName(String name) {
432430
* @param forStringWithKey Key of string to override.
433431
*/
434432
public void setValue(String value, String forStringWithKey) {
435-
InstabugCustomTextPlaceHolder.Key key = ArgsRegistry.getDeserializedValue(forStringWithKey,
436-
InstabugCustomTextPlaceHolder.Key.class);
433+
InstabugCustomTextPlaceHolder.Key key = ArgsRegistry.getDeserializedValue(forStringWithKey);
437434
placeHolder.set(key, value);
438435
Instabug.setCustomTextPlaceHolders(placeHolder);
439436
}
@@ -560,8 +557,7 @@ public void clearFileAttachments() {
560557
* beta or disabled.
561558
*/
562559
public void setWelcomeMessageMode(String welcomeMessageMode) {
563-
WelcomeMessage.State resolvedWelcomeMessageMode = ArgsRegistry.getDeserializedValue(welcomeMessageMode,
564-
WelcomeMessage.State.class);
560+
WelcomeMessage.State resolvedWelcomeMessageMode = ArgsRegistry.getDeserializedValue(welcomeMessageMode);
565561
Instabug.setWelcomeMessageState(resolvedWelcomeMessageMode);
566562
}
567563

@@ -627,7 +623,7 @@ public void run() {
627623
InstabugInvocationEvent[] invocationEventsArray = new InstabugInvocationEvent[invocationEvents.size()];
628624
for (int i = 0; i < invocationEvents.size(); i++) {
629625
String key = invocationEvents.get(i);
630-
invocationEventsArray[i] = ArgsRegistry.getDeserializedValue(key, InstabugInvocationEvent.class);
626+
invocationEventsArray[i] = ArgsRegistry.getDeserializedValue(key);
631627
}
632628
BugReporting.setInvocationEvents(invocationEventsArray);
633629
}
@@ -663,7 +659,7 @@ public void run() {
663659
int[] reportTypesArray = new int[reportTypes.size()];
664660
for (int i = 0; i < reportTypes.size(); i++) {
665661
String key = reportTypes.get(i);
666-
reportTypesArray[i] = ArgsRegistry.getDeserializedValue(key, Integer.class);
662+
reportTypesArray[i] = ArgsRegistry.getDeserializedValue(key);
667663
}
668664
BugReporting.setReportTypes(reportTypesArray);
669665
}
@@ -677,8 +673,7 @@ public void run() {
677673
* @param extendedBugReportMode
678674
*/
679675
public void setExtendedBugReportMode(String extendedBugReportMode) {
680-
ExtendedBugReport.State extendedBugReport = ArgsRegistry.getDeserializedValue(extendedBugReportMode,
681-
ExtendedBugReport.State.class);
676+
ExtendedBugReport.State extendedBugReport = ArgsRegistry.getDeserializedValue(extendedBugReportMode);
682677
BugReporting.setExtendedBugReportState(extendedBugReport);
683678
}
684679

@@ -690,7 +685,7 @@ public void setExtendedBugReportMode(String extendedBugReportMode) {
690685
public void setInvocationOptions(List<String> invocationOptions) {
691686
int[] options = new int[invocationOptions.size()];
692687
for (int i = 0; i < invocationOptions.size(); i++) {
693-
options[i] = ArgsRegistry.getDeserializedValue(invocationOptions.get(i), Integer.class);
688+
options[i] = ArgsRegistry.getDeserializedValue(invocationOptions.get(i));
694689
}
695690
BugReporting.setOptions(options);
696691
}
@@ -705,9 +700,9 @@ public void showBugReportingWithReportTypeAndOptions(final String reportType,
705700
final List<String> invocationOptions) {
706701
int[] options = new int[invocationOptions.size()];
707702
for (int i = 0; i < invocationOptions.size(); i++) {
708-
options[i] = ArgsRegistry.getDeserializedValue(invocationOptions.get(i), Integer.class);
703+
options[i] = ArgsRegistry.getDeserializedValue(invocationOptions.get(i));
709704
}
710-
int reportTypeInt = ArgsRegistry.getDeserializedValue(reportType, Integer.class);
705+
int reportTypeInt = ArgsRegistry.getDeserializedValue(reportType);
711706
BugReporting.show(reportTypeInt, options);
712707
}
713708

@@ -843,7 +838,7 @@ public void showFeatureRequests() {
843838
public void setEmailFieldRequiredForFeatureRequests(final Boolean isEmailRequired, final List<String> actionTypes) {
844839
int[] actions = new int[actionTypes.size()];
845840
for (int i = 0; i < actionTypes.size(); i++) {
846-
actions[i] = ArgsRegistry.getDeserializedValue(actionTypes.get(i), Integer.class);
841+
actions[i] = ArgsRegistry.getDeserializedValue(actionTypes.get(i));
847842
}
848843
FeatureRequests.setEmailFieldRequired(isEmailRequired, actions);
849844
}
@@ -1015,7 +1010,7 @@ public void setAPMLogLevel(final String logLevel) {
10151010
@Override
10161011
public void run() {
10171012
try {
1018-
if (ArgsRegistry.getDeserializedValue(logLevel, Integer.class) == null) {
1013+
if (ArgsRegistry.getDeserializedValue(logLevel) == null) {
10191014
return;
10201015
}
10211016
APM.setLogLevel((int) ArgsRegistry.getRawValue(logLevel));
@@ -1251,7 +1246,7 @@ public void reportScreenChange(String screenName) {
12511246
*/
12521247
public void setReproStepsMode(String reproStepsMode) {
12531248
try {
1254-
Instabug.setReproStepsState(ArgsRegistry.getDeserializedValue(reproStepsMode, State.class));
1249+
Instabug.setReproStepsState(ArgsRegistry.getDeserializedValue(reproStepsMode));
12551250
} catch (Exception e) {
12561251
e.printStackTrace();
12571252
}

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class ArgsRegistryTest {
6767
public void givenFabInvocationIsPresent_when$getDeserializedValue_thenShouldReturnNonNullLocale() {
6868
// when
6969
InstabugInvocationEvent deserializedValue = ArgsRegistry.getDeserializedValue(
70-
"InvocationEvent.floatingButton", InstabugInvocationEvent.class);
70+
"InvocationEvent.floatingButton");
7171
// then
7272
Assert.assertNotNull(deserializedValue);
7373
Assert.assertEquals(InstabugInvocationEvent.FLOATING_BUTTON, deserializedValue);
@@ -77,7 +77,7 @@ public class ArgsRegistryTest {
7777
public void givenWelcomeMessageBetaIsPresent_when$getDeserializedValue_thenShouldReturnNonNullLocale() {
7878
// when
7979
WelcomeMessage.State deserializedValue = ArgsRegistry.getDeserializedValue(
80-
"WelcomeMessageMode.beta", WelcomeMessage.State.class);
80+
"WelcomeMessageMode.beta");
8181
// then
8282
Assert.assertNotNull(deserializedValue);
8383
Assert.assertEquals(WelcomeMessage.State.BETA, deserializedValue);
@@ -86,7 +86,7 @@ public class ArgsRegistryTest {
8686
@Test
8787
public void givenEnglishLocaleIsPresent_when$getDeserializedValue_thenShouldReturnNonNullLocale() {
8888
// when
89-
Locale actualLocale = ArgsRegistry.getDeserializedValue("IBGLocale.english", Locale.class);
89+
Locale actualLocale = ArgsRegistry.getDeserializedValue("IBGLocale.english");
9090
// then
9191
Assert.assertNotNull(actualLocale);
9292
Assert.assertEquals("en", actualLocale.getLanguage());
@@ -105,8 +105,8 @@ public class ArgsRegistryTest {
105105
@Test
106106
public void givenShakeHintIsPresent_when$getDeserializedValue_thenShouldReturnNonNullKey() {
107107
// when
108-
InstabugCustomTextPlaceHolder.Key actualKey =
109-
ArgsRegistry.getDeserializedValue("CustomTextPlaceHolderKey.shakeHint", InstabugCustomTextPlaceHolder.Key.class);
108+
InstabugCustomTextPlaceHolder.Key actualKey = ArgsRegistry
109+
.getDeserializedValue("CustomTextPlaceHolderKey.shakeHint");
110110
// then
111111
Assert.assertNotNull(actualKey);
112112
Assert.assertEquals(InstabugCustomTextPlaceHolder.Key.SHAKE_HINT, actualKey);
@@ -148,8 +148,6 @@ private void assertAllWelcomeMessageStatesArePresent(Map<String, Object> map) {
148148
Assert.assertTrue(map.containsValue(WelcomeMessage.State.DISABLED));
149149
}
150150

151-
152-
153151
private void assertAllSupportedLocalesArePresent(Map<String, Object> map) {
154152
// source of truth
155153
List<Locale> expectedLocales = getCurrentlySupportLanguagesByTheSDK();
@@ -193,7 +191,8 @@ private void assertAllInvocationOptionsArePresent(Map<String, Object> map) {
193191
Assert.assertTrue(map.containsValue(Option.EMAIL_FIELD_OPTIONAL));
194192
}
195193

196-
private void assertAllSupportedCustomTextPlaceHolderKeysArePresent(Map<String, Object> map, List<InstabugCustomTextPlaceHolder.Key> expectedKeys) {
194+
private void assertAllSupportedCustomTextPlaceHolderKeysArePresent(Map<String, Object> map,
195+
List<InstabugCustomTextPlaceHolder.Key> expectedKeys) {
197196
// actual
198197
List<InstabugCustomTextPlaceHolder.Key> actualKeys = new ArrayList<>();
199198
for (Map.Entry m : map.entrySet()) {

0 commit comments

Comments
 (0)