summaryrefslogtreecommitdiffstats
path: root/packages/DocumentsUI/tests
diff options
context:
space:
mode:
authorTomasz Mikolajewski <mtomasz@google.com>2015-04-13 13:27:14 +0900
committerTomasz Mikolajewski <mtomasz@google.com>2015-04-13 13:35:23 +0900
commit97397938c44252dde51207b675225703984783a3 (patch)
treeb6f4582625336239b85d35a0a41b526d65df7095 /packages/DocumentsUI/tests
parentd5d5c91dfc1a718207f3b57b3809ee1d09200bcd (diff)
downloadframeworks_base-97397938c44252dde51207b675225703984783a3.zip
frameworks_base-97397938c44252dde51207b675225703984783a3.tar.gz
frameworks_base-97397938c44252dde51207b675225703984783a3.tar.bz2
Add support for notifying about child changes in StubProvider.
Change-Id: I256856a2bbefa6d831e6b912583eca86eeb03ba7
Diffstat (limited to 'packages/DocumentsUI/tests')
-rw-r--r--packages/DocumentsUI/tests/src/com/android/documentsui/StubProvider.java33
1 files changed, 21 insertions, 12 deletions
diff --git a/packages/DocumentsUI/tests/src/com/android/documentsui/StubProvider.java b/packages/DocumentsUI/tests/src/com/android/documentsui/StubProvider.java
index 0ba8ed1..75effa7 100644
--- a/packages/DocumentsUI/tests/src/com/android/documentsui/StubProvider.java
+++ b/packages/DocumentsUI/tests/src/com/android/documentsui/StubProvider.java
@@ -70,7 +70,7 @@ public class StubProvider extends DocumentsProvider {
public boolean onCreate() {
final File cacheDir = getContext().getCacheDir();
removeRecursively(cacheDir);
- final StubDocument document = new StubDocument(cacheDir, Document.MIME_TYPE_DIR);
+ final StubDocument document = new StubDocument(cacheDir, Document.MIME_TYPE_DIR, null);
mRootDocumentId = document.documentId;
mStorage.put(mRootDocumentId, document);
return true;
@@ -95,7 +95,7 @@ public class StubProvider extends DocumentsProvider {
if (file == null) {
throw new FileNotFoundException();
}
- includeFile(result, file);
+ includeDocument(result, file);
return result;
}
@@ -129,8 +129,9 @@ public class StubProvider extends DocumentsProvider {
}
}
- final StubDocument document = new StubDocument(file, mimeType);
+ final StubDocument document = new StubDocument(file, mimeType, parentDocument);
mStorage.put(document.documentId, document);
+ notifyParentChanged(document.parentId);
return document.documentId;
}
@@ -144,22 +145,25 @@ public class StubProvider extends DocumentsProvider {
synchronized (mWriteLock) {
mStorageUsedBytes -= fileSize;
}
- notifyStorageChanged();
+ notifyParentChanged(document.parentId);
}
@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder)
throws FileNotFoundException {
- final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION);
final StubDocument parentDocument = mStorage.get(parentDocumentId);
if (parentDocument == null || parentDocument.file.isFile()) {
throw new FileNotFoundException();
}
+ final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION);
+ result.setNotificationUri(getContext().getContentResolver(),
+ DocumentsContract.buildChildDocumentsUri(mAuthority, parentDocumentId));
StubDocument document;
for (File file : parentDocument.file.listFiles()) {
document = mStorage.get(StubDocument.getDocumentIdForFile(file));
- if (document != null)
- includeFile(result, document);
+ if (document != null) {
+ includeDocument(result, document);
+ }
}
return result;
}
@@ -235,7 +239,7 @@ public class StubProvider extends DocumentsProvider {
}
finally {
closePipeSilently(readPipe);
- notifyStorageChanged();
+ notifyParentChanged(document.parentId);
}
}
}.start();
@@ -259,11 +263,14 @@ public class StubProvider extends DocumentsProvider {
}
}
- private void notifyStorageChanged() {
+ private void notifyParentChanged(String parentId) {
+ getContext().getContentResolver().notifyChange(
+ DocumentsContract.buildChildDocumentsUri(mAuthority, parentId), null, false);
+ // Notify also about possible change in remaining space on the root.
getContext().getContentResolver().notifyChange(DocumentsContract.buildRootsUri(mAuthority), null, false);
}
- private void includeFile(MatrixCursor result, StubDocument document) {
+ private void includeDocument(MatrixCursor result, StubDocument document) {
final RowBuilder row = result.newRow();
row.add(Document.COLUMN_DOCUMENT_ID, document.documentId);
row.add(Document.COLUMN_DISPLAY_NAME, document.file.getName());
@@ -294,11 +301,13 @@ class StubDocument {
public final File file;
public final String mimeType;
public final String documentId;
+ public final String parentId;
- StubDocument(File file, String mimeType) {
+ StubDocument(File file, String mimeType, StubDocument parent) {
this.file = file;
- this.mimeType = this.mimeType;
+ this.mimeType = mimeType;
this.documentId = getDocumentIdForFile(file);
+ this.parentId = parent != null ? parent.documentId : null;
}
public static String getDocumentIdForFile(File file) {