protected boolean update() {
long startTime = System.currentTimeMillis();
compareCacheToPackageManager();
updateCache();
long duration = System.currentTimeMillis() - startTime;
Log.d(TAG, "Took " + duration + "ms to compare the installed app cache with PackageManager.");
return hasChanged();
}
比对系统的已安装的应用,查询需要插入和删除的应用列表
private void compareCacheToPackageManager() {
Map<String, Integer> cachedInfo = InstalledAppProvider.Helper.all(context);
List<PackageInfo> installedPackages = context.getPackageManager().getInstalledPackages(0);
for (PackageInfo appInfo : installedPackages) {
toInsert.add(appInfo);
if (cachedInfo.containsKey(appInfo.packageName)) {
cachedInfo.remove(appInfo.packageName);
}
}
if (cachedInfo.size() > 0) {
for (Map.Entry<String, Integer> entry : cachedInfo.entrySet() ) {
toDelete.add(entry.getKey());
}
}
}