* Check null result for all MTP APIs that can return null.
* Don't regard valid parent handles that are more than 0x80000000 as
error.
* Check boolean result from importFile.
Change-Id: I262511ac3c935ebb54e52c03eaefd3535a3e2f29
Fix: 28155538
For testing, we use blockDocument and unblockDocument test mehtods to
control flow of DocumentLoader's background thread.
Previously testCancelTask may exit before the background thread goes
back from blocking, which causes InterruptedException.
Fixes: 28125289
Change-Id: Id03826733c5b6f1da66b9280838eb1d2897ed5fc
When deleting files, MtpDocumentsProvider clears LoadingTask in
DocumentsLoader to update directory contents list. Previously it can
clear ongoing task, and it skips calling Mapper#stopAddingDocuments.
Since Mapper#startAddingDocuments and Mapper#stopAddingDocuments must be
called 1 to 1, it causes precondition check failure at the next call of
Mapper#startAddingDocuments.
Change-Id: I23e2b117da826297e45404be4db4cc29f96e5510
Fix: 28076320
Previously MtpDocumentsProvider used pipes to transfer bytes from an
application to the provider when writing a document. The problem was
application could not ensure that the last chunk of bytes was
successfully written to MTP device, since pipes had been already closed
when the provider transferred bytes to MTP device. Though the provider
encountered an error, the provider could not report the error to an
application.
The CL switches the method to transfer bytes from pipes to AppFuse. Now
application can flush() bytes on the file descriptor, and flush will not
complete until the provider completes writing bytes to MTP device.
Fixed: 23093747
Change-Id: I4e28f8cbf19d6c97e591943349a7535241d768f7
To open files by using AppFuse, the provider needs to know the size of
file. Previously we cannot open 4G+ files because we cannot obtain file
size for such large files.
Now MtpDatabase contains correct size for 4GB+ file size. The CL starts
opening files by using AppFuse which obtains partial bytes by using
getObjectPartial64 operation.
FIXED=26840097
Change-Id: I1cb41972175c2b98f4aa76981decc6b3ad35486d
MtpObjectInfo contains object size as 32-bit integer and the provider
needs to invoke MtpDevice#getObjectSizeLong hidden API to get 64-bit
object size.
The CL switches to use MtpDevice#getObjectSizeLong hidden API if
MtpObjectInfo#getCompressedSize() returns 0xffffffffL, which means the
object size is more than 4GB.
BUG=27805369
Change-Id: I87ea02c09aa784246cf016def309d1f39ed20e90
The CL adds a handler for FUSE_WRITE command which invokes a Java
handler.
BUG=23093747
Change-Id: I1903fca6b5663e6241ad540a89fe812310ba6810
(cherry picked from commit 35693da25af11583053d4af6a70d4acbf446978d)
Root documents must be added by RootScanner.
Previously DocumentLoader unintentionally tries to load unmapped root
documents, which causes crash.
BUG=27731902
Change-Id: I8674473d80d6e7f758f6636d30148f5d2118bc25
Previously DocumentLoader#LoaderTask had a counter to count loaded
documents and completes adding documents to the database. However it
does not count documents where a MTP device returns an error for
getObjectInfo. The CL fixes the problem to ensure we complete documents
loading.
BUG=27729653
Change-Id: I696eac790a6535f1bd7a1855dc2d6f932e32eae5
If we have an existing file in the destination directory, which has the
same name with the source file, adding suffix number is
DocumentsProvider's responsibility.
Because MTP does not provide a way to check existance of files with
given name, the logic is implemented as try-and error strategy. The CL
lets If we MtpDocumentsProvider assume we have a file that shares the
same name with the source file if it failed to invoke
MtpDevice#sendObjectInfo. In this case MtpDocumentsProvider retry to
invoke sendObjectInfo with new name with suffix number.
BUG=26991190
Change-Id: I223ac5031f079bc91eb27709b0356f621a1ed55b
The error should be regarded as an expected error that failes onCreate,
rather than crash.
BUG=27244513
Change-Id: Icf5164b0cba6cb919077539afe7701ada1e0c247
Previously if DocumentsProvider found timeout when terminatnig
RootScanner's background thread, it just output it in error log. Thus
the timeout is not regarded as an error in MtpDocumentsProviderTest, and
it makes flaky PipeManagerTest which runs just after
MtpDocumentsProviderTest.
The CL
* lets MtpDocumentsProvider throw TimeoutException for timeout.
* removes redundant resumeRootScanner calls to avoid timeout of
RootScanner#pause.
Also the CL did cleanup the logic that pauses RootScanner when we don't
find any devices. Previously the logic was in
MtpDocumentsProvider#closeInternal but it is not efficient because we
invokes RootScanner#resume just after
MtpDocumentsProvider#closeInternal. Now the CL moves the logic to
RootScanner so that it can pause itself automatically.
BUG=27638500
Change-Id: Ic11bca67c099cbb0f46679db2f035988045d67d6
File extensions contain more information to determine mime type than MTP
format codes. The CL lets MtpDocumentsProvider return mime type from
file extensions if it's not inconsitent with format code.
BUG=27004954
Change-Id: I08a4a91235b1d3f48e77b70b28c8c5aedf8d601d
When rebooting a device, applicaitons lose temporary URI permissions so
we don't need to keep document ID that are not granted persistent URI
permissions.
1. Check Settings.Global.BOOT_COUNT to find out if it's first time to
launch MtpDocumentsProvider since booting.
2. If so, invokes clean up method of MtpDatabase.
BUG=26212981
Change-Id: Ic9a8ca7e7a9cac1ed91fdfb01e9dce14ce819243
Previously RootScanner is implemented by FutureTask, and if it is
cancelled before it starts running in background thread, the scan will
be never executed.
The CL stops using FutureTask and introduces CountDownLatch to control
UpdateRootsRunnable.
BUG=27369585
Change-Id: Ica8799faba0a8e5ca91a6b8be36dc4f5118d6333
MTP devices can return supported operation list. The CL sets root flag
by referring it.
BUG=26147375
Change-Id: I02397821e208cf5a8fcf7457aa279d2818ce24c7
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
Once MTP device is disconnected from Android, the files on MTP device
are marked as 'DISCONNECTED' in metadata database. These metadata will
be back when MtpDocumentsProvider finds the reconnected MTP device and
fetches the files again.
Previously the 'DISCONNECTED' files are not automatically
refetched. User needs to see files in Documents UI again to reuse
document ID of 'DISCONNECTED' files. The CL changes DocumentLoader so
that it automatically refetches disconnected documents.
BUG=26212981
Change-Id: I5cb2cc9c11af72632e481c59a505794f43ed62ea
The MTP spec does not offer a way to update bytes of exisitng files, so
our provider implementation creates a new file with new bytes and
removes old one.
Previously the new file uses new document ID and the exising document ID
is expired. Also the provider does not update the metadata
database. Thus users see the old flie in DocumentsUI but actually the
files is not accessible.
The CL updates the database with exisitng document ID, so that we can
access the new file with exisiting document ID.
BUG=26549400
Change-Id: I629b707a2e662b34625e8b28857ef818d8933996
The CL introduces MAPPING_KEY column to the database and lets Mapper use
the column to map IDs of devices.
It also removes the concept of mapping mode from Mapper for
simplyfing. Now Mapper just tries to multiple mapping keys (MTP
identifier, display name, and mapping key) to find candidate of ID
mapping.
BUG=26212981
Change-Id: I19f6c7dac146047e9978de4eb33d5076406037ad
(cherry picked from commit 637a2010f4a0c0484b13c4cb87aa2858bdf079b2)
If the remote MTP device is a smartphone, it does not provide files
until a user unlocks the device. The CL adds specific error message for
the situation.
BUG=26318917
Change-Id: Ic4c34609c55ec9c99b7b8a9143d6dae3835784e3
Previously when tapping the MTP devce notification, MtpDocumentsProvider
opens home direcotry in Files app. The CL adds data URI of connected
device to the intent so that MtpDocumentsProvider can open the connected
device's root in Files app.
BUG=26611224
Change-Id: I97ecd6669852cd2fc875294cbcbf5660fbfaa0da
When MTP device is busy (e.g. used by other application),
MtpDocumentsProvider cannot open the device. The CL introduces specific
error message for the case.
BUG=26694828
Change-Id: Iffee2e1c554e4089601186469ff0eac2fd04decd
According to DocumentsContract mime type field is required.
MtpDocumentsProvider should returns mime type for unknown types of MTP
files as well.
BUG=27148801
Change-Id: I7e4b832f6c00f438cf90190c074f204fdedceef5
disconnected.
To restore Document IDs when the device is reconnected, we need to keep
the metadata in database so that we can use it as hint to remap document
ID with new MTP IDs.
BUG=26212981
Change-Id: Idcc93c41c09d082a709281022c56188dabc80515
(cherry picked from commit 53f5af3f2ba1328d301a0f8a4ae3f574ccc5da65)
MtpDocumentsProvider remembers the mapping between SAF's ID and MTP's
ID. Sometimes we need to do heuristic to restore the mapping when MTP
device is reconnected.
Previously we do the mapping files that shares the same name more
strictly. For example,
1. Found file name "test.txt". Assign document ID "1".
2. MTP device is disconnected and the MTP ID of "1" is lost.
3. Found two files that have same name "test.txt" in the same directory.
Previously we don't reuse existing document ID "1" for neither of two
"test.txt" because it's not 1-to-1 mapping and we cannot determine which
one should be mapped with existing document ID. It means we need the
complete list of files in a directory to remap IDs. It takes long time
to fetch all file names in a directory when a directory has 100+
files. It's rare that a MTP device has the two files sharing the same
name in the same directory. Also the strict rule makes the mapping code
more complex.
The CL relax the rule of mapping, and it allows to reuse existing
document ID even if it is not 1-to-1 mapping. For the previous example,
it assigns "1" for either of "test.txt".
BUG=27053734
Change-Id: I19406fafc21f13ab94ba99411ce5e7f55ce7f658
(cherry picked from commit acdbc6e740ffbd465488b6eb0cf9388d43ae860a)