Merge "Add archive support to Bug report docs provider." into nyc-dev
This commit is contained in:
@@ -5,7 +5,8 @@ LOCAL_MODULE_TAGS := optional
|
|||||||
|
|
||||||
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||||
|
|
||||||
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4
|
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4 \
|
||||||
|
android-support-documents-archive
|
||||||
|
|
||||||
LOCAL_PACKAGE_NAME := Shell
|
LOCAL_PACKAGE_NAME := Shell
|
||||||
LOCAL_CERTIFICATE := platform
|
LOCAL_CERTIFICATE := platform
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import android.os.ParcelFileDescriptor;
|
|||||||
import android.provider.DocumentsContract.Document;
|
import android.provider.DocumentsContract.Document;
|
||||||
import android.provider.DocumentsContract.Root;
|
import android.provider.DocumentsContract.Root;
|
||||||
import android.provider.DocumentsProvider;
|
import android.provider.DocumentsProvider;
|
||||||
|
import android.support.provider.DocumentArchiveHelper;
|
||||||
import android.webkit.MimeTypeMap;
|
import android.webkit.MimeTypeMap;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -44,10 +45,12 @@ public class BugreportStorageProvider extends DocumentsProvider {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private File mRoot;
|
private File mRoot;
|
||||||
|
private DocumentArchiveHelper mArchiveHelper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreate() {
|
public boolean onCreate() {
|
||||||
mRoot = new File(getContext().getFilesDir(), "bugreports");
|
mRoot = new File(getContext().getFilesDir(), "bugreports");
|
||||||
|
mArchiveHelper = new DocumentArchiveHelper(this, (char) 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,6 +69,10 @@ public class BugreportStorageProvider extends DocumentsProvider {
|
|||||||
@Override
|
@Override
|
||||||
public Cursor queryDocument(String documentId, String[] projection)
|
public Cursor queryDocument(String documentId, String[] projection)
|
||||||
throws FileNotFoundException {
|
throws FileNotFoundException {
|
||||||
|
if (mArchiveHelper.isArchivedDocument(documentId)) {
|
||||||
|
return mArchiveHelper.queryDocument(documentId, projection);
|
||||||
|
}
|
||||||
|
|
||||||
final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
|
final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
|
||||||
if (DOC_ID_ROOT.equals(documentId)) {
|
if (DOC_ID_ROOT.equals(documentId)) {
|
||||||
final RowBuilder row = result.newRow();
|
final RowBuilder row = result.newRow();
|
||||||
@@ -84,6 +91,11 @@ public class BugreportStorageProvider extends DocumentsProvider {
|
|||||||
public Cursor queryChildDocuments(
|
public Cursor queryChildDocuments(
|
||||||
String parentDocumentId, String[] projection, String sortOrder)
|
String parentDocumentId, String[] projection, String sortOrder)
|
||||||
throws FileNotFoundException {
|
throws FileNotFoundException {
|
||||||
|
if (mArchiveHelper.isArchivedDocument(parentDocumentId) ||
|
||||||
|
mArchiveHelper.isSupportedArchiveType(getDocumentType(parentDocumentId))) {
|
||||||
|
return mArchiveHelper.queryChildDocuments(parentDocumentId, projection, sortOrder);
|
||||||
|
}
|
||||||
|
|
||||||
final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
|
final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
|
||||||
if (DOC_ID_ROOT.equals(parentDocumentId)) {
|
if (DOC_ID_ROOT.equals(parentDocumentId)) {
|
||||||
final File[] files = mRoot.listFiles();
|
final File[] files = mRoot.listFiles();
|
||||||
@@ -100,6 +112,10 @@ public class BugreportStorageProvider extends DocumentsProvider {
|
|||||||
public ParcelFileDescriptor openDocument(
|
public ParcelFileDescriptor openDocument(
|
||||||
String documentId, String mode, CancellationSignal signal)
|
String documentId, String mode, CancellationSignal signal)
|
||||||
throws FileNotFoundException {
|
throws FileNotFoundException {
|
||||||
|
if (mArchiveHelper.isArchivedDocument(documentId)) {
|
||||||
|
return mArchiveHelper.openDocument(documentId, mode, signal);
|
||||||
|
}
|
||||||
|
|
||||||
if (ParcelFileDescriptor.parseMode(mode) != ParcelFileDescriptor.MODE_READ_ONLY) {
|
if (ParcelFileDescriptor.parseMode(mode) != ParcelFileDescriptor.MODE_READ_ONLY) {
|
||||||
throw new FileNotFoundException("Failed to open: " + documentId + ", mode = " + mode);
|
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) {
|
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();
|
final RowBuilder row = result.newRow();
|
||||||
row.add(Document.COLUMN_DOCUMENT_ID, getDocIdForFile(file));
|
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_DISPLAY_NAME, file.getName());
|
||||||
row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified());
|
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());
|
row.add(Document.COLUMN_SIZE, file.length());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user