From eaa282c4c0f95dc02e02ce2ca0b16bfed5ee5e41 Mon Sep 17 00:00:00 2001 From: Debanjan Chatterjee Date: Mon, 20 May 2024 10:24:18 +0530 Subject: [PATCH 1/4] fix: key "batch" was being obfuscated due to proguard (#423) fix: "batch" was being obfuscated due to proguard. Mentioned the serialized name as annotation. As a safeguard also added the file to proguard rules --- core/proguard-consumer-rules.pro | 1 + .../sdk/core/TransformationRequest.java | 3 ++- sample-kotlin/gradle.properties | 1 + sample-kotlin/proguard-rules.pro | 21 ------------------- 4 files changed, 4 insertions(+), 22 deletions(-) create mode 100644 sample-kotlin/gradle.properties diff --git a/core/proguard-consumer-rules.pro b/core/proguard-consumer-rules.pro index ddc88ea27..76c16b197 100644 --- a/core/proguard-consumer-rules.pro +++ b/core/proguard-consumer-rules.pro @@ -39,6 +39,7 @@ -keep class com.rudderstack.android.sdk.core.persistence.DefaultPersistenceProviderFactory { *; } # Required for Device Mode Transformations +-keep class com.rudderstack.android.sdk.core.TransformationRequest { *; } -keep class com.rudderstack.android.sdk.core.TransformationResponse { *; } -keep class com.rudderstack.android.sdk.core.TransformationResponseDeserializer { *; } diff --git a/core/src/main/java/com/rudderstack/android/sdk/core/TransformationRequest.java b/core/src/main/java/com/rudderstack/android/sdk/core/TransformationRequest.java index 28208835d..7426aa442 100644 --- a/core/src/main/java/com/rudderstack/android/sdk/core/TransformationRequest.java +++ b/core/src/main/java/com/rudderstack/android/sdk/core/TransformationRequest.java @@ -5,9 +5,10 @@ import java.util.List; public class TransformationRequest { + @SerializedName(value="batch") final List batch; - public TransformationRequest(List batch) { + TransformationRequest(List batch) { this.batch = batch; } diff --git a/sample-kotlin/gradle.properties b/sample-kotlin/gradle.properties new file mode 100644 index 000000000..71f9fe936 --- /dev/null +++ b/sample-kotlin/gradle.properties @@ -0,0 +1 @@ +android.enableR8.fullMode=true \ No newline at end of file diff --git a/sample-kotlin/proguard-rules.pro b/sample-kotlin/proguard-rules.pro index 141fda239..7b28c455f 100644 --- a/sample-kotlin/proguard-rules.pro +++ b/sample-kotlin/proguard-rules.pro @@ -22,9 +22,6 @@ # These rules should be kept as part of the reporter module, as the fields of Entities are getting removed # this deals with `There should be at least one field in @Entity` --keep class com.rudderstack.android.ruddermetricsreporterandroid.models.LabelEntity { *; } --keep class com.rudderstack.android.ruddermetricsreporterandroid.models.MetricEntity { *; } --keep class com.rudderstack.android.ruddermetricsreporterandroid.models.ErrorEntity { *; } # Required for the usage off TypeToken class in Utils.converToMap, Utils.convertToList -keep class com.google.gson.reflect.TypeToken { *; } @@ -34,31 +31,13 @@ -keep class com.google.gson.internal.LinkedTreeMap { *; } -keep class * implements java.io.Serializable { *; } --keep class com.rudderstack.rudderjsonadapter.RudderTypeAdapter { *; } --keep class * extends com.rudderstack.rudderjsonadapter.RudderTypeAdapter - -# Required to ensure the DefaultPersistenceProviderFactory is not removed by Proguard and works as expected -# even when the customer is not using encryption feature. --dontwarn net.sqlcipher.Cursor --dontwarn net.sqlcipher.database.SQLiteDatabase$CursorFactory --dontwarn net.sqlcipher.database.SQLiteDatabase --dontwarn net.sqlcipher.database.SQLiteOpenHelper --keep class com.rudderstack.android.sdk.core.persistence.DefaultPersistenceProviderFactory { *; } - # Required for the usage of annotations across reporter and web modules -dontwarn com.fasterxml.jackson.annotation.JsonIgnore -dontwarn com.squareup.moshi.Json -dontwarn com.fasterxml.jackson.annotation.JsonProperty -# because of an issue with the dependencies used by the instruementation tests as mentioned here -# androidTestImplementation 'androidx.test.ext:junit:1.1.5' -# androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' # the errors didn't go even after adding the below rule, hence needed to remove the instrumentation tests for the time being. -dontwarn com.google.errorprone.annotations # Required for Amplitude Device Mode -keep class com.rudderstack.android.integrations.amplitude.AmplitudeDestinationConfig { *; } - -# Required for DMT --keep class com.rudderstack.android.sdk.core.TransformationResponse { *; } --keep class com.rudderstack.android.sdk.core.TransformationResponseDeserializer { *; } \ No newline at end of file From a739a789fddcd5afec0a8fc9fceaa1fd1d1bd8ab Mon Sep 17 00:00:00 2001 From: Debanjan Chatterjee Date: Mon, 20 May 2024 12:06:18 +0530 Subject: [PATCH 2/4] feat: migrate from sqlcipher legacy to latest version (#419) feat: migrate from sqlcipher legacy to latest version feat: update sqlite version --- core/build.gradle | 4 ++-- .../DefaultPersistenceProvider.java | 18 +++++++++--------- .../core/persistence/EncryptedPersistence.java | 14 +++++++------- sample-kotlin/build.gradle | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index 2400e3eee..cac6e77dc 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -54,8 +54,8 @@ dependencies { compileOnly 'androidx.lifecycle:lifecycle-common:2.6.1' //sql-cipher - compileOnly "net.zetetic:android-database-sqlcipher:4.5.4" - compileOnly "androidx.sqlite:sqlite:2.3.1" + compileOnly "net.zetetic:sqlcipher-android:4.5.6@aar" + compileOnly "androidx.sqlite:sqlite:2.4.0" //test testImplementation('com.android.support.test:rules:1.0.2') diff --git a/core/src/main/java/com/rudderstack/android/sdk/core/persistence/DefaultPersistenceProvider.java b/core/src/main/java/com/rudderstack/android/sdk/core/persistence/DefaultPersistenceProvider.java index 0760e9cc4..81ff048e3 100644 --- a/core/src/main/java/com/rudderstack/android/sdk/core/persistence/DefaultPersistenceProvider.java +++ b/core/src/main/java/com/rudderstack/android/sdk/core/persistence/DefaultPersistenceProvider.java @@ -1,6 +1,7 @@ package com.rudderstack.android.sdk.core.persistence; import android.app.Application; +import android.database.Cursor; import android.database.sqlite.SQLiteException; import androidx.annotation.NonNull; @@ -9,8 +10,8 @@ import com.rudderstack.android.sdk.core.ReportManager; import com.rudderstack.android.sdk.core.RudderLogger; -import net.sqlcipher.Cursor; -import net.sqlcipher.database.SQLiteDatabase; + +import net.zetetic.database.sqlcipher.SQLiteDatabase; import java.io.File; import java.util.Collections; @@ -21,7 +22,6 @@ public class DefaultPersistenceProvider implements PersistenceProvider { private final Application application; private final ProviderParams params; - DefaultPersistenceProvider(Application application, ProviderParams params) { this.application = application; this.params = params; @@ -88,7 +88,7 @@ private EncryptedPersistence createEncryptedObject(@Nullable Persistence.DbCreat private boolean checkIfEncryptionIsValid(File encryptedDbPath) { try (SQLiteDatabase database = SQLiteDatabase.openDatabase(encryptedDbPath.getAbsolutePath(), - params.encryptionKey, null, SQLiteDatabase.OPEN_READWRITE)) { + params.encryptionKey, null, SQLiteDatabase.OPEN_READWRITE, null)) { Cursor cursor = database.rawQuery("PRAGMA cipher_version", null); cursor.close(); return true; @@ -118,12 +118,12 @@ private DefaultPersistence getDefaultPersistence(@Nullable Persistence.DbCreateL private void createDefaultDatabase() { File databasePath = application.getDatabasePath(params.dbName); - SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(databasePath.getAbsolutePath(), "", null); + SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(databasePath.getAbsolutePath(), "",null, null); database.close(); } private void initCipheredDatabase() { - SQLiteDatabase.loadLibs(application); + System.loadLibrary("sqlcipher"); } private void deleteEncryptedDb() { @@ -140,7 +140,7 @@ private void migrateToDefaultDatabase(File databasePath) { File encryptedDb = application.getDatabasePath(params.encryptedDbName); String encryptedPath = encryptedDb.getAbsolutePath(); - SQLiteDatabase database = SQLiteDatabase.openDatabase(encryptedPath, params.encryptionKey, null, SQLiteDatabase.OPEN_READWRITE); + SQLiteDatabase database = SQLiteDatabase.openDatabase(encryptedPath, params.encryptionKey, null, SQLiteDatabase.OPEN_READWRITE, null); //will throw exception if encryption key is invalid database.isDatabaseIntegrityOk(); database.rawExecSQL(String.format("ATTACH DATABASE '%s' AS rl_persistence KEY ''", @@ -163,11 +163,11 @@ private void migrateToEncryptedDatabase(File encryptedDbPath) { ReportManager.LABEL_TYPE, ReportManager.LABEL_TYPE_MIGRATE_TO_ENCRYPT )); - SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(encryptedDbPath.getAbsolutePath(), params.encryptionKey, null); + SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(encryptedDbPath.getAbsolutePath(), params.encryptionKey,null, null); database.close(); File decryptedDb = application.getDatabasePath(params.dbName); String decryptedPath = decryptedDb.getAbsolutePath(); - database = SQLiteDatabase.openDatabase(decryptedPath, "", null, SQLiteDatabase.OPEN_READWRITE); + database = SQLiteDatabase.openDatabase(decryptedPath, "", null, SQLiteDatabase.OPEN_READWRITE, null); database.rawExecSQL(String.format("ATTACH DATABASE '%s' AS rl_persistence_encrypted KEY '%s'", encryptedDbPath.getAbsolutePath(), params.encryptionKey)); database.rawExecSQL("select sqlcipher_export('rl_persistence_encrypted')"); diff --git a/core/src/main/java/com/rudderstack/android/sdk/core/persistence/EncryptedPersistence.java b/core/src/main/java/com/rudderstack/android/sdk/core/persistence/EncryptedPersistence.java index f8c560904..bc852ddc3 100644 --- a/core/src/main/java/com/rudderstack/android/sdk/core/persistence/EncryptedPersistence.java +++ b/core/src/main/java/com/rudderstack/android/sdk/core/persistence/EncryptedPersistence.java @@ -14,8 +14,8 @@ import com.rudderstack.android.sdk.core.RudderLogger; -import net.sqlcipher.database.SQLiteDatabase; -import net.sqlcipher.database.SQLiteOpenHelper; +import net.zetetic.database.sqlcipher.SQLiteDatabase; +import net.zetetic.database.sqlcipher.SQLiteOpenHelper; import java.io.File; import java.util.List; @@ -29,21 +29,21 @@ public class EncryptedPersistence extends SQLiteOpenHelper implements Persistence { private final List dbCloseListeners = new java.util.concurrent.CopyOnWriteArrayList<>(); private final DbCreateListener dbCreateListener; - private final String encryptPassword; private SQLiteDatabase initialDatabase = null; EncryptedPersistence(Application application, DbParams params, @Nullable DbCreateListener dbCreateListener) { - super(application, params.dbName, null, params.dbVersion); - this.encryptPassword = params.encryptPassword; + super(application, params.dbName, params.encryptPassword,null, params.dbVersion, + 0, null, null, false); this.dbCreateListener = dbCreateListener; } - private SQLiteDatabase getWritableDatabase() { + @NonNull + public SQLiteDatabase getWritableDatabase() { if (initialDatabase != null) { return initialDatabase; } - return getWritableDatabase(encryptPassword); + return super.getWritableDatabase(); } @Override diff --git a/sample-kotlin/build.gradle b/sample-kotlin/build.gradle index b85bdb0a7..980aa2c78 100644 --- a/sample-kotlin/build.gradle +++ b/sample-kotlin/build.gradle @@ -67,7 +67,7 @@ dependencies { implementation "androidx.work:work-runtime:2.7.1" //sql-cipher - implementation "net.zetetic:android-database-sqlcipher:4.5.4" + implementation "net.zetetic:sqlcipher-android:4.5.6@aar" implementation "androidx.sqlite:sqlite:2.3.1" // required for new life cycle methods From 3b58967202adfb37efb4cb2c9374885986c927de Mon Sep 17 00:00:00 2001 From: Abhishek Pandey <64667840+1abhishekpandey@users.noreply.github.com> Date: Mon, 20 May 2024 12:06:28 +0530 Subject: [PATCH 3/4] fix: check if the referrer is not null before casting it to a string (#425) This is to prevent NullPointerException --- .../java/com/rudderstack/android/sdk/core/util/Utils.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/com/rudderstack/android/sdk/core/util/Utils.java b/core/src/main/java/com/rudderstack/android/sdk/core/util/Utils.java index d11410933..633f59bbd 100644 --- a/core/src/main/java/com/rudderstack/android/sdk/core/util/Utils.java +++ b/core/src/main/java/com/rudderstack/android/sdk/core/util/Utils.java @@ -12,11 +12,9 @@ import android.os.Build; import android.text.TextUtils; -import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.rudderstack.android.sdk.core.ReportManager; import com.rudderstack.android.sdk.core.RudderLogger; -import com.rudderstack.android.sdk.core.RudderMessage; import com.rudderstack.android.sdk.core.gson.RudderGson; import java.io.File; @@ -26,7 +24,6 @@ import java.util.Date; import java.util.GregorianCalendar; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -200,7 +197,8 @@ public static boolean fileExists(Context context, String filename) { public static String getReferrer(Activity activity) { // If devices running on SDK versions greater than equal to 22 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { - return activity.getReferrer().toString(); + Uri referrer = activity.getReferrer(); + return referrer != null ? referrer.toString() : null; } // If devices running on SDK versions greater than equal to 19 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { From 725a0d5456d58356e3ae02cc36262854ba0a0a32 Mon Sep 17 00:00:00 2001 From: GitHub actions Date: Mon, 20 May 2024 06:43:00 +0000 Subject: [PATCH 4/4] chore(release): 1.23.0 --- CHANGELOG.md | 13 +++++++++++++ gradle.properties | 4 ++-- package.json | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 840728a44..8d782c2c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,19 @@ 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.23.0](https://github.com/rudderlabs/rudder-sdk-android/compare/v1.22.0...v1.23.0) (2024-05-20) + + +### Features + +* migrate from sqlcipher legacy to latest version ([#419](https://github.com/rudderlabs/rudder-sdk-android/issues/419)) ([a739a78](https://github.com/rudderlabs/rudder-sdk-android/commit/a739a789fddcd5afec0a8fc9fceaa1fd1d1bd8ab)) + + +### Bug Fixes + +* check if the referrer is not null before casting it to a string ([#425](https://github.com/rudderlabs/rudder-sdk-android/issues/425)) ([3b58967](https://github.com/rudderlabs/rudder-sdk-android/commit/3b58967202adfb37efb4cb2c9374885986c927de)) +* key "batch" was being obfuscated due to proguard ([#423](https://github.com/rudderlabs/rudder-sdk-android/issues/423)) ([eaa282c](https://github.com/rudderlabs/rudder-sdk-android/commit/eaa282c4c0f95dc02e02ce2ca0b16bfed5ee5e41)) + ## [1.22.0](https://github.com/rudderlabs/rudder-sdk-android/compare/v1.21.3...v1.22.0) (2024-03-19) diff --git a/gradle.properties b/gradle.properties index 47638c0d3..81f2699d7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,8 +5,8 @@ android.enableJetifier=true android.enableR8.fullMode=true kotlin.code.style=official GROUP=com.rudderstack.android.sdk -VERSION_CODE=26 -VERSION_NAME=1.22.0 +VERSION_CODE=27 +VERSION_NAME=1.23.0 POM_NAME=Rudderstack SDK for android POM_DESCRIPTION=Rudderstack SDK for android POM_ARTIFACT_ID=core diff --git a/package.json b/package.json index 46c5a6990..2ab4384dc 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.22.0", + "version": "1.23.0", "dependencies": { "properties-reader": "^2.2.0" }