From 4097ea40f9c39966bed2ecad501a78defd93e2c1 Mon Sep 17 00:00:00 2001 From: Chryssa Date: Fri, 6 Oct 2023 20:22:00 +0300 Subject: [PATCH 1/3] fix: typo in sample-kotlin build.gradle --- sample-kotlin/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample-kotlin/build.gradle b/sample-kotlin/build.gradle index 7c8ce75ab..1ee3f8dfe 100644 --- a/sample-kotlin/build.gradle +++ b/sample-kotlin/build.gradle @@ -28,7 +28,7 @@ android { versionCode 4 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - buildConfigField("String", "DATA_PLANE_URL", properties.getProperty('dataplaneUrl', 'https://api.rudderstack.com')) + buildConfigField("String", "DATA_PLANE_URL", properties.getProperty('dataplaneUrl', "\"https://api.rudderstack.com\"")) buildConfigField("String", "CONTROL_PLANE_URL", properties.getProperty('controlplaneUrl', "\"https://api.rudderstack.com\"")) buildConfigField("String", "WRITE_KEY", properties.getProperty('writeKey', "\"\"")) } From d10fc244e105fe885628105dc8c22344a2d2e549 Mon Sep 17 00:00:00 2001 From: Debanjan Chatterjee Date: Mon, 16 Oct 2023 05:22:14 +0000 Subject: [PATCH 2/3] fix: work manager not getting initialised if (#330) fix: work manager not getting initialised if app is pre-installed fix: fix a probable null pointer chore: add work manager metric chore: changed v2 dependencies to dynamic --- core/build.gradle | 6 +++--- .../sdk/core/ApplicationLifeCycleManager.java | 4 ---- .../android/sdk/core/EventRepository.java | 4 +++- .../android/sdk/core/FlushEventsWorker.java | 3 ++- .../android/sdk/core/ReportManager.java | 16 +++++++++++----- .../sdk/core/RudderDeviceModeManager.java | 9 +++++---- .../sdk/core/RudderFlushWorkManager.java | 17 +++++------------ .../sdk/core/RudderPreferenceManager.java | 8 -------- sample-kotlin/build.gradle | 2 ++ .../android/sample/kotlin/MainApplication.kt | 2 ++ 10 files changed, 33 insertions(+), 38 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index daef0319e..664fd77c3 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 33 + compileSdk 33 defaultConfig { minSdkVersion 19 targetSdkVersion 33 @@ -44,10 +44,10 @@ dependencies { implementation 'androidx.annotation:annotation:1.6.0' - implementation ('com.rudderstack.android.sdk:rudderreporter:0.3.0') + implementation ('com.rudderstack.android.sdk:rudderreporter:0.3.+') // implementation(project(path: ':rudderreporter')) // implementation(project(path: ':gsonrudderadapter')) - implementation 'com.rudderstack.kotlin.sdk:gsonrudderadapter:0.2.0' + implementation 'com.rudderstack.kotlin.sdk:gsonrudderadapter:0.2.+' // required for new life cycle methods compileOnly 'androidx.lifecycle:lifecycle-process:2.6.1' diff --git a/core/src/main/java/com/rudderstack/android/sdk/core/ApplicationLifeCycleManager.java b/core/src/main/java/com/rudderstack/android/sdk/core/ApplicationLifeCycleManager.java index a0615297b..c0dc9afbb 100644 --- a/core/src/main/java/com/rudderstack/android/sdk/core/ApplicationLifeCycleManager.java +++ b/core/src/main/java/com/rudderstack/android/sdk/core/ApplicationLifeCycleManager.java @@ -12,7 +12,6 @@ public class ApplicationLifeCycleManager { private final RudderConfig config; - private final RudderFlushWorkManager rudderFlushWorkManager; private final EventRepository repository; public static final String VERSION = "version"; private static final AtomicBoolean isFirstLaunch = new AtomicBoolean(true); @@ -20,11 +19,9 @@ public class ApplicationLifeCycleManager { private final AppVersion appVersion; public ApplicationLifeCycleManager(RudderConfig config, AppVersion appVersion, - RudderFlushWorkManager rudderFlushWorkManager, EventRepository repository, RudderPreferenceManager preferenceManager) { this.config = config; - this.rudderFlushWorkManager = rudderFlushWorkManager; this.repository = repository; this.preferenceManager = preferenceManager; this.appVersion = appVersion; @@ -43,7 +40,6 @@ void trackApplicationUpdateStatus() { if (this.appVersion.isApplicationInstalled()) { // application was not installed previously, now triggering Application Installed event sendApplicationInstalled(appVersion.currentBuild, appVersion.currentVersion); - rudderFlushWorkManager.registerPeriodicFlushWorker(); } else if (this.appVersion.isApplicationUpdated()) { sendApplicationUpdated(appVersion.previousBuild, appVersion.currentBuild, appVersion.previousVersion, appVersion.currentVersion); } diff --git a/core/src/main/java/com/rudderstack/android/sdk/core/EventRepository.java b/core/src/main/java/com/rudderstack/android/sdk/core/EventRepository.java index 760be3a5a..7f4cbcef4 100644 --- a/core/src/main/java/com/rudderstack/android/sdk/core/EventRepository.java +++ b/core/src/main/java/com/rudderstack/android/sdk/core/EventRepository.java @@ -144,9 +144,11 @@ public void handleMessage(Message msg) { // initiate ApplicationLifeCycleManager RudderLogger.logDebug("EventRepository: constructor: Initiating ApplicationLifeCycleManager"); AppVersion appVersion = new AppVersion(application); - this.applicationLifeCycleManager = new ApplicationLifeCycleManager(config, appVersion, rudderFlushWorkManager, this, preferenceManager); + this.applicationLifeCycleManager = new ApplicationLifeCycleManager(config, appVersion, this, preferenceManager); this.applicationLifeCycleManager.trackApplicationUpdateStatus(); + rudderFlushWorkManager.registerPeriodicFlushWorker(); + initializeLifecycleTracking(applicationLifeCycleManager); initiateRudderReporterFromPrefetchedConfig(); diff --git a/core/src/main/java/com/rudderstack/android/sdk/core/FlushEventsWorker.java b/core/src/main/java/com/rudderstack/android/sdk/core/FlushEventsWorker.java index 2953faabf..c1d9d9f16 100644 --- a/core/src/main/java/com/rudderstack/android/sdk/core/FlushEventsWorker.java +++ b/core/src/main/java/com/rudderstack/android/sdk/core/FlushEventsWorker.java @@ -17,10 +17,11 @@ public FlushEventsWorker( @NonNull WorkerParameters params) { super(context, params); persistenceProviderFactoryClassName = params.getInputData().getString(PERSISTENCE_PROVIDER_FACTORY_CLASS_NAME_KEY); + ReportManager.incrementWorkManagerInitCounter(1); } private void addWorkerMetrics() { - ReportManager.incrementWorkManagerInitializationCounter(1); + ReportManager.incrementWorkManagerCallCounter(1); } @Override diff --git a/core/src/main/java/com/rudderstack/android/sdk/core/ReportManager.java b/core/src/main/java/com/rudderstack/android/sdk/core/ReportManager.java index 53730cd4d..c3b6cc2d6 100644 --- a/core/src/main/java/com/rudderstack/android/sdk/core/ReportManager.java +++ b/core/src/main/java/com/rudderstack/android/sdk/core/ReportManager.java @@ -76,7 +76,8 @@ private ReportManager() { private static LongCounter sourceConfigDownloadAbortCounter = null; private static LongCounter dbEncryptionCounter = null; - private static LongCounter workManagerSuccessInitializationCounter = null; + private static LongCounter workManagerCallCounter = null; + private static LongCounter workManagerInitCounter = null; private static final String EVENTS_SUBMITTED_COUNTER_TAG = "submitted_events"; @@ -95,7 +96,8 @@ private ReportManager() { private static final String SOURCE_CONFIG_DOWNLOAD_RETRY_COUNTER_TAG = "sc_attempt_retry"; private static final String SOURCE_CONFIG_DOWNLOAD_ABORT_COUNTER_TAG = "sc_attempt_abort"; - private static final String FLUSH_WORKER_INIT_COUNTER_TAG = "flush_worker_call"; + private static final String FLUSH_WORKER_CALL_COUNTER_TAG = "flush_worker_call"; + private static final String FLUSH_WORKER_INIT_COUNTER_TAG = "flush_worker_init"; private static final String ENCRYPTED_DB_COUNTER_TAG = "db_encrypt"; private static final String METRICS_URL_DEV = "https://sdk-metrics.dev-rudder.rudderlabs.com/"; @@ -139,7 +141,8 @@ private static void createCounters(@NonNull Metrics metrics) { dmtEventRetryCounter = metrics.getLongCounter(DMT_RETRY_COUNTER_TAG); dmtEventAbortCounter = metrics.getLongCounter(DMT_DISCARD_COUNTER_TAG); - workManagerSuccessInitializationCounter = metrics.getLongCounter(FLUSH_WORKER_INIT_COUNTER_TAG); + workManagerCallCounter = metrics.getLongCounter(FLUSH_WORKER_CALL_COUNTER_TAG); + workManagerInitCounter = metrics.getLongCounter(FLUSH_WORKER_INIT_COUNTER_TAG); } private static void incrementCounter(LongCounter counter, int value, Map attributes) { @@ -320,8 +323,11 @@ public static void incrementDbEncryptionCounter(int value, Map a incrementCounter(dbEncryptionCounter, value, attributes); } - static void incrementWorkManagerInitializationCounter(int value) { - incrementCounter(workManagerSuccessInitializationCounter, value); + static void incrementWorkManagerCallCounter(int value) { + incrementCounter(workManagerCallCounter, value); + } + static void incrementWorkManagerInitCounter(int value) { + incrementCounter(workManagerInitCounter, value); } public static void reportError(Throwable throwable) { diff --git a/core/src/main/java/com/rudderstack/android/sdk/core/RudderDeviceModeManager.java b/core/src/main/java/com/rudderstack/android/sdk/core/RudderDeviceModeManager.java index e563bc71f..6e4229beb 100644 --- a/core/src/main/java/com/rudderstack/android/sdk/core/RudderDeviceModeManager.java +++ b/core/src/main/java/com/rudderstack/android/sdk/core/RudderDeviceModeManager.java @@ -110,14 +110,14 @@ private static void collectDissentedMetrics(List destin List destinationsCopy = new ArrayList<>(destinations); destinationsCopy.removeAll(consentedDestinations); for (RudderServerDestination destination : destinationsCopy) { - reportDiscardedDestinationWithType(destination, ReportManager.LABEL_TYPE_DESTINATION_DISSENTED); + reportDiscardedDestinationWithType(destination.getDestinationDefinition().displayName, ReportManager.LABEL_TYPE_DESTINATION_DISSENTED); } } - private static void reportDiscardedDestinationWithType(RudderServerDestination destination, String type) { + private static void reportDiscardedDestinationWithType(String destinationName, String type) { Map labelsMap = new HashMap<>(); labelsMap.put(ReportManager.LABEL_TYPE, type); - labelsMap.put(ReportManager.LABEL_INTEGRATION, destination.getDestinationDefinition().displayName); + labelsMap.put(ReportManager.LABEL_INTEGRATION, destinationName); ReportManager.incrementDeviceModeDiscardedCounter(1, labelsMap); } @@ -202,7 +202,8 @@ private void initiateFactories(List destinations) { integrationOperationsMap.put(key, nativeOp); handleCallBacks(key, nativeOp); } else { - reportDiscardedDestinationWithType(destination, ReportManager.LABEL_TYPE_DESTINATION_DISABLED); + reportDiscardedDestinationWithType(destination == null? key : destination.destinationDefinition.displayName + , ReportManager.LABEL_TYPE_DESTINATION_DISABLED); RudderLogger.logDebug(String.format(Locale.US, "EventRepository: initiateFactories: destination was null or not enabled for %s", key)); } } else { diff --git a/core/src/main/java/com/rudderstack/android/sdk/core/RudderFlushWorkManager.java b/core/src/main/java/com/rudderstack/android/sdk/core/RudderFlushWorkManager.java index b7f289ea7..b02990b71 100644 --- a/core/src/main/java/com/rudderstack/android/sdk/core/RudderFlushWorkManager.java +++ b/core/src/main/java/com/rudderstack/android/sdk/core/RudderFlushWorkManager.java @@ -24,6 +24,7 @@ public class RudderFlushWorkManager { static final String RUDDER_FLUSH_CONFIG_FILE_NAME = "RudderFlushConfig"; static final String PERSISTENCE_PROVIDER_FACTORY_CLASS_NAME_KEY = "persistenceProviderFactory"; + private static final String UNIQUE_FLUSH_WORK_NAME = "flushEvents"; RudderFlushWorkManager(Context context, RudderConfig config, RudderPreferenceManager preferenceManager) { this.context = context; this.config = config; @@ -77,14 +78,11 @@ void registerPeriodicFlushWorker() { .build(); WorkManager.getInstance(context).enqueueUniquePeriodicWork( - "flushEvents", + UNIQUE_FLUSH_WORK_NAME, ExistingPeriodicWorkPolicy.KEEP, flushPendingEvents); - String periodicWorkRequestId = flushPendingEvents.getId().toString(); - preferenceManager.savePeriodicWorkRequestId(periodicWorkRequestId); - - RudderLogger.logDebug("EventRepository: registerPeriodicFlushWorker: Registered PeriodicWorkRequest with ID " + periodicWorkRequestId); + RudderLogger.logDebug("EventRepository: registerPeriodicFlushWorker: Registered PeriodicWorkRequest with name " + UNIQUE_FLUSH_WORK_NAME); } } @@ -97,12 +95,7 @@ void cancelPeriodicFlushWorker() { RudderLogger.logWarn("EventRepository: cancelPeriodicFlushWorker: WorkManager dependency not found, please add it to your build.gradle"); return; } - String periodicWorkRequestId = preferenceManager.getPeriodicWorkRequestId(); - if (periodicWorkRequestId == null) { - RudderLogger.logWarn("EventRepository: cancelPeriodicFlushWorker: Couldn't find PeriodicWorkRequest Id, cannot cancel PeriodicWorkRequest"); - return; - } - WorkManager.getInstance(context).cancelWorkById(UUID.fromString(periodicWorkRequestId)); - RudderLogger.logDebug("EventRepository: cancelPeriodicFlushWorker: Successfully cancelled PeriodicWorkRequest With ID " + periodicWorkRequestId); + WorkManager.getInstance(context).cancelUniqueWork(UNIQUE_FLUSH_WORK_NAME); + RudderLogger.logDebug("EventRepository: cancelPeriodicFlushWorker: Successfully cancelled PeriodicWorkRequest With name " + UNIQUE_FLUSH_WORK_NAME); } } diff --git a/core/src/main/java/com/rudderstack/android/sdk/core/RudderPreferenceManager.java b/core/src/main/java/com/rudderstack/android/sdk/core/RudderPreferenceManager.java index 18147911c..2370b47bc 100644 --- a/core/src/main/java/com/rudderstack/android/sdk/core/RudderPreferenceManager.java +++ b/core/src/main/java/com/rudderstack/android/sdk/core/RudderPreferenceManager.java @@ -157,14 +157,6 @@ long getOptOutTime() { return preferences.getLong(RUDDER_OPT_OUT_TIME_KEY, -1); } - void savePeriodicWorkRequestId(String periodicWorkRequestId) { - preferences.edit().putString(RUDDER_PERIODIC_WORK_REQUEST_ID_KEY, periodicWorkRequestId).apply(); - } - - String getPeriodicWorkRequestId() { - return preferences.getString(RUDDER_PERIODIC_WORK_REQUEST_ID_KEY, null); - } - void saveLastEventTimeStamp(Long time) { preferences.edit().putLong(RUDDER_LAST_EVENT_TIMESTAMP_KEY, time).apply(); } diff --git a/sample-kotlin/build.gradle b/sample-kotlin/build.gradle index 1ee3f8dfe..382e053be 100644 --- a/sample-kotlin/build.gradle +++ b/sample-kotlin/build.gradle @@ -88,6 +88,8 @@ dependencies { implementation 'com.rudderstack.android.integration:braze:1.0.6' implementation "com.appboy:android-sdk-ui:21.0.0" + //work-manager + implementation 'androidx.work:work-runtime:2.8.1' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.2.0' diff --git a/sample-kotlin/src/main/java/com/rudderstack/android/sample/kotlin/MainApplication.kt b/sample-kotlin/src/main/java/com/rudderstack/android/sample/kotlin/MainApplication.kt index 6754c581e..786b06394 100644 --- a/sample-kotlin/src/main/java/com/rudderstack/android/sample/kotlin/MainApplication.kt +++ b/sample-kotlin/src/main/java/com/rudderstack/android/sample/kotlin/MainApplication.kt @@ -7,6 +7,7 @@ import com.rudderstack.android.integrations.amplitude.AmplitudeIntegrationFactor import com.rudderstack.android.sdk.core.RudderClient import com.rudderstack.android.sdk.core.RudderConfig import com.rudderstack.android.sdk.core.RudderLogger +import java.util.concurrent.TimeUnit class MainApplication : Application(), Configuration.Provider { companion object { @@ -27,6 +28,7 @@ class MainApplication : Application(), Configuration.Provider { .withDataPlaneUrl(DATA_PLANE_URL) .withControlPlaneUrl(BuildConfig.CONTROL_PLANE_URL) .withLogLevel(RudderLogger.RudderLogLevel.NONE) + .withFlushPeriodically(20,TimeUnit.MINUTES) .withCollectDeviceId(false) .withFactory(BrazeIntegrationFactory.FACTORY) .withFactory(AmplitudeIntegrationFactory.FACTORY) From 31f90d9b7ff8cf3d01bc4a81a8133f1aa1ec6707 Mon Sep 17 00:00:00 2001 From: GitHub actions Date: Mon, 16 Oct 2023 05:26:14 +0000 Subject: [PATCH 3/3] chore(release): 1.20.1 --- CHANGELOG.md | 8 ++++++++ gradle.properties | 4 ++-- package.json | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3e3fe250..8f3b269e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ 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.20.1](https://github.com/rudderlabs/rudder-sdk-android/compare/v1.20.0...v1.20.1) (2023-10-16) + + +### Bug Fixes + +* typo in sample-kotlin build.gradle ([4097ea4](https://github.com/rudderlabs/rudder-sdk-android/commit/4097ea40f9c39966bed2ecad501a78defd93e2c1)) +* work manager not getting initialised if ([#330](https://github.com/rudderlabs/rudder-sdk-android/issues/330)) ([d10fc24](https://github.com/rudderlabs/rudder-sdk-android/commit/d10fc244e105fe885628105dc8c22344a2d2e549)) + ## [1.20.0](https://github.com/rudderlabs/rudder-sdk-android/compare/v1.19.1...v1.20.0) (2023-10-03) diff --git a/gradle.properties b/gradle.properties index 136d85233..c8314c491 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=19 -VERSION_NAME=1.20.0 +VERSION_CODE=20 +VERSION_NAME=1.20.1 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 9be707432..af6b71ea3 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.20.0", + "version": "1.20.1", "dependencies": { "properties-reader": "^2.2.0" }