首页 > 代码库 > F-droid源码片段(一)

F-droid源码片段(一)

 

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());
            }
        }
    }

 

F-droid源码片段(一)