2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

Bug 1840341 - Add memory telemetry for experiment

This commit is contained in:
t-p-white 2023-06-21 15:54:09 +01:00 committed by mergify[bot]
parent 7d246d2134
commit 40d5446c4b
3 changed files with 54 additions and 1 deletions

View File

@ -2434,6 +2434,24 @@ metrics:
metadata: metadata:
tags: tags:
- Notifications - Notifications
ram_more_than_threshold:
type: boolean
lifetime: application
description: True if the device's asserted 'advertised' RAM is more than the given threshold.
send_in_pings:
- metrics
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1840341
data_reviews:
- https://github.com/mozilla-mobile/firefox-android/pull/2620
data_sensitivity:
- technical
notification_emails:
- android-probes@mozilla.com
expires: 128
metadata:
tags:
- Experiments
customize_home: customize_home:
most_visited_sites: most_visited_sites:

View File

@ -5,6 +5,8 @@
package org.mozilla.fenix package org.mozilla.fenix
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.ActivityManager
import android.content.Context
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Build.VERSION.SDK_INT import android.os.Build.VERSION.SDK_INT
@ -109,6 +111,19 @@ import org.mozilla.fenix.wallpapers.Wallpaper
import java.util.UUID import java.util.UUID
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
/**
* The actual RAM threshold is 2GB.
*
* To enable simpler reporting, we want to use the device's 'advertised' RAM.
* As [ActivityManager.MemoryInfo.totalMem] is not the device's 'advertised' RAM spec & we cannot
* access [ActivityManager.MemoryInfo.advertisedMem] across all Android versions, we will use a
* proxy value of 1.6GB. This is based on 1.5GB with a small 'excess' buffer. We assert that all
* values above this proxy value are 2GB or more.
*/
private const val RAM_THRESHOLD_PROXY_GB = 1.6F
private const val RAM_THRESHOLD_BYTES = RAM_THRESHOLD_PROXY_GB * (1e+9).toLong()
/** /**
*The main application class for Fenix. Records data to measure initialization performance. *The main application class for Fenix. Records data to measure initialization performance.
* Installs [CrashReporter], initializes [Glean] in fenix builds and setup Megazord in the main process. * Installs [CrashReporter], initializes [Glean] in fenix builds and setup Megazord in the main process.
@ -689,6 +704,7 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
settings: Settings, settings: Settings,
browsersCache: BrowsersCache = BrowsersCache, browsersCache: BrowsersCache = BrowsersCache,
mozillaProductDetector: MozillaProductDetector = MozillaProductDetector, mozillaProductDetector: MozillaProductDetector = MozillaProductDetector,
isDeviceRamAboveThreshold: Boolean = isDeviceRamAboveThreshold(),
) { ) {
setPreferenceMetrics(settings) setPreferenceMetrics(settings)
with(Metrics) { with(Metrics) {
@ -786,6 +802,8 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
marketingNotificationAllowed.set( marketingNotificationAllowed.set(
notificationManagerCompat.isNotificationChannelEnabled(MARKETING_CHANNEL_ID), notificationManagerCompat.isNotificationChannelEnabled(MARKETING_CHANNEL_ID),
) )
ramMoreThanThreshold.set(isDeviceRamAboveThreshold)
} }
with(AndroidAutofill) { with(AndroidAutofill) {
@ -826,6 +844,16 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
} }
} }
private fun deviceRamBytes(): Long {
val memoryInfo = ActivityManager.MemoryInfo()
val activityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
activityManager.getMemoryInfo(memoryInfo)
return memoryInfo.totalMem
}
private fun isDeviceRamAboveThreshold() = deviceRamBytes() > RAM_THRESHOLD_BYTES
@Suppress("ComplexMethod") @Suppress("ComplexMethod")
private fun setPreferenceMetrics( private fun setPreferenceMetrics(
settings: Settings, settings: Settings,

View File

@ -148,7 +148,13 @@ class FenixApplicationTest {
assertTrue(settings.contileContextId.isEmpty()) assertTrue(settings.contileContextId.isEmpty())
assertNull(TopSites.contextId.testGetValue()) assertNull(TopSites.contextId.testGetValue())
application.setStartupMetrics(browserStore, settings, browsersCache, mozillaProductDetector) application.setStartupMetrics(
browserStore = browserStore,
settings = settings,
browsersCache = browsersCache,
mozillaProductDetector = mozillaProductDetector,
isDeviceRamAboveThreshold = true,
)
// Verify that browser defaults metrics are set. // Verify that browser defaults metrics are set.
assertEquals("Mozilla", Metrics.distributionId.testGetValue()) assertEquals("Mozilla", Metrics.distributionId.testGetValue())
@ -186,6 +192,7 @@ class FenixApplicationTest {
assertEquals(true, Preferences.inactiveTabsEnabled.testGetValue()) assertEquals(true, Preferences.inactiveTabsEnabled.testGetValue())
assertEquals(expectedAppInstallSource, Metrics.installSource.testGetValue()) assertEquals(expectedAppInstallSource, Metrics.installSource.testGetValue())
assertEquals(true, Metrics.defaultWallpaper.testGetValue()) assertEquals(true, Metrics.defaultWallpaper.testGetValue())
assertEquals(true, Metrics.ramMoreThanThreshold.testGetValue())
val contextId = TopSites.contextId.testGetValue()!!.toString() val contextId = TopSites.contextId.testGetValue()!!.toString()