OSDN Git Service

Relax mapping rule to make the mapping logic simple.
authorDaichi Hirono <hirono@google.com>
Sun, 7 Feb 2016 04:20:22 +0000 (13:20 +0900)
committerDaichi Hirono <hirono@google.com>
Sun, 7 Feb 2016 04:31:01 +0000 (13:31 +0900)
commitacdbc6e740ffbd465488b6eb0cf9388d43ae860a
tree31f9c67d52bd1b325a131cc7bbe1a10682dea6fb
parent6213cefbc06170f9463abf40c240322be11047bc
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
packages/MtpDocumentsProvider/src/com/android/mtp/Mapper.java
packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabaseConstants.java
packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDatabaseTest.java