Skip to content

Commit 6c066f3

Browse files
authored
Add os_version, app_build_version, device_manufacturer for Sessions #11222 (#4984)
1 parent c3b0dcc commit 6c066f3

File tree

6 files changed

+50
-7
lines changed

6 files changed

+50
-7
lines changed

firebase-sessions/src/main/kotlin/com/google/firebase/sessions/ApplicationInfo.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ internal data class AndroidApplicationInfo(
3737
/** The package name of the application/bundle name. */
3838
val packageName: String,
3939

40-
/** The version of the application. */
40+
/** The display version of the application. */
4141
val versionName: String,
42+
43+
/** The build version of the application. */
44+
val appBuildVersion: String,
45+
46+
/** The manufacturer of the device that runs the application. */
47+
val deviceManufacturer: String,
4248
)
4349

4450
internal data class ApplicationInfo(
@@ -51,6 +57,9 @@ internal data class ApplicationInfo(
5157
/** The SDK version of the sessions library. */
5258
val sessionSdkVersion: String,
5359

60+
/** The display version of the Android operating system. */
61+
val osVersion: String,
62+
5463
/** The logging environment for the events. */
5564
val logEnvironment: LogEnvironment,
5665

firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionEvents.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ internal object SessionEvents {
8181
ctx.add(FieldDescriptor.of("app_id"), applicationInfo.appId)
8282
ctx.add(FieldDescriptor.of("device_model"), applicationInfo.deviceModel)
8383
ctx.add(FieldDescriptor.of("session_sdk_version"), applicationInfo.sessionSdkVersion)
84+
ctx.add(FieldDescriptor.of("os_version"), applicationInfo.osVersion)
8485
ctx.add(FieldDescriptor.of("log_environment"), applicationInfo.logEnvironment)
8586
ctx.add(FieldDescriptor.of("android_app_info"), applicationInfo.androidAppInfo)
8687
}
@@ -92,6 +93,8 @@ internal object SessionEvents {
9293
run {
9394
ctx.add(FieldDescriptor.of("package_name"), androidAppInfo.packageName)
9495
ctx.add(FieldDescriptor.of("version_name"), androidAppInfo.versionName)
96+
ctx.add(FieldDescriptor.of("app_build_version"), androidAppInfo.appBuildVersion)
97+
ctx.add(FieldDescriptor.of("device_manufacturer"), androidAppInfo.deviceManufacturer)
9598
}
9699
}
97100
}
@@ -125,14 +128,26 @@ internal object SessionEvents {
125128
val context = firebaseApp.applicationContext
126129
val packageName = context.packageName
127130
val packageInfo = context.packageManager.getPackageInfo(packageName, 0)
131+
val buildVersion =
132+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
133+
packageInfo.longVersionCode.toString()
134+
} else {
135+
@Suppress("DEPRECATION") packageInfo.versionCode.toString()
136+
}
128137

129138
return ApplicationInfo(
130139
appId = firebaseApp.options.applicationId,
131140
deviceModel = Build.MODEL,
132141
sessionSdkVersion = BuildConfig.VERSION_NAME,
142+
osVersion = Build.VERSION.RELEASE,
133143
logEnvironment = LogEnvironment.LOG_ENVIRONMENT_PROD,
134144
androidAppInfo =
135-
AndroidApplicationInfo(packageName = packageName, versionName = packageInfo.versionName)
145+
AndroidApplicationInfo(
146+
packageName = packageName,
147+
versionName = packageInfo.versionName,
148+
appBuildVersion = buildVersion,
149+
deviceManufacturer = Build.MANUFACTURER,
150+
)
136151
)
137152
}
138153
}

firebase-sessions/src/test/kotlin/com/google/firebase/sessions/ApplicationInfoTest.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ class ApplicationInfoTest {
3939
appId = FakeFirebaseApp.MOCK_APP_ID,
4040
deviceModel = Build.MODEL,
4141
sessionSdkVersion = BuildConfig.VERSION_NAME,
42+
osVersion = Build.VERSION.RELEASE,
4243
logEnvironment = LogEnvironment.LOG_ENVIRONMENT_PROD,
4344
AndroidApplicationInfo(
4445
packageName = ApplicationProvider.getApplicationContext<Context>().packageName,
45-
versionName = FakeFirebaseApp.MOCK_APP_VERSION
46+
versionName = FakeFirebaseApp.MOCK_APP_VERSION,
47+
appBuildVersion = FakeFirebaseApp.MOCK_APP_BUILD_VERSION,
48+
deviceManufacturer = Build.MANUFACTURER,
4649
)
4750
)
4851
)

firebase-sessions/src/test/kotlin/com/google/firebase/sessions/SessionEventEncoderTest.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,13 @@ class SessionEventEncoderTest {
8282
"app_id":"1:12345:android:app",
8383
"device_model":"${Build.MODEL}",
8484
"session_sdk_version":"0.1.0",
85+
"os_version":"${Build.VERSION.RELEASE}",
8586
"log_environment":3,
8687
"android_app_info":{
8788
"package_name":"com.google.firebase.sessions.test",
88-
"version_name":"1.0.0"
89+
"version_name":"1.0.0",
90+
"app_build_version":"0",
91+
"device_manufacturer":"${Build.MANUFACTURER}"
8992
}
9093
}
9194
}
@@ -112,8 +115,14 @@ class SessionEventEncoderTest {
112115
appId = "",
113116
deviceModel = "",
114117
sessionSdkVersion = "",
118+
osVersion = "",
115119
logEnvironment = LogEnvironment.LOG_ENVIRONMENT_PROD,
116-
AndroidApplicationInfo(packageName = "", versionName = ""),
120+
AndroidApplicationInfo(
121+
packageName = "",
122+
versionName = "",
123+
appBuildVersion = "",
124+
deviceManufacturer = "",
125+
),
117126
)
118127
)
119128

@@ -140,10 +149,13 @@ class SessionEventEncoderTest {
140149
"app_id":"",
141150
"device_model":"",
142151
"session_sdk_version":"",
152+
"os_version":"",
143153
"log_environment":3,
144154
"android_app_info":{
145155
"package_name":"",
146-
"version_name":""
156+
"version_name":"",
157+
"app_build_version":"",
158+
"device_manufacturer":""
147159
}
148160
}
149161
}

firebase-sessions/src/test/kotlin/com/google/firebase/sessions/testing/FakeFirebaseApp.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ internal class FakeFirebaseApp(metadata: Bundle? = null) {
5757
internal const val MOCK_APP_ID = "1:12345:android:app"
5858
internal const val MOCK_API_KEY = "RANDOM_APIKEY_FOR_TESTING"
5959
internal const val MOCK_APP_VERSION = "1.0.0"
60+
internal const val MOCK_APP_BUILD_VERSION = "0"
6061
}
6162
}

firebase-sessions/src/test/kotlin/com/google/firebase/sessions/testing/TestSessionEventData.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,13 @@ internal object TestSessionEventData {
5757
appId = FakeFirebaseApp.MOCK_APP_ID,
5858
deviceModel = Build.MODEL,
5959
sessionSdkVersion = BuildConfig.VERSION_NAME,
60+
osVersion = Build.VERSION.RELEASE,
6061
logEnvironment = LogEnvironment.LOG_ENVIRONMENT_PROD,
6162
AndroidApplicationInfo(
6263
packageName = ApplicationProvider.getApplicationContext<Context>().packageName,
63-
versionName = FakeFirebaseApp.MOCK_APP_VERSION
64+
versionName = FakeFirebaseApp.MOCK_APP_VERSION,
65+
appBuildVersion = FakeFirebaseApp.MOCK_APP_BUILD_VERSION,
66+
deviceManufacturer = Build.MANUFACTURER,
6467
),
6568
)
6669
)

0 commit comments

Comments
 (0)