Source:
<code>public synchronized void startMonitoring() { log("Monitoring"); List<PackageInfo> apps = mPackageManager.getInstalledPackages(GET_PERMISSIONS | <START> MATCH_KNOWN_PACKAGES); <END> if (apps == null) { loge("No apps"); return; } SparseIntArray netdPermsUids = new SparseIntArray(); for (PackageInfo app : apps) { int uid = app.applicationInfo != null ? app.applicationInfo.uid : INVALID_UID; if (uid < 0) { continue; } boolean isNetwork = hasNetworkPermission(app); boolean hasRestrictedPermission = hasRestrictedNetworkPermission(app); if (isNetwork || hasRestrictedPermission) { Boolean permission = mApps.get(uid); if (permission == null || permission == NETWORK) { mApps.put(uid, hasRestrictedPermission); } } if (app.requestedPermissions != null) { int otherNetdPerms = filterPermission(Arrays.asList(app.requestedPermissions)); if (otherNetdPerms != 0) { netdPermsUids.put(uid, netdPermsUids.get(uid) | otherNetdPerms); mPackageNameUidMap.put(app.applicationInfo.packageName, uid); } } } List<UserInfo> users = mUserManager.getUsers(true); if (users != null) { for (UserInfo user : users) { mUsers.add(user.id); } } log("Users: " + mUsers.size() + ", Apps: " + mApps.size()); update(mUsers, mApps, true); sendPackagesPermissionsToNetd(netdPermsUids); PackageManagerInternal pmi = LocalServices.getService(PackageManagerInternal.class); pmi.getPackageList(new PackageListObserver()); }</code><technical_language>MATCH_KNOWN_PACKAGES is MATCH_UNINSTALLED_PACKAGES | MATCH_ANY_USER. MATCH_UNINSTALLED_PACKAGES include packages want, I think: * Flag parameter retrieve some information applications (even * uninstalled ones) data directories. This state * resulted if applications deleted flag * {@code DONT_DELETE_DATA} a possibility of replaced * reinstalled in future. want is MATCH_ANY_USER</technical_language>

Target:
public synchronized void startMonitoring() { log("Monitoring"); PackageManagerInternal pmi = LocalServices.getService(PackageManagerInternal.class); pmi.getPackageList(new PackageListObserver()); List<PackageInfo> apps = mPackageManager.getInstalledPackages(GET_PERMISSIONS | MATCH_ANY_USER); if (apps == null) { loge("No apps"); return; } SparseIntArray netdPermsUids = new SparseIntArray(); for (PackageInfo app : apps) { int uid = app.applicationInfo != null ? app.applicationInfo.uid : INVALID_UID; if (uid < 0) { continue; } boolean isNetwork = hasNetworkPermission(app); boolean hasRestrictedPermission = hasRestrictedNetworkPermission(app); if (isNetwork || hasRestrictedPermission) { Boolean permission = mApps.get(uid); if (permission == null || permission == NETWORK) { mApps.put(uid, hasRestrictedPermission); } } if (app.requestedPermissions != null) { int otherNetdPerms = filterPermission(Arrays.asList(app.requestedPermissions)); if (otherNetdPerms != 0) { netdPermsUids.put(uid, netdPermsUids.get(uid) | otherNetdPerms); synchronized (mPackageNameUidMap) { mPackageNameUidMap.put(app.applicationInfo.packageName, uid); } } } } List<UserInfo> users = mUserManager.getUsers(true); if (users != null) { for (UserInfo user : users) { mUsers.add(user.id); } } log("Users: " + mUsers.size() + ", Apps: " + mApps.size()); update(mUsers, mApps, true); sendPackagePermissionsToNetd(netdPermsUids); }