• 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 com.android.server.companion.virtual;
18 
19 import android.annotation.NonNull;
20 import android.companion.virtual.IVirtualDevice;
21 
22 import java.util.Set;
23 
24 /**
25  * Virtual device manager local service interface.
26  * Only for use within system server.
27  */
28 public abstract class VirtualDeviceManagerInternal {
29 
30     /** Interface to listen to the creation and destruction of virtual displays. */
31     public interface VirtualDisplayListener {
32         /** Notifies that a virtual display was created. */
onVirtualDisplayCreated(int displayId)33         void onVirtualDisplayCreated(int displayId);
34 
35         /** Notifies that a virtual display was removed. */
onVirtualDisplayRemoved(int displayId)36         void onVirtualDisplayRemoved(int displayId);
37     }
38 
39 
40     /** Interface to listen to the changes on the list of app UIDs running on any virtual device. */
41     public interface AppsOnVirtualDeviceListener {
42         /** Notifies that running apps on any virtual device has changed */
onAppsOnAnyVirtualDeviceChanged(Set<Integer> allRunningUids)43         void onAppsOnAnyVirtualDeviceChanged(Set<Integer> allRunningUids);
44     }
45 
46     /** Register a listener for the creation and destruction of virtual displays. */
registerVirtualDisplayListener( @onNull VirtualDisplayListener listener)47     public abstract void registerVirtualDisplayListener(
48             @NonNull VirtualDisplayListener listener);
49 
50     /** Unregister a listener for the creation and destruction of virtual displays. */
unregisterVirtualDisplayListener( @onNull VirtualDisplayListener listener)51     public abstract void unregisterVirtualDisplayListener(
52             @NonNull VirtualDisplayListener listener);
53 
54     /** Register a listener for changes of running app UIDs on any virtual device. */
registerAppsOnVirtualDeviceListener( @onNull AppsOnVirtualDeviceListener listener)55     public abstract void registerAppsOnVirtualDeviceListener(
56             @NonNull AppsOnVirtualDeviceListener listener);
57 
58     /** Unregister a listener for changes of running app UIDs on any virtual device. */
unregisterAppsOnVirtualDeviceListener( @onNull AppsOnVirtualDeviceListener listener)59     public abstract void unregisterAppsOnVirtualDeviceListener(
60             @NonNull AppsOnVirtualDeviceListener listener);
61 
62     /**
63      * Notifies that the set of apps running on virtual devices has changed.
64      * This method only notifies the listeners when the union of running UIDs on all virtual devices
65      * has changed.
66      */
onAppsOnVirtualDeviceChanged()67     public abstract void onAppsOnVirtualDeviceChanged();
68 
69     /**
70      * Validate the virtual device.
71      */
isValidVirtualDevice(IVirtualDevice virtualDevice)72     public abstract boolean isValidVirtualDevice(IVirtualDevice virtualDevice);
73 
74     /**
75      * Notifies that a virtual display is created.
76      *
77      * @param displayId The display id of the created virtual display.
78      */
onVirtualDisplayCreated(int displayId)79     public abstract void onVirtualDisplayCreated(int displayId);
80 
81     /**
82      * Notifies that a virtual display is removed.
83      *
84      * @param virtualDevice The virtual device where the virtual display located.
85      * @param displayId     The display id of the removed virtual display.
86      */
onVirtualDisplayRemoved(IVirtualDevice virtualDevice, int displayId)87     public abstract void onVirtualDisplayRemoved(IVirtualDevice virtualDevice, int displayId);
88 
89     /**
90      * Returns the flags that should be added to any virtual displays created on this virtual
91      * device.
92      */
getBaseVirtualDisplayFlags(IVirtualDevice virtualDevice)93     public abstract int getBaseVirtualDisplayFlags(IVirtualDevice virtualDevice);
94 
95     /**
96      * Returns true if the given {@code uid} is the owner of any virtual devices that are
97      * currently active.
98      */
isAppOwnerOfAnyVirtualDevice(int uid)99     public abstract boolean isAppOwnerOfAnyVirtualDevice(int uid);
100 
101     /**
102      * Returns true if the given {@code uid} is currently running on any virtual devices. This is
103      * determined by whether the app has any activities in the task stack on a virtual-device-owned
104      * display.
105      */
isAppRunningOnAnyVirtualDevice(int uid)106     public abstract boolean isAppRunningOnAnyVirtualDevice(int uid);
107 
108     /**
109      * Returns true if the {@code displayId} is owned by any virtual device
110      */
isDisplayOwnedByAnyVirtualDevice(int displayId)111     public abstract boolean isDisplayOwnedByAnyVirtualDevice(int displayId);
112 }
113