Skip to content

Commit 084912a

Browse files
committed
Fix getPackageInfo on API 33+ devices
On my Android 16 phone, I am unable to query installed package version without using the Tiramisu version of the API. If I use QUERY_ALL_PACKAGES, it is fine but the filtered <queries> version only works with the new APIs for me.
1 parent be14eb8 commit 084912a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

app/src/main/java/org/mozilla/tryfox/data/MozillaPackageManager.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.mozilla.tryfox.data
22

33
import android.content.pm.PackageInfo
44
import android.content.pm.PackageManager
5+
import android.os.Build
56
import android.util.Log
67
import org.mozilla.tryfox.model.AppState
78

@@ -21,7 +22,13 @@ class MozillaPackageManager(private val packageManager: PackageManager) {
2122
*/
2223
private fun getPackageInfo(packageName: String): PackageInfo? {
2324
return try {
24-
packageManager.getPackageInfo(packageName, 0)
25+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
26+
// API 33+
27+
packageManager.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(0))
28+
} else {
29+
// API 32 and below
30+
packageManager.getPackageInfo(packageName, 0)
31+
}
2532
} catch (_: PackageManager.NameNotFoundException) {
2633
Log.d("MozillaPackageManager", "Package not found: $packageName")
2734
null

0 commit comments

Comments
 (0)