diff --git a/app/metrics.yaml b/app/metrics.yaml index 8aeb63e4a..a578c7c45 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -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 diff --git a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt index 13ca500bd..ea2859cec 100644 --- a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt +++ b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt @@ -801,6 +801,7 @@ open class FenixApplication : LocaleAwareApplication(), Provider { ) ramMoreThanThreshold.set(isDeviceRamAboveThreshold) + deviceTotalRam.set(getDeviceTotalRAM()) } with(AndroidAutofill) { @@ -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() } diff --git a/app/src/test/java/org/mozilla/fenix/FenixApplicationTest.kt b/app/src/test/java/org/mozilla/fenix/FenixApplicationTest.kt index d30adaa4e..87c0cff1f 100644 --- a/app/src/test/java/org/mozilla/fenix/FenixApplicationTest.kt +++ b/app/src/test/java/org/mozilla/fenix/FenixApplicationTest.kt @@ -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 @@ -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()