Add tests for the artd Binder interface.

This CL adds a test to make sure the artd binder interface can be
found and called.

Test: m ArtdIntegrationTests
Bug: 177273468
Change-Id: Ie456cb43ad6320bc4ce206d1f8e7948622491dff
diff --git a/artd/artd.cc b/artd/artd.cc
index fe0675b..1dcd2e8 100644
--- a/artd/artd.cc
+++ b/artd/artd.cc
@@ -32,10 +32,20 @@
 namespace android {
 namespace artd {
 
-class ArtD : public aidl::android::os::BnArtd {
+class Artd : public aidl::android::os::BnArtd {
   constexpr static const char* const SERVICE_NAME = "artd";
 
  public:
+  Artd() {}
+
+  /*
+   * Binder API
+   */
+
+  ScopedAStatus isAlive(bool* _aidl_return) {
+    *_aidl_return = true;
+    return ScopedAStatus::ok();
+  }
 
   /*
    * Server API
@@ -62,7 +72,7 @@
   setenv("ANDROID_LOG_TAGS", "*:v", 1);
   android::base::InitLogging(argv);
 
-  android::artd::ArtD artd;
+  android::artd::Artd artd;
 
   if (auto ret = artd.Start(); !ret.isOk()) {
     LOG(ERROR) << "Unable to start artd: " << ret.getMessage();
diff --git a/artd/binder/Android.bp b/artd/binder/Android.bp
index 2e69c78..94f3f17 100644
--- a/artd/binder/Android.bp
+++ b/artd/binder/Android.bp
@@ -30,7 +30,7 @@
     host_supported: true,
     backend: {
         java: {
-            enabled: false,
+            enabled: true,
         },
         cpp: {
             enabled: false,
@@ -48,5 +48,6 @@
     unstable: true,
     visibility: [
         "//system/tools/aidl/build",
+        "//art:__subpackages__",
     ],
 }
diff --git a/artd/binder/android/os/IArtd.aidl b/artd/binder/android/os/IArtd.aidl
index 4f5f214..a16764b 100644
--- a/artd/binder/android/os/IArtd.aidl
+++ b/artd/binder/android/os/IArtd.aidl
@@ -18,4 +18,6 @@
 
 /** {@hide} */
 interface IArtd {
+    // Test to see if the artd service is available.
+    boolean isAlive();
 }
diff --git a/artd/tests/Android.bp b/artd/tests/Android.bp
new file mode 100644
index 0000000..e6a6411
--- /dev/null
+++ b/artd/tests/Android.bp
@@ -0,0 +1,36 @@
+//
+// Copyright (C) 2021 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 {
+    // See: http://go/android-license-faq
+    // A large-scale-change added 'default_applicable_licenses' to import
+    // all of the 'license_kinds' from "frameworks_base_license"
+    // to get the below license kinds:
+    //   SPDX-license-identifier-Apache-2.0
+    default_applicable_licenses: ["art_license"],
+}
+
+android_test {
+    name: "ArtdIntegrationTests",
+    srcs: ["src/**/*.java"],
+    static_libs: [
+        "androidx.test.rules",
+        "artd-aidl-java",
+    ],
+    platform_apis: true,
+    test_suites: ["device-tests"],
+    certificate: "platform",
+}
diff --git a/artd/tests/AndroidManifest.xml b/artd/tests/AndroidManifest.xml
new file mode 100644
index 0000000..a0c4274
--- /dev/null
+++ b/artd/tests/AndroidManifest.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2021 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+        package="com.android.art.artdtest">
+
+    <!-- Uses API introduced in O (26) -->
+    <uses-sdk
+        android:minSdkVersion="1"
+        android:targetSdkVersion="26" />
+
+    <application>
+        <uses-library android:name="android.test.runner" />
+    </application>
+
+    <instrumentation
+        android:name="androidx.test.runner.AndroidJUnitRunner"
+        android:targetPackage="com.android.art.artdtest"
+        android:label="Integration test for Artd" />
+</manifest>
diff --git a/artd/tests/AndroidTest.xml b/artd/tests/AndroidTest.xml
new file mode 100644
index 0000000..1b30b19
--- /dev/null
+++ b/artd/tests/AndroidTest.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2021 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="Runs Artd Integration Tests">
+    <!--Test app needs to be installed when we change its settings below-->
+    <target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup">
+        <option name="test-file-name" value="ArtdIntegrationTests.apk"/>
+        <option name="cleanup-apks" value="true"/>
+    </target_preparer>
+
+    <option name="test-suite-tag" value="apct"/>
+    <option name="test-tag" value="ArtdIntegrationTests"/>
+    <test class="com.android.tradefed.testtype.AndroidJUnitTest">
+        <option name="package" value="com.android.art.artdtest"/>
+        <option name="runner" value="androidx.test.runner.AndroidJUnitRunner"/>
+    </test>
+</configuration>
diff --git a/artd/tests/src/com/android/art/ArtdIntegrationTests.java b/artd/tests/src/com/android/art/ArtdIntegrationTests.java
new file mode 100644
index 0000000..7d40adb
--- /dev/null
+++ b/artd/tests/src/com/android/art/ArtdIntegrationTests.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2021 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 com.android.art;
+
+import android.os.IArtd;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import java.lang.IllegalStateException;
+
+/**
+ * Integration tests for Artd.
+ *
+ * Run with "atest ArtdIntegrationTests".
+ */
+@RunWith(JUnit4.class)
+public final class ArtdIntegrationTests {
+
+    private static final String TAG = "ArtdTests";
+
+    private static IArtd mArtd;
+
+    @Before
+    public void setUp() {
+        IBinder rawBinderService = ServiceManager.getService("artd");
+        if (rawBinderService == null) {
+            throw new IllegalStateException("Unable to fetch artd service from binder.");
+        }
+
+        mArtd = IArtd.Stub.asInterface(rawBinderService);
+    }
+
+    // Test basic build and publish functionality for Artd.
+    @Test
+    public void testLiveness() throws RemoteException {
+        Assert.assertTrue(mArtd.isAlive());
+    }
+}