Continue to replace 'rm' by deleteFile API

Bug: 123529934
Test: unit tests
Bug: 123528776
Change-Id: I63ebda09dd305403cb8658e8129d4efa74c39f92
Merged-In: I63ebda09dd305403cb8658e8129d4efa74c39f92
diff --git a/src/com/android/tradefed/device/TestDevice.java b/src/com/android/tradefed/device/TestDevice.java
index bc40082..fdea4a2 100644
--- a/src/com/android/tradefed/device/TestDevice.java
+++ b/src/com/android/tradefed/device/TestDevice.java
@@ -1387,7 +1387,7 @@
         }
         File dump = dumpAndPullHeap(pid, devicePath);
         // Clean the device.
-        executeShellCommand(String.format("rm %s", devicePath));
+        deleteFile(devicePath);
         return dump;
     }
 
diff --git a/src/com/android/tradefed/targetprep/PushFilePreparer.java b/src/com/android/tradefed/targetprep/PushFilePreparer.java
index 81b684d..4732332 100644
--- a/src/com/android/tradefed/targetprep/PushFilePreparer.java
+++ b/src/com/android/tradefed/targetprep/PushFilePreparer.java
@@ -189,7 +189,7 @@
                 device.remountSystemWritable();
             }
             for (String devicePath : mFilesPushed) {
-                device.executeShellCommand("rm -r " + devicePath);
+                device.deleteFile(devicePath);
             }
         }
     }
diff --git a/src/com/android/tradefed/testtype/GTest.java b/src/com/android/tradefed/testtype/GTest.java
index 3e50ada..047e879 100644
--- a/src/com/android/tradefed/testtype/GTest.java
+++ b/src/com/android/tradefed/testtype/GTest.java
@@ -605,7 +605,7 @@
             // Pull the result file, may not exist if issue with the test.
             testDevice.pullFile(tmpResName, tmpOutput);
             // Clean the file on the device
-            testDevice.executeShellCommand("rm " + tmpResName);
+            testDevice.deleteFile(tmpResName);
             GTestXmlResultParser parser = createXmlParser(testRunName, listener);
             // Attempt to parse the file, doesn't matter if the content is invalid.
             if (tmpOutput.exists()) {
diff --git a/tests/src/com/android/tradefed/device/TestDeviceFuncTest.java b/tests/src/com/android/tradefed/device/TestDeviceFuncTest.java
index e14cf50..bce52a1 100644
--- a/tests/src/com/android/tradefed/device/TestDeviceFuncTest.java
+++ b/tests/src/com/android/tradefed/device/TestDeviceFuncTest.java
@@ -208,7 +208,7 @@
             assertNotNull(externalStorePath);
             deviceFilePath = String.format("%s/%s", externalStorePath, "tmp_testPushPull.txt");
             // ensure file does not already exist
-            mTestDevice.executeShellCommand(String.format("rm %s", deviceFilePath));
+            mTestDevice.deleteFile(deviceFilePath);
             assertFalse(String.format("%s exists", deviceFilePath),
                     mTestDevice.doesFileExist(deviceFilePath));
 
@@ -223,7 +223,7 @@
                 tmpDestFile.delete();
             }
             if (deviceFilePath != null) {
-                mTestDevice.executeShellCommand(String.format("rm %s", deviceFilePath));
+                mTestDevice.deleteFile(deviceFilePath);
             }
         }
     }
@@ -385,9 +385,9 @@
         final String extStore = "/data/local";
 
         // Clean up after potential failed run
-        mTestDevice.executeShellCommand(String.format("rm %s/testdir", extStore));
-        mTestDevice.executeShellCommand(String.format("rm %s/testdir2/foo.txt", extStore));
-        mTestDevice.executeShellCommand(String.format("rmdir %s/testdir2", extStore));
+        mTestDevice.deleteFile(String.format("%s/testdir", extStore));
+        mTestDevice.deleteFile(String.format("%s/testdir2/foo.txt", extStore));
+        mTestDevice.deleteFile(String.format("%s/testdir2", extStore));
 
         try {
             assertEquals("",
@@ -401,9 +401,9 @@
 
             assertNotNull(mTestDevice.getFileEntry(String.format("%s/testdir/foo.txt", extStore)));
         } finally {
-            mTestDevice.executeShellCommand(String.format("rm %s/testdir", extStore));
-            mTestDevice.executeShellCommand(String.format("rm %s/testdir2/foo.txt", extStore));
-            mTestDevice.executeShellCommand(String.format("rmdir %s/testdir2", extStore));
+            mTestDevice.deleteFile(String.format("%s/testdir", extStore));
+            mTestDevice.deleteFile(String.format("%s/testdir2/foo.txt", extStore));
+            mTestDevice.deleteFile(String.format("%s/testdir2", extStore));
         }
     }
 
@@ -469,7 +469,7 @@
         } finally {
             if (expectedDeviceFilePath != null && externalStorePath != null) {
                 // note that expectedDeviceFilePath has externalStorePath prepended at definition
-                mTestDevice.executeShellCommand(String.format("rm -r %s", expectedDeviceFilePath));
+                mTestDevice.deleteFile(expectedDeviceFilePath);
             }
             FileUtil.recursiveDelete(tmpDir);
         }
@@ -495,8 +495,8 @@
 
         } finally {
             if (expectedDeviceFilePath != null && externalStorePath != null) {
-                mTestDevice.executeShellCommand(String.format("rm -r %s/%s", externalStorePath,
-                        expectedDeviceFilePath));
+                mTestDevice.deleteFile(
+                        String.format("%s/%s", externalStorePath, expectedDeviceFilePath));
             }
             FileUtil.recursiveDelete(rootDir);
         }
diff --git a/tests/src/com/android/tradefed/device/TestDeviceStressTest.java b/tests/src/com/android/tradefed/device/TestDeviceStressTest.java
index 080dc2c..2588889 100644
--- a/tests/src/com/android/tradefed/device/TestDeviceStressTest.java
+++ b/tests/src/com/android/tradefed/device/TestDeviceStressTest.java
@@ -120,7 +120,7 @@
             // device before the test start.
             tmpDir = createTempTestFiles();
             for (int i = 0; i < mIterations; i++) {
-                mTestDevice.executeShellCommand(String.format("rm -r %s", deviceFilePath));
+                mTestDevice.deleteFile(deviceFilePath);
                 assertFalse(String.format("%s exists", deviceFilePath),
                         mTestDevice.doesFileExist(deviceFilePath));
                 assertTrue(mTestDevice.pushDir(tmpDir, deviceFilePath));
@@ -130,7 +130,7 @@
             if (tmpDir != null) {
                 FileUtil.recursiveDelete(tmpDir);
             }
-            mTestDevice.executeShellCommand(String.format("rm -r %s", deviceFilePath));
+            mTestDevice.deleteFile(deviceFilePath);
             assertFalse(String.format("%s exists", deviceFilePath),
                     mTestDevice.doesFileExist(deviceFilePath));
         }
@@ -159,7 +159,7 @@
             if (tmpDir != null) {
                 FileUtil.recursiveDelete(tmpDir);
             }
-            mTestDevice.executeShellCommand(String.format("rm -r %s", deviceFilePath));
+            mTestDevice.deleteFile(deviceFilePath);
             assertFalse(String.format("%s exists", deviceFilePath),
                     mTestDevice.doesFileExist(deviceFilePath));
         }
diff --git a/tests/src/com/android/tradefed/device/TestDeviceTest.java b/tests/src/com/android/tradefed/device/TestDeviceTest.java
index 01cc636..3164167 100644
--- a/tests/src/com/android/tradefed/device/TestDeviceTest.java
+++ b/tests/src/com/android/tradefed/device/TestDeviceTest.java
@@ -3674,7 +3674,8 @@
         injectShellResponse("pidof system_server", "929");
         injectShellResponse("am dumpheap 929 /data/dump.hprof", "");
         injectShellResponse("ls \"/data/dump.hprof\"", "/data/dump.hprof");
-        injectShellResponse("rm /data/dump.hprof", "");
+        injectShellResponse("rm -rf \"/data/dump.hprof\"", "");
+
         EasyMock.replay(mMockIDevice, mMockRunUtil);
         File res = mTestDevice.dumpHeap("system_server", "/data/dump.hprof");
         assertNotNull(res);
diff --git a/tests/src/com/android/tradefed/testtype/GTestTest.java b/tests/src/com/android/tradefed/testtype/GTestTest.java
index 5d636d3..af2c822 100644
--- a/tests/src/com/android/tradefed/testtype/GTestTest.java
+++ b/tests/src/com/android/tradefed/testtype/GTestTest.java
@@ -409,9 +409,8 @@
                 .andReturn("-rwxr-xr-x 1 root shell 7 2009-01-01 00:00 " + testPath2);
         String[] files = new String[] {"test1", "test2"};
         EasyMock.expect(mMockITestDevice.getChildren(nativeTestPath)).andReturn(files);
-        EasyMock.expect(mMockITestDevice.executeShellCommand(EasyMock.contains("rm")))
-                .andReturn("")
-                .times(2);
+        mMockITestDevice.deleteFile(testPath1 + "_res.xml");
+        mMockITestDevice.deleteFile(testPath2 + "_res.xml");
         EasyMock.expect(mMockITestDevice.pullFile((String)EasyMock.anyObject(),
                 (File)EasyMock.anyObject())).andStubReturn(true);
         mMockITestDevice.executeShellCommand(EasyMock.contains(test1),