Search in sources :

Example 31 with MatrixCursor

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

the class HeatMapProvider method queryDocument.

@Override
public Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    // includeFile(result, documentId, null);
    synchronized (mRootsLock) {
        for (String rootId : mIdToPath.keySet()) {
            final RootInfo root = mIdToRoot.get(rootId);
            final File path = mIdToPath.get(rootId);
            final String mimeType = getTypeForFile(path);
            final RowBuilder row = result.newRow();
            // row.add(Document.COLUMN_DOCUMENT_ID, documentId);
            row.add(Document.COLUMN_DOCUMENT_ID, root.docId);
            row.add(Document.COLUMN_FLAGS, root.flags);
            row.add(Document.COLUMN_DISPLAY_NAME, root.title);
            row.add(Document.COLUMN_MIME_TYPE, mimeType);
            row.add(Document.COLUMN_PATH, path.getAbsolutePath());
            if (ROOT_ID_PRIMARY_EMULATED.equals(root.rootId) || root.rootId.startsWith(ROOT_ID_SECONDARY)) {
                row.add(Document.COLUMN_SIZE, path.getFreeSpace());
            }
            if (path.isDirectory() && null != path.list()) {
                String summary = FileUtils.formatFileCount(path.list().length);
                row.add(Document.COLUMN_SUMMARY, summary);
            }
            // Only publish dates reasonably after epoch
            long lastModified = path.lastModified();
            if (lastModified > 31536000000L) {
                row.add(Document.COLUMN_LAST_MODIFIED, lastModified);
            }
        }
    }
    return result;
}
Also used : RowBuilder(dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder) File(java.io.File) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Example 32 with MatrixCursor

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

the class NonMediaDocumentsProvider method queryDocument.

@Override
public Cursor queryDocument(String docId, String[] projection) throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    final Ident ident = getIdentForDocId(docId);
    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        if (TYPE_DOCUMENT_ROOT.equals(ident.type)) {
            includeFileRootDocument(result, TYPE_DOCUMENT_ROOT, R.string.root_document);
        } else if (TYPE_DOCUMENT.equals(ident.type)) {
            queryFile(resolver, cursor, result, DOCUMENT_MIMES, "text");
        } else if (TYPE_ARCHIVE_ROOT.equals(ident.type)) {
            includeFileRootDocument(result, TYPE_ARCHIVE_ROOT, R.string.root_archive);
        } else if (TYPE_ARCHIVE.equals(ident.type)) {
            queryFile(resolver, cursor, result, ARCHIVE_MIMES);
        } else if (TYPE_APK_ROOT.equals(ident.type)) {
            includeFileRootDocument(result, TYPE_APK_ROOT, R.string.root_apk);
        } else if (TYPE_APK.equals(ident.type)) {
            queryFile(resolver, cursor, result, APK_MIMES);
        } else {
            throw new UnsupportedOperationException("Unsupported document " + docId);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
Also used : MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor) Cursor(android.database.Cursor) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor) ContentResolver(android.content.ContentResolver)

Example 33 with MatrixCursor

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

the class NonMediaDocumentsProvider method queryChildDocuments.

@Override
public Cursor queryChildDocuments(String docId, String[] projection, String sortOrder) throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    final Ident ident = getIdentForDocId(docId);
    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        if (TYPE_DOCUMENT_ROOT.equals(ident.type)) {
            queryFile(resolver, cursor, result, DOCUMENT_MIMES, "text");
        } else if (TYPE_ARCHIVE_ROOT.equals(ident.type)) {
            queryFile(resolver, cursor, result, ARCHIVE_MIMES);
        } else if (TYPE_APK_ROOT.equals(ident.type)) {
            queryFile(resolver, cursor, result, APK_MIMES);
        } else {
            throw new UnsupportedOperationException("Unsupported document " + docId);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
Also used : MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor) Cursor(android.database.Cursor) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor) ContentResolver(android.content.ContentResolver)

Example 34 with MatrixCursor

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

the class RootedStorageProvider method querySearchDocuments.

@SuppressWarnings("unused")
@Override
public Cursor querySearchDocuments(String rootId, String query, String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    final RootFile parent;
    synchronized (mRootsLock) {
        parent = mRoots.get(rootId).path;
    }
    try {
        BufferedReader br = RootCommands.findFiles(parent.getPath(), query);
        if (null != br) {
            Scanner scanner = new Scanner(br);
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                try {
                    includeRootFile(result, null, new RootFile(parent, line));
                } catch (Exception e) {
                    CrashReportingManager.logException(e);
                }
            }
            scanner.close();
        }
    } catch (Exception e) {
        CrashReportingManager.logException(e);
    }
    return result;
}
Also used : Scanner(java.util.Scanner) BufferedReader(java.io.BufferedReader) RootFile(dev.dworks.apps.anexplorer.root.RootFile) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 35 with MatrixCursor

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

the class RootedStorageProvider method queryChildDocuments.

@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException {
    final RootFile parent = getRootFileForDocId(parentDocumentId);
    final MatrixCursor result = new DirectoryCursor(resolveDocumentProjection(projection), parentDocumentId, parent);
    try {
        BufferedReader br = RootCommands.listFiles(parent.getPath());
        if (null != br) {
            Scanner scanner = new Scanner(br);
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                try {
                    includeRootFile(result, null, new RootFile(parent, line));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            scanner.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}
Also used : Scanner(java.util.Scanner) BufferedReader(java.io.BufferedReader) RootFile(dev.dworks.apps.anexplorer.root.RootFile) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

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