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.car.builtin.view; 18 19 import android.annotation.SystemApi; 20 import android.car.builtin.annotation.AddedIn; 21 import android.car.builtin.annotation.PlatformVersion; 22 import android.view.Display; 23 import android.view.DisplayAddress; 24 25 /** 26 * Provide access to {@code android.view.Display} calls. 27 * @hide 28 */ 29 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) 30 public final class DisplayHelper { 31 32 @AddedIn(PlatformVersion.TIRAMISU_0) 33 public static final int INVALID_PORT = -1; 34 35 /** Display type: Physical display connected through an internal port. */ 36 @AddedIn(PlatformVersion.TIRAMISU_0) 37 public static final int TYPE_INTERNAL = Display.TYPE_INTERNAL; 38 /** Display type: Physical display connected through an external port. */ 39 @AddedIn(PlatformVersion.TIRAMISU_0) 40 public static final int TYPE_EXTERNAL = Display.TYPE_EXTERNAL; 41 /** Display type: Virtual display. */ 42 @AddedIn(PlatformVersion.TIRAMISU_0) 43 public static final int TYPE_VIRTUAL = Display.TYPE_VIRTUAL; 44 DisplayHelper()45 private DisplayHelper() { 46 throw new UnsupportedOperationException(); 47 } 48 49 /** 50 * @return the physical port number of the display, or {@code INVALID_PORT} if the display isn't 51 * the physical one. 52 */ 53 @AddedIn(PlatformVersion.TIRAMISU_0) getPhysicalPort(Display display)54 public static int getPhysicalPort(Display display) { 55 DisplayAddress address = display.getAddress(); 56 if (address instanceof DisplayAddress.Physical) { 57 DisplayAddress.Physical physicalAddress = (DisplayAddress.Physical) address; 58 if (physicalAddress != null) { 59 return physicalAddress.getPort(); 60 } 61 } 62 return INVALID_PORT; 63 } 64 65 /** 66 * @return the uniqueId of the given display. 67 */ 68 @AddedIn(PlatformVersion.TIRAMISU_0) getUniqueId(Display display)69 public static String getUniqueId(Display display) { 70 return display.getUniqueId(); 71 } 72 73 /** 74 * Gets the display type. 75 * @see Display.getType() 76 */ 77 @AddedIn(PlatformVersion.TIRAMISU_0) getType(Display display)78 public static int getType(Display display) { 79 return display.getType(); 80 } 81 } 82