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)
MTP spec defines format code as a file type of object, but we don't have
format code for some file types like PDF. This CL adds fallback that
tries to obtain mime type from file name in such case.
BUG=27004957
Change-Id: Id61352bf4726f4e044e57edadcefbf179fe3f882
When device has multiple storages, storage are shown as directory under
the device root. In this case, we would not like to add device name to
storage.
Note that we still use "device name + storage name" for root name if the
device has a single storage because we skip storage directory in this
case and shows storage's contents directly under the device.
BUG=26625708
Change-Id: Ie13b044e71ae9b5131c4a01ee9d605023d05f168
Previously MtpDocumentsProvider opens a device just after device is
connected to Android. But MtpDocumentsProvider should open MTP device on
demand so that other applications can open device if user starts to use
the application before using MtpDocumentsProvider.
BUG=26625708
Change-Id: I6083b8c7cef49ee6e9fb0d15ca4adc129734f3eb
The tree structure of MTP model looks like /device/storage/objects. But
almost all MTP device has only single storage, so it's redundant to show
a single storage as a child of device in UI.
MtpDocumentsProvider has a special logic to skip single storage, and
shows storage's object as a children of device in such case. Previously
the logic was applied when MtpDocumentsProvider returned a root
list. The provider returns a storage as a Documents.Root, instead of
device if the device has only one storage.
However the number of root cannot be obtain for closed device. Thus the
previous logic did not work for closed devices that have a single
storage. The CL moves the logic from queryRoot to
queryChildDocuments. Now MtpDocumentsProvider always returns a device as
root, then it returns storage's objects as the device's children, where
we has already opened the device.
BUG=26481574
Change-Id: I25af0fc220410e321a378d67f226798ec4bba19c
The CL adds launch notification that are shown after MTP/PTP device is
connected to Android device. By tapping the notification, Users can
launch an applicaiton that can handle USB_DEVICE_ATTACHED intent of MTP
device.
BUG=26611224
Change-Id: I6fd179ccd436531dfff6ff9a50dc2b754c20f190
Before MtpDocumentsProvider opens a device, it cannot fetch the storage
size. Currently it says 0 bytes available. But actually it is unknown.
BUG=26866812
Change-Id: I3f24773da8e76fe1092c11f1335aac9703f1b3f9
Previously AppFuse getObjectBytes returns byte array and the array's
length needs to equals to the exact number of bytes the method read.
The CL change the function signature so that it can return the number of
read bytes. And reuse a buffer array instead of slicing the array with
valid length.
BUG=None
Change-Id: I78b714554cac9ae71b895cb8929bc98969f5a8ca
* Allow buffer size that is greater than requested read size in JNI,
because we reuse fixed-size buffer among multiple requests.
* Fix condition to check if the file size is greater than 4GB or
not. We need to use 0xffffffffl instead of 0xffffffff because
0xffffffff is int and its value is -1.
BUG=None
Change-Id: I155916e139353b15dc1ab535234faf50d942996d
* Replace tentative resources with real ones.
* Show the notification for each device as per request from UX.
BUG=26625702
Change-Id: Ibcfe7075e4827d5aee216ce5c0007f6dd4572efe
Previously IllegalStateException is thrown in app fuse main loop, if the
loop thread starts just after closing device FD.
BUG=None
Change-Id: Ia5232857d29f9f324446aa38acf3c062f359d406
* Use try-with-resource block to ensure close auto-closeable stream.
* Define local variables just above the place where they are used.
BUG=None
Change-Id: I9d6c952ebac096c51567a4a787b2bc9fff6502de
* Return attributes for all files as well as root.
* Fix buffer size for reading and add a check for reading size.
BUG=25756419
Change-Id: I572f718bc01d96616ec94f85d800b8b57eedd2ea
The CL was previously reviewed at ag/842930.
> We can obtain detailed information of MtpEvent from devices. e.g. object
> handle of changed object. The CL adds the detailed information as
> properties of MtpEvent class.
>
> BUG=26480986
Change-Id: I93afad9caf118d74cd0923d70242133c4fb2a648
* Integrate two while loops waiting for valid device.
* Try to open a device just after getting an device ownership so that
other applicaitons do not steal device ownership before TestUtil
opens a device.
Change-Id: Ia273cfb2a47fe630efd8c54b22d6ef5823a402b8
Because not all MTP devices support getPartialObject, we need to check
supported operation of MTP devices. The CL adds operationsSupported
field to MtpDeviceInfo class.
BUG=26147375
Change-Id: Iaad968fb4497a5ad11bf6489097abea99c3cbac7
Previously MtpDocumentsProvider used to remove device info in the
database when the device is closed. It loses a chance that RootScanner
handles the removal of roots. As a result, notifications for root cursor
does not issued.
The CL stops removing device info at MtpDocumentsProvider, and let
RootScanner remove it.
BUG=26321346
Change-Id: I6aec0cf843a1e5c93e7f67a718cabd26841d9799
The test for readEvent cancelling was flakiness because it can
successfully receives an event before the test tries to cancel it.
Change-Id: Ie7625dff53e07b8bc9888da03e78155e683a6d46
The CL lets MountService to observe device FD, and request unmount to
vold when the device FD was closed, or remote application providing
appfuse is crashed.
BUG=25756420
Change-Id: I7990694d32affa7f89e3f40badb25098d74d744d