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 com.android.server.companion.virtual; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.companion.virtual.IVirtualDevice; 22 import android.companion.virtual.sensor.VirtualSensor; 23 import android.os.LocaleList; 24 import android.util.ArraySet; 25 26 import java.util.Set; 27 28 /** 29 * Virtual device manager local service interface. 30 * Only for use within system server. 31 */ 32 public abstract class VirtualDeviceManagerInternal { 33 34 /** Interface to listen to the creation and destruction of virtual displays. */ 35 public interface VirtualDisplayListener { 36 /** Notifies that a virtual display was created. */ onVirtualDisplayCreated(int displayId)37 void onVirtualDisplayCreated(int displayId); 38 39 /** Notifies that a virtual display was removed. */ onVirtualDisplayRemoved(int displayId)40 void onVirtualDisplayRemoved(int displayId); 41 } 42 43 /** Interface to listen to the changes on the list of app UIDs running on any virtual device. */ 44 public interface AppsOnVirtualDeviceListener { 45 /** Notifies that running apps on any virtual device has changed */ onAppsOnAnyVirtualDeviceChanged(Set<Integer> allRunningUids)46 void onAppsOnAnyVirtualDeviceChanged(Set<Integer> allRunningUids); 47 } 48 49 /** Register a listener for the creation and destruction of virtual displays. */ registerVirtualDisplayListener( @onNull VirtualDisplayListener listener)50 public abstract void registerVirtualDisplayListener( 51 @NonNull VirtualDisplayListener listener); 52 53 /** Unregister a listener for the creation and destruction of virtual displays. */ unregisterVirtualDisplayListener( @onNull VirtualDisplayListener listener)54 public abstract void unregisterVirtualDisplayListener( 55 @NonNull VirtualDisplayListener listener); 56 57 /** Register a listener for changes of running app UIDs on any virtual device. */ registerAppsOnVirtualDeviceListener( @onNull AppsOnVirtualDeviceListener listener)58 public abstract void registerAppsOnVirtualDeviceListener( 59 @NonNull AppsOnVirtualDeviceListener listener); 60 61 /** Unregister a listener for changes of running app UIDs on any virtual device. */ unregisterAppsOnVirtualDeviceListener( @onNull AppsOnVirtualDeviceListener listener)62 public abstract void unregisterAppsOnVirtualDeviceListener( 63 @NonNull AppsOnVirtualDeviceListener listener); 64 65 /** 66 * Notifies that the set of apps running on virtual devices has changed. 67 * This method only notifies the listeners when the union of running UIDs on all virtual devices 68 * has changed. 69 */ onAppsOnVirtualDeviceChanged()70 public abstract void onAppsOnVirtualDeviceChanged(); 71 72 /** 73 * Notifies that an authentication prompt is about to be shown for an app with the given uid. 74 */ onAuthenticationPrompt(int uid)75 public abstract void onAuthenticationPrompt(int uid); 76 77 /** 78 * Gets the owner uid for a deviceId. 79 * 80 * @param deviceId which device we're asking about 81 * @return the uid of the app which created and owns the VirtualDevice with the given deviceId, 82 * or {@link android.os.Process#INVALID_UID} if no such device exists. 83 */ getDeviceOwnerUid(int deviceId)84 public abstract int getDeviceOwnerUid(int deviceId); 85 86 /** 87 * Returns the VirtualSensor for the given deviceId and sensor handle, if any. 88 * 89 * @param deviceId the virtual device that owns the sensor 90 * @param handle the sensor handle 91 * @return the VirtualSensor with the given handle, or {@code null} if no such sensor exists. 92 */ getVirtualSensor(int deviceId, int handle)93 public abstract @Nullable VirtualSensor getVirtualSensor(int deviceId, int handle); 94 95 /** 96 * Finds VirtualDevices where an app is running. 97 * 98 * @param uid - the app's uid 99 * @return a set of id's of VirtualDevices where the app with the given uid is running. 100 * *Note* this only checks VirtualDevices, and does not include information about whether 101 * the app is running on the default device or not. 102 */ getDeviceIdsForUid(int uid)103 public abstract @NonNull ArraySet<Integer> getDeviceIdsForUid(int uid); 104 105 /** 106 * Notifies that a virtual display is created. 107 * 108 * @param displayId The display id of the created virtual display. 109 */ onVirtualDisplayCreated(int displayId)110 public abstract void onVirtualDisplayCreated(int displayId); 111 112 /** 113 * Notifies that a virtual display is removed. 114 * 115 * @param virtualDevice The virtual device where the virtual display located. 116 * @param displayId The display id of the removed virtual display. 117 */ onVirtualDisplayRemoved(IVirtualDevice virtualDevice, int displayId)118 public abstract void onVirtualDisplayRemoved(IVirtualDevice virtualDevice, int displayId); 119 120 /** 121 * Returns the flags that should be added to any virtual displays created on this virtual 122 * device. 123 */ getBaseVirtualDisplayFlags(IVirtualDevice virtualDevice)124 public abstract int getBaseVirtualDisplayFlags(IVirtualDevice virtualDevice); 125 126 /** 127 * Returns the preferred locale hints of the Virtual Device on which the given app is running, 128 * or {@code null} if the hosting virtual device doesn't have a virtual keyboard or the app is 129 * not on any virtual device. 130 * 131 * If an app is on multiple virtual devices, the locale of the virtual device created the 132 * earliest will be returned. 133 * 134 * See {@link android.hardware.input.VirtualKeyboardConfig#setLanguageTag() for how the locale 135 * is specified for virtual keyboard. 136 */ 137 @Nullable getPreferredLocaleListForUid(int uid)138 public abstract LocaleList getPreferredLocaleListForUid(int uid); 139 140 /** 141 * Returns true if the given {@code uid} is currently running on any virtual devices. This is 142 * determined by whether the app has any activities in the task stack on a virtual-device-owned 143 * display. 144 */ isAppRunningOnAnyVirtualDevice(int uid)145 public abstract boolean isAppRunningOnAnyVirtualDevice(int uid); 146 147 /** 148 * Returns true if the {@code displayId} is owned by any virtual device 149 */ isDisplayOwnedByAnyVirtualDevice(int displayId)150 public abstract boolean isDisplayOwnedByAnyVirtualDevice(int displayId); 151 152 /** 153 * Gets the ids of VirtualDisplays owned by a VirtualDevice. 154 * 155 * @param deviceId which device we're asking about 156 * @return the set of display ids for all VirtualDisplays owned by the device 157 */ getDisplayIdsForDevice(int deviceId)158 public abstract @NonNull ArraySet<Integer> getDisplayIdsForDevice(int deviceId); 159 } 160