1 /* 2 * Copyright (C) 2010 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.hardware.usb; 18 19 import android.app.PendingIntent; 20 import android.content.ComponentName; 21 import android.hardware.usb.IUsbOperationInternal; 22 import android.hardware.usb.UsbAccessory; 23 import android.hardware.usb.UsbDevice; 24 import android.hardware.usb.ParcelableUsbPort; 25 import android.hardware.usb.UsbPortStatus; 26 import android.os.Bundle; 27 import android.os.ParcelFileDescriptor; 28 import android.os.UserHandle; 29 30 /** @hide */ 31 interface IUsbManager 32 { 33 /* Returns a list of all currently attached USB devices */ getDeviceList(out Bundle devices)34 void getDeviceList(out Bundle devices); 35 36 /* Returns a file descriptor for communicating with the USB device. 37 * The native fd can be passed to usb_device_new() in libusbhost. 38 */ openDevice(String deviceName, String packageName)39 ParcelFileDescriptor openDevice(String deviceName, String packageName); 40 41 /* Returns the currently attached USB accessory */ getCurrentAccessory()42 UsbAccessory getCurrentAccessory(); 43 44 /* Returns a file descriptor for communicating with the USB accessory. 45 * This file descriptor can be used with standard Java file operations. 46 */ openAccessory(in UsbAccessory accessory)47 ParcelFileDescriptor openAccessory(in UsbAccessory accessory); 48 49 /* Sets the default package for a USB device 50 * (or clears it if the package name is null) 51 */ setDevicePackage(in UsbDevice device, String packageName, int userId)52 void setDevicePackage(in UsbDevice device, String packageName, int userId); 53 54 /* Sets the default package for a USB accessory 55 * (or clears it if the package name is null) 56 */ setAccessoryPackage(in UsbAccessory accessory, String packageName, int userId)57 void setAccessoryPackage(in UsbAccessory accessory, String packageName, int userId); 58 59 /* Adds packages to the set of "denied and don't ask again" launch preferences for a device */ addDevicePackagesToPreferenceDenied(in UsbDevice device, in String[] packageNames, in UserHandle user)60 void addDevicePackagesToPreferenceDenied(in UsbDevice device, in String[] packageNames, in UserHandle user); 61 62 /* Adds packages to the set of "denied and don't ask again" launch preferences for an accessory */ addAccessoryPackagesToPreferenceDenied(in UsbAccessory accessory, in String[] packageNames, in UserHandle user)63 void addAccessoryPackagesToPreferenceDenied(in UsbAccessory accessory, in String[] packageNames, in UserHandle user); 64 65 /* Removes packages from the set of "denied and don't ask again" launch preferences for a device */ removeDevicePackagesFromPreferenceDenied(in UsbDevice device, in String[] packageNames, in UserHandle user)66 void removeDevicePackagesFromPreferenceDenied(in UsbDevice device, in String[] packageNames, in UserHandle user); 67 68 /* Removes packages from the set of "denied and don't ask again" launch preferences for an accessory */ removeAccessoryPackagesFromPreferenceDenied(in UsbAccessory device, in String[] packageNames, in UserHandle user)69 void removeAccessoryPackagesFromPreferenceDenied(in UsbAccessory device, in String[] packageNames, in UserHandle user); 70 71 /* Sets the persistent permission granted state for USB device 72 */ setDevicePersistentPermission(in UsbDevice device, int uid, in UserHandle user, boolean shouldBeGranted)73 void setDevicePersistentPermission(in UsbDevice device, int uid, in UserHandle user, boolean shouldBeGranted); 74 75 /* Sets the persistent permission granted state for USB accessory 76 */ setAccessoryPersistentPermission(in UsbAccessory accessory, int uid, in UserHandle user, boolean shouldBeGranted)77 void setAccessoryPersistentPermission(in UsbAccessory accessory, int uid, in UserHandle user, boolean shouldBeGranted); 78 79 /* Returns true if the caller has permission to access the device. */ hasDevicePermission(in UsbDevice device, String packageName)80 boolean hasDevicePermission(in UsbDevice device, String packageName); 81 82 /* Returns true if the caller has permission to access the accessory. */ hasAccessoryPermission(in UsbAccessory accessory)83 boolean hasAccessoryPermission(in UsbAccessory accessory); 84 85 /* Requests permission for the given package to access the device. 86 * Will display a system dialog to query the user if permission 87 * had not already been given. 88 */ requestDevicePermission(in UsbDevice device, String packageName, in PendingIntent pi)89 void requestDevicePermission(in UsbDevice device, String packageName, in PendingIntent pi); 90 91 /* Requests permission for the given package to access the accessory. 92 * Will display a system dialog to query the user if permission 93 * had not already been given. Result is returned via pi. 94 */ requestAccessoryPermission(in UsbAccessory accessory, String packageName, in PendingIntent pi)95 void requestAccessoryPermission(in UsbAccessory accessory, String packageName, 96 in PendingIntent pi); 97 98 /* Grants permission for the given UID to access the device */ grantDevicePermission(in UsbDevice device, int uid)99 void grantDevicePermission(in UsbDevice device, int uid); 100 101 /* Grants permission for the given UID to access the accessory */ grantAccessoryPermission(in UsbAccessory accessory, int uid)102 void grantAccessoryPermission(in UsbAccessory accessory, int uid); 103 104 /* Returns true if the USB manager has default preferences or permissions for the package */ hasDefaults(String packageName, int userId)105 boolean hasDefaults(String packageName, int userId); 106 107 /* Clears default preferences and permissions for the package */ clearDefaults(String packageName, int userId)108 void clearDefaults(String packageName, int userId); 109 110 /* Returns true if the specified USB function is enabled. */ isFunctionEnabled(String function)111 boolean isFunctionEnabled(String function); 112 113 /* Sets the current USB function. */ setCurrentFunctions(long functions)114 void setCurrentFunctions(long functions); 115 116 /* Compatibility version of setCurrentFunctions(long). */ setCurrentFunction(String function, boolean usbDataUnlocked)117 void setCurrentFunction(String function, boolean usbDataUnlocked); 118 119 /* Gets the current USB functions. */ getCurrentFunctions()120 long getCurrentFunctions(); 121 122 /* Gets the current USB Speed. */ getCurrentUsbSpeed()123 int getCurrentUsbSpeed(); 124 125 /* Gets the Gadget Hal Version. */ getGadgetHalVersion()126 int getGadgetHalVersion(); 127 128 /* Sets the screen unlocked USB function(s), which will be set automatically 129 * when the screen is unlocked. 130 */ setScreenUnlockedFunctions(long functions)131 void setScreenUnlockedFunctions(long functions); 132 133 /* Gets the current screen unlocked functions. */ getScreenUnlockedFunctions()134 long getScreenUnlockedFunctions(); 135 136 /* Resets the USB gadget. */ resetUsbGadget()137 void resetUsbGadget(); 138 139 /* Resets the USB port. */ resetUsbPort(in String portId, int operationId, in IUsbOperationInternal callback)140 void resetUsbPort(in String portId, int operationId, in IUsbOperationInternal callback); 141 142 /* Set USB data on or off */ enableUsbData(in String portId, boolean enable, int operationId, in IUsbOperationInternal callback)143 boolean enableUsbData(in String portId, boolean enable, int operationId, in IUsbOperationInternal callback); 144 145 /* Enable USB data when disabled due to docking event */ enableUsbDataWhileDocked(in String portId, int operationId, in IUsbOperationInternal callback)146 void enableUsbDataWhileDocked(in String portId, int operationId, in IUsbOperationInternal callback); 147 148 /* Gets the USB Hal Version. */ getUsbHalVersion()149 int getUsbHalVersion(); 150 151 /* Get the functionfs control handle for the given function. Usb 152 * descriptors will already be written, and the handle will be 153 * ready to use. 154 */ getControlFd(long function)155 ParcelFileDescriptor getControlFd(long function); 156 157 /* Gets the list of USB ports. */ getPorts()158 List<ParcelableUsbPort> getPorts(); 159 160 /* Gets the status of the specified USB port. */ getPortStatus(in String portId)161 UsbPortStatus getPortStatus(in String portId); 162 163 /* Sets the port's current role. */ setPortRoles(in String portId, int powerRole, int dataRole)164 void setPortRoles(in String portId, int powerRole, int dataRole); 165 166 /* Limit power transfer in & out of the port within the allowed limit by the USB 167 * specification. 168 */ enableLimitPowerTransfer(in String portId, boolean limit, int operationId, in IUsbOperationInternal callback)169 void enableLimitPowerTransfer(in String portId, boolean limit, int operationId, in IUsbOperationInternal callback); 170 171 /* Enable/disable contaminant detection */ enableContaminantDetection(in String portId, boolean enable)172 void enableContaminantDetection(in String portId, boolean enable); 173 174 /* Sets USB device connection handler. */ setUsbDeviceConnectionHandler(in ComponentName usbDeviceConnectionHandler)175 void setUsbDeviceConnectionHandler(in ComponentName usbDeviceConnectionHandler); 176 } 177