From 4fdba1c29bd9302cd7e9d765caa807cc455d64d1 Mon Sep 17 00:00:00 2001 From: AyaMahmoud148 Date: Mon, 28 Apr 2025 16:56:49 +0300 Subject: [PATCH 1/5] feat: support BR adding user consents --- .../flutter/modules/BugReportingApi.java | 22 +++++++++++++++ .../instabug/flutter/util/ArgsRegistry.java | 6 ++++ .../instabug/flutter/BugReportingApiTest.java | 19 +++++++++++++ .../ios/InstabugTests/BugReportingApiTests.m | 24 +++++++++++++++- ios/Classes/Modules/BugReportingApi.m | 17 +++++++++++ ios/Classes/Util/ArgsRegistry.h | 1 + ios/Classes/Util/ArgsRegistry.m | 8 +++++- lib/src/modules/bug_reporting.dart | 28 +++++++++++++++++++ pigeons/bug_reporting.api.dart | 7 +++++ 9 files changed, 130 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/instabug/flutter/modules/BugReportingApi.java b/android/src/main/java/com/instabug/flutter/modules/BugReportingApi.java index 56d91600b..f3236bb4e 100644 --- a/android/src/main/java/com/instabug/flutter/modules/BugReportingApi.java +++ b/android/src/main/java/com/instabug/flutter/modules/BugReportingApi.java @@ -186,4 +186,26 @@ public void setCommentMinimumCharacterCount(@NonNull Long limit, @Nullable List< } BugReporting.setCommentMinimumCharacterCount(limit.intValue(), reportTypesArray); } + + @Override +public void addUserConsents(String key, String description, Boolean mandatory, Boolean checked, String actionType) { + ThreadManager.runOnMainThread(new Runnable() { + @Override + public void run() { + String mappedActionType; + try { + if (actionType==null) { + mappedActionType = null; + } + else { + mappedActionType = ArgsRegistry.userConsentActionType.get(actionType); + } + + BugReporting.addUserConsent(key, description, mandatory, checked, mappedActionType); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); +} } diff --git a/android/src/main/java/com/instabug/flutter/util/ArgsRegistry.java b/android/src/main/java/com/instabug/flutter/util/ArgsRegistry.java index 222a72836..c38028707 100644 --- a/android/src/main/java/com/instabug/flutter/util/ArgsRegistry.java +++ b/android/src/main/java/com/instabug/flutter/util/ArgsRegistry.java @@ -75,6 +75,12 @@ public T get(Object key) { put("Position.bottomRight", InstabugVideoRecordingButtonPosition.BOTTOM_RIGHT); }}; + public static final ArgsMap userConsentActionType = new ArgsMap() {{ + put("UserConsentActionType.dropAutoCapturedMedia", com.instabug.bug.userConsent.ActionType.DROP_AUTO_CAPTURED_MEDIA); + put("UserConsentActionType.dropLogs", com.instabug.bug.userConsent.ActionType.DROP_LOGS); + put("UserConsentActionType.noChat", com.instabug.bug.userConsent.ActionType.NO_CHAT); + }}; + public static ArgsMap welcomeMessageStates = new ArgsMap() {{ put("WelcomeMessageMode.live", WelcomeMessage.State.LIVE); put("WelcomeMessageMode.beta", WelcomeMessage.State.BETA); diff --git a/android/src/test/java/com/instabug/flutter/BugReportingApiTest.java b/android/src/test/java/com/instabug/flutter/BugReportingApiTest.java index 683b5f49a..4d1abb56a 100644 --- a/android/src/test/java/com/instabug/flutter/BugReportingApiTest.java +++ b/android/src/test/java/com/instabug/flutter/BugReportingApiTest.java @@ -194,4 +194,23 @@ public void testSetCommentMinimumCharacterCount() { mBugReporting.verify(() -> BugReporting.setCommentMinimumCharacterCount(limit.intValue(), BugReporting.ReportType.BUG, BugReporting.ReportType.QUESTION)); } + + @Test + public void TestAddUserConsent() { + final Map args = ArgsRegistry.userConsentActionType; + final String[] keysArray = args.keySet().toArray(new String[0]); + + final String key = "testKey"; + final String description = "Consent description"; + final boolean mandatory = true; + final boolean checked = true; + final String inputAction = keysArray[0]; + + final String expectedMappedAction = args.get(inputAction); + + bugReportingModule.addUserConsent(key, description, mandatory, checked, inputAction); + + verify(BugReporting.class, VerificationModeFactory.times(1)); + BugReporting.addUserConsent(key, description, mandatory, checked, expectedMappedAction); + } } diff --git a/example/ios/InstabugTests/BugReportingApiTests.m b/example/ios/InstabugTests/BugReportingApiTests.m index 16f5fbee0..900b73e82 100644 --- a/example/ios/InstabugTests/BugReportingApiTests.m +++ b/example/ios/InstabugTests/BugReportingApiTests.m @@ -174,5 +174,27 @@ - (void)testSetCommentMinimumCharacterCountGivenNoReportTypes { OCMVerify([self.mBugReporting setCommentMinimumCharacterCountForReportTypes:IBGBugReportingReportTypeBug | IBGBugReportingReportTypeFeedback | IBGBugReportingReportTypeQuestion withLimit:limit.intValue]); } - +- (void)testAddUserConsentWithKey { + NSString *key = @"testKey"; + NSString *description = @"Consent description"; + NSNumber *mandatory = @1; + NSNumber *checked = @0; + NSString *actionType= @"UserConsentActionType.dropAutoCapturedMedia"; + FlutterError *error; + IBGActionType mappedActionType = IBGActionTypeDropAutoCapturedMedia; + + [self.api addUserConsentsKey:key + description:description + mandatory:mandatory + checked:checked + actionType:actionType + error: &error + ]; + + OCMVerify([self.mBugReporting addUserConsentWithKey:key + description:description + mandatory:mandatory + checked:checked + actionType:mappedActionType]); +} @end diff --git a/ios/Classes/Modules/BugReportingApi.m b/ios/Classes/Modules/BugReportingApi.m index 3c914b789..bc4eb0711 100644 --- a/ios/Classes/Modules/BugReportingApi.m +++ b/ios/Classes/Modules/BugReportingApi.m @@ -165,4 +165,21 @@ - (void)setCommentMinimumCharacterCountLimit:(NSNumber *)limit reportTypes:(null [IBGBugReporting setCommentMinimumCharacterCountForReportTypes:resolvedTypes withLimit:limit.intValue]; } +- (void)addUserConsentsKey:(NSString *)key + description:(NSString *)description + mandatory:(NSNumber *)mandatory + checked:(NSNumber *)checked + actionType:(nullable NSString *)actionType + error:(FlutterError *_Nullable *_Nonnull)error { + + IBGActionType mappedActionType = (ArgsRegistry.userConsentActionTypes[actionType]).integerValue; + + [IBGBugReporting addUserConsentWithKey:key + description:description + mandatory:mandatory + checked:checked + actionType:mappedActionType]; +} + + @end diff --git a/ios/Classes/Util/ArgsRegistry.h b/ios/Classes/Util/ArgsRegistry.h index a465365df..110b4d5f5 100644 --- a/ios/Classes/Util/ArgsRegistry.h +++ b/ios/Classes/Util/ArgsRegistry.h @@ -21,5 +21,6 @@ typedef NSDictionary ArgsDictionary; + (ArgsDictionary *)locales; + (NSDictionary *)placeholders; ++ (ArgsDictionary *) userConsentActionTypes; @end diff --git a/ios/Classes/Util/ArgsRegistry.m b/ios/Classes/Util/ArgsRegistry.m index b8cdaa21a..c4732550e 100644 --- a/ios/Classes/Util/ArgsRegistry.m +++ b/ios/Classes/Util/ArgsRegistry.m @@ -211,5 +211,11 @@ + (ArgsDictionary *)locales { @"CustomTextPlaceHolderKey.insufficientContentMessage" : kIBGInsufficientContentMessageStringName, }; } - ++ (ArgsDictionary *) userConsentActionTypes { + return @{ + @"UserConsentActionType.dropAutoCapturedMedia": @(IBGActionTypeDropAutoCapturedMedia), + @"UserConsentActionType.dropLogs": @(IBGActionTypeDropLogs), + @"UserConsentActionType.noChat": @(IBGActionTypeNoChat) + }; +} @end diff --git a/lib/src/modules/bug_reporting.dart b/lib/src/modules/bug_reporting.dart index bf2bca82c..381e227ee 100644 --- a/lib/src/modules/bug_reporting.dart +++ b/lib/src/modules/bug_reporting.dart @@ -15,6 +15,12 @@ enum InvocationOption { emailFieldOptional } +enum UserConsentActionType { + dropAutoCapturedMedia, + dropLogs, + noChat, +} + enum DismissType { cancel, submit, addAttachment } enum ReportType { bug, feedback, question, other } @@ -255,4 +261,26 @@ class BugReporting implements BugReportingFlutterApi { reportTypes?.mapToString(), ); } + + /// Adds a user consent item to the bug reporting form. + /// [key] A unique identifier string for the consent item. + /// [description] The text shown to the user describing the consent item. + /// [mandatory] Whether the user must agree to this item before submitting a report. + /// [checked] Whether the consent checkbox is pre-selected. + /// [actionType] A string representing the action type to map to SDK behavior. + static Future addUserConsents( + String key, + String description, + bool mandatory, + bool checked, [ + UserConsentActionType? actionType, + ]) async { + return _host.addUserConsents( + key, + description, + mandatory, + checked, + actionType?.toString(), + ); + } } diff --git a/pigeons/bug_reporting.api.dart b/pigeons/bug_reporting.api.dart index faa180893..8bf127531 100644 --- a/pigeons/bug_reporting.api.dart +++ b/pigeons/bug_reporting.api.dart @@ -32,4 +32,11 @@ abstract class BugReportingHostApi { int limit, List? reportTypes, ); + void addUserConsents( + String key, + String description, + bool mandatory, + bool checked, + String? actionType, + ); } From 9bd5ab6e8e6657ef38831f7fbf90d5bd2a248782 Mon Sep 17 00:00:00 2001 From: AyaMahmoud148 Date: Mon, 28 Apr 2025 16:59:14 +0300 Subject: [PATCH 2/5] feat: add change log --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 950d295b0..498ca39e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [Unreleased] + +### Added + +- Add support for BugReporting user consents. ([#573](https://github.com/Instabug/Instabug-Flutter/pull/573)) + ## [14.3.0](https://github.com/Instabug/Instabug-Flutter/compare/v14.1.0...14.3.0) (April 21, 2025) ### Added From d6558d6b7fce7471c43d369bd9eea8519668fe2d Mon Sep 17 00:00:00 2001 From: AyaMahmoud148 Date: Mon, 28 Apr 2025 17:49:57 +0300 Subject: [PATCH 3/5] fix: android test --- .../com/instabug/flutter/BugReportingApiTest.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/android/src/test/java/com/instabug/flutter/BugReportingApiTest.java b/android/src/test/java/com/instabug/flutter/BugReportingApiTest.java index 4d1abb56a..6d22e26b8 100644 --- a/android/src/test/java/com/instabug/flutter/BugReportingApiTest.java +++ b/android/src/test/java/com/instabug/flutter/BugReportingApiTest.java @@ -27,7 +27,7 @@ import java.util.List; import io.flutter.plugin.common.BinaryMessenger; - +import com.instabug.bug.userConsent.ActionType; public class BugReportingApiTest { private final BinaryMessenger mMessenger = mock(BinaryMessenger.class); @@ -196,21 +196,17 @@ public void testSetCommentMinimumCharacterCount() { } @Test - public void TestAddUserConsent() { - final Map args = ArgsRegistry.userConsentActionType; - final String[] keysArray = args.keySet().toArray(new String[0]); + public void TestAddUserConsents() { final String key = "testKey"; final String description = "Consent description"; final boolean mandatory = true; final boolean checked = true; - final String inputAction = keysArray[0]; + final String actionType = "UserConsentActionType.dropAutoCapturedMedia"; - final String expectedMappedAction = args.get(inputAction); - bugReportingModule.addUserConsent(key, description, mandatory, checked, inputAction); + api.addUserConsents(key, description, mandatory, checked, actionType); - verify(BugReporting.class, VerificationModeFactory.times(1)); - BugReporting.addUserConsent(key, description, mandatory, checked, expectedMappedAction); + mBugReporting.verify(()->BugReporting.addUserConsent(key, description, mandatory, checked,"drop_auto_captured_media")); } } From e0a6d535d5da206d11bb6459d01b9e18299a5b2c Mon Sep 17 00:00:00 2001 From: AyaMahmoud148 Date: Tue, 29 Apr 2025 11:59:47 +0300 Subject: [PATCH 4/5] fix: use named parameters --- ios/Classes/Modules/BugReportingApi.m | 4 ++-- lib/src/modules/bug_reporting.dart | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ios/Classes/Modules/BugReportingApi.m b/ios/Classes/Modules/BugReportingApi.m index bc4eb0711..5268a5061 100644 --- a/ios/Classes/Modules/BugReportingApi.m +++ b/ios/Classes/Modules/BugReportingApi.m @@ -176,8 +176,8 @@ - (void)addUserConsentsKey:(NSString *)key [IBGBugReporting addUserConsentWithKey:key description:description - mandatory:mandatory - checked:checked + mandatory:[mandatory boolValue] + checked:[checked boolValue] actionType:mappedActionType]; } diff --git a/lib/src/modules/bug_reporting.dart b/lib/src/modules/bug_reporting.dart index 381e227ee..b19147d3d 100644 --- a/lib/src/modules/bug_reporting.dart +++ b/lib/src/modules/bug_reporting.dart @@ -268,13 +268,13 @@ class BugReporting implements BugReportingFlutterApi { /// [mandatory] Whether the user must agree to this item before submitting a report. /// [checked] Whether the consent checkbox is pre-selected. /// [actionType] A string representing the action type to map to SDK behavior. - static Future addUserConsents( - String key, - String description, - bool mandatory, - bool checked, [ + static Future addUserConsents({ + required String key, + required String description, + required bool mandatory, + required bool checked, UserConsentActionType? actionType, - ]) async { + }) async { return _host.addUserConsents( key, description, From 6f579c9c093e92d6d500a46812bdaa9424e49e1f Mon Sep 17 00:00:00 2001 From: AyaMahmoud148 Date: Tue, 29 Apr 2025 12:11:45 +0300 Subject: [PATCH 5/5] fix: ios tests --- example/ios/InstabugTests/BugReportingApiTests.m | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/example/ios/InstabugTests/BugReportingApiTests.m b/example/ios/InstabugTests/BugReportingApiTests.m index 900b73e82..a9d5fd314 100644 --- a/example/ios/InstabugTests/BugReportingApiTests.m +++ b/example/ios/InstabugTests/BugReportingApiTests.m @@ -190,11 +190,10 @@ - (void)testAddUserConsentWithKey { actionType:actionType error: &error ]; - OCMVerify([self.mBugReporting addUserConsentWithKey:key description:description - mandatory:mandatory - checked:checked + mandatory:[mandatory boolValue] + checked:[checked boolValue] actionType:mappedActionType]); } @end