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 27 /** 28 * Interface for communication between VirtualDeviceManager and VirtualDeviceManagerService. 29 * 30 * @hide 31 */ 32 interface IVirtualDeviceManager { 33 34 /** 35 * Creates a virtual device that can be used to create virtual displays and stream contents. 36 * 37 * @param token The binder token created by the caller of this API. 38 * @param packageName The package name of the caller. Implementation of this method must verify 39 * that this belongs to the calling UID. 40 * @param associationId The association ID as returned by {@link AssociationInfo#getId()} from 41 * CDM. Virtual devices must have a corresponding association with CDM in order to be created. 42 * @param params The parameters for creating this virtual device. See {@link 43 * VirtualDeviceManager.VirtualDeviceParams}. 44 * @param activityListener The listener to listen for activity changes in a virtual device. 45 * @param soundEffectListener The listener to listen for sound effect playback requests. 46 */ 47 @EnforcePermission("CREATE_VIRTUAL_DEVICE") createVirtualDevice( in IBinder token, in AttributionSource attributionSource, int associationId, in VirtualDeviceParams params, in IVirtualDeviceActivityListener activityListener, in IVirtualDeviceSoundEffectListener soundEffectListener)48 IVirtualDevice createVirtualDevice( 49 in IBinder token, in AttributionSource attributionSource, int associationId, 50 in VirtualDeviceParams params, in IVirtualDeviceActivityListener activityListener, 51 in IVirtualDeviceSoundEffectListener soundEffectListener); 52 53 /** 54 * Returns the details of all available virtual devices. 55 */ getVirtualDevices()56 List<VirtualDevice> getVirtualDevices(); 57 58 /** 59 * Returns the details of the virtual device with the given ID, if any. 60 */ getVirtualDevice(int deviceId)61 VirtualDevice getVirtualDevice(int deviceId); 62 63 /** 64 * Registers a virtual device listener to receive notifications for virtual device events. 65 */ registerVirtualDeviceListener(in IVirtualDeviceListener listener)66 void registerVirtualDeviceListener(in IVirtualDeviceListener listener); 67 68 /** 69 * Unregisters a previously registered virtual device listener. 70 */ unregisterVirtualDeviceListener(in IVirtualDeviceListener listener)71 void unregisterVirtualDeviceListener(in IVirtualDeviceListener listener); 72 73 /** 74 * Returns the ID of the device which owns the display with the given ID. 75 */ getDeviceIdForDisplayId(int displayId)76 int getDeviceIdForDisplayId(int displayId); 77 78 /** 79 * Returns the display name corresponding to the given persistent device ID, if any. 80 */ getDisplayNameForPersistentDeviceId(in String persistentDeviceId)81 CharSequence getDisplayNameForPersistentDeviceId(in String persistentDeviceId); 82 83 /** 84 * Checks whether the passed {@code deviceId} is a valid virtual device ID or not. 85 * {@link VirtualDeviceManager#DEVICE_ID_DEFAULT} is not valid as it is the ID of the default 86 * device which is not a virtual device. {@code deviceId} must correspond to a virtual device 87 * created by {@link VirtualDeviceManager#createVirtualDevice(int, VirtualDeviceParams)}. 88 */ isValidVirtualDeviceId(int deviceId)89 boolean isValidVirtualDeviceId(int deviceId); 90 91 /** 92 * Returns the device policy for the given virtual device and policy type. 93 */ getDevicePolicy(int deviceId, int policyType)94 int getDevicePolicy(int deviceId, int policyType); 95 96 /** 97 * Returns device-specific session id for playback, or AUDIO_SESSION_ID_GENERATE 98 * if there's none. 99 */ getAudioPlaybackSessionId(int deviceId)100 int getAudioPlaybackSessionId(int deviceId); 101 102 /** 103 * Returns device-specific session id for recording, or AUDIO_SESSION_ID_GENERATE 104 * if there's none. 105 */ getAudioRecordingSessionId(int deviceId)106 int getAudioRecordingSessionId(int deviceId); 107 108 /** 109 * Triggers sound effect playback on virtual device. 110 * 111 * @param deviceId id of the virtual device. 112 * @param sound effect type corresponding to 113 * {@code android.media.AudioManager.SystemSoundEffect} 114 */ playSoundEffect(int deviceId, int effectType)115 void playSoundEffect(int deviceId, int effectType); 116 117 /** 118 * Returns whether the given display is an auto-mirror display owned by a virtual 119 * device. 120 */ isVirtualDeviceOwnedMirrorDisplay(int displayId)121 boolean isVirtualDeviceOwnedMirrorDisplay(int displayId); 122 123 /** 124 * Returns all current persistent device IDs, including the ones for which no virtual device 125 * exists, as long as one may have existed or can be created. 126 */ getAllPersistentDeviceIds()127 List<String> getAllPersistentDeviceIds(); 128 } 129