33import android .content .Context ;
44import android .content .pm .ApplicationInfo ;
55import android .os .Bundle ;
6+ import io .sentry .DataCollection ;
7+ import io .sentry .HttpBodyType ;
68import io .sentry .ILogger ;
79import io .sentry .InitPriority ;
10+ import io .sentry .KeyValueCollectionBehavior ;
811import io .sentry .ProfileLifecycle ;
912import io .sentry .ScreenshotStrategyType ;
1013import io .sentry .SentryFeedbackOptions ;
1619import java .util .ArrayList ;
1720import java .util .Arrays ;
1821import java .util .Collections ;
22+ import java .util .EnumSet ;
1923import java .util .List ;
2024import java .util .Locale ;
2125import java .util .Map ;
26+ import java .util .Set ;
2227import org .jetbrains .annotations .ApiStatus ;
2328import org .jetbrains .annotations .NotNull ;
2429import org .jetbrains .annotations .Nullable ;
@@ -106,6 +111,22 @@ final class ManifestMetadataReader {
106111
107112 static final String SEND_DEFAULT_PII = "io.sentry.send-default-pii" ;
108113
114+ static final String DATA_COLLECTION_USER_INFO = "io.sentry.data-collection.user-info" ;
115+ static final String DATA_COLLECTION_HTTP_BODIES = "io.sentry.data-collection.http-bodies" ;
116+ static final String DATA_COLLECTION_COOKIES = "io.sentry.data-collection.cookies" ;
117+ static final String DATA_COLLECTION_HTTP_REQUEST_HEADERS =
118+ "io.sentry.data-collection.http-headers.request" ;
119+ static final String DATA_COLLECTION_HTTP_RESPONSE_HEADERS =
120+ "io.sentry.data-collection.http-headers.response" ;
121+ static final String DATA_COLLECTION_URL_QUERY_PARAMS =
122+ "io.sentry.data-collection.url-query-params" ;
123+ static final String DATA_COLLECTION_GRAPHQL_DOCUMENT =
124+ "io.sentry.data-collection.graphql.document" ;
125+ static final String DATA_COLLECTION_GRAPHQL_VARIABLES =
126+ "io.sentry.data-collection.graphql.variables" ;
127+ static final String DATA_COLLECTION_DATABASE_QUERY_DATA =
128+ "io.sentry.data-collection.database-query-data" ;
129+
109130 static final String PERFORM_FRAMES_TRACKING = "io.sentry.traces.frames-tracking" ;
110131
111132 static final String SENTRY_GRADLE_PLUGIN_INTEGRATIONS = "io.sentry.gradle-plugin-integrations" ;
@@ -779,6 +800,12 @@ static void applyMetadata(
779800 options .setEnableAnrFingerprinting (
780801 readBool (
781802 metadata , logger , ENABLE_ANR_FINGERPRINTING , options .isEnableAnrFingerprinting ()));
803+
804+ final @ Nullable DataCollection dataCollection =
805+ readDataCollection (metadata , logger , options .getDataCollection ());
806+ if (dataCollection != null ) {
807+ mergeDataCollection (options .getDataCollection (), dataCollection );
808+ }
782809 }
783810 options
784811 .getLogger ()
@@ -791,6 +818,152 @@ static void applyMetadata(
791818 }
792819 }
793820
821+ private static @ Nullable DataCollection readDataCollection (
822+ final @ NotNull Object metadata ,
823+ final @ NotNull ILogger logger ,
824+ final @ NotNull DataCollection currentDataCollection ) {
825+ final @ NotNull DataCollection dataCollection = new DataCollection (false );
826+
827+ if (containsKey (metadata , DATA_COLLECTION_USER_INFO )) {
828+ dataCollection .setUserInfo (readBool (metadata , logger , DATA_COLLECTION_USER_INFO , false ));
829+ }
830+
831+ if (containsKey (metadata , DATA_COLLECTION_HTTP_BODIES )) {
832+ dataCollection .setHttpBodies (readHttpBodyTypes (metadata , logger ));
833+ }
834+
835+ final @ Nullable KeyValueCollectionBehavior cookies =
836+ readKeyValueCollectionBehavior (
837+ metadata , logger , DATA_COLLECTION_COOKIES , currentDataCollection .getCookies ());
838+ if (cookies != null ) {
839+ dataCollection .setCookies (cookies );
840+ }
841+
842+ final @ Nullable KeyValueCollectionBehavior requestHeaders =
843+ readKeyValueCollectionBehavior (
844+ metadata ,
845+ logger ,
846+ DATA_COLLECTION_HTTP_REQUEST_HEADERS ,
847+ currentDataCollection .getHttpHeaders ().getRequest ());
848+ if (requestHeaders != null ) {
849+ dataCollection .getHttpHeaders ().setRequest (requestHeaders );
850+ }
851+
852+ final @ Nullable KeyValueCollectionBehavior responseHeaders =
853+ readKeyValueCollectionBehavior (
854+ metadata ,
855+ logger ,
856+ DATA_COLLECTION_HTTP_RESPONSE_HEADERS ,
857+ currentDataCollection .getHttpHeaders ().getResponse ());
858+ if (responseHeaders != null ) {
859+ dataCollection .getHttpHeaders ().setResponse (responseHeaders );
860+ }
861+
862+ final @ Nullable KeyValueCollectionBehavior urlQueryParams =
863+ readKeyValueCollectionBehavior (
864+ metadata ,
865+ logger ,
866+ DATA_COLLECTION_URL_QUERY_PARAMS ,
867+ currentDataCollection .getUrlQueryParams ());
868+ if (urlQueryParams != null ) {
869+ dataCollection .setUrlQueryParams (urlQueryParams );
870+ }
871+
872+ if (containsKey (metadata , DATA_COLLECTION_GRAPHQL_DOCUMENT )) {
873+ dataCollection
874+ .getGraphql ()
875+ .setDocument (readBool (metadata , logger , DATA_COLLECTION_GRAPHQL_DOCUMENT , false ));
876+ }
877+
878+ if (containsKey (metadata , DATA_COLLECTION_GRAPHQL_VARIABLES )) {
879+ dataCollection
880+ .getGraphql ()
881+ .setVariables (readBool (metadata , logger , DATA_COLLECTION_GRAPHQL_VARIABLES , false ));
882+ }
883+
884+ if (containsKey (metadata , DATA_COLLECTION_DATABASE_QUERY_DATA )) {
885+ dataCollection .setDatabaseQueryData (
886+ readBool (metadata , logger , DATA_COLLECTION_DATABASE_QUERY_DATA , false ));
887+ }
888+
889+ return dataCollection .isExplicitlyConfigured () ? dataCollection : null ;
890+ }
891+
892+ private static void mergeDataCollection (
893+ final @ NotNull DataCollection target , final @ NotNull DataCollection source ) {
894+ if (source .getUserInfo () != null ) {
895+ target .setUserInfo (source .getUserInfo ());
896+ }
897+ if (source .getHttpBodies () != null ) {
898+ target .setHttpBodies (source .getHttpBodies ());
899+ }
900+ if (source .getCookies () != null ) {
901+ target .setCookies (source .getCookies ());
902+ }
903+ if (source .getHttpHeaders ().getRequest () != null ) {
904+ target .getHttpHeaders ().setRequest (source .getHttpHeaders ().getRequest ());
905+ }
906+ if (source .getHttpHeaders ().getResponse () != null ) {
907+ target .getHttpHeaders ().setResponse (source .getHttpHeaders ().getResponse ());
908+ }
909+ if (source .getUrlQueryParams () != null ) {
910+ target .setUrlQueryParams (source .getUrlQueryParams ());
911+ }
912+ if (source .getGraphql ().getDocument () != null ) {
913+ target .getGraphql ().setDocument (source .getGraphql ().getDocument ());
914+ }
915+ if (source .getGraphql ().getVariables () != null ) {
916+ target .getGraphql ().setVariables (source .getGraphql ().getVariables ());
917+ }
918+ if (source .getDatabaseQueryData () != null ) {
919+ target .setDatabaseQueryData (source .getDatabaseQueryData ());
920+ }
921+ }
922+
923+ private static @ NotNull Set <HttpBodyType > readHttpBodyTypes (
924+ final @ NotNull Object metadata , final @ NotNull ILogger logger ) {
925+ final @ Nullable List <String > bodyTypes =
926+ readList (metadata , logger , DATA_COLLECTION_HTTP_BODIES );
927+ if (bodyTypes == null || (bodyTypes .size () == 1 && bodyTypes .get (0 ).isEmpty ())) {
928+ return Collections .emptySet ();
929+ }
930+
931+ final @ NotNull Set <HttpBodyType > result = EnumSet .noneOf (HttpBodyType .class );
932+ for (final String bodyType : bodyTypes ) {
933+ result .add (HttpBodyType .valueOf (bodyType .toUpperCase (Locale .ROOT )));
934+ }
935+ return result ;
936+ }
937+
938+ private static @ Nullable KeyValueCollectionBehavior readKeyValueCollectionBehavior (
939+ final @ NotNull Object metadata ,
940+ final @ NotNull ILogger logger ,
941+ final @ NotNull String key ,
942+ final @ Nullable KeyValueCollectionBehavior currentBehavior ) {
943+ final @ NotNull String modeKey = key + ".mode" ;
944+ final @ NotNull String termsKey = key + ".terms" ;
945+ if (!containsKey (metadata , modeKey ) && !containsKey (metadata , termsKey )) {
946+ return null ;
947+ }
948+
949+ final @ NotNull KeyValueCollectionBehavior behavior = new KeyValueCollectionBehavior ();
950+ if (currentBehavior != null ) {
951+ behavior .setMode (currentBehavior .getMode ());
952+ behavior .setTerms (currentBehavior .getTerms ());
953+ }
954+ if (containsKey (metadata , modeKey )) {
955+ final @ Nullable String mode = readString (metadata , logger , modeKey , null );
956+ if (mode != null ) {
957+ behavior .setMode (KeyValueCollectionBehavior .Mode .valueOf (mode .toUpperCase (Locale .ROOT )));
958+ }
959+ }
960+ if (containsKey (metadata , termsKey )) {
961+ final @ Nullable List <String > terms = readList (metadata , logger , termsKey );
962+ behavior .setTerms (terms == null ? Collections .<String >emptyList () : terms );
963+ }
964+ return behavior ;
965+ }
966+
794967 private static boolean readBool (
795968 final @ NotNull Object metadata ,
796969 final @ NotNull ILogger logger ,
0 commit comments