diff options
| author | Maurice Lam <yukl@google.com> | 2021-08-04 20:23:41 -0700 |
|---|---|---|
| committer | Maurice Lam <yukl@google.com> | 2021-10-26 20:41:00 -0700 |
| commit | 771c72a607caa96016d93ea6eb7e53ae2bfdfa83 (patch) | |
| tree | f1484c06b16f5d6552436baa6ed9a31e7effa57e /core/java | |
| parent | bbd05d765e4bd5bc22baf74c5c087048d4b2ca8b (diff) | |
Create VirtualDeviceManager
CTS-Coverage-Bug: 194949534
Bug: 194949534
Test: ag/15781910
Change-Id: I06d245d91827390de99b9ff3e514af4294a11476
Diffstat (limited to 'core/java')
5 files changed, 171 insertions, 0 deletions
diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index 8ea1f8315b89..37228a581a8e 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -54,6 +54,8 @@ import android.appwidget.AppWidgetManager; import android.bluetooth.BluetoothManager; import android.companion.CompanionDeviceManager; import android.companion.ICompanionDeviceManager; +import android.companion.virtual.IVirtualDeviceManager; +import android.companion.virtual.VirtualDeviceManager; import android.content.ClipboardManager; import android.content.ContentCaptureOptions; import android.content.Context; @@ -875,6 +877,16 @@ public final class SystemServiceRegistry { return new CompanionDeviceManager(service, ctx.getOuterContext()); }}); + registerService(Context.VIRTUAL_DEVICE_SERVICE, VirtualDeviceManager.class, + new CachedServiceFetcher<VirtualDeviceManager>() { + @Override + public VirtualDeviceManager createService(ContextImpl ctx) + throws ServiceNotFoundException { + IVirtualDeviceManager service = IVirtualDeviceManager.Stub.asInterface( + ServiceManager.getServiceOrThrow(Context.VIRTUAL_DEVICE_SERVICE)); + return new VirtualDeviceManager(service, ctx.getOuterContext()); + }}); + registerService(Context.CONSUMER_IR_SERVICE, ConsumerIrManager.class, new CachedServiceFetcher<ConsumerIrManager>() { @Override diff --git a/core/java/android/companion/virtual/IVirtualDevice.aidl b/core/java/android/companion/virtual/IVirtualDevice.aidl new file mode 100644 index 000000000000..0aa442bfc503 --- /dev/null +++ b/core/java/android/companion/virtual/IVirtualDevice.aidl @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2021 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 android.companion.virtual; + +/** + * Interface for a virtual device. + * + * @hide + */ +interface IVirtualDevice { + void close(); +} diff --git a/core/java/android/companion/virtual/IVirtualDeviceManager.aidl b/core/java/android/companion/virtual/IVirtualDeviceManager.aidl new file mode 100644 index 000000000000..91e717d719a9 --- /dev/null +++ b/core/java/android/companion/virtual/IVirtualDeviceManager.aidl @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2021 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 android.companion.virtual; + +import android.companion.virtual.IVirtualDevice; + +/** + * Interface for communication between VirtualDeviceManager and VirtualDeviceManagerService. + * + * @hide + */ +interface IVirtualDeviceManager { + + IVirtualDevice createVirtualDevice(); +} diff --git a/core/java/android/companion/virtual/VirtualDeviceManager.java b/core/java/android/companion/virtual/VirtualDeviceManager.java new file mode 100644 index 000000000000..6187de57a216 --- /dev/null +++ b/core/java/android/companion/virtual/VirtualDeviceManager.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2021 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 android.companion.virtual; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.annotation.RequiresPermission; +import android.annotation.SystemApi; +import android.annotation.SystemService; +import android.content.Context; +import android.os.RemoteException; + +/** + * System level service for managing virtual devices. + * + * @hide + */ +@SystemApi +@SystemService(Context.VIRTUAL_DEVICE_SERVICE) +public final class VirtualDeviceManager { + + private static final boolean DEBUG = false; + private static final String LOG_TAG = "VirtualDeviceManager"; + + private final IVirtualDeviceManager mService; + private final Context mContext; + + /** @hide */ + public VirtualDeviceManager( + @Nullable IVirtualDeviceManager service, @NonNull Context context) { + mService = service; + mContext = context; + } + + /** + * Creates a virtual device. + * + * @hide + */ + @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) + @Nullable + public VirtualDevice createVirtualDevice() { + // TODO(b/194949534): Add CDM association ID here and unhide this API + try { + IVirtualDevice virtualDevice = mService.createVirtualDevice(); + return new VirtualDevice(mContext, virtualDevice); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** + * A virtual device has its own virtual display, audio output, microphone, and camera etc. The + * creator of a virtual device can take the output from the virtual display and stream it over + * to another device, and inject input events that are received from the remote device. + */ + public static class VirtualDevice implements AutoCloseable { + + private final Context mContext; + private final IVirtualDevice mVirtualDevice; + + private VirtualDevice(Context context, IVirtualDevice virtualDevice) { + mContext = context.getApplicationContext(); + mVirtualDevice = virtualDevice; + } + + /** + * Closes the virtual device, stopping and tearing down any virtual displays, + * audio policies, and event injection that's currently in progress. + */ + public void close() { + try { + mVirtualDevice.close(); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + } +} diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index cfd34174f9e3..bfc43334d7c1 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -3799,6 +3799,7 @@ public abstract class Context { //@hide: INCIDENT_COMPANION_SERVICE, //@hide: STATS_COMPANION_SERVICE, COMPANION_DEVICE_SERVICE, + //@hide: VIRTUAL_DEVICE_SERVICE, CROSS_PROFILE_APPS_SERVICE, //@hide: SYSTEM_UPDATE_SERVICE, //@hide: TIME_DETECTOR_SERVICE, @@ -5262,6 +5263,16 @@ public abstract class Context { /** * Use with {@link #getSystemService(String)} to retrieve a + * {@link android.companion.virtual.VirtualDeviceManager} for managing virtual devices. + * + * @see #getSystemService(String) + * @see android.companion.virtual.VirtualDeviceManager + * @hide + */ + public static final String VIRTUAL_DEVICE_SERVICE = "virtualdevice"; + + /** + * Use with {@link #getSystemService(String)} to retrieve a * {@link android.hardware.ConsumerIrManager} for transmitting infrared * signals from the device. * |
