Handle pushFile request for directories

Ensure we handle nicely a request to push a directory via
the wrong API.
Similar behavior as non content provider pushFile.

Test: unit tests
Bug: 144570068
Change-Id: I98dfd4f82184b0c97b967cf6c6db1dce41099abb
diff --git a/device_build_interfaces/com/android/tradefed/device/contentprovider/ContentProviderHandler.java b/device_build_interfaces/com/android/tradefed/device/contentprovider/ContentProviderHandler.java
index e251858..055cc73 100644
--- a/device_build_interfaces/com/android/tradefed/device/contentprovider/ContentProviderHandler.java
+++ b/device_build_interfaces/com/android/tradefed/device/contentprovider/ContentProviderHandler.java
@@ -220,14 +220,14 @@
      */
     public boolean pushFile(File fileToPush, String deviceFilePath)
             throws DeviceNotAvailableException, IllegalArgumentException {
-        if (fileToPush.isDirectory()) {
-            throw new IllegalArgumentException(
-                    String.format("File '%s' to push is a directory.", fileToPush));
-        }
         if (!fileToPush.exists()) {
             CLog.w("File '%s' to push does not exist.", fileToPush);
             return false;
         }
+        if (fileToPush.isDirectory()) {
+            CLog.w("'%s' is not a file but a directory, can't use #pushFile on it.", fileToPush);
+            return false;
+        }
         String contentUri = createEscapedContentUri(deviceFilePath);
         String pushCommand =
                 String.format(
diff --git a/tests/src/com/android/tradefed/device/contentprovider/ContentProviderHandlerTest.java b/tests/src/com/android/tradefed/device/contentprovider/ContentProviderHandlerTest.java
index 2fc39d2..7f56715 100644
--- a/tests/src/com/android/tradefed/device/contentprovider/ContentProviderHandlerTest.java
+++ b/tests/src/com/android/tradefed/device/contentprovider/ContentProviderHandlerTest.java
@@ -170,6 +170,33 @@
         }
     }
 
+    /** Test {@link ContentProviderHandler#pushFile(File, String)} when the file doesn't exists */
+    @Test
+    public void testPushFile_notExists() throws Exception {
+        File toPush = new File("content-provider-test.txt");
+        try {
+            String devicePath = "path/somewhere/file.txt";
+            assertFalse(mProvider.pushFile(toPush, devicePath));
+        } finally {
+            FileUtil.deleteFile(toPush);
+        }
+    }
+
+    /**
+     * Test {@link ContentProviderHandler#pushFile(File, String)} when the file exists but is a
+     * directory
+     */
+    @Test
+    public void testPushFile_directory() throws Exception {
+        File toPush = FileUtil.createTempDir("content-provider-test");
+        try {
+            String devicePath = "path/somewhere/file.txt";
+            assertFalse(mProvider.pushFile(toPush, devicePath));
+        } finally {
+            FileUtil.recursiveDelete(toPush);
+        }
+    }
+
     /** Test {@link ContentProviderHandler#pullFile(String, File)}. */
     @Test
     public void testPullFile_verifyShellCommand() throws Exception {