147 Commits

Author SHA1 Message Date
Daichi Hirono
f578fa275a Update object info when writing a file.
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
2016-02-19 18:05:42 +09:00
Daichi Hirono
ebd2405159 Use device key to map device documents.
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)
2016-02-17 08:18:13 +00:00
Daichi Hirono
0abde68519 Merge "Add error message for locked device." into nyc-dev 2016-02-12 02:51:17 +00:00
Daichi Hirono
2965776ba4 Add error message for locked device.
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
2016-02-11 18:45:30 -08:00
Daichi Hirono
46d537716e Merge "Open the connected device in Files app when tapping notification." into nyc-dev 2016-02-12 02:38:29 +00:00
Daichi Hirono
90b345138f Merge "Show specific error message for busy device." into nyc-dev 2016-02-12 01:02:53 +00:00
Daichi Hirono
1e3744441a Open the connected device in Files app when tapping notification.
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
2016-02-11 16:36:49 -08:00
Daichi Hirono
c18f8076eb Show specific error message for busy device.
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
2016-02-11 12:45:55 -08:00
Daichi Hirono
ef2feefab7 Returns "application/octet-stream" for unknown types of MTP files.
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
2016-02-11 12:41:39 -08:00
Daichi Hirono
8e87364a67 Keep metadata of documents as disconnected status after the device is
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)
2016-02-10 16:59:22 +00:00
Daichi Hirono
619afdaae1 Check parent existance when adding/removing documents.
BUG=26212981
Change-Id: I8109e2324c027ec2182c6f521d57f3fe078a8660
(cherry picked from commit df803ec6ebd47ddc7f97ea8ef13aa359ecc7fb95)
2016-02-10 02:17:28 +00:00
Daichi Hirono
9fca541ab8 Relax mapping rule to make the mapping logic simple.
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)
2016-02-09 18:36:27 +00:00
Daichi Hirono
bf1c501306 Merge "Fix NullPointerException around getObjectInfo." 2016-02-05 09:14:37 +00:00
Daichi Hirono
6213cefbc0 Fetch mime type from file name when format code does not help.
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
2016-02-05 17:21:13 +09:00
Daichi Hirono
cfaab20c24 Fix NullPointerException around getObjectInfo.
BUG=27000341

Change-Id: I8888b627c62e9baaf91c19194dc89d95c65b8225
2016-02-05 16:04:19 +09:00
Daichi Hirono
f83ccbd7ed Drop device name from storage document name.
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
2016-02-04 17:27:52 +09:00
Daichi Hirono
19aa93249e Fix Identifier.equals method.
Previously the string was compared by ==.

BUG=26970351

Change-Id: If88b74392955388c9bf59002f2d2a186c2dff71a
2016-02-04 14:19:52 +09:00
Daichi Hirono
fda7474c5f Open MTP device on demand.
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
2016-02-04 12:45:58 +09:00
Daichi Hirono
6a5ea7eae8 Move logic to skip single storage.
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
2016-02-03 15:53:48 +09:00
Daichi Hirono
163e4b6ae8 Add launch notification for MTP devices.
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
2016-02-01 13:28:01 +09:00
Daichi Hirono
f11f14cbde Merge "Return NULL available bytes when the MTP device is closed." 2016-01-29 09:17:07 +00:00
Daichi Hirono
83983d75cb Return NULL available bytes when the MTP device is closed.
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
2016-01-29 17:37:36 +09:00
Daichi Hirono
2f310f6d5d Reuse buffer when reading bytes from files.
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
2016-01-28 14:09:26 +09:00
Daichi Hirono
a4d207cf64 Merge "Fix bugs that prevent from using AppFuse." 2016-01-26 07:51:49 +00:00
Daichi Hirono
b36b15586a Fix bugs that prevent from using AppFuse.
* 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
2016-01-26 16:30:08 +09:00
Daichi Hirono
7d1ca068a2 Merge "Update "accessing files" notification resources." 2016-01-25 08:28:23 +00:00
Daichi Hirono
e6bffff9d9 Update "accessing files" notification resources.
* Replace tentative resources with real ones.
 * Show the notification for each device as per request from UX.

BUG=26625702

Change-Id: Ibcfe7075e4827d5aee216ce5c0007f6dd4572efe
2016-01-25 16:27:19 +09:00
Daichi Hirono
148954a657 Add eventsSupported property to MtpDeviceInfo.
The property provides the set of event code that are supported by
MtpDevice.

BUG=26147375

Change-Id: I54be75e4bb52ddfe9aba8630538ddd32d1a641c8
2016-01-25 10:47:01 +09:00
Daichi Hirono
af6b66529e Ensure to release local reference in AppFuse JNI.
Previously get_object_bytes() leaked local reference of Java buffer
array.

BUG=None

Change-Id: Ic27e57281f984fee4aa285ad21de522ccb0fe4ed
2016-01-21 11:07:48 +09:00
Daichi Hirono
e6054c0ff0 Fix race in AppFuseTest.
Previously IllegalStateException is thrown in app fuse main loop, if the
loop thread starts just after closing device FD.

BUG=None

Change-Id: Ia5232857d29f9f324446aa38acf3c062f359d406
2016-01-21 10:51:25 +09:00
Daichi Hirono
f52ef008c7 Start to use app fuse in MtpDocumentsProvider.
BUG=25756419

Change-Id: I050e7cf7523926710291875737602e95c47be088
2016-01-19 11:20:59 +09:00
Daichi Hirono
35fb36b222 Merge "Clean MtpManagerTest code." 2016-01-19 00:48:28 +00:00
Daichi Hirono
3a6212ae55 Clean MtpManagerTest code.
* 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
2016-01-18 10:31:25 +09:00
Daichi Hirono
fab4a97a79 Fix compile error introduced by ag/842950.
BUG=25756419

Change-Id: I8ac270946b3915c02b21a07cf0a9c5b62d69effc
2016-01-15 16:54:24 +09:00
Daichi Hirono
2153e822ee Fix AppFuse JNI.
* 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
2016-01-15 13:45:47 +09:00
Daichi Hirono
d426ed2785 Add a test for createDocument and getPartialObject.
BUG=26482337

Change-Id: Ifda5055b422c3960f7c3c5275a1697f96e36bd06
2016-01-14 14:23:48 +09:00
Daichi Hirono
0ec4312475 Merge "Remove unused lines in MtpDocumentsProvider." 2016-01-12 04:23:07 +00:00
Daichi Hirono
2a9a43369b Reland "Add event parameters to MtpEvent."
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
2016-01-12 12:14:30 +09:00
Daichi Hirono
a12e7d1ba6 Remove unused lines in MtpDocumentsProvider.
Change-Id: I8de1b50441003648547829a3e8dd78153e6f8f31
2016-01-11 17:30:03 +09:00
Daichi Hirono
ab03cb1b46 Clean up TestUtil.
* 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
2016-01-11 16:32:57 +09:00
Daichi Hirono
1d4779c29a Add operationsSupported to device info.
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
2016-01-08 16:58:24 +09:00
Daichi Hirono
af5ea38b8c RealDeviceTest for MTP does not need to ask device permission.
MtpDocumentsProvider can obtain permission itself now because it's
system component.

BUG=26415299

Change-Id: Ia2cd275e57cffadbaefd0f1bf3cb99cde12e5e33
2016-01-07 18:24:59 +09:00
Daichi Hirono
fff12cd70a Merge "Implement FUSE operations in AppFuse JNI." 2016-01-07 01:21:07 +00:00
Daichi Hirono
b596175d80 Merge "Stop to remove device rows at MtpDocumentsProvider." 2015-12-25 07:09:38 +00:00
Daichi Hirono
8e3b9db544 Stop to remove device rows at MtpDocumentsProvider.
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
2015-12-25 15:59:47 +09:00
Daichi Hirono
4c4061210e Fix flakiness MtpManagerTest test.
The test for readEvent cancelling was flakiness because it can
successfully receives an event before the test tries to cancel it.

Change-Id: Ie7625dff53e07b8bc9888da03e78155e683a6d46
2015-12-24 12:45:03 +09:00
Daichi Hirono
cc9a7d78d5 Implement FUSE operations in AppFuse JNI.
The CL adds the following operations.

 * FUSE_LOOKUP
 * FUSE_OPEN
 * FUSE_READ
 * FUSE_RELEASE
 * FUSE_FLUSH

BUG=25756145

Change-Id: Ib57d7d0ade3343a604a1c40e4b2c2a2d089f3715
2015-12-24 11:11:27 +09:00
Daichi Hirono
e442872eaa Merge "Unmount appfuse when the device FD is closed." 2015-12-22 05:31:57 +00:00
Daichi Hirono
91e3b50636 Unmount appfuse when the device FD is closed.
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
2015-12-22 13:41:33 +09:00
Daichi Hirono
bdb5a45f8d Merge "Break while loop when the thread interuppted." 2015-12-22 04:03:27 +00:00