Migrate deprecated PackageManager flag APIs to API 33+ typed overloads#235
Conversation
Agent-Logs-Url: https://github.com/Goooler/Tabby/sessions/99d1e82d-611f-4237-afd2-8f2f4b5869c7 Co-authored-by: Goooler <10363352+Goooler@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR migrates PackageManager calls away from deprecated Int-flag overloads by using the API 33+ typed flag overloads (PackageInfoFlags / ResolveInfoFlags) while keeping behavior-compatible fallbacks for older Android versions.
Changes:
- Update installed packages query to use
PackageInfoFlagson API 33+ with an older-API fallback. - Update launcher activity resolution query to use
ResolveInfoFlagson API 33+ with an older-API fallback.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| ui/settings/src/main/kotlin/com/github/kr328/clash/settings/vm/AccessControlViewModel.kt | Gates getInstalledPackages behind API 33+ typed flags overload with pre-33 fallback. |
| glue/src/main/kotlin/com/github/kr328/clash/glue/util/Intent.kt | Gates queryIntentActivities behind API 33+ typed flags overload with pre-33 fallback. |
Comments suppressed due to low confidence (1)
ui/settings/src/main/kotlin/com/github/kr328/clash/settings/vm/AccessControlViewModel.kt:206
- The pre-API 33 fallback still calls the deprecated
getInstalledPackages(Int)overload. With KotlinallWarningsAsErrors=true, this will typically fail compilation unless the deprecated call is suppressed. Consider adding@Suppress("DEPRECATION")to the fallback call/site (or refactoring into a helper annotated with the suppression).
val packages =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
pm.getInstalledPackages(PackageManager.PackageInfoFlags.of(resolveFlags.toLong()))
} else {
pm.getInstalledPackages(resolveFlags)
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
common/src/main/kotlin/com/github/kr328/clash/common/compat/PackageManager.kt:22
- The pre-API 33 fallback still calls the deprecated
PackageManager.queryIntentActivities(Intent, Int)overload. WithallWarningsAsErrors=true(build.gradle.kts:45-51), this will keep failing compilation unless suppressed; add@Suppress("DEPRECATION")on the fallback call (or at the compat function/file level) so call sites remain warning-free.
fun PackageManager.queryIntentActivitiesCompat(intent: Intent, flags: Int): List<ResolveInfo> {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
queryIntentActivities(intent, PackageManager.ResolveInfoFlags.of(flags.toLong()))
} else {
queryIntentActivities(intent, flags)
}
This updates two deprecated
PackageManagercalls that currently useIntflags, which generate warnings on newer SDKs and risk future incompatibility. The behavior is kept unchanged by using API 33+ typed flag overloads with pre-33 fallbacks.Installed packages query (
PackageInfoFlags)AccessControlViewModel, replaced directgetInstalledPackages(GET_PERMISSIONS)usage with an SDK-gated call:getInstalledPackages(PackageInfoFlags.of(...))Int-flags overloadLauncher activity resolution (
ResolveInfoFlags)glue/util/Intent.kt, replaced directqueryIntentActivities(intent, flags)usage with an SDK-gated call:queryIntentActivities(intent, ResolveInfoFlags.of(...))Int-flags overload