I want to list all apps that use internet, I see this feature from the app WireGuard, this is how it does(link to the code):
val packageInfos = getPackagesHoldingPermissions(pm, arrayOf(Manifest.permission.INTERNET))
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)
}
}
It shows all apps, including non-system apps like whatsapp or any third party apps.
Then I tried this code in my app, but it only shows apps like "com.android.x" and "com.google.x", there are no non-system apps at all. I thought it might be caused by permission, I deleted all permissions in WireGuard's Manifest.xml, and it still works, so I think it's not caused by permission, but why is that?
WireGuard has:
<queries>
<intent>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent>
</queries>
in its manifest, to address package visibility. My guess is that you do not.