From e59cb735f33e1ee5524073fe9fb2c417efcda6fe Mon Sep 17 00:00:00 2001 From: Zim Date: Thu, 12 Dec 2019 10:54:45 +0000 Subject: Revert "Remove the rename() interceptor" This reverts I0f9ac456104759887c0410fe64acc32cab19b62b And adds an additional check to only fallback handle the EXDEV from paths on /storage We are bringing back the interceptor because the implementation of scoped storage in R uses a FUSE filesystem mounted on /sdcard with an sdcardfs filesystem mounted on /sdcard/Android/ (for now, just /sdcard/Android in Ic17a5751b5a94846ee565ff935644a078044ab06) Test: atest android.appsecurity.cts.ExternalStorageHostTest#testExternalStorageRename with FUSE enabled passes Bug: 135341433 Change-Id: I7876bfe00890f24559576f260ba456afb07e9482 --- core/java/android/app/ActivityThread.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'core/java/android/app/ActivityThread.java') diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 49a8e2f3f816..93b6454edcf3 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -7395,6 +7395,24 @@ public final class ActivityThread extends ClientTransactionHandler { super.remove(path); } } + + @Override + public void rename(String oldPath, String newPath) throws ErrnoException { + try { + super.rename(oldPath, newPath); + } catch (ErrnoException e) { + if (e.errno == OsConstants.EXDEV && oldPath.startsWith("/storage/")) { + Log.v(TAG, "Recovering failed rename " + oldPath + " to " + newPath); + try { + Files.move(new File(oldPath).toPath(), new File(newPath).toPath()); + } catch (IOException e2) { + throw e; + } + } else { + throw e; + } + } + } } public static void main(String[] args) { -- cgit v1.2.3