diff options
| author | 2016-04-26 15:49:50 -0700 | |
|---|---|---|
| committer | 2016-04-27 16:46:16 -0700 | |
| commit | 53a528bb4f4cdb5a8d07b0d91405fdb2edb62201 (patch) | |
| tree | bfd00cbf2a9a0e1e1bef2bc5dba3034497067d55 /packages/Shell/src | |
| parent | 477af0d4ea0042b8e05084c80ff6960b41d9ef12 (diff) | |
Add archive support to Bug report docs provider.
Bug: 28386918
Change-Id: I2270324be3f020d73a68151002f885f70eb1449c
Diffstat (limited to 'packages/Shell/src')
| -rw-r--r-- | packages/Shell/src/com/android/shell/BugreportStorageProvider.java | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/packages/Shell/src/com/android/shell/BugreportStorageProvider.java b/packages/Shell/src/com/android/shell/BugreportStorageProvider.java index 814aa8cb8c06..0f92fa6e8add 100644 --- a/packages/Shell/src/com/android/shell/BugreportStorageProvider.java +++ b/packages/Shell/src/com/android/shell/BugreportStorageProvider.java @@ -25,6 +25,7 @@ import android.os.ParcelFileDescriptor; import android.provider.DocumentsContract.Document; import android.provider.DocumentsContract.Root; import android.provider.DocumentsProvider; +import android.support.provider.DocumentArchiveHelper; import android.webkit.MimeTypeMap; import java.io.File; @@ -44,10 +45,12 @@ public class BugreportStorageProvider extends DocumentsProvider { }; private File mRoot; + private DocumentArchiveHelper mArchiveHelper; @Override public boolean onCreate() { mRoot = new File(getContext().getFilesDir(), "bugreports"); + mArchiveHelper = new DocumentArchiveHelper(this, (char) 0); return true; } @@ -66,6 +69,10 @@ public class BugreportStorageProvider extends DocumentsProvider { @Override public Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException { + if (mArchiveHelper.isArchivedDocument(documentId)) { + return mArchiveHelper.queryDocument(documentId, projection); + } + final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection)); if (DOC_ID_ROOT.equals(documentId)) { final RowBuilder row = result.newRow(); @@ -84,6 +91,11 @@ public class BugreportStorageProvider extends DocumentsProvider { public Cursor queryChildDocuments( String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException { + if (mArchiveHelper.isArchivedDocument(parentDocumentId) || + mArchiveHelper.isSupportedArchiveType(getDocumentType(parentDocumentId))) { + return mArchiveHelper.queryChildDocuments(parentDocumentId, projection, sortOrder); + } + final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection)); if (DOC_ID_ROOT.equals(parentDocumentId)) { final File[] files = mRoot.listFiles(); @@ -100,6 +112,10 @@ public class BugreportStorageProvider extends DocumentsProvider { public ParcelFileDescriptor openDocument( String documentId, String mode, CancellationSignal signal) throws FileNotFoundException { + if (mArchiveHelper.isArchivedDocument(documentId)) { + return mArchiveHelper.openDocument(documentId, mode, signal); + } + if (ParcelFileDescriptor.parseMode(mode) != ParcelFileDescriptor.MODE_READ_ONLY) { throw new FileNotFoundException("Failed to open: " + documentId + ", mode = " + mode); } @@ -153,12 +169,18 @@ public class BugreportStorageProvider extends DocumentsProvider { } private void addFileRow(MatrixCursor result, File file) { + String mimeType = getTypeForName(file.getName()); + int flags = Document.FLAG_SUPPORTS_DELETE; + if (mArchiveHelper.isSupportedArchiveType(mimeType)) { + flags |= Document.FLAG_ARCHIVE; + } + final RowBuilder row = result.newRow(); row.add(Document.COLUMN_DOCUMENT_ID, getDocIdForFile(file)); - row.add(Document.COLUMN_MIME_TYPE, getTypeForName(file.getName())); + row.add(Document.COLUMN_MIME_TYPE, mimeType); row.add(Document.COLUMN_DISPLAY_NAME, file.getName()); row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified()); - row.add(Document.COLUMN_FLAGS, Document.FLAG_SUPPORTS_DELETE); + row.add(Document.COLUMN_FLAGS, flags); row.add(Document.COLUMN_SIZE, file.length()); } } |