Skip to content

Migrate deprecated PackageManager flag APIs to API 33+ typed overloads#235

Merged
Goooler merged 4 commits into
trunkfrom
copilot/migrate-package-manager-api
May 13, 2026
Merged

Migrate deprecated PackageManager flag APIs to API 33+ typed overloads#235
Goooler merged 4 commits into
trunkfrom
copilot/migrate-package-manager-api

Conversation

Copy link
Copy Markdown

Copilot AI commented May 13, 2026

This updates two deprecated PackageManager calls that currently use Int flags, 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)

    • In AccessControlViewModel, replaced direct getInstalledPackages(GET_PERMISSIONS) usage with an SDK-gated call:
      • API 33+: getInstalledPackages(PackageInfoFlags.of(...))
      • Older APIs: existing Int-flags overload
  • Launcher activity resolution (ResolveInfoFlags)

    • In glue/util/Intent.kt, replaced direct queryIntentActivities(intent, flags) usage with an SDK-gated call:
      • API 33+: queryIntentActivities(intent, ResolveInfoFlags.of(...))
      • Older APIs: existing Int-flags overload
val packages =
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
    pm.getInstalledPackages(
      PackageManager.PackageInfoFlags.of(PackageManager.GET_PERMISSIONS.toLong())
    )
  } else {
    pm.getInstalledPackages(PackageManager.GET_PERMISSIONS)
  }

Copilot AI linked an issue May 13, 2026 that may be closed by this pull request
Agent-Logs-Url: https://github.com/Goooler/Tabby/sessions/99d1e82d-611f-4237-afd2-8f2f4b5869c7

Co-authored-by: Goooler <10363352+Goooler@users.noreply.github.com>
@Goooler Goooler marked this pull request as ready for review May 13, 2026 09:31
Copilot AI changed the title [WIP] Migrate PackageManager.getInstalledPackages to use PackageInfoFlags Migrate deprecated PackageManager flag APIs to API 33+ typed overloads May 13, 2026
Copilot AI requested a review from Goooler May 13, 2026 09:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PackageInfoFlags on API 33+ with an older-API fallback.
  • Update launcher activity resolution query to use ResolveInfoFlags on 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 Kotlin allWarningsAsErrors=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.

Comment thread glue/src/main/kotlin/com/github/kr328/clash/glue/util/Intent.kt Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. With allWarningsAsErrors=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)
  }

@Goooler Goooler merged commit 6c6f5e8 into trunk May 13, 2026
8 checks passed
@Goooler Goooler deleted the copilot/migrate-package-manager-api branch May 13, 2026 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate PackageManager.getInstalledPackages

3 participants