Convert terminal test to kotlin

and change visibility of class and method which is used for testing

Bug: 387266878
Test: atest TerminalAppTest
Change-Id: I1ceace5aa7a272d7399a571a27c4d5cb909ed435
diff --git a/tests/Terminal/Android.bp b/tests/Terminal/Android.bp
index 029fbea..a4e1f6b 100644
--- a/tests/Terminal/Android.bp
+++ b/tests/Terminal/Android.bp
@@ -4,7 +4,7 @@
 
 android_test {
     name: "TerminalAppTests",
-    srcs: ["src/**/*.java"],
+    srcs: ["src/**/*.kt"],
     libs: [
         "android.test.runner.stubs.system",
         "android.test.base.stubs.system",
diff --git a/tests/Terminal/src/com/android/virtualization/terminal/TerminalAppTest.java b/tests/Terminal/src/com/android/virtualization/terminal/TerminalAppTest.java
deleted file mode 100644
index b0afb54..0000000
--- a/tests/Terminal/src/com/android/virtualization/terminal/TerminalAppTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (C) 2024 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.virtualization.terminal;
-
-import static org.junit.Assert.assertTrue;
-
-import android.app.Instrumentation;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.SystemProperties;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.runner.AndroidJUnit4;
-
-import com.android.microdroid.test.common.DeviceProperties;
-import com.android.microdroid.test.common.MetricsProcessor;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-@RunWith(AndroidJUnit4.class)
-public class TerminalAppTest {
-    private Instrumentation mInstr;
-    private Context mTargetContext;
-    private DeviceProperties mProperties;
-    private final MetricsProcessor mMetricsProc = new MetricsProcessor("avf_perf/terminal/");
-
-    @Before
-    public void setup() {
-        mInstr = InstrumentationRegistry.getInstrumentation();
-        mTargetContext = mInstr.getTargetContext();
-        mProperties = DeviceProperties.create(SystemProperties::get);
-        installVmImage();
-    }
-
-    private void installVmImage() {
-        final long INSTALL_TIMEOUT_MILLIS = 300_000; // 5 min
-
-        Intent intent = new Intent(mTargetContext, InstallerActivity.class);
-        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
-        if (mInstr.startActivitySync(intent) instanceof InstallerActivity activity) {
-            assertTrue(
-                    "Failed to install VM image",
-                    activity.waitForInstallCompleted(INSTALL_TIMEOUT_MILLIS));
-        }
-    }
-
-    @Test
-    public void boot() throws Exception {
-        final boolean isNestedVirt = mProperties.isCuttlefish() || mProperties.isGoldfish();
-        final long BOOT_TIMEOUT_MILLIS = isNestedVirt ? 180_000 : 30_000; // 30 sec (or 3 min)
-
-        Intent intent = new Intent(mTargetContext, MainActivity.class);
-        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
-        long start = System.currentTimeMillis();
-        if (mInstr.startActivitySync(intent) instanceof MainActivity activity) {
-            assertTrue("Failed to boot in 30s", activity.waitForBootCompleted(BOOT_TIMEOUT_MILLIS));
-        }
-        long delay = System.currentTimeMillis() - start;
-
-        // TODO: measure multiple times?
-        List<Long> measurements = new ArrayList<>();
-        measurements.add(delay);
-        Map<String, Double> stats = mMetricsProc.computeStats(measurements, "boot", "ms");
-        Bundle bundle = new Bundle();
-        for (Map.Entry<String, Double> entry : stats.entrySet()) {
-            bundle.putDouble(entry.getKey(), entry.getValue());
-        }
-        mInstr.sendStatus(0, bundle);
-    }
-
-    @After
-    public void tearDown() throws IOException {
-        PortsStateManager.getInstance(mTargetContext).clearEnabledPorts();
-        InstalledImage.getDefault(mTargetContext).uninstallFully();
-    }
-}
diff --git a/tests/Terminal/src/com/android/virtualization/terminal/TerminalAppTest.kt b/tests/Terminal/src/com/android/virtualization/terminal/TerminalAppTest.kt
new file mode 100644
index 0000000..946d28f
--- /dev/null
+++ b/tests/Terminal/src/com/android/virtualization/terminal/TerminalAppTest.kt
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2024 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.virtualization.terminal
+
+import android.app.Instrumentation
+import android.content.Context
+import android.content.Intent
+import android.os.Bundle
+import android.os.SystemProperties
+import androidx.test.InstrumentationRegistry
+import androidx.test.runner.AndroidJUnit4
+import com.android.microdroid.test.common.DeviceProperties
+import com.android.microdroid.test.common.MetricsProcessor
+import java.io.IOException
+import java.lang.Exception
+import java.util.ArrayList
+import org.junit.After
+import org.junit.Assert
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class TerminalAppTest {
+    private lateinit var instr: Instrumentation
+    private lateinit var targetContext: Context
+    private lateinit var properties: DeviceProperties
+    private val metricsProc = MetricsProcessor("avf_perf/terminal/")
+
+    @Before
+    fun setup() {
+        instr = InstrumentationRegistry.getInstrumentation()
+        targetContext = instr.targetContext
+        properties =
+            DeviceProperties.create(DeviceProperties.PropertyGetter { SystemProperties.get(it) })
+        installVmImage()
+    }
+
+    private fun installVmImage() {
+        val INSTALL_TIMEOUT_MILLIS: Long = 300000 // 5 min
+
+        val intent = Intent(targetContext, InstallerActivity::class.java)
+        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+        val activity = instr.startActivitySync(intent)
+        if (activity is InstallerActivity) {
+            Assert.assertTrue(
+                "Failed to install VM image",
+                activity.waitForInstallCompleted(INSTALL_TIMEOUT_MILLIS),
+            )
+        }
+    }
+
+    @Test
+    @Throws(Exception::class)
+    fun boot() {
+        val isNestedVirt = properties.isCuttlefish() || properties.isGoldfish()
+        val BOOT_TIMEOUT_MILLIS =
+            (if (isNestedVirt) 180000 else 30000).toLong() // 30 sec (or 3 min)
+
+        val intent = Intent(targetContext, MainActivity::class.java)
+        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+
+        val start = System.currentTimeMillis()
+        val activity = instr.startActivitySync(intent)
+        if (activity is MainActivity) {
+            Assert.assertTrue(
+                "Failed to boot in 30s",
+                activity.waitForBootCompleted(BOOT_TIMEOUT_MILLIS),
+            )
+        }
+        val delay = System.currentTimeMillis() - start
+
+        // TODO: measure multiple times?
+        val measurements: MutableList<Long?> = ArrayList<Long?>()
+        measurements.add(delay)
+        val stats = metricsProc.computeStats(measurements, "boot", "ms")
+        val bundle = Bundle()
+        for (entry in stats.entries) {
+            bundle.putDouble(entry.key, entry.value)
+        }
+        instr.sendStatus(0, bundle)
+    }
+
+    @After
+    @Throws(IOException::class)
+    fun tearDown() {
+        PortsStateManager.getInstance(targetContext).clearEnabledPorts()
+        InstalledImage.getDefault(targetContext).uninstallFully()
+    }
+}