Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5c690557 authored by Daichi Hirono's avatar Daichi Hirono
Browse files

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
parent 073f5aae
Loading
Loading
Loading
Loading
+16 −10
Original line number Diff line number Diff line
@@ -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;
                }
            }