Merge "VmTerminalApp: Mark configs as translatable="false"" into main
diff --git a/android/TerminalApp/java/com/android/virtualization/terminal/MainActivity.java b/android/TerminalApp/java/com/android/virtualization/terminal/MainActivity.java
index 416f4c9..b1ebb9e 100644
--- a/android/TerminalApp/java/com/android/virtualization/terminal/MainActivity.java
+++ b/android/TerminalApp/java/com/android/virtualization/terminal/MainActivity.java
@@ -45,6 +45,7 @@
import android.widget.Toast;
import com.android.virtualization.vmlauncher.InstallUtils;
+import com.android.virtualization.vmlauncher.VmLauncherService;
import com.android.virtualization.vmlauncher.VmLauncherServices;
import com.google.android.material.appbar.MaterialToolbar;
@@ -428,22 +429,46 @@
Intent intent = new Intent();
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
-
+ Intent stopIntent = new Intent();
+ stopIntent.setClass(this, VmLauncherService.class);
+ stopIntent.setAction(VmLauncherServices.ACTION_STOP_VM_LAUNCHER_SERVICE);
+ PendingIntent stopPendingIntent =
+ PendingIntent.getService(
+ this,
+ 0,
+ stopIntent,
+ PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
Icon icon = Icon.createWithResource(getResources(), R.drawable.ic_launcher_foreground);
- Notification notification = new Notification.Builder(this, TAG)
- .setChannelId(TAG)
- .setSmallIcon(R.drawable.ic_launcher_foreground)
- .setContentTitle(getResources().getString(R.string.service_notification_title))
- .setContentText(getResources().getString(R.string.service_notification_content))
- .setContentIntent(pendingIntent)
- .setOngoing(true)
- .addAction(new Notification.Action.Builder(icon,
- getResources().getString(R.string.service_notification_settings),
- pendingIntent).build())
- .addAction(new Notification.Action.Builder(icon,
- getResources().getString(R.string.service_notification_quit_action),
- pendingIntent).build())
- .build();
+ Notification notification =
+ new Notification.Builder(this, TAG)
+ .setChannelId(TAG)
+ .setSmallIcon(R.drawable.ic_launcher_foreground)
+ .setContentTitle(
+ getResources().getString(R.string.service_notification_title))
+ .setContentText(
+ getResources().getString(R.string.service_notification_content))
+ .setContentIntent(pendingIntent)
+ .setOngoing(true)
+ .addAction(
+ new Notification.Action.Builder(
+ icon,
+ getResources()
+ .getString(
+ R.string
+ .service_notification_settings),
+ pendingIntent)
+ .build())
+ .addAction(
+ new Notification.Action.Builder(
+ icon,
+ getResources()
+ .getString(
+ R.string
+ .service_notification_quit_action),
+ stopPendingIntent)
+ .build())
+ .setDeleteIntent(stopPendingIntent)
+ .build();
android.os.Trace.beginAsyncSection("executeTerminal", 0);
VmLauncherServices.startVmLauncherService(this, this, notification);
diff --git a/android/TerminalApp/proguard.flags b/android/TerminalApp/proguard.flags
index 13ec24e..b93240c 100644
--- a/android/TerminalApp/proguard.flags
+++ b/android/TerminalApp/proguard.flags
@@ -1,7 +1,33 @@
-# Keep the no-args constructor of the deserialized class
--keepclassmembers class com.android.virtualization.vmlauncher.ConfigJson {
- <init>();
+##---------------Begin: proguard configuration for Gson ----------
+# Gson uses generic type information stored in a class file when working with fields. Proguard
+# removes such information by default, so configure it to keep all of it.
+-keepattributes Signature
+
+# For using GSON @Expose annotation
+-keepattributes *Annotation*
+
+# Gson specific classes
+-dontwarn sun.misc.**
+#-keep class com.google.gson.stream.** { *; }
+
+# Application classes that will be serialized/deserialized over Gson
+-keep class com.android.virtualization.vmlauncher.ConfigJson { <fields>; }
+-keep class com.android.virtualization.vmlauncher.ConfigJson$* { <fields>; }
+
+# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
+# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
+-keep class * extends com.google.gson.TypeAdapter
+-keep class * implements com.google.gson.TypeAdapterFactory
+-keep class * implements com.google.gson.JsonSerializer
+-keep class * implements com.google.gson.JsonDeserializer
+
+# Prevent R8 from leaving Data object members always null
+-keepclassmembers,allowobfuscation class * {
+ @com.google.gson.annotations.SerializedName <fields>;
}
--keepclassmembers class com.android.virtualization.vmlauncher.ConfigJson$* {
- <init>();
-}
+
+# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher.
+-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
+-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken
+
+##---------------End: proguard configuration for Gson ----------
\ No newline at end of file
diff --git a/android/VmLauncherApp/proguard.flags b/android/VmLauncherApp/proguard.flags
index 13ec24e..b93240c 100644
--- a/android/VmLauncherApp/proguard.flags
+++ b/android/VmLauncherApp/proguard.flags
@@ -1,7 +1,33 @@
-# Keep the no-args constructor of the deserialized class
--keepclassmembers class com.android.virtualization.vmlauncher.ConfigJson {
- <init>();
+##---------------Begin: proguard configuration for Gson ----------
+# Gson uses generic type information stored in a class file when working with fields. Proguard
+# removes such information by default, so configure it to keep all of it.
+-keepattributes Signature
+
+# For using GSON @Expose annotation
+-keepattributes *Annotation*
+
+# Gson specific classes
+-dontwarn sun.misc.**
+#-keep class com.google.gson.stream.** { *; }
+
+# Application classes that will be serialized/deserialized over Gson
+-keep class com.android.virtualization.vmlauncher.ConfigJson { <fields>; }
+-keep class com.android.virtualization.vmlauncher.ConfigJson$* { <fields>; }
+
+# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
+# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
+-keep class * extends com.google.gson.TypeAdapter
+-keep class * implements com.google.gson.TypeAdapterFactory
+-keep class * implements com.google.gson.JsonSerializer
+-keep class * implements com.google.gson.JsonDeserializer
+
+# Prevent R8 from leaving Data object members always null
+-keepclassmembers,allowobfuscation class * {
+ @com.google.gson.annotations.SerializedName <fields>;
}
--keepclassmembers class com.android.virtualization.vmlauncher.ConfigJson$* {
- <init>();
-}
+
+# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher.
+-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
+-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken
+
+##---------------End: proguard configuration for Gson ----------
\ No newline at end of file
diff --git a/android/virtualizationservice/aidl/android/system/virtualizationservice/IVirtualMachine.aidl b/android/virtualizationservice/aidl/android/system/virtualizationservice/IVirtualMachine.aidl
index e52222a..a01d385 100644
--- a/android/virtualizationservice/aidl/android/system/virtualizationservice/IVirtualMachine.aidl
+++ b/android/virtualizationservice/aidl/android/system/virtualizationservice/IVirtualMachine.aidl
@@ -71,9 +71,9 @@
/** Set the name of the peer end (ptsname) of the host console. */
void setHostConsoleName(in @utf8InCpp String pathname);
- /** Suspends the VM. */
+ /** Suspends the VM vcpus. */
void suspend();
- /** Resumes the suspended VM. */
+ /** Resumes the suspended VM vcpus. */
void resume();
}
diff --git a/libs/vm_launcher_lib/java/com/android/virtualization/vmlauncher/VmLauncherService.java b/libs/vm_launcher_lib/java/com/android/virtualization/vmlauncher/VmLauncherService.java
index 3731854..5cd7b92 100644
--- a/libs/vm_launcher_lib/java/com/android/virtualization/vmlauncher/VmLauncherService.java
+++ b/libs/vm_launcher_lib/java/com/android/virtualization/vmlauncher/VmLauncherService.java
@@ -33,6 +33,7 @@
import java.io.IOException;
import java.nio.file.Path;
+import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -62,6 +63,11 @@
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
+ if (Objects.equals(
+ intent.getAction(), VmLauncherServices.ACTION_STOP_VM_LAUNCHER_SERVICE)) {
+ stopSelf();
+ return START_NOT_STICKY;
+ }
if (mVirtualMachine != null) {
Log.d(TAG, "VM instance is already started");
return START_NOT_STICKY;
diff --git a/libs/vm_launcher_lib/java/com/android/virtualization/vmlauncher/VmLauncherServices.java b/libs/vm_launcher_lib/java/com/android/virtualization/vmlauncher/VmLauncherServices.java
index 2fa0b32..6eca2b3 100644
--- a/libs/vm_launcher_lib/java/com/android/virtualization/vmlauncher/VmLauncherServices.java
+++ b/libs/vm_launcher_lib/java/com/android/virtualization/vmlauncher/VmLauncherServices.java
@@ -36,6 +36,8 @@
private static final String ACTION_START_VM_LAUNCHER_SERVICE =
"android.virtualization.START_VM_LAUNCHER_SERVICE";
+ public static final String ACTION_STOP_VM_LAUNCHER_SERVICE =
+ "android.virtualization.STOP_VM_LAUNCHER_SERVICE";
private static final int RESULT_START = 0;
private static final int RESULT_STOP = 1;
private static final int RESULT_ERROR = 2;