Merge changes Ib65ecec6,I64fd9fed into main
* changes:
Use separate channels in terminal app
Add Application class
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..f027520 100644
--- a/android/TerminalApp/java/com/android/virtualization/terminal/MainActivity.kt
+++ b/android/TerminalApp/java/com/android/virtualization/terminal/MainActivity.kt
@@ -409,7 +409,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..f2aa3c0 100644
--- a/android/TerminalApp/java/com/android/virtualization/terminal/VmLauncherService.kt
+++ b/android/TerminalApp/java/com/android/virtualization/terminal/VmLauncherService.kt
@@ -182,7 +182,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>