Call access(2) on all files/dirs modified by Mtp

External sdcards are accessed through /mnt/media_rw,
so access() each touched file for sdcardfs to update
its metadata.

Java handles single object renames directly so that
is the only place where it is needed.

Bug: 77849654
Test: use mtp with emulated sdcard
Change-Id: Ie460398010f1fe74d8084808a6333b121674362c
This commit is contained in:
Jerry Zhang
2018-05-14 12:19:08 -07:00
parent 14de2930ba
commit d470a1eca6
2 changed files with 14 additions and 4 deletions

View File

@@ -35,6 +35,9 @@ import android.provider.MediaStore;
import android.provider.MediaStore.Audio;
import android.provider.MediaStore.Files;
import android.provider.MediaStore.MediaColumns;
import android.system.ErrnoException;
import android.system.Os;
import android.system.OsConstants;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
@@ -560,6 +563,13 @@ public class MtpDatabase implements AutoCloseable {
return MtpConstants.RESPONSE_GENERAL_ERROR;
Path newPath = obj.getPath();
boolean success = oldPath.toFile().renameTo(newPath.toFile());
try {
Os.access(oldPath.toString(), OsConstants.F_OK);
Os.access(newPath.toString(), OsConstants.F_OK);
} catch (ErrnoException e) {
// Ignore. Could fail if the metadata was already updated.
}
if (!mManager.endRenameObject(obj, oldPath.getFileName().toString(), success)) {
Log.e(TAG, "Failed to end rename object");
}

View File

@@ -104,10 +104,10 @@ public class MtpStorageManagerTest {
mainStorageDir = createNewDir(TEMP_DIR_FILE);
secondaryStorageDir = createNewDir(TEMP_DIR_FILE);
StorageVolume mainStorage = new StorageVolume("1", mainStorageDir, "", true, false, true,
false, -1, UserHandle.CURRENT, "", "");
StorageVolume secondaryStorage = new StorageVolume("2", secondaryStorageDir, "", false,
false, true, false, -1, UserHandle.CURRENT, "", "");
StorageVolume mainStorage = new StorageVolume("1", mainStorageDir, mainStorageDir,
"", true, false, true, false, -1, UserHandle.CURRENT, "", "");
StorageVolume secondaryStorage = new StorageVolume("2", secondaryStorageDir,
secondaryStorageDir, "", false, false, true, false, -1, UserHandle.CURRENT, "", "");
objectsAdded = new ArrayList<>();
objectsRemoved = new ArrayList<>();