Skip to content
Open
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
2 changes: 1 addition & 1 deletion dd-sdk-android-core/api/apiSurface
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ data class com.datadog.android.api.context.AccountInfo
data class com.datadog.android.api.context.DatadogContext
constructor(com.datadog.android.DatadogSite, String, String, String, String, Int, String, String, String, TimeInfo, ProcessInfo, NetworkInfo, DeviceInfo, UserInfo, AccountInfo?, com.datadog.android.privacy.TrackingConsent, String?, Map<String, Map<String, Any?>>)
data class com.datadog.android.api.context.DeviceInfo
constructor(String, String, String, DeviceType, String, String, String, String, String, Int?, LocaleInfo)
constructor(String, String, String, DeviceType, String, String, String, String, String, Int?, LocaleInfo, Int, Int?, Boolean?)
enum com.datadog.android.api.context.DeviceType
- MOBILE
- TABLET
Expand Down
12 changes: 9 additions & 3 deletions dd-sdk-android-core/api/dd-sdk-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,13 @@ public final class com/datadog/android/api/context/DatadogContext {
}

public final class com/datadog/android/api/context/DeviceInfo {
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/datadog/android/api/context/DeviceType;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Lcom/datadog/android/api/context/LocaleInfo;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/datadog/android/api/context/DeviceType;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Lcom/datadog/android/api/context/LocaleInfo;ILjava/lang/Integer;Ljava/lang/Boolean;)V
public final fun component1 ()Ljava/lang/String;
public final fun component10 ()Ljava/lang/Integer;
public final fun component11 ()Lcom/datadog/android/api/context/LocaleInfo;
public final fun component12 ()I
public final fun component13 ()Ljava/lang/Integer;
public final fun component14 ()Ljava/lang/Boolean;
public final fun component2 ()Ljava/lang/String;
public final fun component3 ()Ljava/lang/String;
public final fun component4 ()Lcom/datadog/android/api/context/DeviceType;
Expand All @@ -221,8 +224,8 @@ public final class com/datadog/android/api/context/DeviceInfo {
public final fun component7 ()Ljava/lang/String;
public final fun component8 ()Ljava/lang/String;
public final fun component9 ()Ljava/lang/String;
public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/datadog/android/api/context/DeviceType;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Lcom/datadog/android/api/context/LocaleInfo;)Lcom/datadog/android/api/context/DeviceInfo;
public static synthetic fun copy$default (Lcom/datadog/android/api/context/DeviceInfo;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/datadog/android/api/context/DeviceType;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Lcom/datadog/android/api/context/LocaleInfo;ILjava/lang/Object;)Lcom/datadog/android/api/context/DeviceInfo;
public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/datadog/android/api/context/DeviceType;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Lcom/datadog/android/api/context/LocaleInfo;ILjava/lang/Integer;Ljava/lang/Boolean;)Lcom/datadog/android/api/context/DeviceInfo;
public static synthetic fun copy$default (Lcom/datadog/android/api/context/DeviceInfo;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/datadog/android/api/context/DeviceType;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Lcom/datadog/android/api/context/LocaleInfo;ILjava/lang/Integer;Ljava/lang/Boolean;ILjava/lang/Object;)Lcom/datadog/android/api/context/DeviceInfo;
public fun equals (Ljava/lang/Object;)Z
public final fun getArchitecture ()Ljava/lang/String;
public final fun getDeviceBrand ()Ljava/lang/String;
Expand All @@ -231,11 +234,14 @@ public final class com/datadog/android/api/context/DeviceInfo {
public final fun getDeviceName ()Ljava/lang/String;
public final fun getDeviceType ()Lcom/datadog/android/api/context/DeviceType;
public final fun getLocaleInfo ()Lcom/datadog/android/api/context/LocaleInfo;
public final fun getLogicalCpuCount ()I
public final fun getNumberOfDisplays ()Ljava/lang/Integer;
public final fun getOsMajorVersion ()Ljava/lang/String;
public final fun getOsName ()Ljava/lang/String;
public final fun getOsVersion ()Ljava/lang/String;
public final fun getTotalRam ()Ljava/lang/Integer;
public fun hashCode ()I
public final fun isLowRam ()Ljava/lang/Boolean;
public fun toString ()Ljava/lang/String;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ package com.datadog.android.api.context
* @property architecture The CPU architecture of the device.
* @property numberOfDisplays The number of displays on the device.
* @property localeInfo locale information on the device such as timezone and region settings.
* @property logicalCpuCount Number of logical CPU cores available for scheduling on the device at
* runtime, as reported by the operating system.
* @property totalRam Total RAM available on the device in Megabytes.
* @property isLowRam Whether the device is considered a low RAM device by the OS.
*/
data class DeviceInfo(
val deviceName: String,
Expand All @@ -32,5 +36,8 @@ data class DeviceInfo(
val osVersion: String,
val architecture: String,
val numberOfDisplays: Int?,
val localeInfo: LocaleInfo
val localeInfo: LocaleInfo,
val logicalCpuCount: Int,
val totalRam: Int?,
val isLowRam: Boolean?
)
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ internal class DatadogContextProvider(
currentLocale = currentLocale,
timeZone = timeZone
)
}
},
logicalCpuCount = logicalCpuCount,
totalRam = totalRam,
isLowRam = isLowRam
)
},
userInfo = coreFeature.userInfoProvider.getUserInfo(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ internal class NoOpContextProvider : ContextProvider {
locales = emptyList(),
currentLocale = "",
timeZone = ""
)
),
logicalCpuCount = 0,
totalRam = null,
isLowRam = null
),
userInfo = UserInfo(null, null, null, null, emptyMap()),
accountInfo = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@ internal interface AndroidInfoProvider {
val currentLocale: String

val timeZone: String

val logicalCpuCount: Int

val totalRam: Int?

val isLowRam: Boolean?
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package com.datadog.android.core.internal.system

import android.app.ActivityManager
import android.app.UiModeManager
import android.content.Context
import android.content.pm.PackageManager
Expand Down Expand Up @@ -129,10 +130,35 @@ internal class DefaultAndroidInfoProvider(
}
}

override val logicalCpuCount: Int by lazy {
Runtime.getRuntime().availableProcessors()
}

override val totalRam: Int? by lazy {
try {
val activityManager = appContext.getSystemService(ActivityManager::class.java)
val info = ActivityManager.MemoryInfo()
activityManager.getMemoryInfo(info)
(info.totalMem / MB_IN_BYTES).toInt()
} catch (_: Exception) {
null
}
}

override val isLowRam: Boolean? by lazy {
try {
val activityManager = appContext.getSystemService(ActivityManager::class.java)
activityManager.isLowRamDevice
} catch (_: Exception) {
null
}
}

companion object {

const val FEATURE_GOOGLE_ANDROID_TV = "com.google.android.tv"
const val MIN_TABLET_WIDTH_DP = 800
const val MB_IN_BYTES = 1048576L

private fun resolveDeviceType(model: String, appContext: Context): DeviceType {
return if (isTv(appContext)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ internal class NoOpAndroidInfoProvider : AndroidInfoProvider {
override val locales: List<String> = emptyList()
override val currentLocale: String = ""
override val timeZone: String = ""
override val logicalCpuCount: Int = 0
override val totalRam: Int? = null
override val isLowRam: Boolean? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ internal class AndroidInfoProviderForgeryFactory : ForgeryFactory<AndroidInfoPro
val locales = forge.aList { forge.aString() }
val currentLocale = forge.aString()
val timeZone = forge.aString()
val logicalCpuCount = forge.anInt()
val totalRam = forge.anInt()
val isLowRam = forge.aBool()

return object : AndroidInfoProvider {
override val deviceName = deviceName
Expand All @@ -42,6 +45,9 @@ internal class AndroidInfoProviderForgeryFactory : ForgeryFactory<AndroidInfoPro
override val locales: List<String> = locales
override val currentLocale: String = currentLocale
override val timeZone: String = timeZone
override val logicalCpuCount: Int = logicalCpuCount
override val totalRam: Int? = totalRam
override val isLowRam: Boolean? = isLowRam
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ class DeviceInfoForgeryFactory : ForgeryFactory<DeviceInfo> {
osMajorVersion = forge.aString(),
architecture = forge.aString(),
numberOfDisplays = forge.aNullable { forge.anInt() },
localeInfo = forge.getForgery()
localeInfo = forge.getForgery(),
logicalCpuCount = forge.anInt(),
totalRam = forge.aNullable { anInt() },
isLowRam = forge.aNullable { aBool() }
)
}
}
1 change: 1 addition & 0 deletions detekt_custom_safe_calls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ datadog:
- "android.content.Context.createDeviceProtectedStorageContext()"
- "android.content.Context.getSharedPreferences(kotlin.String?, kotlin.Int)"
- "android.content.Context.getSystemService(kotlin.String)"
- "android.content.Context.getSystemService(java.lang.Class)"
- "android.content.Context.registerComponentCallbacks(android.content.ComponentCallbacks?)"
- "android.content.Context.registerReceiver(android.content.BroadcastReceiver?, android.content.IntentFilter?)"
- "android.content.Context.registerReceiver(android.content.BroadcastReceiver?, android.content.IntentFilter?, kotlin.Int)"
Expand Down
2 changes: 2 additions & 0 deletions detekt_custom_unsafe_calls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ datadog:
knownThrowingCalls:
# region Android
- "android.app.ActivityManager.getHistoricalProcessExitReasons(kotlin.String?, kotlin.Int, kotlin.Int):java.lang.RuntimeException"
- "android.app.ActivityManager.MemoryInfo.constructor():java.lang.RuntimeException"
- "android.app.ActivityManager.getMemoryInfo(android.app.ActivityManager.MemoryInfo?):java.lang.RuntimeException"
- "android.app.ApplicationExitInfo.getTraceInputStream():java.io.IOException"
- "android.content.pm.PackageManager.getPackageInfo(kotlin.String, android.content.pm.PackageManager.PackageInfoFlags):android.content.pm.PackageManager.NameNotFoundException"
- "android.content.pm.PackageManager.getPackageInfo(kotlin.String, kotlin.Int):android.content.pm.PackageManager.NameNotFoundException"
Expand Down
2 changes: 1 addition & 1 deletion features/dd-sdk-android-logs/api/apiSurface
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ data class com.datadog.android.log.model.LogEvent
fun fromJson(kotlin.String): LogEvent
fun fromJsonObject(com.google.gson.JsonObject): LogEvent
data class LogEventDevice
constructor(Type? = null, kotlin.String? = null, kotlin.String? = null, kotlin.String? = null, kotlin.String? = null, kotlin.String? = null, kotlin.collections.List<kotlin.String>? = null, kotlin.String? = null, kotlin.Number? = null, kotlin.Boolean? = null, kotlin.Number? = null)
constructor(Type? = null, kotlin.String? = null, kotlin.String? = null, kotlin.String? = null, kotlin.String? = null, kotlin.String? = null, kotlin.collections.List<kotlin.String>? = null, kotlin.String? = null, kotlin.Number? = null, kotlin.Boolean? = null, kotlin.Number? = null, kotlin.Number? = null, kotlin.Number? = null, kotlin.Boolean? = null)
fun toJson(): com.google.gson.JsonElement
companion object
fun fromJson(kotlin.String): LogEventDevice
Expand Down
14 changes: 10 additions & 4 deletions features/dd-sdk-android-logs/api/dd-sdk-android-logs.api
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,14 @@ public final class com/datadog/android/log/model/LogEvent$Error$Companion {
public final class com/datadog/android/log/model/LogEvent$LogEventDevice {
public static final field Companion Lcom/datadog/android/log/model/LogEvent$LogEventDevice$Companion;
public fun <init> ()V
public fun <init> (Lcom/datadog/android/log/model/LogEvent$Type;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Boolean;Ljava/lang/Number;)V
public synthetic fun <init> (Lcom/datadog/android/log/model/LogEvent$Type;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Boolean;Ljava/lang/Number;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lcom/datadog/android/log/model/LogEvent$Type;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Boolean;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Boolean;)V
public synthetic fun <init> (Lcom/datadog/android/log/model/LogEvent$Type;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Boolean;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Boolean;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Lcom/datadog/android/log/model/LogEvent$Type;
public final fun component10 ()Ljava/lang/Boolean;
public final fun component11 ()Ljava/lang/Number;
public final fun component12 ()Ljava/lang/Number;
public final fun component13 ()Ljava/lang/Number;
public final fun component14 ()Ljava/lang/Boolean;
public final fun component2 ()Ljava/lang/String;
public final fun component3 ()Ljava/lang/String;
public final fun component4 ()Ljava/lang/String;
Expand All @@ -286,8 +289,8 @@ public final class com/datadog/android/log/model/LogEvent$LogEventDevice {
public final fun component7 ()Ljava/util/List;
public final fun component8 ()Ljava/lang/String;
public final fun component9 ()Ljava/lang/Number;
public final fun copy (Lcom/datadog/android/log/model/LogEvent$Type;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Boolean;Ljava/lang/Number;)Lcom/datadog/android/log/model/LogEvent$LogEventDevice;
public static synthetic fun copy$default (Lcom/datadog/android/log/model/LogEvent$LogEventDevice;Lcom/datadog/android/log/model/LogEvent$Type;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Boolean;Ljava/lang/Number;ILjava/lang/Object;)Lcom/datadog/android/log/model/LogEvent$LogEventDevice;
public final fun copy (Lcom/datadog/android/log/model/LogEvent$Type;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Boolean;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Boolean;)Lcom/datadog/android/log/model/LogEvent$LogEventDevice;
public static synthetic fun copy$default (Lcom/datadog/android/log/model/LogEvent$LogEventDevice;Lcom/datadog/android/log/model/LogEvent$Type;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Boolean;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Boolean;ILjava/lang/Object;)Lcom/datadog/android/log/model/LogEvent$LogEventDevice;
public fun equals (Ljava/lang/Object;)Z
public static final fun fromJson (Ljava/lang/String;)Lcom/datadog/android/log/model/LogEvent$LogEventDevice;
public static final fun fromJsonObject (Lcom/google/gson/JsonObject;)Lcom/datadog/android/log/model/LogEvent$LogEventDevice;
Expand All @@ -297,12 +300,15 @@ public final class com/datadog/android/log/model/LogEvent$LogEventDevice {
public final fun getBrightnessLevel ()Ljava/lang/Number;
public final fun getLocale ()Ljava/lang/String;
public final fun getLocales ()Ljava/util/List;
public final fun getLogicalCpuCount ()Ljava/lang/Number;
public final fun getModel ()Ljava/lang/String;
public final fun getName ()Ljava/lang/String;
public final fun getPowerSavingMode ()Ljava/lang/Boolean;
public final fun getTimeZone ()Ljava/lang/String;
public final fun getTotalRam ()Ljava/lang/Number;
public final fun getType ()Lcom/datadog/android/log/model/LogEvent$Type;
public fun hashCode ()I
public final fun isLowRam ()Ljava/lang/Boolean;
public final fun toJson ()Lcom/google/gson/JsonElement;
public fun toString ()Ljava/lang/String;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ internal class DatadogLogGenerator(
name = deviceInfo.deviceName,
model = deviceInfo.deviceModel,
brand = deviceInfo.deviceBrand,
architecture = deviceInfo.architecture
architecture = deviceInfo.architecture,
logicalCpuCount = deviceInfo.logicalCpuCount,
totalRam = deviceInfo.totalRam,
isLowRam = deviceInfo.isLowRam
)

private fun resolveDeviceType(deviceType: DeviceType): LogEvent.Type = when (deviceType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,13 +455,16 @@ internal class LogEventSerializerTest {
val deviceName = deviceInfo.name
val deviceModel = deviceInfo.model
val deviceBrand = deviceInfo.brand
val deviceArhitecture = deviceInfo.architecture
val deviceArchitecture = deviceInfo.architecture
val deviceLocale = deviceInfo.locale
val deviceLocales = deviceInfo.locales
val deviceTimezone = deviceInfo.timeZone
val deviceBatteryLevel = deviceInfo.batteryLevel
val devicePowerSavingMode = deviceInfo.powerSavingMode
val deviceBrightnessLevel = deviceInfo.brightnessLevel
val deviceLogicalCpuCount = deviceInfo.logicalCpuCount
val deviceTotalRam = deviceInfo.totalRam
val deviceIsLowRam = deviceInfo.isLowRam
if (deviceType != null) {
hasField(KEY_TYPE, deviceType.name.lowercase(Locale.US))
} else {
Expand All @@ -482,8 +485,8 @@ internal class LogEventSerializerTest {
} else {
doesNotHaveField(KEY_BRAND)
}
if (deviceArhitecture != null) {
hasField(KEY_ARCHITECTURE, deviceArhitecture)
if (deviceArchitecture != null) {
hasField(KEY_ARCHITECTURE, deviceArchitecture)
} else {
doesNotHaveField(KEY_ARCHITECTURE)
}
Expand Down Expand Up @@ -517,6 +520,21 @@ internal class LogEventSerializerTest {
} else {
doesNotHaveField(KEY_BRIGHTNESS_LEVEL)
}
if (deviceLogicalCpuCount != null) {
hasField(KEY_LOGICAL_CPU_COUNT, deviceLogicalCpuCount)
} else {
doesNotHaveField(KEY_LOGICAL_CPU_COUNT)
}
if (deviceTotalRam != null) {
hasField(KEY_TOTAL_RAM, deviceTotalRam)
} else {
doesNotHaveField(KEY_TOTAL_RAM)
}
if (deviceIsLowRam != null) {
hasField(KEY_IS_LOW_RAM, deviceIsLowRam)
} else {
doesNotHaveField(KEY_IS_LOW_RAM)
}
}

// endregion
Expand Down Expand Up @@ -567,5 +585,8 @@ internal class LogEventSerializerTest {
private const val KEY_BATTERY_LEVEL = "battery_level"
private const val KEY_POWER_SAVING_MODE = "power_saving_mode"
private const val KEY_BRIGHTNESS_LEVEL = "brightness_level"
private const val KEY_IS_LOW_RAM = "is_low_ram"
private const val KEY_LOGICAL_CPU_COUNT = "logical_cpu_count"
private const val KEY_TOTAL_RAM = "total_ram"
}
}
Loading
Loading