• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.example.android.vdmdemo.host;
18 
19 import android.companion.virtual.VirtualDeviceManager.VirtualDevice;
20 import android.companion.virtual.flags.Flags;
21 import android.content.Context;
22 import android.hardware.display.VirtualDisplayConfig;
23 import android.hardware.input.InputManager;
24 import android.view.InputDevice;
25 
26 import androidx.core.os.BuildCompat;
27 
28 public class VdmCompat {
29 
30     // Hidden DisplayManager.VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS.
31     private static final int VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS = 1 << 9;
32 
VdmCompat()33     private VdmCompat() {}
34 
setHomeSupported( VirtualDisplayConfig.Builder builder, int flags)35     static VirtualDisplayConfig.Builder setHomeSupported(
36             VirtualDisplayConfig.Builder builder, int flags) {
37         if (BuildCompat.isAtLeastV() && Flags.vdmCustomHome()) {
38             return builder.setHomeSupported(true);
39         } else {
40             return builder.setFlags(flags | VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS);
41         }
42     }
43 
setDisplayImePolicy(VirtualDevice virtualDevice, int displayId, int policy)44     static void setDisplayImePolicy(VirtualDevice virtualDevice, int displayId, int policy) {
45         if (BuildCompat.isAtLeastV()) {
46             virtualDevice.setDisplayImePolicy(displayId, policy);
47         }
48     }
49 
canCreateVirtualMouse(Context context)50     static boolean canCreateVirtualMouse(Context context) {
51         if (BuildCompat.isAtLeastV()) {
52             return true;
53         }
54         InputManager inputManager = context.getSystemService(InputManager.class);
55         for (int inputDeviceId : inputManager.getInputDeviceIds()) {
56             InputDevice inputDevice = inputManager.getInputDevice(inputDeviceId);
57             String inputDeviceName = inputDevice.getName();
58             if (inputDeviceName != null && inputDeviceName.startsWith("vdmdemo-mouse")) {
59                 return false;
60             }
61         }
62         return true;
63     }
64 }
65