From 0b2fe605cecbd56858d9d3f981865d6410ab223c Mon Sep 17 00:00:00 2001 From: mcarare Date: Wed, 6 Jul 2022 15:23:44 +0300 Subject: [PATCH] For #25808: Handle PackageManager methods deprecation. --- app/src/main/java/org/mozilla/fenix/IntentReceiverActivity.kt | 3 ++- .../org/mozilla/fenix/components/metrics/MetricsStorage.kt | 3 ++- .../mozilla/fenix/components/metrics/MozillaProductDetector.kt | 3 ++- .../java/org/mozilla/fenix/settings/about/AboutFragment.kt | 3 ++- app/src/main/java/org/mozilla/fenix/share/ShareViewModel.kt | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/IntentReceiverActivity.kt b/app/src/main/java/org/mozilla/fenix/IntentReceiverActivity.kt index d633d31600..33af4e1ebe 100644 --- a/app/src/main/java/org/mozilla/fenix/IntentReceiverActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/IntentReceiverActivity.kt @@ -15,6 +15,7 @@ import mozilla.components.feature.intent.ext.sanitize import mozilla.components.feature.intent.processing.IntentProcessor import mozilla.components.support.utils.EXTRA_ACTIVITY_REFERRER_CATEGORY import mozilla.components.support.utils.EXTRA_ACTIVITY_REFERRER_PACKAGE +import mozilla.components.support.utils.ext.getApplicationInfoCompat import org.mozilla.fenix.GleanMetrics.Events import org.mozilla.fenix.HomeActivity.Companion.PRIVATE_BROWSING_MODE import org.mozilla.fenix.components.IntentProcessorType @@ -125,7 +126,7 @@ class IntentReceiverActivity : Activity() { // Category is supported for API>=26. r.host?.let { host -> try { - val category = packageManager.getApplicationInfo(host, 0).category + val category = packageManager.getApplicationInfoCompat(host, 0).category intent.putExtra(EXTRA_ACTIVITY_REFERRER_CATEGORY, category) } catch (e: PackageManager.NameNotFoundException) { // At least we tried. diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/MetricsStorage.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/MetricsStorage.kt index e0777df7b1..c8f56491d9 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/MetricsStorage.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/MetricsStorage.kt @@ -8,6 +8,7 @@ import android.content.Context import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext +import mozilla.components.support.utils.ext.getPackageInfoCompat import org.mozilla.fenix.ext.settings import org.mozilla.fenix.nimbus.FxNimbus import org.mozilla.fenix.utils.Settings @@ -76,7 +77,7 @@ internal class DefaultMetricsStorage( fun shouldSendGenerally(context: Context): Boolean { val installedTime = context.packageManager - .getPackageInfo(context.packageName, 0) + .getPackageInfoCompat(context.packageName, 0) .firstInstallTime val timeDifference = System.currentTimeMillis() - installedTime val withinWindow = timeDifference in windowStartMillis..windowEndMillis diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/MozillaProductDetector.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/MozillaProductDetector.kt index 388b0e01ae..fc42937b71 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/MozillaProductDetector.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/MozillaProductDetector.kt @@ -6,6 +6,7 @@ package org.mozilla.fenix.components.metrics import android.content.Context import android.content.pm.PackageManager +import mozilla.components.support.utils.ext.getPackageInfoCompat import org.mozilla.fenix.utils.BrowsersCache object MozillaProductDetector { @@ -45,7 +46,7 @@ object MozillaProductDetector { fun packageIsInstalled(context: Context, packageName: String): Boolean { try { - context.packageManager.getPackageInfo(packageName, 0) + context.packageManager.getPackageInfoCompat(packageName, 0) } catch (e: PackageManager.NameNotFoundException) { return false } diff --git a/app/src/main/java/org/mozilla/fenix/settings/about/AboutFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/about/AboutFragment.kt index 242f007c91..5eae0d639a 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/about/AboutFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/about/AboutFragment.kt @@ -15,6 +15,7 @@ import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.DividerItemDecoration import mozilla.components.service.glean.private.NoExtras +import mozilla.components.support.utils.ext.getPackageInfoCompat import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.GleanMetrics.Events @@ -96,7 +97,7 @@ class AboutFragment : Fragment(), AboutPageListener { private fun populateAboutHeader() { val aboutText = try { val packageInfo = - requireContext().packageManager.getPackageInfo(requireContext().packageName, 0) + requireContext().packageManager.getPackageInfoCompat(requireContext().packageName, 0) val versionCode = PackageInfoCompat.getLongVersionCode(packageInfo).toString() val maybeFenixGitHash = if (BuildConfig.GIT_HASH.isNotBlank()) ", ${BuildConfig.GIT_HASH}" else "" val componentsAbbreviation = getString(R.string.components_abbreviation) diff --git a/app/src/main/java/org/mozilla/fenix/share/ShareViewModel.kt b/app/src/main/java/org/mozilla/fenix/share/ShareViewModel.kt index cb600d81e1..3d1303a74a 100644 --- a/app/src/main/java/org/mozilla/fenix/share/ShareViewModel.kt +++ b/app/src/main/java/org/mozilla/fenix/share/ShareViewModel.kt @@ -24,6 +24,7 @@ import kotlinx.coroutines.launch import mozilla.components.concept.sync.DeviceCapability import mozilla.components.feature.share.RecentAppsStorage import mozilla.components.service.fxa.manager.FxaAccountManager +import mozilla.components.support.utils.ext.queryIntentActivitiesCompat import org.mozilla.fenix.R import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.isOnline @@ -162,7 +163,7 @@ class ShareViewModel(application: Application) : AndroidViewModel(application) { @VisibleForTesting @WorkerThread fun getIntentActivities(shareIntent: Intent, context: Context): List? { - return context.packageManager.queryIntentActivities(shareIntent, 0) + return context.packageManager.queryIntentActivitiesCompat(shareIntent, 0) } /**