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 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..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); @@ -194,4 +194,19 @@ public void testSetCommentMinimumCharacterCount() { mBugReporting.verify(() -> BugReporting.setCommentMinimumCharacterCount(limit.intValue(), BugReporting.ReportType.BUG, BugReporting.ReportType.QUESTION)); } + + @Test + public void TestAddUserConsents() { + + final String key = "testKey"; + final String description = "Consent description"; + final boolean mandatory = true; + final boolean checked = true; + final String actionType = "UserConsentActionType.dropAutoCapturedMedia"; + + + api.addUserConsents(key, description, mandatory, checked, actionType); + + mBugReporting.verify(()->BugReporting.addUserConsent(key, description, mandatory, checked,"drop_auto_captured_media")); + } } diff --git a/example/ios/InstabugTests/BugReportingApiTests.m b/example/ios/InstabugTests/BugReportingApiTests.m index 16f5fbee0..a9d5fd314 100644 --- a/example/ios/InstabugTests/BugReportingApiTests.m +++ b/example/ios/InstabugTests/BugReportingApiTests.m @@ -174,5 +174,26 @@ - (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 boolValue] + checked:[checked boolValue] + actionType:mappedActionType]); +} @end diff --git a/ios/Classes/Modules/BugReportingApi.m b/ios/Classes/Modules/BugReportingApi.m index 3c914b789..5268a5061 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 boolValue] + checked:[checked boolValue] + 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..b19147d3d 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({ + required String key, + required String description, + required bool mandatory, + required 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, + ); }