-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1919a2
commit 16a2e72
Showing
3 changed files
with
101 additions
and
11 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
Provider/src/main/java/com/spotify/confidence/CommonContextBuilder.kt
This file contains 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,56 @@ | ||
package com.spotify.confidence | ||
|
||
import android.content.Context | ||
import android.os.Build | ||
import com.spotify.confidence.Constants.APP_BUILD_KEY | ||
import com.spotify.confidence.Constants.APP_NAMESPACE_KEY | ||
import com.spotify.confidence.Constants.APP_NAME_KEY | ||
import com.spotify.confidence.Constants.APP_VERSION_KEY | ||
import com.spotify.confidence.Constants.DEVICE_MANUFACTURER_KEY | ||
import com.spotify.confidence.Constants.DEVICE_MODEL_KEY | ||
import com.spotify.confidence.Constants.DEVICE_NAME_KEY | ||
import com.spotify.confidence.Constants.DEVICE_TYPE_KEY | ||
import com.spotify.confidence.Constants.OS_NAME_KEY | ||
import com.spotify.confidence.Constants.OS_VERSION_KEY | ||
import com.spotify.confidence.Constants.SCREEN_DENSITY_KEY | ||
import com.spotify.confidence.Constants.SCREEN_HEIGHT_KEY | ||
import com.spotify.confidence.Constants.SCREEN_WIDTH_KEY | ||
|
||
fun Confidence.addCommonContext(context: Context): Confidence { | ||
val newContext = withContext(mapOf()) | ||
with(newContext) { | ||
// OS and OS Version | ||
putContext(OS_NAME_KEY, ConfidenceValue.String("Android")) | ||
putContext(OS_VERSION_KEY, ConfidenceValue.String(Build.VERSION.RELEASE)) | ||
// Screen | ||
val displayMetrics = context.resources.displayMetrics | ||
putContext(SCREEN_DENSITY_KEY, ConfidenceValue.Double(displayMetrics.density.toDouble())) | ||
putContext(SCREEN_HEIGHT_KEY, ConfidenceValue.Double(displayMetrics.heightPixels.toDouble())) | ||
putContext(SCREEN_WIDTH_KEY, ConfidenceValue.Integer(displayMetrics.widthPixels)) | ||
// Package | ||
val packageManager = context.packageManager | ||
val packageInfo = packageManager.getPackageInfo(context.packageName, 0) | ||
putContext( | ||
APP_NAME_KEY, | ||
ConfidenceValue.String(packageInfo.applicationInfo.loadLabel(packageManager).toString()) | ||
) | ||
putContext(APP_VERSION_KEY, ConfidenceValue.String(packageInfo.versionName)) | ||
putContext(APP_NAMESPACE_KEY, ConfidenceValue.String(packageInfo.packageName)) | ||
|
||
val appBuild = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
packageInfo.longVersionCode.toString() | ||
} else { | ||
@Suppress("DEPRECATION") | ||
packageInfo.versionCode.toString() | ||
} | ||
putContext(APP_BUILD_KEY, ConfidenceValue.String(appBuild)) | ||
|
||
// Device ID | ||
putContext(DEVICE_MANUFACTURER_KEY, ConfidenceValue.String(Build.MANUFACTURER)) | ||
putContext(DEVICE_MODEL_KEY, ConfidenceValue.String(Build.MODEL)) | ||
putContext(DEVICE_NAME_KEY, ConfidenceValue.String(Build.DEVICE)) | ||
putContext(DEVICE_TYPE_KEY, ConfidenceValue.String("android")) | ||
} | ||
|
||
return newContext | ||
} |
38 changes: 38 additions & 0 deletions
38
Provider/src/main/java/com/spotify/confidence/CommonContextKeys.kt
This file contains 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,38 @@ | ||
package com.spotify.confidence | ||
object CommonContextKeys { | ||
const val LOCALE_KEY = "locale" | ||
const val USER_AGENT_KEY = "userAgent" | ||
const val TIMEZONE_KEY = "timezone" | ||
|
||
// App | ||
const val APP_KEY = "app" | ||
const val APP_NAME_KEY = "name" | ||
const val APP_VERSION_KEY = "version" | ||
const val APP_NAMESPACE_KEY = "namespace" | ||
const val APP_BUILD_KEY = "build" | ||
|
||
// Device | ||
const val DEVICE_KEY = "device" | ||
const val DEVICE_ID_KEY = "id" | ||
const val DEVICE_MANUFACTURER_KEY = "manufacturer" | ||
const val DEVICE_MODEL_KEY = "model" | ||
const val DEVICE_NAME_KEY = "name" | ||
const val DEVICE_TYPE_KEY = "type" | ||
|
||
// Network | ||
const val NETWORK_KEY = "network" | ||
const val NETWORK_BLUETOOTH_KEY = "bluetooth" | ||
const val NETWORK_CELLULAR_KEY = "cellular" | ||
const val NETWORK_WIFI_KEY = "wifi" | ||
|
||
// OS | ||
const val OS_KEY = "os" | ||
const val OS_NAME_KEY = "name" | ||
const val OS_VERSION_KEY = "version" | ||
|
||
// Screen | ||
const val SCREEN_KEY = "screen" | ||
const val SCREEN_DENSITY_KEY = "density" | ||
const val SCREEN_HEIGHT_KEY = "height" | ||
const val SCREEN_WIDTH_KEY = "width" | ||
} |
This file contains 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