Merge "Import translations. DO NOT MERGE ANYWHERE" into main
diff --git a/android/TerminalApp/AndroidManifest.xml b/android/TerminalApp/AndroidManifest.xml
index 726004c..53fdafc 100644
--- a/android/TerminalApp/AndroidManifest.xml
+++ b/android/TerminalApp/AndroidManifest.xml
@@ -35,7 +35,8 @@
android:theme="@style/VmTerminalAppTheme"
android:usesCleartextTraffic="true"
android:supportsRtl="true"
- android:enabled="false">
+ android:enabled="false"
+ android:name=".Application">
<activity android:name=".MainActivity"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden|navigation|uiMode|screenLayout|smallestScreenSize"
android:exported="true">
diff --git a/android/TerminalApp/java/com/android/virtualization/terminal/Application.kt b/android/TerminalApp/java/com/android/virtualization/terminal/Application.kt
new file mode 100644
index 0000000..efe651e
--- /dev/null
+++ b/android/TerminalApp/java/com/android/virtualization/terminal/Application.kt
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2025 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.Application as AndroidApplication
+import android.app.NotificationChannel
+import android.app.NotificationManager
+import android.content.Context
+
+public class Application : AndroidApplication() {
+ override fun onCreate() {
+ super.onCreate()
+ setupNotificationChannels()
+ }
+
+ private fun setupNotificationChannels() {
+ val nm = getSystemService<NotificationManager>(NotificationManager::class.java)
+
+ nm.createNotificationChannel(
+ NotificationChannel(
+ CHANNEL_LONG_RUNNING_ID,
+ getString(R.string.notification_channel_long_running_name),
+ NotificationManager.IMPORTANCE_DEFAULT,
+ )
+ )
+
+ nm.createNotificationChannel(
+ NotificationChannel(
+ CHANNEL_SYSTEM_EVENTS_ID,
+ getString(R.string.notification_channel_system_events_name),
+ NotificationManager.IMPORTANCE_HIGH,
+ )
+ )
+ }
+
+ companion object {
+ const val CHANNEL_LONG_RUNNING_ID = "long_running"
+ const val CHANNEL_SYSTEM_EVENTS_ID = "system_events"
+
+ fun getInstance(c: Context): Application = c.getApplicationContext() as Application
+ }
+}
diff --git a/android/TerminalApp/java/com/android/virtualization/terminal/BaseActivity.kt b/android/TerminalApp/java/com/android/virtualization/terminal/BaseActivity.kt
index e7ac8d9..70bc5e4 100644
--- a/android/TerminalApp/java/com/android/virtualization/terminal/BaseActivity.kt
+++ b/android/TerminalApp/java/com/android/virtualization/terminal/BaseActivity.kt
@@ -16,8 +16,6 @@
package com.android.virtualization.terminal
import android.Manifest
-import android.app.NotificationChannel
-import android.app.NotificationManager
import android.content.pm.PackageManager
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
@@ -25,18 +23,6 @@
abstract class BaseActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- val notificationManager =
- getSystemService<NotificationManager>(NotificationManager::class.java)
- if (notificationManager.getNotificationChannel(this.packageName) == null) {
- val channel =
- NotificationChannel(
- this.packageName,
- getString(R.string.app_name),
- NotificationManager.IMPORTANCE_HIGH,
- )
- notificationManager.createNotificationChannel(channel)
- }
-
if (this !is ErrorActivity) {
val currentThread = Thread.currentThread()
if (currentThread.uncaughtExceptionHandler !is TerminalExceptionHandler) {
diff --git a/android/TerminalApp/java/com/android/virtualization/terminal/InstallerService.kt b/android/TerminalApp/java/com/android/virtualization/terminal/InstallerService.kt
index 423d66b..7180e87 100644
--- a/android/TerminalApp/java/com/android/virtualization/terminal/InstallerService.kt
+++ b/android/TerminalApp/java/com/android/virtualization/terminal/InstallerService.kt
@@ -71,7 +71,7 @@
PendingIntent.FLAG_IMMUTABLE,
)
notification =
- Notification.Builder(this, this.packageName)
+ Notification.Builder(this, Application.CHANNEL_LONG_RUNNING_ID)
.setSilent(true)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle(getString(R.string.installer_notif_title_text))
diff --git a/android/TerminalApp/java/com/android/virtualization/terminal/MainActivity.kt b/android/TerminalApp/java/com/android/virtualization/terminal/MainActivity.kt
index bf2f573..1ae6ec5 100644
--- a/android/TerminalApp/java/com/android/virtualization/terminal/MainActivity.kt
+++ b/android/TerminalApp/java/com/android/virtualization/terminal/MainActivity.kt
@@ -209,7 +209,10 @@
view: WebView?,
request: WebResourceRequest?,
): Boolean {
- return false
+ val intent = Intent(Intent.ACTION_VIEW, request?.url)
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ startActivity(intent)
+ return true
}
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
@@ -293,6 +296,8 @@
info,
executorService,
object : NsdManager.ServiceInfoCallback {
+ var loaded: Boolean = false
+
override fun onServiceInfoCallbackRegistrationFailed(errorCode: Int) {}
override fun onServiceInfoCallbackUnregistered() {}
@@ -300,13 +305,15 @@
override fun onServiceLost() {}
override fun onServiceUpdated(info: NsdServiceInfo) {
- nsdManager.unregisterServiceInfoCallback(this)
-
Log.i(TAG, "Service found: $info")
val ipAddress = info.hostAddresses[0].hostAddress
val port = info.port
val url = getTerminalServiceUrl(ipAddress, port)
- runOnUiThread(Runnable { terminalView.loadUrl(url.toString()) })
+ if (!loaded) {
+ loaded = true
+ nsdManager.unregisterServiceInfoCallback(this)
+ runOnUiThread(Runnable { terminalView.loadUrl(url.toString()) })
+ }
}
},
)
@@ -409,7 +416,7 @@
)
val icon = Icon.createWithResource(resources, R.drawable.ic_launcher_foreground)
val notification: Notification =
- Notification.Builder(this, this.packageName)
+ Notification.Builder(this, Application.CHANNEL_LONG_RUNNING_ID)
.setSilent(true)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle(resources.getString(R.string.service_notification_title))
diff --git a/android/TerminalApp/java/com/android/virtualization/terminal/PortNotifier.kt b/android/TerminalApp/java/com/android/virtualization/terminal/PortNotifier.kt
index 7c48303..7e58b36 100644
--- a/android/TerminalApp/java/com/android/virtualization/terminal/PortNotifier.kt
+++ b/android/TerminalApp/java/com/android/virtualization/terminal/PortNotifier.kt
@@ -100,7 +100,7 @@
)
.build()
val notification: Notification =
- Notification.Builder(context, context.getPackageName())
+ Notification.Builder(context, Application.CHANNEL_SYSTEM_EVENTS_ID)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle(title)
.setContentText(content)
diff --git a/android/TerminalApp/java/com/android/virtualization/terminal/VmLauncherService.kt b/android/TerminalApp/java/com/android/virtualization/terminal/VmLauncherService.kt
index 8c0368d..f8b1b45 100644
--- a/android/TerminalApp/java/com/android/virtualization/terminal/VmLauncherService.kt
+++ b/android/TerminalApp/java/com/android/virtualization/terminal/VmLauncherService.kt
@@ -149,6 +149,8 @@
info,
executorService!!,
object : NsdManager.ServiceInfoCallback {
+ var started: Boolean = false
+
override fun onServiceInfoCallbackRegistrationFailed(errorCode: Int) {}
override fun onServiceInfoCallbackUnregistered() {}
@@ -156,9 +158,12 @@
override fun onServiceLost() {}
override fun onServiceUpdated(info: NsdServiceInfo) {
- nsdManager.unregisterServiceInfoCallback(this)
Log.i(TAG, "Service found: $info")
- startDebianServer(info.hostAddresses[0].hostAddress)
+ if (!started) {
+ started = true
+ nsdManager.unregisterServiceInfoCallback(this)
+ startDebianServer(info.hostAddresses[0].hostAddress)
+ }
}
},
)
@@ -182,7 +187,7 @@
resources.getString(R.string.service_notification_force_quit_action)
val stopNotificationTitle: String? =
resources.getString(R.string.service_notification_close_title)
- return Notification.Builder(this, this.packageName)
+ return Notification.Builder(this, Application.CHANNEL_SYSTEM_EVENTS_ID)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle(stopNotificationTitle)
.setOngoing(true)
diff --git a/android/TerminalApp/res/values/strings.xml b/android/TerminalApp/res/values/strings.xml
index d3440d3..bdebb83 100644
--- a/android/TerminalApp/res/values/strings.xml
+++ b/android/TerminalApp/res/values/strings.xml
@@ -172,4 +172,10 @@
<!-- This string is for toast message to notify that VirGL is enabled. [CHAR LIMIT=40] -->
<string name="virgl_enabled"><xliff:g>VirGL</xliff:g> is enabled</string>
+
+ <!-- This is the name of the notification channel for long-runnint tasks [CHAR LIMIT=none] -->
+ <string name="notification_channel_long_running_name">Long running tasks</string>
+
+ <!-- This is the name of the notification channel for system events [CHAR LIMIT=none] -->
+ <string name="notification_channel_system_events_name">System events</string>
</resources>
diff --git a/build/debian/fai_config/files/etc/avahi/services/ttyd.service/AVF b/build/debian/fai_config/files/etc/avahi/services/ttyd.service/AVF
deleted file mode 100644
index 64f9d0a..0000000
--- a/build/debian/fai_config/files/etc/avahi/services/ttyd.service/AVF
+++ /dev/null
@@ -1,13 +0,0 @@
-<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
-<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
-
-<service-group>
-
- <name>ttyd</name>
-
- <service protocol="ipv4">
- <type>_http._tcp</type>
- <port>7681</port>
- </service>
-
-</service-group>
diff --git a/build/debian/fai_config/files/etc/systemd/system/ttyd.service/AVF b/build/debian/fai_config/files/etc/systemd/system/ttyd.service/AVF
index 4a32f2b..d86bab0 100644
--- a/build/debian/fai_config/files/etc/systemd/system/ttyd.service/AVF
+++ b/build/debian/fai_config/files/etc/systemd/system/ttyd.service/AVF
@@ -3,11 +3,14 @@
After=syslog.target
After=network.target
After=virtiofs_internal.service
+
[Service]
ExecStart=/usr/local/bin/ttyd --ssl --ssl-cert /etc/ttyd/server.crt --ssl-key /etc/ttyd/server.key --ssl-ca /mnt/internal/ca.crt -t disableLeaveAlert=true -W login -f droid
+ExecStartPost=/usr/bin/avahi-publish-service ttyd _http._tcp 7681
Type=simple
Restart=always
User=root
Group=root
+
[Install]
WantedBy=multi-user.target
diff --git a/tests/hostside/java/com/android/microdroid/test/MicrodroidHostTests.java b/tests/hostside/java/com/android/microdroid/test/MicrodroidHostTests.java
index 4f9806a..1873c2c 100644
--- a/tests/hostside/java/com/android/microdroid/test/MicrodroidHostTests.java
+++ b/tests/hostside/java/com/android/microdroid/test/MicrodroidHostTests.java
@@ -101,6 +101,9 @@
private static final String INSTANCE_IMG = TEST_ROOT + "instance.img";
private static final String INSTANCE_ID_FILE = TEST_ROOT + "instance_id";
+ private static final String DEBUG_LEVEL_FULL = "full";
+ private static final String DEBUG_LEVEL_NONE = "none";
+
private static final int MIN_MEM_ARM64 = 170;
private static final int MIN_MEM_X86_64 = 196;
@@ -465,7 +468,7 @@
try {
microdroid =
MicrodroidBuilder.fromDevicePath(getPathForPackage(PACKAGE_NAME), configPath)
- .debugLevel("full")
+ .debugLevel(DEBUG_LEVEL_FULL)
.memoryMib(minMemorySize())
.cpuTopology("match_host")
.protectedVm(true)
@@ -495,7 +498,7 @@
// Act
mMicrodroidDevice =
MicrodroidBuilder.fromDevicePath(getPathForPackage(PACKAGE_NAME), configPath)
- .debugLevel("full")
+ .debugLevel(DEBUG_LEVEL_FULL)
.memoryMib(minMemorySize())
.cpuTopology("match_host")
.protectedVm(true)
@@ -644,7 +647,7 @@
mMicrodroidDevice =
MicrodroidBuilder.fromDevicePath(getPathForPackage(PACKAGE_NAME), configPath)
- .debugLevel("full")
+ .debugLevel(DEBUG_LEVEL_FULL)
.memoryMib(minMemorySize())
.cpuTopology("match_host")
.protectedVm(protectedVm)
@@ -751,7 +754,7 @@
VIRT_APEX + "bin/vm",
"run-app",
"--debug",
- debuggable ? "full" : "none",
+ debuggable ? DEBUG_LEVEL_FULL : DEBUG_LEVEL_NONE,
apkPath,
idsigPath,
instanceImgPath));
@@ -871,7 +874,7 @@
final String configPath = "assets/vm_config_apex.json"; // path inside the APK
ITestDevice microdroid =
MicrodroidBuilder.fromDevicePath(getPathForPackage(PACKAGE_NAME), configPath)
- .debugLevel("full")
+ .debugLevel(DEBUG_LEVEL_FULL)
.memoryMib(minMemorySize())
.cpuTopology("match_host")
.protectedVm(protectedVm)
@@ -1023,7 +1026,7 @@
final String configPath = "assets/vm_config.json"; // path inside the APK
testMicrodroidBootsWithBuilder(
MicrodroidBuilder.fromDevicePath(getPathForPackage(PACKAGE_NAME), configPath)
- .debugLevel("full")
+ .debugLevel(DEBUG_LEVEL_FULL)
.memoryMib(minMemorySize())
.cpuTopology("match_host")
.protectedVm(protectedVm)
@@ -1061,7 +1064,7 @@
final String configPath = "assets/vm_config.json";
mMicrodroidDevice =
MicrodroidBuilder.fromDevicePath(getPathForPackage(PACKAGE_NAME), configPath)
- .debugLevel("full")
+ .debugLevel(DEBUG_LEVEL_FULL)
.memoryMib(minMemorySize())
.cpuTopology("match_host")
.protectedVm(protectedVm)
@@ -1175,7 +1178,7 @@
"shell",
VIRT_APEX + "bin/vm",
"run-app",
- "--debug full",
+ "--debug " + DEBUG_LEVEL_FULL,
"--console " + CONSOLE_PATH,
"--payload-binary-name",
"MicrodroidEmptyPayloadJniLib.so",
@@ -1357,7 +1360,7 @@
mMicrodroidDevice =
MicrodroidBuilder.fromDevicePath(getPathForPackage(PACKAGE_NAME), configPath)
- .debugLevel("full")
+ .debugLevel(DEBUG_LEVEL_FULL)
.memoryMib(minMemorySize())
.cpuTopology("match_host")
.protectedVm(protectedVm)
@@ -1403,7 +1406,7 @@
final String configPath = "assets/vm_config.json";
mMicrodroidDevice =
MicrodroidBuilder.fromDevicePath(getPathForPackage(PACKAGE_NAME), configPath)
- .debugLevel("full")
+ .debugLevel(DEBUG_LEVEL_FULL)
.memoryMib(minMemorySize())
.cpuTopology("match_host")
.protectedVm(protectedVm)
@@ -1434,7 +1437,7 @@
// Start the VM with the dump DT option.
mMicrodroidDevice =
MicrodroidBuilder.fromDevicePath(getPathForPackage(PACKAGE_NAME), configPath)
- .debugLevel("full")
+ .debugLevel(DEBUG_LEVEL_FULL)
.memoryMib(mem_size)
.cpuTopology("one_cpu")
.protectedVm(false)
@@ -1464,7 +1467,7 @@
// Start the VM with the dump DT option.
mMicrodroidDevice =
MicrodroidBuilder.fromDevicePath(getPathForPackage(PACKAGE_NAME), configPath)
- .debugLevel("full")
+ .debugLevel(DEBUG_LEVEL_FULL)
.memoryMib(mem_size)
.cpuTopology("one_cpu")
.protectedVm(true)