Merge "Snap for 5714901 from 562202cf1e9899b55c457947810c62f97f896b18 to pie-vts-release" into pie-vts-release
diff --git a/src/com/android/tradefed/device/NativeDevice.java b/src/com/android/tradefed/device/NativeDevice.java
index d03ad9f..d5bc048 100644
--- a/src/com/android/tradefed/device/NativeDevice.java
+++ b/src/com/android/tradefed/device/NativeDevice.java
@@ -98,7 +98,7 @@
*/
public class NativeDevice implements IManagedTestDevice {
- private static final String SD_CARD = "/sdcard/";
+ protected static final String SD_CARD = "/sdcard/";
/**
* Allow pauses of up to 2 minutes while receiving bugreport.
* <p/>
diff --git a/src/com/android/tradefed/device/TestDevice.java b/src/com/android/tradefed/device/TestDevice.java
index 9dfb5a1..f845b5a 100644
--- a/src/com/android/tradefed/device/TestDevice.java
+++ b/src/com/android/tradefed/device/TestDevice.java
@@ -763,6 +763,17 @@
return packages;
}
+ /** {@inheritDoc} */
+ @Override
+ public boolean doesFileExist(String deviceFilePath) throws DeviceNotAvailableException {
+ if (deviceFilePath.startsWith(SD_CARD)) {
+ deviceFilePath =
+ deviceFilePath.replaceFirst(
+ SD_CARD, String.format("/storage/emulated/%s/", getCurrentUser()));
+ }
+ return super.doesFileExist(deviceFilePath);
+ }
+
/**
* {@inheritDoc}
*/
diff --git a/tests/src/com/android/tradefed/device/TestDeviceTest.java b/tests/src/com/android/tradefed/device/TestDeviceTest.java
index 98e64ad..80a35d1 100644
--- a/tests/src/com/android/tradefed/device/TestDeviceTest.java
+++ b/tests/src/com/android/tradefed/device/TestDeviceTest.java
@@ -3812,4 +3812,41 @@
// verifyMocks();
// }
// >>>>>>> f39a78ced... Hook up pullFile to use content provider.
+
+ /** Test {@link TestDevice#doesFileExist(String)}. */
+ public void testDoesFileExists() throws Exception {
+ injectShellResponse("ls \"/data/local/tmp/file\"", "file");
+ EasyMock.replay(mMockIDevice);
+ assertTrue(mTestDevice.doesFileExist("/data/local/tmp/file"));
+ EasyMock.verify(mMockIDevice);
+ }
+
+ /** Test {@link TestDevice#doesFileExist(String)} when the file does not exists. */
+ public void testDoesFileExists_notExists() throws Exception {
+ injectShellResponse(
+ "ls \"/data/local/tmp/file\"",
+ "ls: cannot access 'file': No such file or directory\n");
+ EasyMock.replay(mMockIDevice);
+ assertFalse(mTestDevice.doesFileExist("/data/local/tmp/file"));
+ EasyMock.verify(mMockIDevice);
+ }
+
+ /**
+ * Test {@link TestDevice#doesFileExist(String)} when the file exists on an sdcard from another
+ * user.
+ */
+ public void testDoesFileExists_sdcard() throws Exception {
+ mTestDevice =
+ new TestableTestDevice() {
+ @Override
+ public int getCurrentUser()
+ throws DeviceNotAvailableException, DeviceRuntimeException {
+ return 10;
+ }
+ };
+ injectShellResponse("ls \"/storage/emulated/10/file\"", "file");
+ EasyMock.replay(mMockIDevice);
+ assertTrue(mTestDevice.doesFileExist("/sdcard/file"));
+ EasyMock.verify(mMockIDevice);
+ }
}