Skip to content

Commit 95dc1c8

Browse files
AR Abdul Azeezcursoragent
andcommitted
chore: [SDK-5146] drop fcm= from the FID census header
Cohort is gs/snd/def/flag plus the subscription identifier shape, not the library version. Keep a bad AGP parse or header value from failing the request. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent c8422e4 commit 95dc1c8

4 files changed

Lines changed: 22 additions & 23 deletions

File tree

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/internal/device/impl/FidEnv.kt

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ internal const val HTTP_FID_ENV_HEADER_KEY = "OneSignal-Fid-Env"
1717
internal data class FidEnvSnapshot(
1818
val googleServices: Boolean,
1919
val agpVersion: String?,
20-
val fcmVersion: String?,
2120
val fidFlag: Boolean,
2221
val defaultFirebaseApp: Boolean,
2322
val firebaseInitProvider: Boolean,
@@ -29,7 +28,6 @@ internal data class FidEnvSnapshot(
2928
listOf(
3029
"gs=${googleServices.toBit()}",
3130
"agp=${agpVersion.sanitized()}",
32-
"fcm=${fcmVersion.sanitized()}",
3331
"flag=${fidFlag.toBit()}",
3432
"def=${defaultFirebaseApp.toBit()}",
3533
"prov=${firebaseInitProvider.toBit()}",
@@ -40,12 +38,17 @@ internal data class FidEnvSnapshot(
4038
}
4139

4240
internal fun sanitizeToken(value: String): String =
43-
value.filter { it.isLetterOrDigit() || it in "._+-" }.take(MAX_TOKEN_CHARS).ifEmpty { "-" }
41+
value.filter { it in TOKEN_CHARS }.take(MAX_TOKEN_CHARS).ifEmpty { "-" }
4442

43+
@Suppress("TooGenericExceptionCaught")
4544
internal fun parseAgpVersion(propertiesText: String): String? {
46-
val props = Properties()
47-
props.load(propertiesText.reader())
48-
return props.getProperty("androidGradlePluginVersion")?.takeIf { it.isNotBlank() }
45+
return try {
46+
val props = Properties()
47+
props.load(propertiesText.reader())
48+
props.getProperty("androidGradlePluginVersion")?.takeIf { it.isNotBlank() }
49+
} catch (_: Exception) {
50+
null
51+
}
4952
}
5053

5154
internal fun senderMatch(
@@ -78,7 +81,6 @@ internal class AndroidFidEnvReader(
7881
return FidEnvSnapshot(
7982
googleServices = !googleAppId.isNullOrBlank(),
8083
agpVersion = readApkEntry(AGP_METADATA_PATH)?.let { parseAgpVersion(it) },
81-
fcmVersion = firebaseMessagingVersion(),
8284
fidFlag = AndroidUtils.getManifestMetaBoolean(context, FID_FLAG),
8385
defaultFirebaseApp = false,
8486
firebaseInitProvider = hasFirebaseInitProvider(),
@@ -117,15 +119,6 @@ internal class AndroidFidEnvReader(
117119
}
118120
}
119121

120-
@Suppress("TooGenericExceptionCaught")
121-
private fun firebaseMessagingVersion(): String? {
122-
return try {
123-
Class.forName(FIREBASE_MESSAGING_BUILD_CONFIG).getField("VERSION_NAME").get(null) as? String
124-
} catch (_: Throwable) {
125-
null
126-
}
127-
}
128-
129122
@Suppress("TooGenericExceptionCaught", "UNCHECKED_CAST")
130123
private fun hasDefaultFirebaseApp(): Boolean {
131124
return try {
@@ -168,7 +161,6 @@ internal class AndroidFidEnvReader(
168161
private const val FID_FLAG = "firebase_messaging_installation_id_enabled"
169162
private const val FIREBASE_INIT_PROVIDER = "com.google.firebase.provider.FirebaseInitProvider"
170163
private const val AGP_METADATA_PATH = "META-INF/com/android/build/gradle/app-metadata.properties"
171-
private const val FIREBASE_MESSAGING_BUILD_CONFIG = "com.google.firebase.messaging.BuildConfig"
172164
private const val FIREBASE_APP = "com.google.firebase.FirebaseApp"
173165
private const val DEFAULT_APP_NAME = "[DEFAULT]"
174166
}
@@ -197,6 +189,7 @@ internal class FidEnvService(
197189
}
198190

199191
private const val MAX_TOKEN_CHARS = 32
192+
private const val TOKEN_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._+-"
200193

201194
private fun Boolean.toBit(): String = if (this) "1" else "0"
202195

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/internal/http/impl/HttpClient.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ internal class HttpClient(
154154

155155
val fidEnv = _fidEnv.headerValue()
156156
if (fidEnv.isNotEmpty()) {
157-
con.setRequestProperty(HTTP_FID_ENV_HEADER_KEY, fidEnv)
157+
try {
158+
con.setRequestProperty(HTTP_FID_ENV_HEADER_KEY, fidEnv)
159+
} catch (_: IllegalArgumentException) {
160+
}
158161
}
159162

160163
if (jsonBody != null) {

OneSignalSDK/onesignal/core/src/test/java/com/onesignal/core/internal/device/FidEnvTests.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class FidEnvTests : FunSpec({
1313
FidEnvSnapshot(
1414
googleServices = true,
1515
agpVersion = "8.8.2",
16-
fcmVersion = "24.0.0",
1716
fidFlag = false,
1817
defaultFirebaseApp = true,
1918
firebaseInitProvider = true,
@@ -22,15 +21,14 @@ class FidEnvTests : FunSpec({
2221
senderMatch = true,
2322
).toHeaderValue()
2423

25-
header shouldBe "gs=1;agp=8.8.2;fcm=24.0.0;flag=0;def=1;prov=1;min=24;tgt=35;snd=1"
24+
header shouldBe "gs=1;agp=8.8.2;flag=0;def=1;prov=1;min=24;tgt=35;snd=1"
2625
}
2726

2827
test("header uses dashes for unknown optional fields") {
2928
val header =
3029
FidEnvSnapshot(
3130
googleServices = false,
3231
agpVersion = null,
33-
fcmVersion = null,
3432
fidFlag = false,
3533
defaultFirebaseApp = false,
3634
firebaseInitProvider = false,
@@ -39,12 +37,13 @@ class FidEnvTests : FunSpec({
3937
senderMatch = null,
4038
).toHeaderValue()
4139

42-
header shouldBe "gs=0;agp=-;fcm=-;flag=0;def=0;prov=0;min=-;tgt=-;snd=-"
40+
header shouldBe "gs=0;agp=-;flag=0;def=0;prov=0;min=-;tgt=-;snd=-"
4341
}
4442

4543
test("sanitizeToken strips header-unsafe characters and caps length") {
4644
sanitizeToken("8.8.2-alpha01") shouldBe "8.8.2-alpha01"
4745
sanitizeToken("8.8.2 injected\nX-Other: 1") shouldBe "8.8.2injectedX-Other1"
46+
sanitizeToken("8.8.2\u00e9") shouldBe "8.8.2"
4847
sanitizeToken(" ".repeat(40)) shouldBe "-"
4948
sanitizeToken("a".repeat(40)).length shouldBe 32
5049
}
@@ -62,6 +61,10 @@ class FidEnvTests : FunSpec({
6261
parseAgpVersion("appMetadataVersion=1.1\n") shouldBe null
6362
}
6463

64+
test("parseAgpVersion returns null for malformed properties") {
65+
parseAgpVersion("androidGradlePluginVersion=\\uXXXX") shouldBe null
66+
}
67+
6568
test("senderMatch is unknown until dashboard sender is available") {
6669
senderMatch("123", null) shouldBe null
6770
senderMatch(null, null) shouldBe null

OneSignalSDK/onesignal/core/src/test/java/com/onesignal/core/internal/http/HttpClientTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,6 @@ internal class FakeFidEnv(
320320
override fun headerValue(): String = value
321321

322322
companion object {
323-
const val VALUE = "gs=0;agp=8.8.2;fcm=-;flag=0;def=0;prov=0;min=21;tgt=34;snd=-"
323+
const val VALUE = "gs=0;agp=8.8.2;flag=0;def=0;prov=0;min=21;tgt=34;snd=-"
324324
}
325325
}

0 commit comments

Comments
 (0)