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.IVirtualDeviceSoundEffectListener;
22 import android.companion.virtual.VirtualDevice;
23 import android.companion.virtual.VirtualDeviceParams;
24 import android.hardware.display.IVirtualDisplayCallback;
25 import android.hardware.display.VirtualDisplayConfig;
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      */
createVirtualDevice( in IBinder token, String packageName, int associationId, in VirtualDeviceParams params, in IVirtualDeviceActivityListener activityListener, in IVirtualDeviceSoundEffectListener soundEffectListener)47     IVirtualDevice createVirtualDevice(
48             in IBinder token, String packageName, int associationId,
49             in VirtualDeviceParams params, in IVirtualDeviceActivityListener activityListener,
50             in IVirtualDeviceSoundEffectListener soundEffectListener);
51 
52     /**
53      * Returns the details of all available virtual devices.
54      */
getVirtualDevices()55     List<VirtualDevice> getVirtualDevices();
56 
57    /**
58      * Returns the ID of the device which owns the display with the given ID.
59      */
getDeviceIdForDisplayId(int displayId)60     int getDeviceIdForDisplayId(int displayId);
61 
62    /**
63      * Checks whether the passed {@code deviceId} is a valid virtual device ID or not.
64      * {@link VirtualDeviceManager#DEVICE_ID_DEFAULT} is not valid as it is the ID of the default
65      * device which is not a virtual device. {@code deviceId} must correspond to a virtual device
66      * created by {@link VirtualDeviceManager#createVirtualDevice(int, VirtualDeviceParams)}.
67     */
isValidVirtualDeviceId(int deviceId)68    boolean isValidVirtualDeviceId(int deviceId);
69 
70     /**
71      * Returns the device policy for the given virtual device and policy type.
72      */
getDevicePolicy(int deviceId, int policyType)73     int getDevicePolicy(int deviceId, int policyType);
74 
75     /**
76      * Creates a virtual display owned by a particular virtual device.
77      *
78      * @param virtualDisplayConfig The configuration used in creating the display
79      * @param callback A callback that receives display lifecycle events
80      * @param virtualDevice The device that will own this display
81      * @param packageName The package name of the calling app
82      */
createVirtualDisplay(in VirtualDisplayConfig virtualDisplayConfig, in IVirtualDisplayCallback callback, in IVirtualDevice virtualDevice, String packageName)83     int createVirtualDisplay(in VirtualDisplayConfig virtualDisplayConfig,
84             in IVirtualDisplayCallback callback, in IVirtualDevice virtualDevice,
85             String packageName);
86 
87     /**
88      * Returns device-specific session id for playback, or AUDIO_SESSION_ID_GENERATE
89      * if there's none.
90      */
getAudioPlaybackSessionId(int deviceId)91     int getAudioPlaybackSessionId(int deviceId);
92 
93     /**
94      * Returns device-specific session id for recording, or AUDIO_SESSION_ID_GENERATE
95      * if there's none.
96      */
getAudioRecordingSessionId(int deviceId)97     int getAudioRecordingSessionId(int deviceId);
98 
99     /**
100      * Triggers sound effect playback on virtual device.
101      *
102      * @param deviceId id of the virtual device.
103      * @param sound effect type corresponding to
104      *   {@code android.media.AudioManager.SystemSoundEffect}
105      */
playSoundEffect(int deviceId, int effectType)106     void playSoundEffect(int deviceId, int effectType);
107 }
108