Add content provider device check

Feature flag to be able to completely disable CP in case
something goes wrong.

Bug: 123529934
Test: unit tests
Bug: 130035166
Change-Id: I732d8f3f807dcff8f02925867d965bc028b4e9b1
Merged-In: I732d8f3f807dcff8f02925867d965bc028b4e9b1
diff --git a/src/com/android/tradefed/device/NativeDevice.java b/src/com/android/tradefed/device/NativeDevice.java
index 9bc385e..77fb786 100644
--- a/src/com/android/tradefed/device/NativeDevice.java
+++ b/src/com/android/tradefed/device/NativeDevice.java
@@ -2729,6 +2729,8 @@
             throw new UnsupportedOperationException(
                     "Fastboot is not available and cannot reboot into bootloader");
         }
+        // If we go to bootloader, it's probably for flashing so ensure we re-check the provider
+        mShouldSkipContentProviderSetup = false;
         CLog.i("Rebooting device %s in state %s into bootloader", getSerialNumber(),
                 getDeviceState());
         if (TestDeviceState.FASTBOOT.equals(getDeviceState())) {
@@ -4176,6 +4178,10 @@
     /** Returns the {@link ContentProviderHandler} or null if not available. */
     @VisibleForTesting
     ContentProviderHandler getContentProvider() throws DeviceNotAvailableException {
+        // If disabled at the device level, don't attempt any checks.
+        if (!getOptions().shouldUseContentProvider()) {
+            return null;
+        }
         // Prevent usage of content provider before API 25 as it would not work well.
         if (getApiLevel() < 25) {
             return null;
diff --git a/src/com/android/tradefed/device/TestDeviceOptions.java b/src/com/android/tradefed/device/TestDeviceOptions.java
index e4d9569..0f33b2e 100644
--- a/src/com/android/tradefed/device/TestDeviceOptions.java
+++ b/src/com/android/tradefed/device/TestDeviceOptions.java
@@ -115,6 +115,14 @@
             "the minimum battery level required to continue the invocation. Scale: 0-100")
     private Integer mCutoffBattery = null;
 
+    @Option(
+        name = "use-content-provider",
+        description =
+                "Allow to disable the use of the content provider at the device level. "
+                        + "This results in falling back to standard adb push/pull."
+    )
+    private boolean mUseContentProvider = true;
+
     /**
      * Check whether adb root should be enabled on boot for this device
      */
@@ -340,4 +348,9 @@
     public String getWifiUtilAPKPath() {
         return mWifiUtilAPKPath;
     }
+
+    /** Returns whether or not the Tradefed content provider can be used to push/pull files. */
+    public boolean shouldUseContentProvider() {
+        return mUseContentProvider;
+    }
 }