Skip to content

Commit

Permalink
Add logical resolution (#120) (#121)
Browse files Browse the repository at this point in the history
Co-authored-by: Karen Tamayo <[email protected]>

Co-authored-by: Karen Tamayo <[email protected]>
Co-authored-by: Karen Tamayo <[email protected]>
  • Loading branch information
3 people authored Sep 1, 2021
1 parent 1f83dc9 commit 0262e94
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion tealiumlibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'maven-publish'
apply plugin: 'kotlin-allopen'
apply from: '../jacoco.gradle'

version = '1.2.6'
version = '1.2.7'

android {
compileSdkVersion 29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class DeviceCollectorTests {
assertEquals("Android", data[DeviceCollectorConstants.DEVICE_OS_NAME])
assertNotNull(data[DeviceCollectorConstants.DEVICE_RUNTIME])
assertTrue("[0-9]+x[0-9]+".toRegex().matches(data[DeviceCollectorConstants.DEVICE_RESOLUTION] as String))
assertTrue("[0-9]+x[0-9]+".toRegex().matches(data[DeviceCollectorConstants.DEVICE_LOGICAL_RESOLUTION] as String))

assertSame(DeviceCollector.create(tealiumContext), DeviceCollector.create(tealiumContext))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface DeviceData {
val deviceArchitecture: String
val deviceCpuType: String
val deviceResolution: String
val deviceLogicalResolution: String
val deviceRuntime: String
val deviceOrigin: String
val devicePlatform: String
Expand All @@ -43,17 +44,23 @@ class DeviceCollector private constructor(context: Context) : Collector, DeviceD
private val point = Point()

override val device = if (Build.MODEL.startsWith(Build.MANUFACTURER)) Build.MODEL
?: "" else "${Build.MANUFACTURER} ${Build.MODEL}"
?: "" else "${Build.MANUFACTURER} ${Build.MODEL}"
override val deviceModel: String = Build.MODEL
override val deviceManufacturer: String = Build.MANUFACTURER
override val deviceArchitecture = if (Build.SUPPORTED_64_BIT_ABIS.isNotEmpty()) "64bit" else "32bit"
override val deviceArchitecture =
if (Build.SUPPORTED_64_BIT_ABIS.isNotEmpty()) "64bit" else "32bit"
override val deviceCpuType = System.getProperty("os.arch") ?: "unknown"
override val deviceResolution = point.let {
windowManager.defaultDisplay.getSize(it)
"${it.x}x${it.y}"
}
override val deviceLogicalResolution = point.let {
windowManager.defaultDisplay.getRealSize(it)
"${it.x}x${it.y}"
}
override val deviceRuntime = System.getProperty("java.vm.version") ?: "unknown"
override val deviceOrigin = if (uiModeManager.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION) "tv" else "mobile"
override val deviceOrigin =
if (uiModeManager.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION) "tv" else "mobile"
override val devicePlatform = "android"
override val deviceOsName = "Android"
override val deviceOsBuild = Build.VERSION.INCREMENTAL ?: ""
Expand Down Expand Up @@ -85,30 +92,32 @@ class DeviceCollector private constructor(context: Context) : Collector, DeviceD

override suspend fun collect(): Map<String, Any> {
return mapOf(
DeviceCollectorConstants.DEVICE to device,
DeviceCollectorConstants.DEVICE_MODEL to deviceModel,
DeviceCollectorConstants.DEVICE_MANUFACTURER to deviceManufacturer,
DeviceCollectorConstants.DEVICE_ARCHITECTURE to deviceArchitecture,
DeviceCollectorConstants.DEVICE_CPU_TYPE to deviceCpuType,
DeviceCollectorConstants.DEVICE_RESOLUTION to deviceResolution,
DeviceCollectorConstants.DEVICE_RUNTIME to deviceRuntime,
DeviceCollectorConstants.DEVICE_ORIGIN to deviceOrigin,
DeviceCollectorConstants.DEVICE_PLATFORM to devicePlatform,
DeviceCollectorConstants.DEVICE_OS_NAME to deviceOsName,
DeviceCollectorConstants.DEVICE_OS_BUILD to deviceOsBuild,
DeviceCollectorConstants.DEVICE_OS_VERSION to deviceOsVersion,
DeviceCollectorConstants.DEVICE_AVAILABLE_SYSTEM_STORAGE to deviceAvailableSystemStorage,
DeviceCollectorConstants.DEVICE_AVAILABLE_EXTERNAL_STORAGE to deviceAvailableExternalStorage,
DeviceCollectorConstants.DEVICE_ORIENTATION to deviceOrientation,
DeviceCollectorConstants.DEVICE_LANGUAGE to deviceLanguage
DeviceCollectorConstants.DEVICE to device,
DeviceCollectorConstants.DEVICE_MODEL to deviceModel,
DeviceCollectorConstants.DEVICE_MANUFACTURER to deviceManufacturer,
DeviceCollectorConstants.DEVICE_ARCHITECTURE to deviceArchitecture,
DeviceCollectorConstants.DEVICE_CPU_TYPE to deviceCpuType,
DeviceCollectorConstants.DEVICE_RESOLUTION to deviceResolution,
DeviceCollectorConstants.DEVICE_LOGICAL_RESOLUTION to deviceLogicalResolution,
DeviceCollectorConstants.DEVICE_RUNTIME to deviceRuntime,
DeviceCollectorConstants.DEVICE_ORIGIN to deviceOrigin,
DeviceCollectorConstants.DEVICE_PLATFORM to devicePlatform,
DeviceCollectorConstants.DEVICE_OS_NAME to deviceOsName,
DeviceCollectorConstants.DEVICE_OS_BUILD to deviceOsBuild,
DeviceCollectorConstants.DEVICE_OS_VERSION to deviceOsVersion,
DeviceCollectorConstants.DEVICE_AVAILABLE_SYSTEM_STORAGE to deviceAvailableSystemStorage,
DeviceCollectorConstants.DEVICE_AVAILABLE_EXTERNAL_STORAGE to deviceAvailableExternalStorage,
DeviceCollectorConstants.DEVICE_ORIENTATION to deviceOrientation,
DeviceCollectorConstants.DEVICE_LANGUAGE to deviceLanguage
)
}

companion object : CollectorFactory {
const val MODULE_VERSION = BuildConfig.LIBRARY_VERSION
@Volatile private var instance: Collector? = null
@Volatile
private var instance: Collector? = null

override fun create(context: TealiumContext): Collector = instance ?: synchronized(this){
override fun create(context: TealiumContext): Collector = instance ?: synchronized(this) {
instance ?: DeviceCollector(context.config.application).also { instance = it }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ object DeviceCollectorConstants {
const val DEVICE_ARCHITECTURE = "device_architecture"
const val DEVICE_CPU_TYPE = "device_cputype"
const val DEVICE_RESOLUTION = "device_resolution"
const val DEVICE_LOGICAL_RESOLUTION = "device_logical_resolution"
const val DEVICE_RUNTIME = "device_android_runtime"
const val DEVICE_ORIGIN = "origin"
const val DEVICE_PLATFORM = "platform"
Expand Down

0 comments on commit 0262e94

Please sign in to comment.