Skip to content

Commit

Permalink
Bug 1853967 - Capture telemetry for the amount of RAM a device has.
Browse files Browse the repository at this point in the history
  • Loading branch information
Amejia481 authored and mergify[bot] committed Sep 20, 2023
1 parent c793b0e commit 9ccde5e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
22 changes: 22 additions & 0 deletions fenix/app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2539,6 +2539,28 @@ metrics:
metadata:
tags:
- Experiments
device_total_ram:
type: quantity
lifetime: application
description: >
The total amount of memory this device in bytes, when available will be
MemoryInfo.advertisedMem otherwise it will be MemoryInfo.totalMem.
This doesn't represent memory available to the application however.
send_in_pings:
- metrics
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1853967
data_reviews:
- https://github.com/mozilla-mobile/firefox-android/pull/2620
data_sensitivity:
- technical
notification_emails:
- android-probes@mozilla.com
expires: never
unit: integer
metadata:
tags:
- Performance
search_page_load_time:
type: timing_distribution
time_unit: millisecond
Expand Down
20 changes: 18 additions & 2 deletions fenix/app/src/main/java/org/mozilla/fenix/FenixApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
)

ramMoreThanThreshold.set(isDeviceRamAboveThreshold)
deviceTotalRam.set(getDeviceTotalRAM())
}

with(AndroidAutofill) {
Expand Down Expand Up @@ -849,12 +850,27 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
}
}

private fun deviceRamApproxMegabytes(): Long {
@VisibleForTesting
internal fun getDeviceTotalRAM(): Long {
val memoryInfo = getMemoryInfo()
return if (SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
memoryInfo.advertisedMem
} else {
memoryInfo.totalMem
}
}

@VisibleForTesting
internal fun getMemoryInfo(): ActivityManager.MemoryInfo {
val memoryInfo = ActivityManager.MemoryInfo()
val activityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
activityManager.getMemoryInfo(memoryInfo)

val deviceRamBytes = memoryInfo.totalMem
return memoryInfo
}

private fun deviceRamApproxMegabytes(): Long {
val deviceRamBytes = getMemoryInfo().totalMem
return deviceRamBytes.toRoundedMegabytes()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class FenixApplicationTest {
every { settings.showPocketRecommendationsFeature } returns true
every { settings.showContileFeature } returns true
every { application.reportHomeScreenMetrics(settings) } just Runs
every { application.getDeviceTotalRAM() } returns 7L
every { settings.inactiveTabsAreEnabled } returns true
every { application.isDeviceRamAboveThreshold } returns true

Expand Down Expand Up @@ -193,6 +194,7 @@ class FenixApplicationTest {
assertEquals(expectedAppInstallSource, Metrics.installSource.testGetValue())
assertEquals(true, Metrics.defaultWallpaper.testGetValue())
assertEquals(true, Metrics.ramMoreThanThreshold.testGetValue())
assertEquals(7L, Metrics.deviceTotalRam.testGetValue())

val contextId = TopSites.contextId.testGetValue()!!.toString()

Expand Down

0 comments on commit 9ccde5e

Please sign in to comment.