Search in sources :

Example 21 with MatrixCursor

use of dev.dworks.apps.anexplorer.cursor.MatrixCursor in project AnExplorer by 1hakr.

the class AppsProvider method queryChildDocuments.

@Override
public Cursor queryChildDocuments(String docId, String[] projection, String sortOrder) throws FileNotFoundException {
    final MatrixCursor result = new DocumentCursor(resolveDocumentProjection(projection), docId);
    // Delegate to real provider
    final long token = Binder.clearCallingIdentity();
    try {
        if (docId.startsWith(ROOT_ID_USER_APP)) {
            List<PackageInfo> allAppList = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
            for (PackageInfo packageInfo : allAppList) {
                includeAppFromPackage(result, docId, packageInfo, false, null);
            }
        } else if (docId.startsWith(ROOT_ID_SYSTEM_APP)) {
            List<PackageInfo> allAppList = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
            for (PackageInfo packageInfo : allAppList) {
                includeAppFromPackage(result, docId, packageInfo, true, null);
            }
        } else if (docId.startsWith(ROOT_ID_PROCESS)) {
            if (Utils.hasNougat()) {
                List<RunningServiceInfo> runningServices = activityManager.getRunningServices(1000);
                for (RunningServiceInfo process : runningServices) {
                    includeAppFromService(result, docId, process, null);
                }
            } else if (Utils.hasLollipopMR1()) {
                List<AndroidAppProcess> runningAppProcesses = AndroidProcesses.getRunningAppProcesses();
                for (AndroidAppProcess process : runningAppProcesses) {
                    includeAppFromProcess(result, docId, process, null);
                }
            } else {
                List<RunningAppProcessInfo> runningProcessesList = activityManager.getRunningAppProcesses();
                for (RunningAppProcessInfo processInfo : runningProcessesList) {
                    includeAppFromProcess(result, docId, processInfo, null);
                }
            }
        }
    } finally {
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
Also used : RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) PackageInfo(android.content.pm.PackageInfo) RunningServiceInfo(android.app.ActivityManager.RunningServiceInfo) AndroidAppProcess(com.jaredrummler.android.processes.models.AndroidAppProcess) ArrayList(java.util.ArrayList) List(java.util.List) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Example 22 with MatrixCursor

use of dev.dworks.apps.anexplorer.cursor.MatrixCursor in project AnExplorer by 1hakr.

the class DownloadStorageProvider method queryChildDocuments.

@Override
public Cursor queryChildDocuments(String docId, String[] projection, String sortOrder) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    // Delegate to real provider
    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        Query query = new Query();
        DownloadManagerUtils.setOnlyIncludeVisibleInDownloadsUi(query);
        // query.setOnlyIncludeVisibleInDownloadsUi(true);
        query.setFilterByStatus(DownloadManager.STATUS_SUCCESSFUL);
        // query.setFilterByStatus(DownloadManager.STATUS_PENDING | DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_RUNNING | DownloadManager.STATUS_FAILED);
        // .setOnlyIncludeVisibleInDownloadsUi(true)
        cursor = mDm.query(query);
        // copyNotificationUri(result, cursor);
        while (cursor.moveToNext()) {
            includeDownloadFromCursor(result, cursor);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
Also used : Query(android.app.DownloadManager.Query) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor) Cursor(android.database.Cursor) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Example 23 with MatrixCursor

use of dev.dworks.apps.anexplorer.cursor.MatrixCursor in project AnExplorer by 1hakr.

the class DownloadStorageProvider method queryChildDocumentsForManage.

@Override
public Cursor queryChildDocumentsForManage(String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    // Delegate to real provider
    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        cursor = mDm.query(// .setOnlyIncludeVisibleInDownloadsUi(true));
        new DownloadManager.Query());
        // copyNotificationUri(result, cursor);
        while (cursor.moveToNext()) {
            includeDownloadFromCursor(result, cursor);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
Also used : Query(android.app.DownloadManager.Query) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor) Cursor(android.database.Cursor) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Example 24 with MatrixCursor

use of dev.dworks.apps.anexplorer.cursor.MatrixCursor in project AnExplorer by 1hakr.

the class DownloadStorageProvider method queryRoots.

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
    final RowBuilder row = result.newRow();
    row.add(Root.COLUMN_ROOT_ID, DOC_ID_ROOT);
    row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_RECENTS | Root.FLAG_SUPPORTS_CREATE);
    row.add(Root.COLUMN_ICON, R.drawable.ic_root_download);
    row.add(Root.COLUMN_TITLE, getContext().getString(R.string.root_downloads));
    row.add(Root.COLUMN_DOCUMENT_ID, DOC_ID_ROOT);
    return result;
}
Also used : RowBuilder(dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Example 25 with MatrixCursor

use of dev.dworks.apps.anexplorer.cursor.MatrixCursor in project AnExplorer by 1hakr.

the class ExternalStorageProvider method queryRoots.

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
    synchronized (mRootsLock) {
        for (RootInfo root : mRoots.values()) {
            final RowBuilder row = result.newRow();
            row.add(Root.COLUMN_ROOT_ID, root.rootId);
            row.add(Root.COLUMN_FLAGS, root.flags);
            row.add(Root.COLUMN_TITLE, root.title);
            row.add(Root.COLUMN_DOCUMENT_ID, root.docId);
            row.add(Root.COLUMN_PATH, root.path);
            if (ROOT_ID_PRIMARY_EMULATED.equals(root.rootId) || root.rootId.startsWith(ROOT_ID_SECONDARY) || root.rootId.startsWith(ROOT_ID_PHONE)) {
                final File file = root.rootId.startsWith(ROOT_ID_PHONE) ? Environment.getRootDirectory() : root.path;
                row.add(Root.COLUMN_AVAILABLE_BYTES, file.getFreeSpace());
                row.add(Root.COLUMN_CAPACITY_BYTES, file.getTotalSpace());
            }
        }
    }
    return result;
}
Also used : RowBuilder(dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder) FileUtils.getTypeForFile(dev.dworks.apps.anexplorer.misc.FileUtils.getTypeForFile) DocumentFile(android.support.provider.DocumentFile) File(java.io.File) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Aggregations

MatrixCursor (dev.dworks.apps.anexplorer.cursor.MatrixCursor)37 Cursor (android.database.Cursor)10 RowBuilder (dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder)7 ContentResolver (android.content.ContentResolver)6 File (java.io.File)6 FileNotFoundException (java.io.FileNotFoundException)6 IOException (java.io.IOException)5 Query (android.app.DownloadManager.Query)4 DocumentFile (android.support.provider.DocumentFile)3 UsbFile (com.github.mjdev.libaums.fs.UsbFile)3 FileUtils.getTypeForFile (dev.dworks.apps.anexplorer.misc.FileUtils.getTypeForFile)3 ArrayMap (android.support.v4.util.ArrayMap)2 NetworkConnection (dev.dworks.apps.anexplorer.network.NetworkConnection)2 RootFile (dev.dworks.apps.anexplorer.root.RootFile)2 BufferedReader (java.io.BufferedReader)2 Scanner (java.util.Scanner)2 ZipEntry (java.util.zip.ZipEntry)2 RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)1 RunningServiceInfo (android.app.ActivityManager.RunningServiceInfo)1 DownloadManager (android.app.DownloadManager)1