Loading src/com/android/documentsui/CopyService.java +10 −3 Original line number Diff line number Diff line Loading @@ -502,6 +502,11 @@ public class CopyService extends IntentService { // If the file is virtual, but can be converted to another format, then try to copy it // as such format. Also, append an extension for the target mime type (if known). if (srcInfo.isVirtualDocument()) { if (!srcInfo.isTypedDocument()) { // Impossible to copy a file which is virtual, but not typed. mFailedFiles.add(srcInfo); return false; } final String[] streamTypes = getContentResolver().getStreamTypes( srcInfo.derivedUri, "*/*"); if (streamTypes != null && streamTypes.length > 0) { Loading @@ -511,7 +516,8 @@ public class CopyService extends IntentService { dstDisplayName = srcInfo.displayName + (extension != null ? "." + extension : srcInfo.displayName); } else { // The virtual file is not available as any alternative streamable format. // The provider says that it supports typed documents, but doesn't say // anything about available formats. // TODO: Log failures. b/26192412 mFailedFiles.add(srcInfo); return false; Loading Loading @@ -634,8 +640,9 @@ public class CopyService extends IntentService { boolean success = true; try { // If the file is virtual, then try to copy it as an alternative format. if (srcInfo.isVirtualDocument()) { // If the file is virtual, but can be converted to another format, then try to copy it // as such format. if (srcInfo.isVirtualDocument() && srcInfo.isTypedDocument()) { final AssetFileDescriptor srcFileAsAsset = mSrcClient.openTypedAssetFileDescriptor( srcInfo.derivedUri, mimeType, null, canceller); Loading src/com/android/documentsui/model/DocumentInfo.java +4 −0 Original line number Diff line number Diff line Loading @@ -255,6 +255,10 @@ public class DocumentInfo implements Durable, Parcelable { return (flags & Document.FLAG_VIRTUAL_DOCUMENT) != 0; } public boolean isTypedDocument() { return (flags & Document.FLAG_SUPPORTS_TYPED_DOCUMENT) != 0; } public int hashCode() { return derivedUri.hashCode() + mimeType.hashCode(); } Loading tests/src/com/android/documentsui/CopyServiceTest.java +3 −1 Original line number Diff line number Diff line Loading @@ -311,8 +311,10 @@ public class CopyServiceTest extends ServiceTestCase<CopyService> { public void testCopyVirtualNonTypedFile() throws Exception { String srcPath = "/non-typed.sth"; // Empty stream types causes the FLAG_SUPPORTS_TYPED_DOCUMENT to be not set. ArrayList<String> streamTypes = new ArrayList<>(); Uri testFile = mStorage.createVirtualFile(SRC_ROOT, srcPath, "virtual/mime-type", null /* streamTypes */, "I love Tokyo!".getBytes()); streamTypes, "I love Tokyo!".getBytes()); Intent intent = createCopyIntent(Lists.newArrayList(testFile)); startService(intent); Loading tests/src/com/android/documentsui/StubProvider.java +10 −4 Original line number Diff line number Diff line Loading @@ -316,9 +316,12 @@ public class StubProvider extends DocumentsProvider { String documentId, String mimeTypeFilter, Bundle opts, CancellationSignal signal) throws FileNotFoundException { final StubDocument document = mStorage.get(documentId); if (document == null || !document.file.isFile() || document.streamTypes == null) { if (document == null || !document.file.isFile()) { throw new FileNotFoundException(); } if ((document.flags & Document.FLAG_SUPPORTS_TYPED_DOCUMENT) == 0) { throw new IllegalStateException("Tried to open a non-typed document as typed."); } for (final String mimeType : document.streamTypes) { // Strict compare won't accept wildcards, but that's OK for tests, as DocumentsUI // doesn't use them for getStreamTypes nor openTypedDocument. Loading Loading @@ -346,13 +349,13 @@ public class StubProvider extends DocumentsProvider { throw new IllegalArgumentException( "The provided Uri is incorrect, or the file is gone."); } if ((document.flags & Document.FLAG_SUPPORTS_TYPED_DOCUMENT) == 0) { return null; } if (!"*/*".equals(mimeTypeFilter)) { // Not used by DocumentsUI, so don't bother implementing it. throw new UnsupportedOperationException(); } if (document.streamTypes == null) { return null; } return document.streamTypes.toArray(new String[document.streamTypes.size()]); } Loading Loading @@ -625,6 +628,9 @@ public class StubProvider extends DocumentsProvider { File file, String mimeType, List<String> streamTypes, StubDocument parent) { int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE | Document.FLAG_VIRTUAL_DOCUMENT; if (streamTypes.size() > 0) { flags |= Document.FLAG_SUPPORTS_TYPED_DOCUMENT; } return new StubDocument(file, mimeType, streamTypes, flags, parent); } Loading Loading
src/com/android/documentsui/CopyService.java +10 −3 Original line number Diff line number Diff line Loading @@ -502,6 +502,11 @@ public class CopyService extends IntentService { // If the file is virtual, but can be converted to another format, then try to copy it // as such format. Also, append an extension for the target mime type (if known). if (srcInfo.isVirtualDocument()) { if (!srcInfo.isTypedDocument()) { // Impossible to copy a file which is virtual, but not typed. mFailedFiles.add(srcInfo); return false; } final String[] streamTypes = getContentResolver().getStreamTypes( srcInfo.derivedUri, "*/*"); if (streamTypes != null && streamTypes.length > 0) { Loading @@ -511,7 +516,8 @@ public class CopyService extends IntentService { dstDisplayName = srcInfo.displayName + (extension != null ? "." + extension : srcInfo.displayName); } else { // The virtual file is not available as any alternative streamable format. // The provider says that it supports typed documents, but doesn't say // anything about available formats. // TODO: Log failures. b/26192412 mFailedFiles.add(srcInfo); return false; Loading Loading @@ -634,8 +640,9 @@ public class CopyService extends IntentService { boolean success = true; try { // If the file is virtual, then try to copy it as an alternative format. if (srcInfo.isVirtualDocument()) { // If the file is virtual, but can be converted to another format, then try to copy it // as such format. if (srcInfo.isVirtualDocument() && srcInfo.isTypedDocument()) { final AssetFileDescriptor srcFileAsAsset = mSrcClient.openTypedAssetFileDescriptor( srcInfo.derivedUri, mimeType, null, canceller); Loading
src/com/android/documentsui/model/DocumentInfo.java +4 −0 Original line number Diff line number Diff line Loading @@ -255,6 +255,10 @@ public class DocumentInfo implements Durable, Parcelable { return (flags & Document.FLAG_VIRTUAL_DOCUMENT) != 0; } public boolean isTypedDocument() { return (flags & Document.FLAG_SUPPORTS_TYPED_DOCUMENT) != 0; } public int hashCode() { return derivedUri.hashCode() + mimeType.hashCode(); } Loading
tests/src/com/android/documentsui/CopyServiceTest.java +3 −1 Original line number Diff line number Diff line Loading @@ -311,8 +311,10 @@ public class CopyServiceTest extends ServiceTestCase<CopyService> { public void testCopyVirtualNonTypedFile() throws Exception { String srcPath = "/non-typed.sth"; // Empty stream types causes the FLAG_SUPPORTS_TYPED_DOCUMENT to be not set. ArrayList<String> streamTypes = new ArrayList<>(); Uri testFile = mStorage.createVirtualFile(SRC_ROOT, srcPath, "virtual/mime-type", null /* streamTypes */, "I love Tokyo!".getBytes()); streamTypes, "I love Tokyo!".getBytes()); Intent intent = createCopyIntent(Lists.newArrayList(testFile)); startService(intent); Loading
tests/src/com/android/documentsui/StubProvider.java +10 −4 Original line number Diff line number Diff line Loading @@ -316,9 +316,12 @@ public class StubProvider extends DocumentsProvider { String documentId, String mimeTypeFilter, Bundle opts, CancellationSignal signal) throws FileNotFoundException { final StubDocument document = mStorage.get(documentId); if (document == null || !document.file.isFile() || document.streamTypes == null) { if (document == null || !document.file.isFile()) { throw new FileNotFoundException(); } if ((document.flags & Document.FLAG_SUPPORTS_TYPED_DOCUMENT) == 0) { throw new IllegalStateException("Tried to open a non-typed document as typed."); } for (final String mimeType : document.streamTypes) { // Strict compare won't accept wildcards, but that's OK for tests, as DocumentsUI // doesn't use them for getStreamTypes nor openTypedDocument. Loading Loading @@ -346,13 +349,13 @@ public class StubProvider extends DocumentsProvider { throw new IllegalArgumentException( "The provided Uri is incorrect, or the file is gone."); } if ((document.flags & Document.FLAG_SUPPORTS_TYPED_DOCUMENT) == 0) { return null; } if (!"*/*".equals(mimeTypeFilter)) { // Not used by DocumentsUI, so don't bother implementing it. throw new UnsupportedOperationException(); } if (document.streamTypes == null) { return null; } return document.streamTypes.toArray(new String[document.streamTypes.size()]); } Loading Loading @@ -625,6 +628,9 @@ public class StubProvider extends DocumentsProvider { File file, String mimeType, List<String> streamTypes, StubDocument parent) { int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE | Document.FLAG_VIRTUAL_DOCUMENT; if (streamTypes.size() > 0) { flags |= Document.FLAG_SUPPORTS_TYPED_DOCUMENT; } return new StubDocument(file, mimeType, streamTypes, flags, parent); } Loading