Search in sources :

Example 1 with AppDataSorter

use of com.amaze.filemanager.adapters.data.AppDataSorter in project AmazeFileManager by TeamAmaze.

the class AppListLoader method loadInBackground.

@Override
public List<AppDataParcelable> loadInBackground() {
    List<ApplicationInfo> apps = packageManager.getInstalledApplications(PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS);
    if (apps == null)
        return Collections.emptyList();
    mApps = new ArrayList<>(apps.size());
    PackageInfo androidInfo = null;
    try {
        androidInfo = packageManager.getPackageInfo("android", PackageManager.GET_SIGNATURES);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    for (ApplicationInfo object : apps) {
        if (object.sourceDir == null) {
            continue;
        }
        File sourceDir = new File(object.sourceDir);
        String label = object.loadLabel(packageManager).toString();
        PackageInfo info;
        try {
            info = packageManager.getPackageInfo(object.packageName, PackageManager.GET_SIGNATURES);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            info = null;
        }
        boolean isSystemApp = isAppInSystemPartition(object) || isSignedBySystem(info, androidInfo);
        AppDataParcelable elem = new AppDataParcelable(label == null ? object.packageName : label, object.sourceDir, object.packageName, object.flags + "_" + (info != null ? info.versionName : ""), Formatter.formatFileSize(getContext(), sourceDir.length()), sourceDir.length(), sourceDir.lastModified(), isSystemApp, null);
        mApps.add(elem);
    }
    Collections.sort(mApps, new AppDataSorter(sortBy, isAscending));
    return mApps;
}
Also used : AppDataParcelable(com.amaze.filemanager.adapters.data.AppDataParcelable) AppDataSorter(com.amaze.filemanager.adapters.data.AppDataSorter) PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) File(java.io.File)

Aggregations

ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 AppDataParcelable (com.amaze.filemanager.adapters.data.AppDataParcelable)1 AppDataSorter (com.amaze.filemanager.adapters.data.AppDataSorter)1 File (java.io.File)1