From f28f9d22dc3ec5e53aed3c15f3ae7a9d3a529ace Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> Date: Tue, 7 Jan 2025 11:57:48 +0100 Subject: [PATCH] chore: change screenshot image type from JPEG to WEBP (#211) --- CHANGELOG.md | 2 ++ posthog-android/api/posthog-android.api | 2 ++ posthog-android/lint-baseline.xml | 2 +- .../posthog/android/internal/PostHogAndroidUtils.kt | 13 +++++++++++++ .../android/replay/PostHogReplayIntegration.kt | 10 +++++----- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1f9873c..71469a8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Next +- chore: change screenshot image type from JPEG to WEBP ([#211](https://github.com/PostHog/posthog-android/pull/211)) + ## 3.9.3 - 2024-11-26 - no user facing changes diff --git a/posthog-android/api/posthog-android.api b/posthog-android/api/posthog-android.api index 3517f6b8..667a0766 100644 --- a/posthog-android/api/posthog-android.api +++ b/posthog-android/api/posthog-android.api @@ -45,6 +45,8 @@ public final class com/posthog/android/internal/PostHogAndroidUtilsKt { public static final fun base64 (Landroid/graphics/Bitmap;Landroid/graphics/Bitmap$CompressFormat;I)Ljava/lang/String; public static synthetic fun base64$default (Landroid/graphics/Bitmap;Landroid/graphics/Bitmap$CompressFormat;IILjava/lang/Object;)Ljava/lang/String; public static final fun getApplicationInfo (Landroid/content/Context;)Landroid/content/pm/ApplicationInfo; + public static final fun webpBase64 (Landroid/graphics/Bitmap;I)Ljava/lang/String; + public static synthetic fun webpBase64$default (Landroid/graphics/Bitmap;IILjava/lang/Object;)Ljava/lang/String; } public abstract interface class com/posthog/android/replay/PostHogDrawableConverter { diff --git a/posthog-android/lint-baseline.xml b/posthog-android/lint-baseline.xml index 7599f625..f9cee0c3 100644 --- a/posthog-android/lint-baseline.xml +++ b/posthog-android/lint-baseline.xml @@ -36,7 +36,7 @@ 0 } +@PostHogInternal +@Suppress("DEPRECATION") +public fun Bitmap.webpBase64(quality: Int = 30): String? { + val format = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + Bitmap.CompressFormat.WEBP_LOSSY + } else { + Bitmap.CompressFormat.WEBP + } + + return base64(format, quality) +} + @PostHogInternal @Suppress("DEPRECATION") public fun Bitmap.base64( diff --git a/posthog-android/src/main/java/com/posthog/android/replay/PostHogReplayIntegration.kt b/posthog-android/src/main/java/com/posthog/android/replay/PostHogReplayIntegration.kt index 29848ebc..79ca282c 100644 --- a/posthog-android/src/main/java/com/posthog/android/replay/PostHogReplayIntegration.kt +++ b/posthog-android/src/main/java/com/posthog/android/replay/PostHogReplayIntegration.kt @@ -53,10 +53,10 @@ import com.posthog.PostHog import com.posthog.PostHogIntegration import com.posthog.android.PostHogAndroidConfig import com.posthog.android.internal.MainHandler -import com.posthog.android.internal.base64 import com.posthog.android.internal.densityValue import com.posthog.android.internal.displayMetrics import com.posthog.android.internal.screenSize +import com.posthog.android.internal.webpBase64 import com.posthog.android.replay.PostHogMaskModifier.PostHogReplayMask import com.posthog.android.replay.internal.NextDrawListener.Companion.onNextDraw import com.posthog.android.replay.internal.ViewTreeSnapshotStatus @@ -733,7 +733,7 @@ public class PostHogReplayIntegration( canvas.drawRoundRect(RectF(it), 10f, 10f, paint) } - base64 = bitmap.base64() + base64 = bitmap.webpBase64() } } catch (e: Throwable) { config.logger.log("Session Replay PixelCopy failed: $e.") @@ -1106,7 +1106,7 @@ public class PostHogReplayIntegration( ): String? { val convertedBitmap = runDrawableConverter(this) if (convertedBitmap != null) { - return convertedBitmap.base64() + return convertedBitmap.webpBase64() } var clonedDrawable = this @@ -1117,7 +1117,7 @@ public class PostHogReplayIntegration( when (clonedDrawable) { is BitmapDrawable -> { try { - return clonedDrawable.bitmap.base64() + return clonedDrawable.bitmap.webpBase64() } catch (_: Throwable) { // ignore } @@ -1138,7 +1138,7 @@ public class PostHogReplayIntegration( try { val bitmap = clonedDrawable.toBitmap(width, height) - val base64 = bitmap.base64() + val base64 = bitmap.webpBase64() if (!bitmap.isRecycled) { bitmap.recycle() }