diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-26 06:16:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-26 06:16:27 +0000 |
commit | c10c12ce84bcc08d00d37be3f19a8fc23ac535ba (patch) | |
tree | 1a07e6b5389c49f68e13bebdf70843884669a31f /mobile/android/fenix/app/src/main | |
parent | Adding upstream version 127.0.1. (diff) | |
download | firefox-upstream/127.0.2.tar.xz firefox-upstream/127.0.2.zip |
Adding upstream version 127.0.2.upstream/127.0.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mobile/android/fenix/app/src/main')
-rw-r--r-- | mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/metrics/FirstSessionPing.kt | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/metrics/FirstSessionPing.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/metrics/FirstSessionPing.kt index 0666ab06e7..d281f03c06 100644 --- a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/metrics/FirstSessionPing.kt +++ b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/metrics/FirstSessionPing.kt @@ -4,8 +4,13 @@ package org.mozilla.fenix.components.metrics +import android.annotation.SuppressLint import android.content.Context import android.content.SharedPreferences +import android.content.pm.PackageManager +import android.os.Build +import android.os.Build.VERSION.SDK_INT +import androidx.annotation.RequiresApi import androidx.annotation.VisibleForTesting import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -16,6 +21,7 @@ import org.mozilla.fenix.Config import org.mozilla.fenix.GleanMetrics.Events import org.mozilla.fenix.GleanMetrics.FirstSession import org.mozilla.fenix.GleanMetrics.Pings +import org.mozilla.fenix.ext.application import org.mozilla.fenix.ext.settings class FirstSessionPing(private val context: Context) { @@ -70,6 +76,7 @@ class FirstSessionPing(private val context: Context) { }, ) FirstSession.timestamp.set() + FirstSession.installSource.set(installSourcePackage()) } CoroutineScope(Dispatchers.IO).launch { @@ -81,6 +88,38 @@ class FirstSessionPing(private val context: Context) { } } + @SuppressLint("NewApi") // Lint cannot resolve 'sdk' as 'SDK_INT' as it's not referenced directly. + @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) + internal fun installSourcePackage(sdk: Int = SDK_INT) = with(context.application) { + if (sdk >= Build.VERSION_CODES.R) { + installSourcePackageForBuildMinR(packageManager, packageName) + } else { + installSourcePackageForBuildMaxQ(packageManager, packageName) + } + } + + @RequiresApi(Build.VERSION_CODES.R) + private fun installSourcePackageForBuildMinR( + packageManager: PackageManager, + packageName: String, + ) = try { + packageManager.getInstallSourceInfo(packageName).installingPackageName + } catch (e: PackageManager.NameNotFoundException) { + Logger.debug("$packageName is not available to the caller") + null + }.orEmpty() + + private fun installSourcePackageForBuildMaxQ( + packageManager: PackageManager, + packageName: String, + ) = try { + @Suppress("DEPRECATION") + packageManager.getInstallerPackageName(packageName) + } catch (e: IllegalArgumentException) { + Logger.debug("$packageName is not installed") + null + }.orEmpty() + /** * Check that at least one of the metrics values is set before sending the ping. * Note: it is normal for many of these values to not be set as campaigns do not always |