summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorMaurice Lam <yukl@google.com>2022-01-15 01:34:54 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2022-01-15 01:34:54 +0000
commitf487abc91738ac846ee86baaf14a128b083c62ad (patch)
tree1706946ee7b28b09d66cdae465bed0742876295c /core/java
parent1439429dd6cbdea912c5746fce9dce7e3ad5bbfa (diff)
parentf03d832c434cc327f7dbc317324c26e4cd1b1b68 (diff)
Merge "Add VirtualDevice.launchPendingIntent"
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/companion/virtual/IVirtualDevice.aidl9
-rw-r--r--core/java/android/companion/virtual/VirtualDeviceManager.java67
2 files changed, 76 insertions, 0 deletions
diff --git a/core/java/android/companion/virtual/IVirtualDevice.aidl b/core/java/android/companion/virtual/IVirtualDevice.aidl
index 82ad15057fe3..85855bedfbeb 100644
--- a/core/java/android/companion/virtual/IVirtualDevice.aidl
+++ b/core/java/android/companion/virtual/IVirtualDevice.aidl
@@ -16,12 +16,14 @@
package android.companion.virtual;
+import android.app.PendingIntent;
import android.graphics.Point;
import android.hardware.input.VirtualKeyEvent;
import android.hardware.input.VirtualMouseButtonEvent;
import android.hardware.input.VirtualMouseRelativeEvent;
import android.hardware.input.VirtualMouseScrollEvent;
import android.hardware.input.VirtualTouchEvent;
+import android.os.ResultReceiver;
/**
* Interface for a virtual device.
@@ -41,6 +43,7 @@ interface IVirtualDevice {
* Closes the virtual device and frees all associated resources.
*/
void close();
+
void createVirtualKeyboard(
int displayId,
String inputDeviceName,
@@ -66,4 +69,10 @@ interface IVirtualDevice {
boolean sendRelativeEvent(IBinder token, in VirtualMouseRelativeEvent event);
boolean sendScrollEvent(IBinder token, in VirtualMouseScrollEvent event);
boolean sendTouchEvent(IBinder token, in VirtualTouchEvent event);
+
+ /**
+ * Launches a pending intent on the given display that is owned by this virtual device.
+ */
+ void launchPendingIntent(
+ int displayId, in PendingIntent pendingIntent, in ResultReceiver resultReceiver);
}
diff --git a/core/java/android/companion/virtual/VirtualDeviceManager.java b/core/java/android/companion/virtual/VirtualDeviceManager.java
index 858e4daa136f..8ab668873f33 100644
--- a/core/java/android/companion/virtual/VirtualDeviceManager.java
+++ b/core/java/android/companion/virtual/VirtualDeviceManager.java
@@ -23,6 +23,8 @@ import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.SystemService;
+import android.app.Activity;
+import android.app.PendingIntent;
import android.companion.AssociationInfo;
import android.content.Context;
import android.graphics.Point;
@@ -33,15 +35,19 @@ import android.hardware.input.VirtualKeyboard;
import android.hardware.input.VirtualMouse;
import android.hardware.input.VirtualTouchscreen;
import android.os.Binder;
+import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
+import android.os.Looper;
import android.os.RemoteException;
+import android.os.ResultReceiver;
import android.view.Surface;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import java.util.concurrent.Executor;
/**
* System level service for managing virtual devices.
@@ -129,6 +135,49 @@ public final class VirtualDeviceManager {
}
/**
+ * Launches a given pending intent on the give display ID.
+ *
+ * @param displayId The display to launch the pending intent on. This display must be
+ * created from this virtual device.
+ * @param pendingIntent The pending intent to be launched. If the intent is an activity
+ * intent, the activity will be started on the virtual display using
+ * {@link android.app.ActivityOptions#setLaunchDisplayId}. If the intent is a service or
+ * broadcast intent, an attempt will be made to catch activities started as a result of
+ * sending the pending intent and move them to the given display.
+ * @param executor The executor to run {@code launchCallback} on.
+ * @param launchCallback Callback that is called when the pending intent launching is
+ * complete.
+ *
+ * @hide
+ */
+ public void launchPendingIntent(
+ int displayId,
+ @NonNull PendingIntent pendingIntent,
+ @NonNull Executor executor,
+ @NonNull LaunchCallback launchCallback) {
+ try {
+ mVirtualDevice.launchPendingIntent(
+ displayId,
+ pendingIntent,
+ new ResultReceiver(new Handler(Looper.myLooper())) {
+ @Override
+ protected void onReceiveResult(int resultCode, Bundle resultData) {
+ super.onReceiveResult(resultCode, resultData);
+ executor.execute(() -> {
+ if (resultCode == Activity.RESULT_OK) {
+ launchCallback.onLaunchSuccess();
+ } else {
+ launchCallback.onLaunchFailed();
+ }
+ });
+ }
+ });
+ } catch (RemoteException e) {
+ e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
* Creates a virtual display for this virtual device. All displays created on the same
* device belongs to the same display group.
*
@@ -299,4 +348,22 @@ public final class VirtualDeviceManager {
}
}
}
+
+ /**
+ * Callback for launching pending intents on the virtual device.
+ *
+ * @hide
+ */
+ // TODO(b/194949534): Unhide this API
+ public interface LaunchCallback {
+ /**
+ * Called when the pending intent launched successfully.
+ */
+ void onLaunchSuccess();
+
+ /**
+ * Called when the pending intent failed to launch.
+ */
+ void onLaunchFailed();
+ }
}