diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4673345b..cec4f040 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,10 +26,10 @@ jobs: needs: [authorize] steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up JDK 8 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '8' distribution: 'zulu' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a00f4518..defc5257 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,10 +14,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up JDK 8 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '8' distribution: 'zulu' diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c92c6c0..1f539dae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## [2.40.1](https://github.com/amplitude/Amplitude-Android/compare/v2.40.0...v2.40.1) (2024-04-17) + + +### Bug Fixes + +* always run middleware flush on updateServer ([#400](https://github.com/amplitude/Amplitude-Android/issues/400)) ([fbee357](https://github.com/amplitude/Amplitude-Android/commit/fbee357d6ba9eb540101cf09393f7eebafdfd49d)) + +# [2.40.0](https://github.com/amplitude/Amplitude-Android/compare/v2.39.9...v2.40.0) (2024-04-17) + + +### Features + +* middleware session replay integration ([#399](https://github.com/amplitude/Amplitude-Android/issues/399)) ([28bbbe6](https://github.com/amplitude/Amplitude-Android/commit/28bbbe6ad2d0a0fe6424645e6105ecb8c2be7a4f)) + ## [2.39.9](https://github.com/amplitude/Amplitude-Android/compare/v2.39.8...v2.39.9) (2024-02-27) diff --git a/gradle.properties b/gradle.properties index 73058224..42f81b00 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -ARTIFACT_VERSION=2.39.9 +ARTIFACT_VERSION=2.40.1 ARTIFACT_GROUP=com.amplitude POM_PACKAGING=aar diff --git a/src/main/java/com/amplitude/api/AmplitudeClient.java b/src/main/java/com/amplitude/api/AmplitudeClient.java index c90b53e3..1b027eed 100644 --- a/src/main/java/com/amplitude/api/AmplitudeClient.java +++ b/src/main/java/com/amplitude/api/AmplitudeClient.java @@ -738,6 +738,10 @@ public void run() { return this; } + public Boolean getOptOut() { + return optOut; + } + /** * Library name is default as `amplitude-android`. * Notice: You will only want to set it when following conditions are met. @@ -2154,6 +2158,9 @@ protected void updateServer(boolean limit) { return; } + // Flush middleware + middlewareRunner.flush(); + // if returning out of this block, always be sure to set uploadingCurrently to false!! if (!uploadingCurrently.getAndSet(true)) { long totalEventCount = dbHelper.getTotalEventCount(); diff --git a/src/main/java/com/amplitude/api/MiddlewareExtended.java b/src/main/java/com/amplitude/api/MiddlewareExtended.java new file mode 100644 index 00000000..0c929c48 --- /dev/null +++ b/src/main/java/com/amplitude/api/MiddlewareExtended.java @@ -0,0 +1,5 @@ +package com.amplitude.api; + +interface MiddlewareExtended extends Middleware { + void flush(); +} \ No newline at end of file diff --git a/src/main/java/com/amplitude/api/MiddlewareRunner.java b/src/main/java/com/amplitude/api/MiddlewareRunner.java index ac5a44d3..73f5fb34 100644 --- a/src/main/java/com/amplitude/api/MiddlewareRunner.java +++ b/src/main/java/com/amplitude/api/MiddlewareRunner.java @@ -44,4 +44,12 @@ public void run(MiddlewarePayload payload, MiddlewareNext next) { List middlewareList = new ArrayList<>(this.middlewares); runMiddlewares(middlewareList, payload, next); } + + void flush() { + for (Middleware middleware : middlewares) { + if (middleware instanceof MiddlewareExtended) { + ((MiddlewareExtended) middleware).flush(); + } + } + } } \ No newline at end of file diff --git a/src/test/java/com/amplitude/api/MiddlewareRunnerTest.java b/src/test/java/com/amplitude/api/MiddlewareRunnerTest.java index d70dd2fe..485aaf95 100644 --- a/src/test/java/com/amplitude/api/MiddlewareRunnerTest.java +++ b/src/test/java/com/amplitude/api/MiddlewareRunnerTest.java @@ -12,6 +12,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.util.concurrent.atomic.AtomicInteger; + @RunWith(AndroidJUnit4.class) @Config(manifest= Config.NONE) public class MiddlewareRunnerTest { @@ -79,4 +81,29 @@ public void run(MiddlewarePayload payload, MiddlewareNext next) { assertEquals(event.getString("user_id"), middlewareUser); } + @Test + public void testMiddlewareFlush() throws JSONException { + AtomicInteger runCount = new AtomicInteger(0); + AtomicInteger flushCount = new AtomicInteger(0); + + MiddlewareExtended flushMiddleware = new MiddlewareExtended() { + @Override + public void run(MiddlewarePayload payload, MiddlewareNext next) { + runCount.incrementAndGet(); + } + + @Override + public void flush() { + flushCount.incrementAndGet(); + } + }; + + middlewareRunner.add(flushMiddleware); + + middlewareRunner.flush(); + + assertEquals(flushCount.get(), 1); + assertEquals(runCount.get(), 0); + } + }