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