1 /* 2 * Copyright (C) 2022 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.gadget; 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.gadget.UsbGadgetHidl; 22 import com.android.server.usb.hal.gadget.UsbGadgetAidl; 23 import com.android.server.usb.UsbDeviceManager; 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 UsbGadgetHalInstance { 30 getInstance(UsbDeviceManager deviceManager, IndentingPrintWriter pw)31 public static UsbGadgetHal getInstance(UsbDeviceManager deviceManager, 32 IndentingPrintWriter pw) { 33 34 logAndPrint(Log.DEBUG, pw, "Querying USB Gadget HAL version"); 35 if (UsbGadgetAidl.isServicePresent(null)) { 36 logAndPrint(Log.INFO, pw, "USB Gadget HAL AIDL present"); 37 return new UsbGadgetAidl(deviceManager, pw); 38 } 39 if (UsbGadgetHidl.isServicePresent(null)) { 40 logAndPrint(Log.INFO, pw, "USB Gadget HAL HIDL present"); 41 return new UsbGadgetHidl(deviceManager, pw); 42 } 43 44 logAndPrint(Log.ERROR, pw, "USB Gadget HAL AIDL/HIDL not present"); 45 return null; 46 } 47 } 48 49