Skip to content

Add os_version, app_build_version, device_manufacturer for Sessions #11222 #4984

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
merged 7 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ internal data class AndroidApplicationInfo(
/** The package name of the application/bundle name. */
val packageName: String,

/** The version of the application. */
/** The display version of the application. */
val versionName: String,

/** The build version of the application. */
val appBuildVersion: String,

/** The manufacturer of the device that runs the application. */
val deviceManufacturer: String,
)

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

/** The display version of the Android operating system. */
val osVersion: String,

/** The logging environment for the events. */
val logEnvironment: LogEnvironment,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ internal object SessionEvents {
ctx.add(FieldDescriptor.of("app_id"), applicationInfo.appId)
ctx.add(FieldDescriptor.of("device_model"), applicationInfo.deviceModel)
ctx.add(FieldDescriptor.of("session_sdk_version"), applicationInfo.sessionSdkVersion)
ctx.add(FieldDescriptor.of("os_version"), applicationInfo.osVersion)
ctx.add(FieldDescriptor.of("log_environment"), applicationInfo.logEnvironment)
ctx.add(FieldDescriptor.of("android_app_info"), applicationInfo.androidAppInfo)
}
Expand All @@ -92,6 +93,8 @@ internal object SessionEvents {
run {
ctx.add(FieldDescriptor.of("package_name"), androidAppInfo.packageName)
ctx.add(FieldDescriptor.of("version_name"), androidAppInfo.versionName)
ctx.add(FieldDescriptor.of("app_build_version"), androidAppInfo.appBuildVersion)
ctx.add(FieldDescriptor.of("device_manufacturer"), androidAppInfo.deviceManufacturer)
}
}
}
Expand Down Expand Up @@ -125,14 +128,26 @@ internal object SessionEvents {
val context = firebaseApp.applicationContext
val packageName = context.packageName
val packageInfo = context.packageManager.getPackageInfo(packageName, 0)
val buildVersion =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
packageInfo.longVersionCode.toString()
} else {
@Suppress("DEPRECATION") packageInfo.versionCode.toString()
}

return ApplicationInfo(
appId = firebaseApp.options.applicationId,
deviceModel = Build.MODEL,
sessionSdkVersion = BuildConfig.VERSION_NAME,
osVersion = Build.VERSION.RELEASE,
logEnvironment = LogEnvironment.LOG_ENVIRONMENT_PROD,
androidAppInfo =
AndroidApplicationInfo(packageName = packageName, versionName = packageInfo.versionName)
AndroidApplicationInfo(
packageName = packageName,
versionName = packageInfo.versionName,
appBuildVersion = buildVersion,
deviceManufacturer = Build.MANUFACTURER,
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ class ApplicationInfoTest {
appId = FakeFirebaseApp.MOCK_APP_ID,
deviceModel = Build.MODEL,
sessionSdkVersion = BuildConfig.VERSION_NAME,
osVersion = Build.VERSION.RELEASE,
logEnvironment = LogEnvironment.LOG_ENVIRONMENT_PROD,
AndroidApplicationInfo(
packageName = ApplicationProvider.getApplicationContext<Context>().packageName,
versionName = FakeFirebaseApp.MOCK_APP_VERSION
versionName = FakeFirebaseApp.MOCK_APP_VERSION,
appBuildVersion = FakeFirebaseApp.MOCK_APP_BUILD_VERSION,
deviceManufacturer = Build.MANUFACTURER,
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@ class SessionEventEncoderTest {
"app_id":"1:12345:android:app",
"device_model":"${Build.MODEL}",
"session_sdk_version":"0.1.0",
"os_version":"${Build.VERSION.RELEASE}",
"log_environment":3,
"android_app_info":{
"package_name":"com.google.firebase.sessions.test",
"version_name":"1.0.0"
"version_name":"1.0.0",
"app_build_version":"0",
"device_manufacturer":"${Build.MANUFACTURER}"
}
}
}
Expand All @@ -101,8 +104,14 @@ class SessionEventEncoderTest {
appId = "",
deviceModel = "",
sessionSdkVersion = "",
osVersion = "",
logEnvironment = LogEnvironment.LOG_ENVIRONMENT_PROD,
AndroidApplicationInfo(packageName = "", versionName = ""),
AndroidApplicationInfo(
packageName = "",
versionName = "",
appBuildVersion = "",
deviceManufacturer = "",
),
)
)

Expand All @@ -129,10 +138,13 @@ class SessionEventEncoderTest {
"app_id":"",
"device_model":"",
"session_sdk_version":"",
"os_version":"",
"log_environment":3,
"android_app_info":{
"package_name":"",
"version_name":""
"version_name":"",
"app_build_version":"",
"device_manufacturer":""
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ internal class FakeFirebaseApp(metadata: Bundle? = null) {
internal const val MOCK_APP_ID = "1:12345:android:app"
internal const val MOCK_API_KEY = "RANDOM_APIKEY_FOR_TESTING"
internal const val MOCK_APP_VERSION = "1.0.0"
internal const val MOCK_APP_BUILD_VERSION = "0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ internal object TestSessionEventData {
appId = FakeFirebaseApp.MOCK_APP_ID,
deviceModel = Build.MODEL,
sessionSdkVersion = BuildConfig.VERSION_NAME,
osVersion = Build.VERSION.RELEASE,
logEnvironment = LogEnvironment.LOG_ENVIRONMENT_PROD,
AndroidApplicationInfo(
packageName = ApplicationProvider.getApplicationContext<Context>().packageName,
versionName = FakeFirebaseApp.MOCK_APP_VERSION
versionName = FakeFirebaseApp.MOCK_APP_VERSION,
appBuildVersion = FakeFirebaseApp.MOCK_APP_BUILD_VERSION,
deviceManufacturer = Build.MANUFACTURER,
),
)
)
Expand Down