From 4c0b9a5fbdcd06df8844affd1253a734aaa27392 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Mon, 7 Jun 2021 15:02:45 -0700 Subject: Fix side effects of trace-ipc and dumpheap commands These shell commands were implicitly deleting any client-named file for which the system uid had deletion capability. They no longer do this, instead using only the client's own capabilities and file manipulation modes. Bug: 185398942 Test: manual "adb shell cmd activity dumpheap system_server /data/system/last-fstrim" Test: atest CtsPermissionTestCases:ShellCommandPermissionTest Merged-In: Ie61ab2c3f4bfbd04de09ca99c1116d1129461e8f Change-Id: Ie61ab2c3f4bfbd04de09ca99c1116d1129461e8f --- .../java/com/android/server/am/ActivityManagerShellCommand.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java index adb7056408ba..f37fcb54e7c2 100644 --- a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java +++ b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java @@ -76,7 +76,6 @@ import com.android.internal.util.MemInfoReader; import com.android.internal.util.Preconditions; import java.io.BufferedReader; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -719,8 +718,7 @@ final class ActivityManagerShellCommand extends ShellCommand { return -1; } - File file = new File(filename); - file.delete(); + // Writes an error message to stderr on failure ParcelFileDescriptor fd = openFileForSystem(filename, "w"); if (fd == null) { return -1; @@ -871,8 +869,7 @@ final class ActivityManagerShellCommand extends ShellCommand { String process = getNextArgRequired(); String heapFile = getNextArgRequired(); - File file = new File(heapFile); - file.delete(); + // Writes an error message to stderr on failure ParcelFileDescriptor fd = openFileForSystem(heapFile, "w"); if (fd == null) { return -1; -- cgit v1.2.3-59-g8ed1b