diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2023-03-22 21:17:18 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2023-03-22 21:35:34 +0530 |
commit | 91227e445a9411059aac5062fc863b1fcb5dcb60 (patch) | |
tree | de0a0883156b15c7472acf8e9678177ed99facc5 /ui/src/main/java/com/wireguard | |
parent | 94e6d99dc76517f51c171a55a6e3a71a5f06490b (diff) |
ui: address PackageManager API deprecations
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'ui/src/main/java/com/wireguard')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.kt | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/ui/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.kt b/ui/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.kt index e137a8b4..627a9728 100644 --- a/ui/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.kt +++ b/ui/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.kt @@ -6,6 +6,10 @@ package com.wireguard.android.fragment import android.Manifest import android.app.Dialog +import android.content.pm.PackageInfo +import android.content.pm.PackageManager +import android.content.pm.PackageManager.PackageInfoFlags +import android.os.Build import android.os.Bundle import android.widget.Button import android.widget.Toast @@ -41,7 +45,7 @@ class AppListDialogFragment : DialogFragment() { try { val applicationData: MutableList<ApplicationData> = ArrayList() withContext(Dispatchers.IO) { - val packageInfos = pm.getPackagesHoldingPermissions(arrayOf(Manifest.permission.INTERNET), 0) + val packageInfos = getPackagesHoldingPermissions(pm, arrayOf(Manifest.permission.INTERNET)) packageInfos.forEach { val packageName = it.packageName val appInfo = it.applicationInfo @@ -78,6 +82,15 @@ class AppListDialogFragment : DialogFragment() { initiallyExcluded = arguments?.getBoolean(KEY_IS_EXCLUDED) ?: true } + private fun getPackagesHoldingPermissions(pm: PackageManager, permissions: Array<String>): List<PackageInfo> { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + pm.getPackagesHoldingPermissions(permissions, PackageInfoFlags.of(0L)) + } else { + @Suppress("DEPRECATION") + pm.getPackagesHoldingPermissions(permissions, 0) + } + } + private fun setButtonText() { val numSelected = appData.count { it.isSelected } button?.text = if (numSelected == 0) |