Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(release): pulling release/1.21.0 into master #362

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [1.21.0](https://github.com/rudderlabs/rudder-sdk-android/compare/v1.20.2...v1.21.0) (2023-11-14)


### Features

* added support for JSONObject and JSONArray as part of RudderMessage object ([#350](https://github.com/rudderlabs/rudder-sdk-android/issues/350)) ([c9bb58f](https://github.com/rudderlabs/rudder-sdk-android/commit/c9bb58f7e2e2b76f9aaed817e36d5f46c3b86bab))


### Bug Fixes

* update lastActiveTimestamp value when reset call is made ([#360](https://github.com/rudderlabs/rudder-sdk-android/issues/360)) ([7596d71](https://github.com/rudderlabs/rudder-sdk-android/commit/7596d718fa63dda0e1d5cb683749acfc6691b295))

### [1.20.2](https://github.com/rudderlabs/rudder-sdk-android/compare/v1.20.1...v1.20.2) (2023-11-01)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@
import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.ProcessLifecycleOwner;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.rudderstack.android.sdk.core.consent.ConsentFilterHandler;
import com.rudderstack.android.sdk.core.consent.RudderConsentFilter;
import com.rudderstack.android.sdk.core.util.RudderContextSerializer;
import com.rudderstack.android.sdk.core.util.RudderTraitsSerializer;
import com.rudderstack.android.sdk.core.gson.RudderGson;
import com.rudderstack.android.sdk.core.util.Utils;

import java.io.UnsupportedEncodingException;
Expand Down Expand Up @@ -63,11 +60,6 @@ class EventRepository {

private @Nullable
ConsentFilterHandler consentFilterHandler = null;

private final Gson gson = new GsonBuilder()
.registerTypeAdapter(RudderTraits.class, new RudderTraitsSerializer())
.registerTypeAdapter(RudderContext.class, new RudderContextSerializer())
.create();
private String dataPlaneUrl;
private final String writeKey;

Expand Down Expand Up @@ -347,7 +339,7 @@ void processMessage(@NonNull RudderMessage message) {
RudderMessage updatedMessage = updateMessageWithConsentedDestinations(message);
userSessionManager.applySessionTracking(updatedMessage);

String eventJson = gson.toJson(updatedMessage);
String eventJson = getEventJsonString(updatedMessage);
RudderLogger.logVerbose(String.format(Locale.US, "EventRepository: dump: message: %s", eventJson));
if (isMessageJsonExceedingMaxSize(eventJson)) {
incrementDiscardedCounter(1, Collections.singletonMap(LABEL_TYPE, ReportManager.LABEL_TYPE_MSG_SIZE_INVALID));
Expand All @@ -357,6 +349,10 @@ void processMessage(@NonNull RudderMessage message) {
dbManager.saveEvent(eventJson, new EventInsertionCallback(message, deviceModeManager));
}

String getEventJsonString(RudderMessage updatedMessage) {
return RudderGson.getInstance().toJson(updatedMessage);
}

private boolean isMessageJsonExceedingMaxSize(String eventJson) {
return Utils.getUTF8Length(eventJson) > Utils.MAX_EVENT_SIZE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import androidx.annotation.Nullable;

import com.rudderstack.android.sdk.core.util.Utils;
import com.rudderstack.gsonrudderadapter.GsonAdapter;

import java.util.Collections;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.SerializedName;
import com.rudderstack.android.sdk.core.util.RudderTraitsSerializer;
import com.rudderstack.android.sdk.core.gson.RudderGson;
import com.rudderstack.android.sdk.core.util.Utils;

import java.util.ArrayList;
Expand Down Expand Up @@ -89,7 +86,7 @@ public class RudderContext {
RudderLogger.logDebug(String.format(Locale.US, "Traits from persistence storage%s", traitsJson));
if (traitsJson == null) {
RudderTraits traits = new RudderTraits(anonymousId);
this.traits = Utils.convertToMap(new Gson().toJson(traits));
this.traits = Utils.convertToMap(RudderGson.getInstance().toJson(traits));
this.persistTraits();
RudderLogger.logDebug("New traits has been saved");
} else {
Expand Down Expand Up @@ -121,8 +118,7 @@ public class RudderContext {
void resetTraits() {
RudderTraits traits = new RudderTraits();
// convert the whole traits to map and take care of the extras
Gson gson = new GsonBuilder().registerTypeAdapter(RudderTraits.class, new RudderTraitsSerializer()).create();
this.traits = Utils.convertToMap(gson.toJson(traits));
this.traits = Utils.convertToMap(RudderGson.getInstance().toJson(traits));
}

void updateTraits(RudderTraits traits) {
Expand All @@ -132,8 +128,7 @@ void updateTraits(RudderTraits traits) {
}

// convert the whole traits to map and take care of the extras
Gson gson = new GsonBuilder().registerTypeAdapter(RudderTraits.class, new RudderTraitsSerializer()).create();
Map<String, Object> traitsMap = Utils.convertToMap(gson.toJson(traits));
Map<String, Object> traitsMap = Utils.convertToMap(RudderGson.getInstance().toJson(traits));

String existingId = (String) this.traits.get("id");
String newId = (String) traitsMap.get("id");
Expand All @@ -159,7 +154,7 @@ void persistTraits() {
try {
if (RudderClient.getApplication() != null) {
RudderPreferenceManager preferenceManger = RudderPreferenceManager.getInstance(RudderClient.getApplication());
preferenceManger.saveTraits(new Gson().toJson(this.traits));
preferenceManger.saveTraits(RudderGson.getInstance().toJson(this.traits));
}
} catch (NullPointerException ex) {
ReportManager.reportError(ex);
Expand Down Expand Up @@ -340,7 +335,7 @@ void persistExternalIds() {
try {
if (RudderClient.getApplication() != null) {
RudderPreferenceManager preferenceManger = RudderPreferenceManager.getInstance(RudderClient.getApplication());
preferenceManger.saveExternalIds(new Gson().toJson(this.externalIds));
preferenceManger.saveExternalIds(RudderGson.getInstance().toJson(this.externalIds));
}
} catch (NullPointerException ex) {
ReportManager.reportError(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
import static com.rudderstack.android.sdk.core.TransformationResponse.TransformedDestination;
import static com.rudderstack.android.sdk.core.TransformationRequest.TransformationRequestEvent;
import static com.rudderstack.android.sdk.core.util.Utils.MAX_FLUSH_QUEUE_SIZE;
import static com.rudderstack.android.sdk.core.util.Utils.getBooleanFromMap;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.rudderstack.android.sdk.core.consent.ConsentFilterHandler;
import com.rudderstack.android.sdk.core.util.RudderContextSerializer;
import com.rudderstack.android.sdk.core.util.RudderTraitsSerializer;
import com.rudderstack.android.sdk.core.gson.RudderGson;
import com.rudderstack.android.sdk.core.util.Utils;

import java.util.ArrayList;
Expand Down Expand Up @@ -54,11 +50,6 @@ public class RudderDeviceModeManager {
RudderDeviceModeTransformationManager deviceModeTransformationManager;
private boolean areDeviceModeFactoriesAbsent = false;

static final Gson gson = new GsonBuilder()
.registerTypeAdapter(RudderTraits.class, new RudderTraitsSerializer())
.registerTypeAdapter(RudderContext.class, new RudderContextSerializer())
.create();

RudderDeviceModeManager(DBPersistentManager dbPersistentManager, RudderNetworkManager networkManager, RudderConfig rudderConfig, RudderDataResidencyManager dataResidencyManager) {
this.dbPersistentManager = dbPersistentManager;
this.networkManager = networkManager;
Expand Down Expand Up @@ -251,7 +242,7 @@ private void replayMessageQueue() {
RudderLogger.logDebug(String.format(Locale.US, "RudderDeviceModeManager: replayMessageQueue: replaying old messages with factories. Count: %d", messageIds.size()));
for (int i = 0; i < messageIds.size(); i++) {
try {
RudderMessage message = gson.fromJson(messages.get(i), RudderMessage.class);
RudderMessage message = RudderGson.getInstance().fromJson(messages.get(i), RudderMessage.class);
makeFactoryDump(message, messageIds.get(i), true);
} catch (Exception e) {
ReportManager.reportError(e);
Expand Down Expand Up @@ -311,7 +302,7 @@ void dumpEventToDestinations(RudderMessage message, List<String> destinations, S
if (integration != null) {
try {
RudderLogger.logDebug(String.format(Locale.US, "RudderDeviceModeManager: %s: dumping event %s for %s", logTag, message.getEventName(), destinationName));
RudderLogger.logVerbose(String.format(Locale.US, "RudderDeviceModeManager: Dumping: %s", gson.toJson(message)));
RudderLogger.logVerbose(String.format(Locale.US, "RudderDeviceModeManager: Dumping: %s", RudderGson.getInstance().toJson(message)));
addDeviceModeCounter(message.getType(), destinationName);
integration.dump(message);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
import static com.rudderstack.android.sdk.core.RudderNetworkManager.Result;
import static com.rudderstack.android.sdk.core.RudderNetworkManager.addEndPoint;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.rudderstack.android.sdk.core.gson.RudderGson;
import com.rudderstack.android.sdk.core.util.MessageUploadLock;
import com.rudderstack.android.sdk.core.util.RudderContextSerializer;
import com.rudderstack.android.sdk.core.util.RudderTraitsSerializer;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -40,10 +37,6 @@ public class RudderDeviceModeTransformationManager {
private static final String TRANSFORMATION_ENDPOINT = "transform";
private static final int MAX_RETRIES = 2; // Maximum number of retries
private static final int MAX_DELAY = 1000; // Maximum delay in milliseconds
private static final Gson gson = new GsonBuilder()
.registerTypeAdapter(RudderTraits.class, new RudderTraitsSerializer())
.registerTypeAdapter(RudderContext.class, new RudderContextSerializer())
.create();

RudderDeviceModeTransformationManager(DBPersistentManager dbManager, RudderNetworkManager rudderNetworkManager, RudderDeviceModeManager rudderDeviceModeManager, RudderConfig config, RudderDataResidencyManager dataResidencyManager) {
this.dbManager = dbManager;
Expand Down Expand Up @@ -76,7 +69,7 @@ public void run() {
}
createMessageIdTransformationRequestMap();
TransformationRequest transformationRequest = createTransformationRequestPayload();
String requestJson = gson.toJson(transformationRequest);
String requestJson = RudderGson.getInstance().toJson(transformationRequest);

RudderLogger.logDebug(String.format(Locale.US, "DeviceModeTransformationManager: TransformationProcessor: Payload: %s", requestJson));
RudderLogger.logInfo(String.format(Locale.US, "DeviceModeTransformationManager: TransformationProcessor: EventCount: %d", messageIds.size()));
Expand All @@ -100,7 +93,7 @@ public void run() {
private void createMessageIdTransformationRequestMap() {
for (int i = 0; i < messageIds.size(); i++) {

RudderMessage message = gson.fromJson(messages.get(i), RudderMessage.class);
RudderMessage message = RudderGson.getInstance().fromJson(messages.get(i), RudderMessage.class);
reportMessageSubmittedMetric(message);
messageIdTransformationRequestMap.put(messageIds.get(i), message);
}
Expand Down Expand Up @@ -192,7 +185,7 @@ private void handleResourceNotFound(TransformationRequest transformationRequest)
private void handleSuccess(Result result) {
deviceModeSleepCount = 0;
try {
TransformationResponse transformationResponse = gson.fromJson(result.response, TransformationResponse.class);
TransformationResponse transformationResponse = RudderGson.getInstance().fromJson(result.response, TransformationResponse.class);
incrementDmtSuccessMetric(transformationResponse);
rudderDeviceModeManager.dumpTransformedEvents(transformationResponse);
completeDeviceModeEventProcessing();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.google.gson.annotations.SerializedName;
import com.rudderstack.android.sdk.core.util.Utils;
Expand Down Expand Up @@ -262,4 +263,9 @@ public Map<String, Object> getIntegrations() {
void setSession(RudderUserSession userSession) {
this.context.setSession(userSession);
}

@VisibleForTesting
String getMessageId () {
return this.messageId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import androidx.annotation.Nullable;

import com.google.gson.Gson;
import com.rudderstack.android.sdk.core.gson.RudderGson;
import com.rudderstack.android.sdk.core.util.Utils;

import java.util.Locale;
Expand All @@ -27,7 +27,7 @@ class RudderPreferenceManager {
private static final String RUDDER_OPT_OUT_TIME_KEY = "rl_opt_out_time";
private static final String RUDDER_ANONYMOUS_ID_KEY = "rl_anonymous_id_key";
private static final String RUDDER_PERIODIC_WORK_REQUEST_ID_KEY = "rl_periodic_work_request_key";
private static final String RUDDER_LAST_EVENT_TIMESTAMP_KEY = "rl_last_event_timestamp_key";
private static final String RUDDER_LAST_ACTIVE_TIMESTAMP_KEY = "rl_last_event_timestamp_key";
private static final String RUDDER_SESSION_ID_KEY = "rl_session_id_key";
private static final String RUDDER_AUTO_SESSION_TRACKING_STATUS_KEY = "rl_auto_session_tracking_status_key";
private static final String RUDDER_DMT_HEADER_KEY = "rl_dmt_header_key";
Expand Down Expand Up @@ -119,7 +119,7 @@ void clearCurrentAnonymousIdValue() {
if (traits != null) {
Map<String, Object> traitsMap = Utils.convertToMap(traits);
traitsMap.remove("anonymousId");
saveTraits(new Gson().toJson(traitsMap));
saveTraits(RudderGson.getInstance().toJson(traitsMap));
}
}

Expand Down Expand Up @@ -157,18 +157,18 @@ long getOptOutTime() {
return preferences.getLong(RUDDER_OPT_OUT_TIME_KEY, -1);
}

void saveLastEventTimeStamp(Long time) {
preferences.edit().putLong(RUDDER_LAST_EVENT_TIMESTAMP_KEY, time).apply();
void saveLastActiveTimestamp(Long time) {
preferences.edit().putLong(RUDDER_LAST_ACTIVE_TIMESTAMP_KEY, time).apply();
}

@Nullable
Long getLastEventTimeStamp() {
long time = preferences.getLong(RUDDER_LAST_EVENT_TIMESTAMP_KEY, -1);
Long getLastActiveTimestamp() {
long time = preferences.getLong(RUDDER_LAST_ACTIVE_TIMESTAMP_KEY, -1);
return (time == -1) ? null : new Long(time);
}

void clearLastEventTimeStamp() {
preferences.edit().remove(RUDDER_LAST_EVENT_TIMESTAMP_KEY).apply();
void clearLastActiveTimestamp() {
preferences.edit().remove(RUDDER_LAST_ACTIVE_TIMESTAMP_KEY).apply();
}

void saveSessionId(Long sessionId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import android.app.Application;
import android.content.Context;

import com.google.gson.Gson;
import com.rudderstack.android.sdk.core.gson.RudderGson;
import com.rudderstack.android.sdk.core.util.Utils;

import java.io.FileInputStream;
Expand Down Expand Up @@ -75,7 +75,7 @@ private void downloadConfig() {
Result result = networkManager.sendNetworkRequest(null, requestUrl, RequestMethod.GET, false);
if (result.status == NetworkResponses.SUCCESS) {
try {
RudderServerConfig rudderServerConfig = new Gson().fromJson(result.response, RudderServerConfig.class);
RudderServerConfig rudderServerConfig = RudderGson.getInstance().fromJson(result.response, RudderServerConfig.class);
RudderLogger.logDebug(String.format(Locale.US, "RudderServerConfigManager: downloadConfig: configJson: %s", result.response));
// save config for future use
preferenceManger.updateLastUpdatedTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import android.app.Application;

import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import com.rudderstack.android.sdk.core.gson.RudderGson;
import com.rudderstack.android.sdk.core.util.Utils;

import java.util.Date;
Expand Down Expand Up @@ -84,7 +84,7 @@ public static String getAnonymousId(Map<String, Object> traitsMap) {
*/
public static String getAddress(Map<String, Object> traitsMap) {
if (traitsMap != null & traitsMap.containsKey(ADDRESS_KEY))
return new Gson().toJson(traitsMap.get(ADDRESS_KEY));
return RudderGson.getInstance().toJson(traitsMap.get(ADDRESS_KEY));
return null;
}

Expand Down Expand Up @@ -672,7 +672,7 @@ public Address putStreet(String street) {
* @return address Address
*/
public static Address fromString(String address) {
return new Gson().fromJson(address, Address.class);
return RudderGson.getInstance().fromJson(address, Address.class);
}
}

Expand Down
Loading
Loading