-
Notifications
You must be signed in to change notification settings - Fork 44
fix(android): preserve manually set releaseIdentifier #661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+104
β12
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "posthog-android": patch | ||
| --- | ||
|
|
||
| Fix a manually configured `releaseIdentifier` being overwritten by the auto-generated fallback (`applicationId@versionName+versionCode`), which broke proguard symbolication due to the map-id mismatch. A pre-set `releaseIdentifier` is now preserved; the value from `posthog-meta.properties` is used when nothing was set, and the fallback only when neither exists. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...og-android/src/test/java/com/posthog/android/internal/PostHogMetaPropertiesApplierTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package com.posthog.android.internal | ||
|
|
||
| import android.content.Context | ||
| import android.content.res.AssetManager | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import com.posthog.android.API_KEY | ||
| import com.posthog.android.PostHogAndroidConfig | ||
| import org.junit.runner.RunWith | ||
| import org.mockito.kotlin.any | ||
| import org.mockito.kotlin.mock | ||
| import org.mockito.kotlin.never | ||
| import org.mockito.kotlin.verify | ||
| import org.mockito.kotlin.whenever | ||
| import java.io.ByteArrayInputStream | ||
| import java.io.FileNotFoundException | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| internal class PostHogMetaPropertiesApplierTest { | ||
| private val context = mock<Context>() | ||
| private val assets = mock<AssetManager>() | ||
| private val config = PostHogAndroidConfig(API_KEY) | ||
|
|
||
| private val sut = PostHogMetaPropertiesApplier() | ||
|
|
||
| private fun mockMetaProperties(content: String) { | ||
| whenever(context.assets).thenReturn(assets) | ||
| whenever(assets.open(any())).thenReturn(ByteArrayInputStream(content.toByteArray())) | ||
| } | ||
|
|
||
| private fun mockMissingMetaProperties() { | ||
| whenever(context.assets).thenReturn(assets) | ||
| whenever(assets.open(any())).thenThrow(FileNotFoundException()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `preserves manually set releaseIdentifier`() { | ||
| config.releaseIdentifier = "manual-id" | ||
| mockMetaProperties("io.posthog.proguard.mapid=meta-id") | ||
|
|
||
| sut.applyToConfig(context, config, FALLBACK) | ||
|
|
||
| assertEquals("manual-id", config.releaseIdentifier) | ||
| verify(assets, never()).open(any()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `uses meta properties map id when releaseIdentifier not set`() { | ||
| mockMetaProperties("io.posthog.proguard.mapid=meta-id") | ||
|
|
||
| sut.applyToConfig(context, config, FALLBACK) | ||
|
|
||
| assertEquals("meta-id", config.releaseIdentifier) | ||
| } | ||
|
|
||
| @Test | ||
| fun `uses fallback when meta properties file is missing`() { | ||
| mockMissingMetaProperties() | ||
|
|
||
| sut.applyToConfig(context, config, FALLBACK) | ||
|
|
||
| assertEquals(FALLBACK, config.releaseIdentifier) | ||
| } | ||
|
|
||
| @Test | ||
| fun `uses fallback when meta properties do not contain map id`() { | ||
| mockMetaProperties("some.other.property=value") | ||
|
|
||
| sut.applyToConfig(context, config, FALLBACK) | ||
|
|
||
| assertEquals(FALLBACK, config.releaseIdentifier) | ||
| } | ||
|
|
||
| @Test | ||
| fun `uses fallback when reading meta properties throws`() { | ||
| whenever(context.assets).thenReturn(assets) | ||
| whenever(assets.open(any())).thenThrow(RuntimeException("boom")) | ||
|
|
||
| sut.applyToConfig(context, config, FALLBACK) | ||
|
|
||
| assertEquals(FALLBACK, config.releaseIdentifier) | ||
| } | ||
|
|
||
| companion object { | ||
| private const val FALLBACK = "com.package@1.0.0+1" | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is actually a more important case I saw in prod, tens of thousands of frames per week here at a first/quick look (although some could be older versions who don't have a releaseIdentifier in the first place).
the first one with manual releaseIdentifier isn't as common