in facebook-core/src/main/java/com/facebook/internal/Utility.kt [643:720]
fun setAppEventExtendedDeviceInfoParameters(params: JSONObject, appContext: Context) {
val extraInfoArray = JSONArray()
extraInfoArray.put(EXTRA_APP_EVENTS_INFO_FORMAT_VERSION)
refreshPeriodicExtendedDeviceInfo(appContext)
// Application Manifest info:
val pkgName = appContext.packageName
var versionCode = -1
var versionName: String? = ""
try {
val pi = appContext.packageManager.getPackageInfo(pkgName, 0) ?: return
versionCode = pi.versionCode
versionName = pi.versionName
} catch (e: PackageManager.NameNotFoundException) {
// Swallow
}
// Application Manifest info:
extraInfoArray.put(pkgName)
extraInfoArray.put(versionCode)
extraInfoArray.put(versionName)
// OS/Device info
extraInfoArray.put(Build.VERSION.RELEASE)
extraInfoArray.put(Build.MODEL)
// Locale
val locale =
try {
appContext.resources.configuration.locale
} catch (e: Exception) {
Locale.getDefault()
}
extraInfoArray.put(locale.language + "_" + locale.country)
// Time zone
extraInfoArray.put(deviceTimezoneAbbreviation)
// Carrier
extraInfoArray.put(carrierName)
// Screen dimensions
var width = 0
var height = 0
var density = 0.0
try {
val display =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
val displayManager =
appContext.getSystemService(Context.DISPLAY_SERVICE) as? DisplayManager
displayManager?.getDisplay(Display.DEFAULT_DISPLAY)
} else {
(appContext.getSystemService(Context.WINDOW_SERVICE) as? WindowManager)?.defaultDisplay
}
if (display != null) {
val displayMetrics = DisplayMetrics()
display.getMetrics(displayMetrics)
width = displayMetrics.widthPixels
height = displayMetrics.heightPixels
density = displayMetrics.density.toDouble()
}
} catch (e: Exception) {
// Swallow
}
extraInfoArray.put(width)
extraInfoArray.put(height)
val df = DecimalFormat("#.##")
extraInfoArray.put(df.format(density))
// CPU Cores
extraInfoArray.put(refreshBestGuessNumberOfCPUCores())
// External Storage
extraInfoArray.put(totalExternalStorageGB)
extraInfoArray.put(availableExternalStorageGB)
extraInfoArray.put(deviceTimeZoneName)
params.put("extinfo", extraInfoArray.toString())
}