diff options
| author | 2016-02-21 16:00:03 +0900 | |
|---|---|---|
| committer | 2016-02-23 16:45:42 +0900 | |
| commit | 5c690557cce825024f5dc9e5e686f256155691a3 (patch) | |
| tree | c0d7697ff2dfbf6dd0f80ee1e8662338a730970e | |
| parent | 073f5aaec7256a693dbe09489ddd433ea8267898 (diff) | |
Delete disconnected row when the corresponding remote file is deleted in a
MTP device.
The CL has MtpDatabase remove file metadata for the case.
1. Files app opens a MTP device. MtpDocumentsProvider stores the
metadata of files in MtpDatabase.
2. A user disconnects the MTP device. MtpDatabase marks the files
metadata as disconnected.
3. A user operates the MTP device and deletes a file in the MTP device.
4. A user connects the MTP device to Android again, and opens the MTP
device again in Files app.
5. MtpDocumentsProvider updates the metadata of files, it should delete
metadata of a file that was deleted at step 3.
BUG=27280143
Change-Id: I79b8df2457cd5b36d1706a9c6e3827c8e7d16208
| -rw-r--r-- | packages/MtpDocumentsProvider/src/com/android/mtp/Mapper.java | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/packages/MtpDocumentsProvider/src/com/android/mtp/Mapper.java b/packages/MtpDocumentsProvider/src/com/android/mtp/Mapper.java index 5e3417aa91f5..48e49fead0fc 100644 --- a/packages/MtpDocumentsProvider/src/com/android/mtp/Mapper.java +++ b/packages/MtpDocumentsProvider/src/com/android/mtp/Mapper.java @@ -162,9 +162,8 @@ class Mapper { /** * Starts adding new documents. - * The methods decides mapping mode depends on if all documents under the given parent have MTP - * identifier or not. If all the documents have MTP identifier, it uses the identifier to find - * a corresponding existing row. Otherwise it does heuristic. + * It changes the direct child documents of the given document from VALID to INVALIDATED. + * Note that it keeps DISCONNECTED documents as they are. * * @param parentDocumentId Parent document ID or NULL for root documents. * @throws FileNotFoundException @@ -286,12 +285,16 @@ class Mapper { } /** - * Maps 'pending' document and 'invalidated' document that shares the same column of groupKey. - * If the database does not find corresponding 'invalidated' document, it just removes - * 'invalidated' document from the database. + * Stops adding documents. + * It handles 'invalidated' and 'disconnected' documents which we don't put corresponding + * documents so far. + * If the type adding document is 'device' or 'storage', the document may appear again + * afterward. The method marks such documents as 'disconnected'. If the type of adding document + * is 'object', it seems the documents are really removed from the remote MTP device. So the + * method deletes the metadata from the database. * * @param parentId Parent document ID or null for root documents. - * @return Whether the methods adds or removed visible rows. + * @return Whether the methods changes file metadata in database. * @throws FileNotFoundException */ boolean stopAddingDocuments(@Nullable String parentId) throws FileNotFoundException { @@ -313,7 +316,9 @@ class Mapper { mInMappingIds.remove(parentId); boolean changed = false; - // Delete/disconnect all invalidated rows that cannot be mapped. + // Delete/disconnect all invalidated/disconnected rows that cannot be mapped. + // If parentIdentifier is null, added documents are devices. + // if parentIdentifier is DOCUMENT_TYPE_DEVICE, added documents are storages. final boolean keepUnmatchedDocument = parentIdentifier == null || parentIdentifier.mDocumentType == DOCUMENT_TYPE_DEVICE; @@ -325,8 +330,9 @@ class Mapper { } } else { if (mDatabase.deleteDocumentsAndRootsRecursively( - COLUMN_ROW_STATE + " = ? AND " + selection, - DatabaseUtils.appendSelectionArgs(strings(ROW_STATE_INVALIDATED), args))) { + COLUMN_ROW_STATE + " IN (?, ?) AND " + selection, + DatabaseUtils.appendSelectionArgs( + strings(ROW_STATE_INVALIDATED, ROW_STATE_DISCONNECTED), args))) { changed = true; } } |