diff --git a/CHANGELOG.md b/CHANGELOG.md index c5af738e1..ec4d2b99a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 23.8.2 +* Fixed APM bug where automatic foreground, background tracking would track wrong if the SDK was not initialized while the app was not in the foreground + ## 23.8.1 * Adding an additional testing call for retrieving AB test experiment information diff --git a/gradle.properties b/gradle.properties index 0e629b15d..5b4d782f4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,7 +22,7 @@ org.gradle.configureondemand=true android.useAndroidX=true android.enableJetifier=true # RELEASE FIELD SECTION -VERSION_NAME=23.8.1 +VERSION_NAME=23.8.2 GROUP=ly.count.android POM_URL=https://github.com/Countly/countly-sdk-android POM_SCM_URL=https://github.com/Countly/countly-sdk-android diff --git a/sdk/src/androidTest/java/ly/count/android/sdk/ConnectionQueueTests.java b/sdk/src/androidTest/java/ly/count/android/sdk/ConnectionQueueTests.java index 94106a6d4..33d3ea40d 100644 --- a/sdk/src/androidTest/java/ly/count/android/sdk/ConnectionQueueTests.java +++ b/sdk/src/androidTest/java/ly/count/android/sdk/ConnectionQueueTests.java @@ -502,7 +502,7 @@ public void testPrepareCommonRequest() { break; case "sdk_version": if (a == 0) { - Assert.assertTrue(pair[1].equals("23.8.1")); + Assert.assertTrue(pair[1].equals("23.8.2")); } else if (a == 1) { Assert.assertTrue(pair[1].equals("123sdf.v-213")); } diff --git a/sdk/src/main/java/ly/count/android/sdk/Countly.java b/sdk/src/main/java/ly/count/android/sdk/Countly.java index deb5abf44..22456d983 100644 --- a/sdk/src/main/java/ly/count/android/sdk/Countly.java +++ b/sdk/src/main/java/ly/count/android/sdk/Countly.java @@ -49,7 +49,7 @@ of this software and associated documentation files (the "Software"), to deal */ public class Countly { - private final String DEFAULT_COUNTLY_SDK_VERSION_STRING = "23.8.1"; + private final String DEFAULT_COUNTLY_SDK_VERSION_STRING = "23.8.2"; /** * Used as request meta data on every request @@ -664,6 +664,7 @@ public synchronized Countly init(CountlyConfig config) { //set global application listeners if (config.application != null) { + L.d("[Countly] Calling registerActivityLifecycleCallbacks"); config.application.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() { @Override public void onActivityCreated(Activity activity, Bundle bundle) { diff --git a/sdk/src/main/java/ly/count/android/sdk/ModuleAPM.java b/sdk/src/main/java/ly/count/android/sdk/ModuleAPM.java index 454ad0bc8..b28b90b72 100644 --- a/sdk/src/main/java/ly/count/android/sdk/ModuleAPM.java +++ b/sdk/src/main/java/ly/count/android/sdk/ModuleAPM.java @@ -39,11 +39,6 @@ public class ModuleAPM extends ModuleBase { activitiesOpen = 0; - if (_cly.lifecycleStateAtLeastStarted()) { - L.d("[ModuleAPM] SDK detects that the app is in the foreground. Increasing the activity counter."); - activitiesOpen++; - } - useManualAppLoadedTrigger = config.appLoadedManualTrigger; if (config.appStartTimestampOverride != null) { //if there is a app start time override, use it @@ -353,7 +348,7 @@ void calculateAppRunningTimes(int previousCount, int newCount) { boolean goingToBackground = (previousCount == 1 && newCount == 0); boolean goingToForeground = (previousCount == 0 && newCount == 1); - L.v("[ModuleAPM] calculateAppRunningTimes, toBG[" + goingToBackground + "] toFG[" + goingToForeground + "]"); + L.v("[ModuleAPM] calculateAppRunningTimes, going toBG[" + goingToBackground + "] going toFG[" + goingToForeground + "] | [" + previousCount + "][" + newCount + "]"); doForegroundBackgroundCalculations(goingToBackground, goingToForeground); } @@ -462,6 +457,18 @@ void onConsentChanged(@NonNull final List consentChangeDelta, final bool } } + @Override + void initFinished(@NonNull CountlyConfig config) { + // we only do this adjustment if we track it automatically + if (!manualForegroundBackgroundTriggers && _cly.lifecycleStateAtLeastStarted()) { + L.d("[ModuleAPM] SDK detects that the app is in the foreground. Increasing the activity counter."); + + calculateAppRunningTimes(activitiesOpen, activitiesOpen + 1); + + activitiesOpen++; + } + } + public class Apm { /** * Start a trace of a action you want to track