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