ui: address PackageManager API deprecations
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
94e6d99dc7
commit
91227e445a
@ -6,6 +6,10 @@ package com.wireguard.android.fragment
|
|||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.app.Dialog
|
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.os.Bundle
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
@ -41,7 +45,7 @@ class AppListDialogFragment : DialogFragment() {
|
|||||||
try {
|
try {
|
||||||
val applicationData: MutableList<ApplicationData> = ArrayList()
|
val applicationData: MutableList<ApplicationData> = ArrayList()
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val packageInfos = pm.getPackagesHoldingPermissions(arrayOf(Manifest.permission.INTERNET), 0)
|
val packageInfos = getPackagesHoldingPermissions(pm, arrayOf(Manifest.permission.INTERNET))
|
||||||
packageInfos.forEach {
|
packageInfos.forEach {
|
||||||
val packageName = it.packageName
|
val packageName = it.packageName
|
||||||
val appInfo = it.applicationInfo
|
val appInfo = it.applicationInfo
|
||||||
@ -78,6 +82,15 @@ class AppListDialogFragment : DialogFragment() {
|
|||||||
initiallyExcluded = arguments?.getBoolean(KEY_IS_EXCLUDED) ?: true
|
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() {
|
private fun setButtonText() {
|
||||||
val numSelected = appData.count { it.isSelected }
|
val numSelected = appData.count { it.isSelected }
|
||||||
button?.text = if (numSelected == 0)
|
button?.text = if (numSelected == 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user