Add isChildDocument to MtpDocumentsProvider.
Bug: 32687127 Test: adb shell am instrument -w -e class com.android.mtp.MtpDocumentsProviderTest#testIsChildDocument com.android.mtp.tests/com.android.mtp.TestResultInstrumentation Change-Id: I44ded3c73443735229a8b3465122f7e10c4da178
This commit is contained in:
@@ -485,6 +485,24 @@ public class MtpDocumentsProvider extends DocumentsProvider {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChildDocument(String parentDocumentId, String documentId) {
|
||||
try {
|
||||
Identifier identifier = mDatabase.createIdentifier(documentId);
|
||||
while (true) {
|
||||
if (parentDocumentId.equals(identifier.mDocumentId)) {
|
||||
return true;
|
||||
}
|
||||
if (identifier.mDocumentType == MtpDatabaseConstants.DOCUMENT_TYPE_DEVICE) {
|
||||
return false;
|
||||
}
|
||||
identifier = mDatabase.getParentIdentifier(identifier.mDocumentId);
|
||||
}
|
||||
} catch (FileNotFoundException error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void openDevice(int deviceId) throws IOException {
|
||||
synchronized (mDeviceListLock) {
|
||||
if (mDeviceToolkits.containsKey(deviceId)) {
|
||||
|
||||
@@ -854,6 +854,18 @@ public class MtpDocumentsProviderTest extends AndroidTestCase {
|
||||
assertEquals("19", path.getPath().get(2));
|
||||
}
|
||||
|
||||
public void testIsChildDocument() throws Exception {
|
||||
setupProvider(MtpDatabaseConstants.FLAG_DATABASE_IN_MEMORY);
|
||||
setupRoots(0, new MtpRoot[] { new MtpRoot(0, 0, "Storage", 1000, 1000, "") });
|
||||
setupHierarchyDocuments("1");
|
||||
assertTrue(mProvider.isChildDocument("1", "1"));
|
||||
assertTrue(mProvider.isChildDocument("1", "14"));
|
||||
assertTrue(mProvider.isChildDocument("2", "14"));
|
||||
assertTrue(mProvider.isChildDocument("5", "14"));
|
||||
assertFalse(mProvider.isChildDocument("3", "14"));
|
||||
assertFalse(mProvider.isChildDocument("6", "14"));
|
||||
}
|
||||
|
||||
private void setupProvider(int flag) {
|
||||
mDatabase = new MtpDatabase(getContext(), flag);
|
||||
mProvider = new MtpDocumentsProvider();
|
||||
|
||||
Reference in New Issue
Block a user