• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.app.PendingIntent;
20 import android.companion.virtual.ActivityPolicyExemption;
21 import android.companion.virtual.IVirtualDeviceActivityListener;
22 import android.companion.virtual.IVirtualDeviceIntentInterceptor;
23 import android.companion.virtual.IVirtualDeviceSoundEffectListener;
24 import android.companion.virtual.audio.IAudioConfigChangedCallback;
25 import android.companion.virtual.audio.IAudioRoutingCallback;
26 import android.companion.virtual.sensor.VirtualSensor;
27 import android.companion.virtual.sensor.VirtualSensorAdditionalInfo;
28 import android.companion.virtual.sensor.VirtualSensorConfig;
29 import android.companion.virtual.sensor.VirtualSensorEvent;
30 import android.companion.virtual.camera.VirtualCameraConfig;
31 import android.content.ComponentName;
32 import android.content.IntentFilter;
33 import android.graphics.Point;
34 import android.graphics.PointF;
35 import android.hardware.display.IVirtualDisplayCallback;
36 import android.hardware.display.VirtualDisplayConfig;
37 import android.hardware.input.VirtualDpadConfig;
38 import android.hardware.input.VirtualKeyboardConfig;
39 import android.hardware.input.VirtualKeyEvent;
40 import android.hardware.input.VirtualMouseButtonEvent;
41 import android.hardware.input.VirtualMouseConfig;
42 import android.hardware.input.VirtualMouseRelativeEvent;
43 import android.hardware.input.VirtualMouseScrollEvent;
44 import android.hardware.input.VirtualRotaryEncoderConfig;
45 import android.hardware.input.VirtualRotaryEncoderScrollEvent;
46 import android.hardware.input.VirtualStylusButtonEvent;
47 import android.hardware.input.VirtualStylusConfig;
48 import android.hardware.input.VirtualStylusMotionEvent;
49 import android.hardware.input.VirtualTouchEvent;
50 import android.hardware.input.VirtualTouchscreenConfig;
51 import android.hardware.input.VirtualNavigationTouchpadConfig;
52 import android.os.ResultReceiver;
53 
54 /**
55  * Interface for a virtual device for communication between the system server and the process of
56  * the owner of the virtual device.
57  *
58  * @hide
59  */
60 interface IVirtualDevice {
61 
62     /**
63      * Returns the CDM association ID of this virtual device.
64      *
65      * @see AssociationInfo#getId()
66      */
getAssociationId()67     int getAssociationId();
68 
69     /**
70      * Returns the unique ID of this virtual device.
71      */
getDeviceId()72     int getDeviceId();
73 
74     /**
75      * Returns the persistent ID of this virtual device.
76      */
getPersistentDeviceId()77     String getPersistentDeviceId();
78 
79     /**
80      * Returns the IDs of all virtual displays of this device.
81      */
getDisplayIds()82     int[] getDisplayIds();
83 
84     /**
85      * Returns the device policy for the given policy type.
86      */
getDevicePolicy(int policyType)87     int getDevicePolicy(int policyType);
88 
89     /**
90      * Returns whether the device has a valid microphone.
91      */
hasCustomAudioInputSupport()92     boolean hasCustomAudioInputSupport();
93 
94     /**
95      * Returns whether this device is allowed to create mirror displays.
96      */
canCreateMirrorDisplays()97     boolean canCreateMirrorDisplays();
98 
99     /*
100     /*
101      * Turns off all trusted non-mirror displays of the virtual device.
102      */
goToSleep()103     void goToSleep();
104 
105     /**
106      * Turns on all trusted non-mirror displays of the virtual device.
107      */
wakeUp()108     void wakeUp();
109 
110     /**
111      * Closes the virtual device and frees all associated resources.
112      */
close()113     void close();
114 
115     /**
116      * Specifies a policy for this virtual device.
117      */
setDevicePolicy(int policyType, int devicePolicy)118     void setDevicePolicy(int policyType, int devicePolicy);
119 
120     /**
121      * Adds an exemption to the default activity launch policy.
122      */
addActivityPolicyExemption(in ActivityPolicyExemption exemption)123     void addActivityPolicyExemption(in ActivityPolicyExemption exemption);
124 
125     /**
126      * Removes an exemption to the default activity launch policy.
127      */
removeActivityPolicyExemption(in ActivityPolicyExemption exemption)128     void removeActivityPolicyExemption(in ActivityPolicyExemption exemption);
129 
130     /**
131      * Specifies a policy for this virtual device on the given display.
132      */
setDevicePolicyForDisplay(int displayId, int policyType, int devicePolicy)133     void setDevicePolicyForDisplay(int displayId, int policyType, int devicePolicy);
134 
135     /**
136      * Notifies that an audio session being started.
137      */
onAudioSessionStarting(int displayId, IAudioRoutingCallback routingCallback, IAudioConfigChangedCallback configChangedCallback)138     void onAudioSessionStarting(int displayId, IAudioRoutingCallback routingCallback,
139             IAudioConfigChangedCallback configChangedCallback);
140 
141     /**
142      * Notifies that an audio session has ended.
143      */
onAudioSessionEnded()144     void onAudioSessionEnded();
145 
146     /**
147      * Creates a virtual display and registers it with the display framework.
148      */
createVirtualDisplay(in VirtualDisplayConfig virtualDisplayConfig, in IVirtualDisplayCallback callback)149     int createVirtualDisplay(in VirtualDisplayConfig virtualDisplayConfig,
150             in IVirtualDisplayCallback callback);
151 
152     /**
153      * Creates a new dpad and registers it with the input framework with the given token.
154      */
createVirtualDpad(in VirtualDpadConfig config, IBinder token)155     void createVirtualDpad(in VirtualDpadConfig config, IBinder token);
156 
157     /**
158      * Creates a new keyboard and registers it with the input framework with the given token.
159      */
createVirtualKeyboard(in VirtualKeyboardConfig config, IBinder token)160     void createVirtualKeyboard(in VirtualKeyboardConfig config, IBinder token);
161 
162     /**
163      * Creates a new mouse and registers it with the input framework with the given token.
164      */
createVirtualMouse(in VirtualMouseConfig config, IBinder token)165     void createVirtualMouse(in VirtualMouseConfig config, IBinder token);
166 
167     /**
168      * Creates a new touchscreen and registers it with the input framework with the given token.
169      */
createVirtualTouchscreen(in VirtualTouchscreenConfig config, IBinder token)170     void createVirtualTouchscreen(in VirtualTouchscreenConfig config, IBinder token);
171 
172     /**
173      * Creates a new navigation touchpad and registers it with the input framework with the given
174      * token.
175      */
createVirtualNavigationTouchpad(in VirtualNavigationTouchpadConfig config, IBinder token)176     void createVirtualNavigationTouchpad(in VirtualNavigationTouchpadConfig config, IBinder token);
177 
178     /**
179      * Creates a new stylus and registers it with the input framework with the given token.
180      */
createVirtualStylus(in VirtualStylusConfig config, IBinder token)181     void createVirtualStylus(in VirtualStylusConfig config, IBinder token);
182 
183     /**
184      * Creates a new rotary encoder and registers it with the input framework with the given token.
185      */
createVirtualRotaryEncoder(in VirtualRotaryEncoderConfig config, IBinder token)186     void createVirtualRotaryEncoder(in VirtualRotaryEncoderConfig config, IBinder token);
187 
188     /**
189      * Removes the input device corresponding to the given token from the framework.
190      */
unregisterInputDevice(IBinder token)191     void unregisterInputDevice(IBinder token);
192 
193     /**
194      * Returns the ID of the device corresponding to the given token, as registered with the input
195      * framework.
196      */
getInputDeviceId(IBinder token)197     int getInputDeviceId(IBinder token);
198 
199     /**
200      * Injects a key event to the virtual dpad corresponding to the given token.
201      */
sendDpadKeyEvent(IBinder token, in VirtualKeyEvent event)202     boolean sendDpadKeyEvent(IBinder token, in VirtualKeyEvent event);
203 
204     /**
205      * Injects a key event to the virtual keyboard corresponding to the given token.
206      */
sendKeyEvent(IBinder token, in VirtualKeyEvent event)207     boolean sendKeyEvent(IBinder token, in VirtualKeyEvent event);
208 
209     /**
210      * Injects a button event to the virtual mouse corresponding to the given token.
211      */
sendButtonEvent(IBinder token, in VirtualMouseButtonEvent event)212     boolean sendButtonEvent(IBinder token, in VirtualMouseButtonEvent event);
213 
214     /**
215      * Injects a relative event to the virtual mouse corresponding to the given token.
216      */
sendRelativeEvent(IBinder token, in VirtualMouseRelativeEvent event)217     boolean sendRelativeEvent(IBinder token, in VirtualMouseRelativeEvent event);
218 
219     /**
220      * Injects a scroll event to the virtual mouse corresponding to the given token.
221      */
sendScrollEvent(IBinder token, in VirtualMouseScrollEvent event)222     boolean sendScrollEvent(IBinder token, in VirtualMouseScrollEvent event);
223 
224     /**
225     * Injects a touch event to the virtual touch input device corresponding to the given token.
226     */
sendTouchEvent(IBinder token, in VirtualTouchEvent event)227     boolean sendTouchEvent(IBinder token, in VirtualTouchEvent event);
228 
229     /**
230      * Injects a motion event from the virtual stylus input device corresponding to the given token.
231      */
sendStylusMotionEvent(IBinder token, in VirtualStylusMotionEvent event)232     boolean sendStylusMotionEvent(IBinder token, in VirtualStylusMotionEvent event);
233 
234     /**
235      * Injects a button event from the virtual stylus input device corresponding to the given token.
236      */
sendStylusButtonEvent(IBinder token, in VirtualStylusButtonEvent event)237     boolean sendStylusButtonEvent(IBinder token, in VirtualStylusButtonEvent event);
238 
239     /**
240      * Injects a scroll event from the virtual rotary encoder corresponding to the given token.
241      */
sendRotaryEncoderScrollEvent(IBinder token, in VirtualRotaryEncoderScrollEvent event)242     boolean sendRotaryEncoderScrollEvent(IBinder token, in VirtualRotaryEncoderScrollEvent event);
243 
244     /**
245      * Returns all virtual sensors created for this device.
246      */
getVirtualSensorList()247     List<VirtualSensor> getVirtualSensorList();
248 
249     /**
250      * Sends an event to the virtual sensor corresponding to the given token.
251      */
sendSensorEvent(IBinder token, in VirtualSensorEvent event)252     boolean sendSensorEvent(IBinder token, in VirtualSensorEvent event);
253 
254     /**
255      * Sends additional information about the virtual sensor corresponding to the given token.
256      */
sendSensorAdditionalInfo(IBinder token, in VirtualSensorAdditionalInfo info)257     boolean sendSensorAdditionalInfo(IBinder token, in VirtualSensorAdditionalInfo info);
258 
259     /**
260      * Launches a pending intent on the given display that is owned by this virtual device.
261      */
launchPendingIntent(int displayId, in PendingIntent pendingIntent, in ResultReceiver resultReceiver)262     void launchPendingIntent(int displayId, in PendingIntent pendingIntent,
263             in ResultReceiver resultReceiver);
264 
265     /**
266      * Returns the current cursor position of the mouse corresponding to the given token, in x and y
267      * coordinates.
268      */
getCursorPosition(IBinder token)269     PointF getCursorPosition(IBinder token);
270 
271     /** Sets whether to show or hide the cursor while this virtual device is active. */
setShowPointerIcon(boolean showPointerIcon)272     void setShowPointerIcon(boolean showPointerIcon);
273 
274     /** Sets an IME policy for the given display. */
setDisplayImePolicy(int displayId, int policy)275     void setDisplayImePolicy(int displayId, int policy);
276 
277     /**
278      * Registers an intent interceptor that will intercept an intent attempting to launch
279      * when matching the provided IntentFilter and calls the callback with the intercepted
280      * intent.
281      */
registerIntentInterceptor(in IVirtualDeviceIntentInterceptor intentInterceptor, in IntentFilter filter)282     void registerIntentInterceptor(in IVirtualDeviceIntentInterceptor intentInterceptor,
283             in IntentFilter filter);
284 
285     /**
286      * Unregisters a previously registered intent interceptor.
287      */
unregisterIntentInterceptor(in IVirtualDeviceIntentInterceptor intentInterceptor)288     void unregisterIntentInterceptor(in IVirtualDeviceIntentInterceptor intentInterceptor);
289 
290     /**
291      * Creates a new virtual camera and registers it with the virtual camera service.
292      */
registerVirtualCamera(in VirtualCameraConfig camera)293     void registerVirtualCamera(in VirtualCameraConfig camera);
294 
295     /**
296      * Destroys the virtual camera with given config and unregisters it from the virtual camera
297      * service.
298      */
unregisterVirtualCamera(in VirtualCameraConfig camera)299     void unregisterVirtualCamera(in VirtualCameraConfig camera);
300 
301     /**
302      * Returns the id of the virtual camera with given config.
303      */
getVirtualCameraId(in VirtualCameraConfig camera)304     String getVirtualCameraId(in VirtualCameraConfig camera);
305 
306     /**
307      * Setter for listeners that live in the client process, namely in
308      * {@link android.companion.virtual.VirtualDeviceInternal}.
309      *
310      * This is needed for virtual devices that are created by the system, as the VirtualDeviceImpl
311      * object is created before the returned VirtualDeviceInternal one.
312      */
setListeners(in IVirtualDeviceActivityListener activityListener, in IVirtualDeviceSoundEffectListener soundEffectListener)313     void setListeners(in IVirtualDeviceActivityListener activityListener,
314             in IVirtualDeviceSoundEffectListener soundEffectListener);
315 }
316