Add CtsAdbManagerHostTestCases.

Bug: 145035407

Test: atest CtsAdbManagerHostTestCases
Change-Id: I9d5e7f97511bf0943f6133483fd247e3b8c6aee0
diff --git a/hostsidetests/adbmanager/Android.bp b/hostsidetests/adbmanager/Android.bp
new file mode 100644
index 0000000..54616e5
--- /dev/null
+++ b/hostsidetests/adbmanager/Android.bp
@@ -0,0 +1,25 @@
+// Copyright (C) 2020 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+java_test_host {
+    name: "CtsAdbManagerHostTestCases",
+    defaults: ["cts_defaults"],
+    srcs: ["src/**/*.java"],
+    test_suites: ["cts", "general-tests"],
+    libs: [
+        "compatibility-host-util",
+        "cts-tradefed",
+        "tradefed"
+    ],
+}
diff --git a/hostsidetests/adbmanager/AndroidTest.xml b/hostsidetests/adbmanager/AndroidTest.xml
new file mode 100644
index 0000000..2194a4c
--- /dev/null
+++ b/hostsidetests/adbmanager/AndroidTest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<configuration description="Config for CTS AdbManager host test cases">
+    <option name="test-suite-tag" value="cts" />
+    <option name="config-descriptor:metadata" key="component" value="framework" />
+    <option name="config-descriptor:metadata" key="parameter" value="not_instant_app" />
+    <option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" />
+    <option name="config-descriptor:metadata" key="parameter" value="secondary_user" />
+    <test class="com.android.compatibility.common.tradefed.testtype.JarHostTest" >
+        <option name="jar" value="CtsAdbManagerHostTestCases.jar" />
+    </test>
+</configuration>
diff --git a/hostsidetests/adbmanager/OWNERS b/hostsidetests/adbmanager/OWNERS
new file mode 100644
index 0000000..8e39c95
--- /dev/null
+++ b/hostsidetests/adbmanager/OWNERS
@@ -0,0 +1,2 @@
+# Bug component: 1352
+joshuaduong@google.com
diff --git a/hostsidetests/adbmanager/src/android/adbmanager/cts/AdbManagerHostDeviceTest.java b/hostsidetests/adbmanager/src/android/adbmanager/cts/AdbManagerHostDeviceTest.java
new file mode 100644
index 0000000..096f3fd
--- /dev/null
+++ b/hostsidetests/adbmanager/src/android/adbmanager/cts/AdbManagerHostDeviceTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.adbmanager.cts;
+
+import com.android.compatibility.common.util.CddTest;
+import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
+import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
+import com.android.tradefed.util.CommandResult;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Tests the AdbManager System APIs via shell commands.
+ */
+@RunWith(DeviceJUnit4ClassRunner.class)
+public class AdbManagerHostDeviceTest extends BaseHostJUnit4Test {
+    private static final String FEATURE_WIFI = "android.hardware.wifi";
+    private static final String FEATURE_CAMERA_ANY = "android.hardware.camera.any";
+
+    private boolean hasFeature(String feature) throws Exception {
+        CommandResult result = getDevice().executeShellV2Command("pm has-feature " + feature);
+        Assert.assertTrue(new Integer(0).equals(result.getExitCode()));
+        return Boolean.parseBoolean(result.getStdout().trim());
+    }
+
+    @Test
+    @CddTest(requirement="6.1/C-1-1")
+    public void test_isadbWifiSupported() throws Exception {
+        boolean expected = hasFeature(FEATURE_WIFI);
+
+        CommandResult result = getDevice().executeShellV2Command("cmd adb is-wifi-supported");
+
+        Assert.assertTrue(new Integer(0).equals(result.getExitCode()));
+        Assert.assertEquals(expected, Boolean.parseBoolean(result.getStdout().trim()));
+    }
+
+    @Test
+    @CddTest(requirement="6.1/C-1-2")
+    public void test_isadbWifiQrSupported() throws Exception {
+        boolean expected = hasFeature(FEATURE_WIFI) && hasFeature(FEATURE_CAMERA_ANY);
+
+        CommandResult result = getDevice().executeShellV2Command("cmd adb is-wifi-qr-supported");
+
+        Assert.assertTrue(new Integer(0).equals(result.getExitCode()));
+        Assert.assertEquals(expected, Boolean.parseBoolean(result.getStdout().trim()));
+    }
+}