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 package com.android.server.usb.hal.port; 17 18 import static com.android.server.usb.UsbPortManager.logAndPrint; 19 20 import com.android.internal.util.IndentingPrintWriter; 21 import com.android.server.usb.hal.port.UsbPortHidl; 22 import com.android.server.usb.hal.port.UsbPortAidl; 23 import com.android.server.usb.UsbPortManager; 24 25 import android.util.Log; 26 /** 27 * Helper class that queries the underlying hal layer to populate UsbPortHal instance. 28 */ 29 public final class UsbPortHalInstance { 30 getInstance(UsbPortManager portManager, IndentingPrintWriter pw)31 public static UsbPortHal getInstance(UsbPortManager portManager, IndentingPrintWriter pw) { 32 33 logAndPrint(Log.DEBUG, null, "Querying USB HAL version"); 34 if (UsbPortAidl.isServicePresent(null)) { 35 logAndPrint(Log.INFO, null, "USB HAL AIDL present"); 36 return new UsbPortAidl(portManager, pw); 37 } 38 if (UsbPortHidl.isServicePresent(null)) { 39 logAndPrint(Log.INFO, null, "USB HAL HIDL present"); 40 return new UsbPortHidl(portManager, pw); 41 } 42 return null; 43 } 44 } 45