Add StubProvider::isChildDocument().
Change-Id: Ib17df4307c1f658c42468f86e1f66d4469eefe58
This commit is contained in:
@@ -23,6 +23,7 @@ import android.database.MatrixCursor.RowBuilder;
|
||||
import android.database.MatrixCursor;
|
||||
import android.graphics.Point;
|
||||
import android.os.CancellationSignal;
|
||||
import android.os.FileUtils;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.provider.DocumentsContract.Document;
|
||||
import android.provider.DocumentsContract.Root;
|
||||
@@ -66,7 +67,7 @@ public class StubProvider extends DocumentsProvider {
|
||||
final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_ROOT_PROJECTION);
|
||||
final RowBuilder row = result.newRow();
|
||||
row.add(Root.COLUMN_ROOT_ID, MY_ROOT_ID);
|
||||
row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE);
|
||||
row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_IS_CHILD);
|
||||
row.add(Root.COLUMN_TITLE, "Foobar SD 4GB");
|
||||
row.add(Root.COLUMN_DOCUMENT_ID, mRootDocumentId);
|
||||
row.add(Root.COLUMN_AVAILABLE_BYTES, STORAGE_SIZE - mStorageUsedBytes);
|
||||
@@ -84,6 +85,17 @@ public class StubProvider extends DocumentsProvider {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChildDocument(String parentDocId, String docId) {
|
||||
try {
|
||||
final File parentFile = getFileForDocumentId(parentDocId).getCanonicalFile();
|
||||
final File childFile = getFileForDocumentId(docId).getCanonicalFile();
|
||||
return FileUtils.contains(parentFile, childFile);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createDocument(String parentDocumentId, String mimeType, String displayName)
|
||||
throws FileNotFoundException {
|
||||
@@ -170,6 +182,10 @@ public class StubProvider extends DocumentsProvider {
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
|
||||
private File getFileForDocumentId(String documentId) {
|
||||
return new File(documentId);
|
||||
}
|
||||
|
||||
private void removeRecursively(File file) {
|
||||
for (File childFile : file.listFiles()) {
|
||||
if (childFile.isDirectory()) {
|
||||
|
||||
Reference in New Issue
Block a user