Android早期版本实现原理请看 Android源码分析-pm命令的实现,列出包名pm list package,列出系统库pm list libraries_pm list packages-CSDN博客
Android12 对adb shell pm 实现原理做了重构:改成了template模式PackageManagerShellCommand extends ShellCommand
adb shell pm list package -3 源码:
adb shell pm 会初始化1个PackageManagerShellCommand对象,
com.android.server.pm.PackageManagerShellCommand#onCommand


final boolean isSystem = !isApex &&
(info.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0;
final boolean isEnabled = !isApex && info.applicationInfo.enabled;
if ((!listDisabled || !isEnabled) &&
(!listEnabled || isEnabled) &&
(!listSystem || isSystem) &&
(!listThirdParty || !isSystem) &&
(!listApexOnly || isApex)) {
pw.print("package:");
是否是3方app主要是看有没有flag:ApplicationInfo.FLAG_SYSTEM
framework已有的api:
ProcessRecord.info.isSystemApp()
android.content.pm.ApplicationInfo#isSystemApp