1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.companion.virtual; 18 19 import android.companion.virtual.IVirtualDevice; 20 import android.companion.virtual.IVirtualDeviceActivityListener; 21 import android.companion.virtual.IVirtualDeviceListener; 22 import android.companion.virtual.IVirtualDeviceSoundEffectListener; 23 import android.companion.virtual.VirtualDevice; 24 import android.companion.virtual.VirtualDeviceParams; 25 import android.content.AttributionSource; 26 import android.hardware.display.IVirtualDisplayCallback; 27 import android.hardware.display.VirtualDisplayConfig; 28 29 /** 30 * Interface for communication between VirtualDeviceManager and VirtualDeviceManagerService. 31 * 32 * @hide 33 */ 34 interface IVirtualDeviceManager { 35 36 /** 37 * Creates a virtual device that can be used to create virtual displays and stream contents. 38 * 39 * @param token The binder token created by the caller of this API. 40 * @param packageName The package name of the caller. Implementation of this method must verify 41 * that this belongs to the calling UID. 42 * @param associationId The association ID as returned by {@link AssociationInfo#getId()} from 43 * CDM. Virtual devices must have a corresponding association with CDM in order to be created. 44 * @param params The parameters for creating this virtual device. See {@link 45 * VirtualDeviceManager.VirtualDeviceParams}. 46 * @param activityListener The listener to listen for activity changes in a virtual device. 47 * @param soundEffectListener The listener to listen for sound effect playback requests. 48 */ 49 @EnforcePermission("CREATE_VIRTUAL_DEVICE") createVirtualDevice( in IBinder token, in AttributionSource attributionSource, int associationId, in VirtualDeviceParams params, in IVirtualDeviceActivityListener activityListener, in IVirtualDeviceSoundEffectListener soundEffectListener)50 IVirtualDevice createVirtualDevice( 51 in IBinder token, in AttributionSource attributionSource, int associationId, 52 in VirtualDeviceParams params, in IVirtualDeviceActivityListener activityListener, 53 in IVirtualDeviceSoundEffectListener soundEffectListener); 54 55 /** 56 * Returns the details of all available virtual devices. 57 */ getVirtualDevices()58 List<VirtualDevice> getVirtualDevices(); 59 60 /** 61 * Returns the details of the virtual device with the given ID, if any. 62 */ getVirtualDevice(int deviceId)63 VirtualDevice getVirtualDevice(int deviceId); 64 65 /** 66 * Registers a virtual device listener to receive notifications for virtual device events. 67 */ registerVirtualDeviceListener(in IVirtualDeviceListener listener)68 void registerVirtualDeviceListener(in IVirtualDeviceListener listener); 69 70 /** 71 * Unregisters a previously registered virtual device listener. 72 */ unregisterVirtualDeviceListener(in IVirtualDeviceListener listener)73 void unregisterVirtualDeviceListener(in IVirtualDeviceListener listener); 74 75 /** 76 * Returns the ID of the device which owns the display with the given ID. 77 */ getDeviceIdForDisplayId(int displayId)78 int getDeviceIdForDisplayId(int displayId); 79 80 /** 81 * Returns the display name corresponding to the given persistent device ID, if any. 82 */ getDisplayNameForPersistentDeviceId(in String persistentDeviceId)83 CharSequence getDisplayNameForPersistentDeviceId(in String persistentDeviceId); 84 85 /** 86 * Checks whether the passed {@code deviceId} is a valid virtual device ID or not. 87 * {@link VirtualDeviceManager#DEVICE_ID_DEFAULT} is not valid as it is the ID of the default 88 * device which is not a virtual device. {@code deviceId} must correspond to a virtual device 89 * created by {@link VirtualDeviceManager#createVirtualDevice(int, VirtualDeviceParams)}. 90 */ isValidVirtualDeviceId(int deviceId)91 boolean isValidVirtualDeviceId(int deviceId); 92 93 /** 94 * Returns the device policy for the given virtual device and policy type. 95 */ getDevicePolicy(int deviceId, int policyType)96 int getDevicePolicy(int deviceId, int policyType); 97 98 /** 99 * Creates a virtual display owned by a particular virtual device. 100 * 101 * @param virtualDisplayConfig The configuration used in creating the display 102 * @param callback A callback that receives display lifecycle events 103 * @param virtualDevice The device that will own this display 104 * @param packageName The package name of the calling app 105 */ createVirtualDisplay(in VirtualDisplayConfig virtualDisplayConfig, in IVirtualDisplayCallback callback, in IVirtualDevice virtualDevice, String packageName)106 int createVirtualDisplay(in VirtualDisplayConfig virtualDisplayConfig, 107 in IVirtualDisplayCallback callback, in IVirtualDevice virtualDevice, 108 String packageName); 109 110 /** 111 * Returns device-specific session id for playback, or AUDIO_SESSION_ID_GENERATE 112 * if there's none. 113 */ getAudioPlaybackSessionId(int deviceId)114 int getAudioPlaybackSessionId(int deviceId); 115 116 /** 117 * Returns device-specific session id for recording, or AUDIO_SESSION_ID_GENERATE 118 * if there's none. 119 */ getAudioRecordingSessionId(int deviceId)120 int getAudioRecordingSessionId(int deviceId); 121 122 /** 123 * Triggers sound effect playback on virtual device. 124 * 125 * @param deviceId id of the virtual device. 126 * @param sound effect type corresponding to 127 * {@code android.media.AudioManager.SystemSoundEffect} 128 */ playSoundEffect(int deviceId, int effectType)129 void playSoundEffect(int deviceId, int effectType); 130 131 /** 132 * Returns whether the given display is an auto-mirror display owned by a virtual 133 * device. 134 */ isVirtualDeviceOwnedMirrorDisplay(int displayId)135 boolean isVirtualDeviceOwnedMirrorDisplay(int displayId); 136 137 /** 138 * Returns all current persistent device IDs, including the ones for which no virtual device 139 * exists, as long as one may have existed or can be created. 140 */ getAllPersistentDeviceIds()141 List<String> getAllPersistentDeviceIds(); 142 } 143